Received: by 10.223.164.202 with SMTP id h10csp1114423wrb; Sun, 26 Nov 2017 20:25:57 -0800 (PST) X-Google-Smtp-Source: AGs4zMboHXlVUMGyWTBTfY5Hz0SRM0eJ+O1X4k81nIMuXyu6ydX4t9XaD628E0AOn5BHPXOGCt2W X-Received: by 10.84.195.36 with SMTP id i33mr16366164pld.189.1511756757566; Sun, 26 Nov 2017 20:25:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511756757; cv=none; d=google.com; s=arc-20160816; b=C0rI3Qbp9E2IcwKQDlefzOqVGMs6RxoFpVGAr+I2j5/MNAoMwY6O4YAj0TsIABeP3A ptlPQ+AZy0W1Zd/M+azVQa3++uKN/JhtxPQ3Z75h/qIBeKDC+t0k0wNtDayA506/WGl7 vyZZDEC0UTz8X7D/4QeuHtGD3UdFfziHgVuXVp8xXhQJVDqWyoHhRfu3P2eUihZTmo3P YG7a8wLqnuHhmfaN3NhFO6q3tpSYh0RlhxjBfKwx0tl+HOzvS6RHUzz8tYPvty8ctZm/ SdIJoAsXxJcm5yyCrHJOdctMOYUu7o0QCBPbvVGcqDbUWQI24dSB8JeGS8t5jIex0Qh4 P9+w== 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:arc-authentication-results; bh=ER7sIZBwb++gpjsz5unX1ak/9HJs9T7C6CO9M8kAd2Q=; b=ytBygPcGgszJG2mQTp1rDGqlbVnNKROiX34AroMdgMrqG2mla1l9ekUaluh3pVtbrw uQYHQrwcFKS83lUieEHmYMnNIIjXEb+KhTlQQ2rD4xUqtyxPz7OegBJYTjIYyS9eKkou YaYbQEv/K0Z75TWYyu+lWm06vgciLpy7tuyy1N/Jiaa7IG0FdCXuCq8dMWTE7JfNOUGz lrKXqL+dn4JYSnyjukfrQjP1zobvyEVgNCuNCPB7V9YPXXYErkqMqkMWOantIB9s00oP 6oFplVQgKsrp45EKC0hjxks+r4tlxbHwD75WauTnyAGQ/lUxDCK+xk4MsJ6FnJCVdCXN hrxQ== 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 h61si23074078pld.330.2017.11.26.20.25.45; Sun, 26 Nov 2017 20:25:57 -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 S1751309AbdK0EYm (ORCPT + 77 others); Sun, 26 Nov 2017 23:24:42 -0500 Received: from smtp2.provo.novell.com ([137.65.250.81]:34220 "EHLO smtp2.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751231AbdK0EYk (ORCPT ); Sun, 26 Nov 2017 23:24:40 -0500 Received: from localhost.localdomain (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Sun, 26 Nov 2017 21:24:29 -0700 From: Davidlohr Bueso To: acme@kernel.org Cc: james.yang@arm.com, kim.phillips@arm.com, dave@stgolabs.net, linux-kernel@vger.kernel.org, Kim Phillips Subject: [PATCH 3/3] perf bench futex: sync waker threads Date: Sun, 26 Nov 2017 20:21:01 -0800 Message-Id: <20171127042101.3659-4-dave@stgolabs.net> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171127042101.3659-1-dave@stgolabs.net> References: <20171127042101.3659-1-dave@stgolabs.net> 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. Cc: Kim Phillips Signed-off-by: James Yang --- tools/perf/bench/futex-wake-parallel.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/perf/bench/futex-wake-parallel.c b/tools/perf/bench/futex-wake-parallel.c index c04e207ea37c..55bff8673d31 100644 --- a/tools/perf/bench/futex-wake-parallel.c +++ b/tools/perf/bench/futex-wake-parallel.c @@ -43,6 +43,7 @@ static bool affine_wakers = 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; @@ -66,6 +67,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); @@ -87,6 +90,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++) { /* @@ -110,9 +115,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) -- 2.13.6 From 1585216163958344436@xxx Mon Nov 27 10:52:21 +0000 2017 X-GM-THRID: 1585216163958344436 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread