From patchwork Wed Dec 6 14:40:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 120862 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp7147076qgn; Wed, 6 Dec 2017 06:49:45 -0800 (PST) X-Google-Smtp-Source: AGs4zMZXl9WyYpEk+xXe2bQz4WWuqpY+ezJcJimB7bhZfW6Sh9I4jEUwdD96jopASmutfd2gx3WS X-Received: by 10.101.98.83 with SMTP id q19mr20884975pgv.71.1512571785412; Wed, 06 Dec 2017 06:49:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512571785; cv=none; d=google.com; s=arc-20160816; b=P8lWUQ86+shQCzoDk+v2meF+y+EvQSn8N+j7CHCnoN65yk08Cx/EaW/xuwOkJncXe0 LpMZLpHX0OgmlKIz29FnfdLQ6Nb5ggAaomgErnyq4Vh3XJ+QYc6ASMp41dBgC1+dx1K/ Ak82Ob1VOSFu09NAoAybuC5vRkPq3sDizJWjuAoV0UOnBCwp4pV2DvhxMCx4meBIMviq Th5947X7seFV7kHEk4nNH+PiltFgzp0r0dko6xW6n86DSvc05DdUKeUoNmt7oFsKEzBZ s5uuG/Zl7Rz1i3QKv8xZQEfFwChj6iuHUZ18RmLq2Ksn9erZDKflRUHTn8mp/cFm0o77 3TKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:arc-authentication-results; bh=KcsRb6TpwIz6nsAS3KbJCg5/jIDtHZILYjYCpNDYdic=; b=W7MlahtjaA8LPDpnfbEJFErTrw2PLXGSDl+HzGSVD9LxpLcgsuRvFBg2CfnSDTuc+t UEwSrAkEbeTEjPx8kJ8ml5HXHC5FP124l5t/OEfBCrso8iR/7SBsJF6ElHCegYZln/8W yRf6QOSA82eewgtcqYSQl+j7GlTltvdaAT+1JyxlHGUSRenW1a+DD8/aWSjA5sBi8CaO PC3v2XBxHCiLAItx406+I/qtqPvVpl1d3lnnPPGQ4NZnWz9V+o81Dtg8YRV8mbargUcg 2BhwAvSO18NVznO6YG92HRbQST3xN4kPaPsqOyoYlNKSLYV5mcTXdHn1HkFkc1eNVn54 VJ7w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j22si2188482pff.69.2017.12.06.06.49.42; Wed, 06 Dec 2017 06:49:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752830AbdLFOtk (ORCPT + 28 others); Wed, 6 Dec 2017 09:49:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:57482 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752166AbdLFOmR (ORCPT ); Wed, 6 Dec 2017 09:42:17 -0500 Received: from jouet.infradead.org (unknown [179.97.41.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B84ED21985; Wed, 6 Dec 2017 14:42:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B84ED21985 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=acme@kernel.org From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, James Yang , Kim Phillips , Davidlohr Bueso , Arnaldo Carvalho de Melo Subject: [PATCH 12/36] perf bench futex: Sync waker threads Date: Wed, 6 Dec 2017 11:40:51 -0300 Message-Id: <20171206144115.15097-13-acme@kernel.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171206144115.15097-1-acme@kernel.org> References: <20171206144115.15097-1-acme@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: James Yang Waker threads in the futex wake-parallel benchmark are started by a loop using pthread_create(). However, there is no synchronization for when the waker threads wake the waiting threads. Comparison of the waker threads' measurement timestamps show they are not all running concurrently because older waker threads finish their task before newer waker threads even start. This patch uses a barrier to better synchronize the waker threads. Signed-off-by: James Yang Link: http://lkml.kernel.org/r/20171127042101.3659-4-dave@stgolabs.net Signed-off-by: Davidlohr Bueso [ Disable the wake-parallel test for systems without pthread_barrier_t ] Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/bench/futex-wake-parallel.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) -- 2.13.6 diff --git a/tools/perf/bench/futex-wake-parallel.c b/tools/perf/bench/futex-wake-parallel.c index 4488c27e8a43..69d8fdc87315 100644 --- a/tools/perf/bench/futex-wake-parallel.c +++ b/tools/perf/bench/futex-wake-parallel.c @@ -7,7 +7,17 @@ * for each individual thread to service its share of work. Ultimately * it can be used to measure futex_wake() changes. */ +#include "bench.h" +#include +#include "../util/debug.h" +#ifndef HAVE_PTHREAD_BARRIER +int bench_futex_wake_parallel(int argc __maybe_unused, const char **argv __maybe_unused) +{ + pr_err("%s: pthread_barrier_t unavailable, disabling this test...\n", __func__); + return 0; +} +#else /* HAVE_PTHREAD_BARRIER */ /* For the CLR_() macros */ #include #include @@ -15,11 +25,9 @@ #include #include "../util/stat.h" #include -#include #include #include #include -#include "bench.h" #include "futex.h" #include "cpumap.h" @@ -43,6 +51,7 @@ static bool done = false, silent = false, fshared = false; static unsigned int nblocked_threads = 0, nwaking_threads = 0; static pthread_mutex_t thread_lock; static pthread_cond_t thread_parent, thread_worker; +static pthread_barrier_t barrier; static struct stats waketime_stats, wakeup_stats; static unsigned int threads_starting; static int futex_flag = 0; @@ -65,6 +74,8 @@ static void *waking_workerfn(void *arg) struct thread_data *waker = (struct thread_data *) arg; struct timeval start, end; + pthread_barrier_wait(&barrier); + gettimeofday(&start, NULL); waker->nwoken = futex_wake(&futex, nwakes, futex_flag); @@ -85,6 +96,8 @@ static void wakeup_threads(struct thread_data *td, pthread_attr_t thread_attr) pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE); + pthread_barrier_init(&barrier, NULL, nwaking_threads + 1); + /* create and block all threads */ for (i = 0; i < nwaking_threads; i++) { /* @@ -97,9 +110,13 @@ static void wakeup_threads(struct thread_data *td, pthread_attr_t thread_attr) err(EXIT_FAILURE, "pthread_create"); } + pthread_barrier_wait(&barrier); + for (i = 0; i < nwaking_threads; i++) if (pthread_join(td[i].worker, NULL)) err(EXIT_FAILURE, "pthread_join"); + + pthread_barrier_destroy(&barrier); } static void *blocked_workerfn(void *arg __maybe_unused) @@ -303,3 +320,4 @@ int bench_futex_wake_parallel(int argc, const char **argv) free(blocked_worker); return ret; } +#endif /* HAVE_PTHREAD_BARRIER */