From patchwork Sun Jun 4 12:06:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 770890 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wgcCY2MSJz9s4s for ; Sun, 4 Jun 2017 22:07:53 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="KepxS5QW"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3wgcCY0jP9zDqL8 for ; Sun, 4 Jun 2017 22:07:53 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="KepxS5QW"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mail-pg0-x241.google.com (mail-pg0-x241.google.com [IPv6:2607:f8b0:400e:c05::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3wgcB61RctzDqKc for ; Sun, 4 Jun 2017 22:06:37 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="KepxS5QW"; dkim-atps=neutral Received: by mail-pg0-x241.google.com with SMTP id v18so3489660pgb.3 for ; Sun, 04 Jun 2017 05:06:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=zEKuWC7JPEjmZwd8Ot5XBBiomIPvfMjYp3dtFsKBxGI=; b=KepxS5QWSsVm33R0Oe5PWGgXZWQXRscChM+nfmK3PfWt6mCXi1OxY/HddhnP27cHMM rFI/KSjLTvvoKBnv+Gy5VtxZrRkc+YZ5EEGoDKUB/HWmzQWCCHDjiedrXosJP8c0rt4L Ba/jmMO5nU2SFmbpkduZDea3CK/sUJWr/8zo2vuruuy7Mw6wIWghUDCxQPBVO6KWTxUC Ua5DWsbVHKYrCSAx8kQU5S5r4z6kHTKs2HOv+JX36DINu8NpQOwN3dQNQBK48/75gCSU flxbxnqTc5WxfJJs8F8nt97NzS3ABktA/3B5IcLadou3M0DXAVoAamyefvEjOJLETcps ZN8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=zEKuWC7JPEjmZwd8Ot5XBBiomIPvfMjYp3dtFsKBxGI=; b=oHj8wPc0XfsBPIpj088XY/ower+5GRr1J8tV3MSUMoNu2gebL7biCdeXoBLzYofdoV 5l52jELOZdIOTnQkRK8hG0XKmPTkRsca5KfYksqOzlUSO2lAL8NdBOI7l0ZZNGQkpvGc V1MIIXW2W02MB265qdCHu8RQfa+Jjzfzwfd82RmJMWNskSy71yQMTq4jKCXu+SX1tNr4 JqcPRHsAOmJjvo3S4unz1blpI8cZgzgyNTR7db7hmuFH2Hay898IxaVPNVo833MMy+To ESNHKt+pLb1dHAvDQpSqNPNGAcEN+AU5ymtfUcFtvp/thHQkNGS79uoZSYDiqmSlmQrz 5Wzg== X-Gm-Message-State: AODbwcBQpF+2g5CDtiZ701ssZ3vEiwQ6kmguJah9oTBm6tEyP6Ts7Rxa XbWyvPdwrAnsZp4C X-Received: by 10.98.73.205 with SMTP id r74mr3235078pfi.151.1496577994746; Sun, 04 Jun 2017 05:06:34 -0700 (PDT) Received: from roar.au.ibm.com (14-202-184-124.tpgi.com.au. [14.202.184.124]) by smtp.gmail.com with ESMTPSA id j71sm8106882pge.63.2017.06.04.05.06.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Jun 2017 05:06:33 -0700 (PDT) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH] selftests/powerpc: context_switch use private futexes with threads Date: Sun, 4 Jun 2017 22:06:22 +1000 Message-Id: <20170604120622.19778-1-npiggin@gmail.com> X-Mailer: git-send-email 2.11.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anton Blanchard , Nicholas Piggin Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" This reduces overhead of mutex locking and increases context switch rate significantly (which helps to measure and profile the context switch path). Signed-off-by: Nicholas Piggin --- .../selftests/powerpc/benchmarks/context_switch.c | 53 ++++++++++++++-------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/tools/testing/selftests/powerpc/benchmarks/context_switch.c b/tools/testing/selftests/powerpc/benchmarks/context_switch.c index 778f5fbfd784..f4241339edd2 100644 --- a/tools/testing/selftests/powerpc/benchmarks/context_switch.c +++ b/tools/testing/selftests/powerpc/benchmarks/context_switch.c @@ -258,9 +258,14 @@ static unsigned long xchg(unsigned long *p, unsigned long val) return __atomic_exchange_n(p, val, __ATOMIC_SEQ_CST); } +static int processes; + static int mutex_lock(unsigned long *m) { int c; + int flags = FUTEX_WAIT; + if (!processes) + flags |= FUTEX_PRIVATE_FLAG; c = cmpxchg(m, 0, 1); if (!c) @@ -270,7 +275,7 @@ static int mutex_lock(unsigned long *m) c = xchg(m, 2); while (c) { - sys_futex(m, FUTEX_WAIT, 2, NULL, NULL, 0); + sys_futex(m, flags, 2, NULL, NULL, 0); c = xchg(m, 2); } @@ -279,12 +284,16 @@ static int mutex_lock(unsigned long *m) static int mutex_unlock(unsigned long *m) { + int flags = FUTEX_WAKE; + if (!processes) + flags |= FUTEX_PRIVATE_FLAG; + if (*m == 2) *m = 0; else if (xchg(m, 0) == 1) return 0; - sys_futex(m, FUTEX_WAKE, 1, NULL, NULL, 0); + sys_futex(m, flags, 1, NULL, NULL, 0); return 0; } @@ -293,26 +302,32 @@ static unsigned long *m1, *m2; static void futex_setup(int cpu1, int cpu2) { - int shmid; - void *shmaddr; + if (!processes) { + static unsigned long _m1, _m2; + m1 = &_m1; + m2 = &_m2; + } else { + int shmid; + void *shmaddr; - shmid = shmget(IPC_PRIVATE, getpagesize(), SHM_R | SHM_W); - if (shmid < 0) { - perror("shmget"); - exit(1); - } + shmid = shmget(IPC_PRIVATE, getpagesize(), SHM_R | SHM_W); + if (shmid < 0) { + perror("shmget"); + exit(1); + } - shmaddr = shmat(shmid, NULL, 0); - if (shmaddr == (char *)-1) { - perror("shmat"); - shmctl(shmid, IPC_RMID, NULL); - exit(1); - } + shmaddr = shmat(shmid, NULL, 0); + if (shmaddr == (char *)-1) { + perror("shmat"); + shmctl(shmid, IPC_RMID, NULL); + exit(1); + } - shmctl(shmid, IPC_RMID, NULL); + shmctl(shmid, IPC_RMID, NULL); - m1 = shmaddr; - m2 = shmaddr + sizeof(*m1); + m1 = shmaddr; + m2 = shmaddr + sizeof(*m1); + } *m1 = 0; *m2 = 0; @@ -352,8 +367,6 @@ static struct actions futex_actions = { .thread2 = futex_thread2, }; -static int processes; - static struct option options[] = { { "test", required_argument, 0, 't' }, { "process", no_argument, &processes, 1 },