From nobody Tue Apr 7 14:52:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D041CECAAA3 for ; Fri, 26 Aug 2022 16:43:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344361AbiHZQnJ (ORCPT ); Fri, 26 Aug 2022 12:43:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344236AbiHZQnC (ORCPT ); Fri, 26 Aug 2022 12:43:02 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2EDEDFB4B for ; Fri, 26 Aug 2022 09:43:00 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-33f8988daecso24907637b3.12 for ; Fri, 26 Aug 2022 09:43:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=OGW6u/w8E7rtFoVCHl2hMelnGzxIW2OVOqfv9qQJktE=; b=TGQQ4SVdRMyECrYYp4Kt7qld0dy+4tSgWYiOultZ0CvS2F5gFmg7ZwGQ8BLh0CN0ex pigqjV1vrOGU9Azq5msrQVMojOOjt9xqvns4hJvY2F/1XE37B3DqEr7O7gh0/uk6wIP8 3k6eelLXytmhZRCxAK9b7oItOUPfTACr/qnbjVmOjm9Ix0hO/09PeD4kIh0IdX37hoXq F34Eh8pvym1cheVDLK91TWf8OEvR9F8jFUnhrlP18BSon4SMw9hESQASxh07iBJKVI73 y9+FGoGR3wL5k2FGcIjY8lY/mOM0w7WKmMcFv3bHJq0mzKb/ip1uUyFQoNN7XDFRJDMJ ccQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=OGW6u/w8E7rtFoVCHl2hMelnGzxIW2OVOqfv9qQJktE=; b=K+TAaabSeKzvQe09wmWZ231NIDkR4OBSMQrr/0op9E3BIf1w70m0LgHl46CO11TL1L r2UMQVb4w1b22B87R/LcrILkWBi5Dpngw0UovkIx/IHXJI763Vl+Be2Z5bwmJsIWe60N OQe5cSO5QTd5ofHostueFkkcuCPOJZdfaHeD3g67LTthVGoHALfeEuWTRcVqRUXp07DB 5YHoyIci2frFFf0TahuWkrkMKnKVL2KJcEReLaMQEIxEqEGU29htu4tSYNfyyQ7XVJAr VX7kks7wVWYERlFhQGfQpRDKaicZPnIw2PsbhgSQTIebixV9XgXevnd80GM6cvMlRbfM fVNQ== X-Gm-Message-State: ACgBeo1zmiThdQDWIBCQLXuMu8VJQkJk+Fc1ibzFW3bFVkYgpQoCvFlY 14kNSaCx5Y9OGGxQ3+T7Pthg6gspsdSD X-Google-Smtp-Source: AA6agR5jwQs39a20cy3Z29YfirEvLxtmk7QoN98uryiBq7PDypA4w0OxnATHL6bXOYVYAVfVqOmmPIFKHMg4 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:ccb1:c46b:7044:2508]) (user=irogers job=sendgmr) by 2002:a5b:6c1:0:b0:669:a7c3:4c33 with SMTP id r1-20020a5b06c1000000b00669a7c34c33mr460617ybq.543.1661532179892; Fri, 26 Aug 2022 09:42:59 -0700 (PDT) Date: Fri, 26 Aug 2022 09:42:25 -0700 In-Reply-To: <20220826164242.43412-1-irogers@google.com> Message-Id: <20220826164242.43412-2-irogers@google.com> Mime-Version: 1.0 References: <20220826164242.43412-1-irogers@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 01/18] perf mutex: Wrapped usage of mutex and cond From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Weiguo Li , Athira Rajeev , Thomas Richter , Ravi Bangoria , Dario Petrillo , Hewenliang , yaowenbin , Wenyu Liu , Song Liu , Andrii Nakryiko , Dave Marchevsky , Leo Yan , Kim Phillips , Pavithra Gurushankar , Alexandre Truong , Quentin Monnet , William Cohen , Andres Freund , Adrian Hunter , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Colin Ian King , James Clark , Fangrui Song , Stephane Eranian , Kajol Jain , Alexey Bayduraev , Riccardo Mancini , Andi Kleen , Masami Hiramatsu , Zechuan Chen , Jason Wang , Christophe JAILLET , Remi Bernon , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Cc: Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Pavithra Gurushankar Added a new header file mutex.h that wraps the usage of pthread_mutex_t and pthread_cond_t. By abstracting these it is possible to introduce error checking. Signed-off-by: Pavithra Gurushankar Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/Build | 1 + tools/perf/util/mutex.c | 117 ++++++++++++++++++++++++++++++++++++++++ tools/perf/util/mutex.h | 48 +++++++++++++++++ 3 files changed, 166 insertions(+) create mode 100644 tools/perf/util/mutex.c create mode 100644 tools/perf/util/mutex.h diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 9dfae1bda9cc..8fd6dc8de521 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -143,6 +143,7 @@ perf-y +=3D branch.o perf-y +=3D mem2node.o perf-y +=3D clockid.o perf-y +=3D list_sort.o +perf-y +=3D mutex.o =20 perf-$(CONFIG_LIBBPF) +=3D bpf-loader.o perf-$(CONFIG_LIBBPF) +=3D bpf_map.o diff --git a/tools/perf/util/mutex.c b/tools/perf/util/mutex.c new file mode 100644 index 000000000000..5029237164e5 --- /dev/null +++ b/tools/perf/util/mutex.c @@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "mutex.h" + +#include "debug.h" +#include +#include + +static void check_err(const char *fn, int err) +{ + char sbuf[STRERR_BUFSIZE]; + + if (err =3D=3D 0) + return; + + pr_err("%s error: '%s'\n", fn, str_error_r(err, sbuf, sizeof(sbuf))); +} + +#define CHECK_ERR(err) check_err(__func__, err) + +static void __mutex_init(struct mutex *mtx, bool pshared) +{ + pthread_mutexattr_t attr; + + CHECK_ERR(pthread_mutexattr_init(&attr)); + +#ifndef NDEBUG + /* In normal builds enable error checking, such as recursive usage. */ + CHECK_ERR(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK)); +#endif + if (pshared) + CHECK_ERR(pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED)); + + CHECK_ERR(pthread_mutex_init(&mtx->lock, &attr)); + CHECK_ERR(pthread_mutexattr_destroy(&attr)); +} + +void mutex_init(struct mutex *mtx) +{ + __mutex_init(mtx, /*pshared=3D*/false); +} + +void mutex_init_pshared(struct mutex *mtx) +{ + __mutex_init(mtx, /*pshared=3D*/true); +} + +void mutex_destroy(struct mutex *mtx) +{ + CHECK_ERR(pthread_mutex_destroy(&mtx->lock)); +} + +void mutex_lock(struct mutex *mtx) +{ + CHECK_ERR(pthread_mutex_lock(&mtx->lock)); +} + +void mutex_unlock(struct mutex *mtx) +{ + CHECK_ERR(pthread_mutex_unlock(&mtx->lock)); +} + +bool mutex_trylock(struct mutex *mtx) +{ + int ret =3D pthread_mutex_trylock(&mtx->lock); + + if (ret =3D=3D 0) + return true; /* Lock acquired. */ + + if (ret =3D=3D EBUSY) + return false; /* Lock busy. */ + + /* Print error. */ + CHECK_ERR(ret); + return false; +} + +static void __cond_init(struct cond *cnd, bool pshared) +{ + pthread_condattr_t attr; + + CHECK_ERR(pthread_condattr_init(&attr)); + if (pshared) + CHECK_ERR(pthread_condattr_setpshared(&attr, PTHREAD_PROCESS_SHARED)); + + CHECK_ERR(pthread_cond_init(&cnd->cond, &attr)); + CHECK_ERR(pthread_condattr_destroy(&attr)); +} + +void cond_init(struct cond *cnd) +{ + __cond_init(cnd, /*pshared=3D*/false); +} + +void cond_init_pshared(struct cond *cnd) +{ + __cond_init(cnd, /*pshared=3D*/true); +} + +void cond_destroy(struct cond *cnd) +{ + CHECK_ERR(pthread_cond_destroy(&cnd->cond)); +} + +void cond_wait(struct cond *cnd, struct mutex *mtx) +{ + CHECK_ERR(pthread_cond_wait(&cnd->cond, &mtx->lock)); +} + +void cond_signal(struct cond *cnd) +{ + CHECK_ERR(pthread_cond_signal(&cnd->cond)); +} + +void cond_broadcast(struct cond *cnd) +{ + CHECK_ERR(pthread_cond_broadcast(&cnd->cond)); +} diff --git a/tools/perf/util/mutex.h b/tools/perf/util/mutex.h new file mode 100644 index 000000000000..cfff32a902d9 --- /dev/null +++ b/tools/perf/util/mutex.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __PERF_MUTEX_H +#define __PERF_MUTEX_H + +#include +#include + +/* + * A wrapper around the mutex implementation that allows perf to error che= ck + * usage, etc. + */ +struct mutex { + pthread_mutex_t lock; +}; + +/* A wrapper around the condition variable implementation. */ +struct cond { + pthread_cond_t cond; +}; + +/* Default initialize the mtx struct. */ +void mutex_init(struct mutex *mtx); +/* + * Initialize the mtx struct and set the process-shared rather than default + * process-private attribute. + */ +void mutex_init_pshared(struct mutex *mtx); +void mutex_destroy(struct mutex *mtx); + +void mutex_lock(struct mutex *mtx); +void mutex_unlock(struct mutex *mtx); +/* Tries to acquire the lock and returns true on success. */ +bool mutex_trylock(struct mutex *mtx); + +/* Default initialize the cond struct. */ +void cond_init(struct cond *cnd); +/* + * Initialize the cond struct and specify the process-shared rather than d= efault + * process-private attribute. + */ +void cond_init_pshared(struct cond *cnd); +void cond_destroy(struct cond *cnd); + +void cond_wait(struct cond *cnd, struct mutex *mtx); +void cond_signal(struct cond *cnd); +void cond_broadcast(struct cond *cnd); + +#endif /* __PERF_MUTEX_H */ --=20 2.37.2.672.g94769d06f0-goog From nobody Tue Apr 7 14:52:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 500B1ECAAA6 for ; Fri, 26 Aug 2022 16:43:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344587AbiHZQne (ORCPT ); Fri, 26 Aug 2022 12:43:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344539AbiHZQnP (ORCPT ); Fri, 26 Aug 2022 12:43:15 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E654DFB72 for ; Fri, 26 Aug 2022 09:43:09 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-3360c0f0583so33668507b3.2 for ; Fri, 26 Aug 2022 09:43:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=ZGIJ7tERl/X5G2g/yFJuinw4oJjB76MF5S9q0o4IoVM=; b=LECzi0WDgoR84MiCFuxJKSv86+iguNeumvCqJR9oL4RlC8rktVVxRoiMs1RGcoqxS2 mGBZBARjbBwL0VhEMk4dnz1+M/CZItaT9dh5LZn+ShDZc/GjNThnFvy/LMkXwjjJ4HjR xYld4ke8nwjFT11xehu7uLD383hQ0CL/gWuR7maupu8roe+gPAFaPOTllhFUCY51G1EQ 6JngjhC6SvppF2huoqLgwz0mnui6qX+CztBDIDDtraWq5qVM80gMaqOkwVY48ZPcxNIm pKKdw+SbsnhsomX0U8HD9i/Zlqh7eCmgs0uKZ9vfAPQUp2YZv1EvosOC47OgJyjdb2R8 B7IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=ZGIJ7tERl/X5G2g/yFJuinw4oJjB76MF5S9q0o4IoVM=; b=Kt+VsRVcqTUrsz8IP89M1sD/FaOHS/dKM3es/cSO0jmmSWNLeP020tj/wt/KvdWTp0 AA6VLoNmeh6Cg+gUGCn9GmqsgPrzOY/3yJexVoZVweeXRU5Yr6E1HitT6GKypmh+yqs/ epNQCxyxyBEW9O1xqENb0azhWsPAxhS5DSuthQNO8UijWekXuyQRERpFQkOYrfoqtJL9 WWUHTB3lkM/Hl/h6c+U+u+xtcyCgQWTJwJuHA6Vvmk7wKlhSpYJkGj1el77m7fLMX+P6 oBT48DPwtWCtrUNYgWYdUrBB6DAx/+hqYaaxu5W2atmtp/g3h85Dw+psudRcZMWWj48G HRTg== X-Gm-Message-State: ACgBeo12CtpDUW7nlB8Eev2KJ1QcWSORfTd1A/jQzdzxoZ8v4Kvr+3yC HiuvmlXRcC+VKUlA+39IEMfk5SYkw75m X-Google-Smtp-Source: AA6agR6cSxYvKDpsJErblWtL3LLw21kbvt0Sdj2GhPpYoUp/RDe61kRwy8yex0G8y97u9BAhsC36b2YaLLax X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:ccb1:c46b:7044:2508]) (user=irogers job=sendgmr) by 2002:a25:bad2:0:b0:695:c271:8140 with SMTP id a18-20020a25bad2000000b00695c2718140mr480245ybk.179.1661532188245; Fri, 26 Aug 2022 09:43:08 -0700 (PDT) Date: Fri, 26 Aug 2022 09:42:26 -0700 In-Reply-To: <20220826164242.43412-1-irogers@google.com> Message-Id: <20220826164242.43412-3-irogers@google.com> Mime-Version: 1.0 References: <20220826164242.43412-1-irogers@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 02/18] perf bench: Update use of pthread mutex/cond From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Weiguo Li , Athira Rajeev , Thomas Richter , Ravi Bangoria , Dario Petrillo , Hewenliang , yaowenbin , Wenyu Liu , Song Liu , Andrii Nakryiko , Dave Marchevsky , Leo Yan , Kim Phillips , Pavithra Gurushankar , Alexandre Truong , Quentin Monnet , William Cohen , Andres Freund , Adrian Hunter , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Colin Ian King , James Clark , Fangrui Song , Stephane Eranian , Kajol Jain , Alexey Bayduraev , Riccardo Mancini , Andi Kleen , Masami Hiramatsu , Zechuan Chen , Jason Wang , Christophe JAILLET , Remi Bernon , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Cc: Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch to the use of mutex wrappers that provide better error checking. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/bench/epoll-ctl.c | 33 ++++----- tools/perf/bench/epoll-wait.c | 33 ++++----- tools/perf/bench/futex-hash.c | 33 ++++----- tools/perf/bench/futex-lock-pi.c | 33 ++++----- tools/perf/bench/futex-requeue.c | 33 ++++----- tools/perf/bench/futex-wake-parallel.c | 33 ++++----- tools/perf/bench/futex-wake.c | 33 ++++----- tools/perf/bench/numa.c | 93 ++++++++++---------------- 8 files changed, 153 insertions(+), 171 deletions(-) diff --git a/tools/perf/bench/epoll-ctl.c b/tools/perf/bench/epoll-ctl.c index 4256dc5d6236..521d1ff97b06 100644 --- a/tools/perf/bench/epoll-ctl.c +++ b/tools/perf/bench/epoll-ctl.c @@ -23,6 +23,7 @@ #include #include =20 +#include "../util/mutex.h" #include "../util/stat.h" #include #include "bench.h" @@ -58,10 +59,10 @@ static unsigned int nested =3D 0; /* amount of fds to monitor, per thread */ static unsigned int nfds =3D 64; =20 -static pthread_mutex_t thread_lock; +static struct mutex thread_lock; static unsigned int threads_starting; static struct stats all_stats[EPOLL_NR_OPS]; -static pthread_cond_t thread_parent, thread_worker; +static struct cond thread_parent, thread_worker; =20 struct worker { int tid; @@ -174,12 +175,12 @@ static void *workerfn(void *arg) struct timespec ts =3D { .tv_sec =3D 0, .tv_nsec =3D 250 }; =20 - pthread_mutex_lock(&thread_lock); + mutex_lock(&thread_lock); threads_starting--; if (!threads_starting) - pthread_cond_signal(&thread_parent); - pthread_cond_wait(&thread_worker, &thread_lock); - pthread_mutex_unlock(&thread_lock); + cond_signal(&thread_parent); + cond_wait(&thread_worker, &thread_lock); + mutex_unlock(&thread_lock); =20 /* Let 'em loose */ do { @@ -367,9 +368,9 @@ int bench_epoll_ctl(int argc, const char **argv) for (i =3D 0; i < EPOLL_NR_OPS; i++) init_stats(&all_stats[i]); =20 - pthread_mutex_init(&thread_lock, NULL); - pthread_cond_init(&thread_parent, NULL); - pthread_cond_init(&thread_worker, NULL); + mutex_init(&thread_lock); + cond_init(&thread_parent); + cond_init(&thread_worker); =20 threads_starting =3D nthreads; =20 @@ -377,11 +378,11 @@ int bench_epoll_ctl(int argc, const char **argv) =20 do_threads(worker, cpu); =20 - pthread_mutex_lock(&thread_lock); + mutex_lock(&thread_lock); while (threads_starting) - pthread_cond_wait(&thread_parent, &thread_lock); - pthread_cond_broadcast(&thread_worker); - pthread_mutex_unlock(&thread_lock); + cond_wait(&thread_parent, &thread_lock); + cond_broadcast(&thread_worker); + mutex_unlock(&thread_lock); =20 sleep(nsecs); toggle_done(0, NULL, NULL); @@ -394,9 +395,9 @@ int bench_epoll_ctl(int argc, const char **argv) } =20 /* cleanup & report results */ - pthread_cond_destroy(&thread_parent); - pthread_cond_destroy(&thread_worker); - pthread_mutex_destroy(&thread_lock); + cond_destroy(&thread_parent); + cond_destroy(&thread_worker); + mutex_destroy(&thread_lock); =20 for (i =3D 0; i < nthreads; i++) { unsigned long t[EPOLL_NR_OPS]; diff --git a/tools/perf/bench/epoll-wait.c b/tools/perf/bench/epoll-wait.c index 2728b0140853..c1cdf03c075d 100644 --- a/tools/perf/bench/epoll-wait.c +++ b/tools/perf/bench/epoll-wait.c @@ -79,6 +79,7 @@ #include =20 #include "../util/stat.h" +#include "../util/mutex.h" #include #include "bench.h" =20 @@ -109,10 +110,10 @@ static bool multiq; /* use an epoll instance per thre= ad */ /* amount of fds to monitor, per thread */ static unsigned int nfds =3D 64; =20 -static pthread_mutex_t thread_lock; +static struct mutex thread_lock; static unsigned int threads_starting; static struct stats throughput_stats; -static pthread_cond_t thread_parent, thread_worker; +static struct cond thread_parent, thread_worker; =20 struct worker { int tid; @@ -189,12 +190,12 @@ static void *workerfn(void *arg) int to =3D nonblocking? 0 : -1; int efd =3D multiq ? w->epollfd : epollfd; =20 - pthread_mutex_lock(&thread_lock); + mutex_lock(&thread_lock); threads_starting--; if (!threads_starting) - pthread_cond_signal(&thread_parent); - pthread_cond_wait(&thread_worker, &thread_lock); - pthread_mutex_unlock(&thread_lock); + cond_signal(&thread_parent); + cond_wait(&thread_worker, &thread_lock); + mutex_unlock(&thread_lock); =20 do { /* @@ -485,9 +486,9 @@ int bench_epoll_wait(int argc, const char **argv) getpid(), nthreads, oneshot ? " (EPOLLONESHOT semantics)": "", nfd= s, nsecs); =20 init_stats(&throughput_stats); - pthread_mutex_init(&thread_lock, NULL); - pthread_cond_init(&thread_parent, NULL); - pthread_cond_init(&thread_worker, NULL); + mutex_init(&thread_lock); + cond_init(&thread_parent); + cond_init(&thread_worker); =20 threads_starting =3D nthreads; =20 @@ -495,11 +496,11 @@ int bench_epoll_wait(int argc, const char **argv) =20 do_threads(worker, cpu); =20 - pthread_mutex_lock(&thread_lock); + mutex_lock(&thread_lock); while (threads_starting) - pthread_cond_wait(&thread_parent, &thread_lock); - pthread_cond_broadcast(&thread_worker); - pthread_mutex_unlock(&thread_lock); + cond_wait(&thread_parent, &thread_lock); + cond_broadcast(&thread_worker); + mutex_unlock(&thread_lock); =20 /* * At this point the workers should be blocked waiting for read events @@ -522,9 +523,9 @@ int bench_epoll_wait(int argc, const char **argv) err(EXIT_FAILURE, "pthread_join"); =20 /* cleanup & report results */ - pthread_cond_destroy(&thread_parent); - pthread_cond_destroy(&thread_worker); - pthread_mutex_destroy(&thread_lock); + cond_destroy(&thread_parent); + cond_destroy(&thread_worker); + mutex_destroy(&thread_lock); =20 /* sort the array back before reporting */ if (randomize) diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c index f05db4cf983d..2005a3fa3026 100644 --- a/tools/perf/bench/futex-hash.c +++ b/tools/perf/bench/futex-hash.c @@ -23,6 +23,7 @@ #include #include =20 +#include "../util/mutex.h" #include "../util/stat.h" #include #include "bench.h" @@ -34,10 +35,10 @@ static bool done =3D false; static int futex_flag =3D 0; =20 struct timeval bench__start, bench__end, bench__runtime; -static pthread_mutex_t thread_lock; +static struct mutex thread_lock; static unsigned int threads_starting; static struct stats throughput_stats; -static pthread_cond_t thread_parent, thread_worker; +static struct cond thread_parent, thread_worker; =20 struct worker { int tid; @@ -73,12 +74,12 @@ static void *workerfn(void *arg) unsigned int i; unsigned long ops =3D w->ops; /* avoid cacheline bouncing */ =20 - pthread_mutex_lock(&thread_lock); + mutex_lock(&thread_lock); threads_starting--; if (!threads_starting) - pthread_cond_signal(&thread_parent); - pthread_cond_wait(&thread_worker, &thread_lock); - pthread_mutex_unlock(&thread_lock); + cond_signal(&thread_parent); + cond_wait(&thread_worker, &thread_lock); + mutex_unlock(&thread_lock); =20 do { for (i =3D 0; i < params.nfutexes; i++, ops++) { @@ -165,9 +166,9 @@ int bench_futex_hash(int argc, const char **argv) getpid(), params.nthreads, params.nfutexes, params.fshared ? "shar= ed":"private", params.runtime); =20 init_stats(&throughput_stats); - pthread_mutex_init(&thread_lock, NULL); - pthread_cond_init(&thread_parent, NULL); - pthread_cond_init(&thread_worker, NULL); + mutex_init(&thread_lock); + cond_init(&thread_parent); + cond_init(&thread_worker); =20 threads_starting =3D params.nthreads; pthread_attr_init(&thread_attr); @@ -203,11 +204,11 @@ int bench_futex_hash(int argc, const char **argv) CPU_FREE(cpuset); pthread_attr_destroy(&thread_attr); =20 - pthread_mutex_lock(&thread_lock); + mutex_lock(&thread_lock); while (threads_starting) - pthread_cond_wait(&thread_parent, &thread_lock); - pthread_cond_broadcast(&thread_worker); - pthread_mutex_unlock(&thread_lock); + cond_wait(&thread_parent, &thread_lock); + cond_broadcast(&thread_worker); + mutex_unlock(&thread_lock); =20 sleep(params.runtime); toggle_done(0, NULL, NULL); @@ -219,9 +220,9 @@ int bench_futex_hash(int argc, const char **argv) } =20 /* cleanup & report results */ - pthread_cond_destroy(&thread_parent); - pthread_cond_destroy(&thread_worker); - pthread_mutex_destroy(&thread_lock); + cond_destroy(&thread_parent); + cond_destroy(&thread_worker); + mutex_destroy(&thread_lock); =20 for (i =3D 0; i < params.nthreads; i++) { unsigned long t =3D bench__runtime.tv_sec > 0 ? diff --git a/tools/perf/bench/futex-lock-pi.c b/tools/perf/bench/futex-lock= -pi.c index 0abb3f7ee24f..2d0417949727 100644 --- a/tools/perf/bench/futex-lock-pi.c +++ b/tools/perf/bench/futex-lock-pi.c @@ -8,6 +8,7 @@ #include =20 #include +#include "../util/mutex.h" #include "../util/stat.h" #include #include @@ -34,10 +35,10 @@ static u_int32_t global_futex =3D 0; static struct worker *worker; static bool done =3D false; static int futex_flag =3D 0; -static pthread_mutex_t thread_lock; +static struct mutex thread_lock; static unsigned int threads_starting; static struct stats throughput_stats; -static pthread_cond_t thread_parent, thread_worker; +static struct cond thread_parent, thread_worker; =20 static struct bench_futex_parameters params =3D { .runtime =3D 10, @@ -83,12 +84,12 @@ static void *workerfn(void *arg) struct worker *w =3D (struct worker *) arg; unsigned long ops =3D w->ops; =20 - pthread_mutex_lock(&thread_lock); + mutex_lock(&thread_lock); threads_starting--; if (!threads_starting) - pthread_cond_signal(&thread_parent); - pthread_cond_wait(&thread_worker, &thread_lock); - pthread_mutex_unlock(&thread_lock); + cond_signal(&thread_parent); + cond_wait(&thread_worker, &thread_lock); + mutex_unlock(&thread_lock); =20 do { int ret; @@ -197,9 +198,9 @@ int bench_futex_lock_pi(int argc, const char **argv) getpid(), params.nthreads, params.runtime); =20 init_stats(&throughput_stats); - pthread_mutex_init(&thread_lock, NULL); - pthread_cond_init(&thread_parent, NULL); - pthread_cond_init(&thread_worker, NULL); + mutex_init(&thread_lock); + cond_init(&thread_parent); + cond_init(&thread_worker); =20 threads_starting =3D params.nthreads; pthread_attr_init(&thread_attr); @@ -208,11 +209,11 @@ int bench_futex_lock_pi(int argc, const char **argv) create_threads(worker, thread_attr, cpu); pthread_attr_destroy(&thread_attr); =20 - pthread_mutex_lock(&thread_lock); + mutex_lock(&thread_lock); while (threads_starting) - pthread_cond_wait(&thread_parent, &thread_lock); - pthread_cond_broadcast(&thread_worker); - pthread_mutex_unlock(&thread_lock); + cond_wait(&thread_parent, &thread_lock); + cond_broadcast(&thread_worker); + mutex_unlock(&thread_lock); =20 sleep(params.runtime); toggle_done(0, NULL, NULL); @@ -224,9 +225,9 @@ int bench_futex_lock_pi(int argc, const char **argv) } =20 /* cleanup & report results */ - pthread_cond_destroy(&thread_parent); - pthread_cond_destroy(&thread_worker); - pthread_mutex_destroy(&thread_lock); + cond_destroy(&thread_parent); + cond_destroy(&thread_worker); + mutex_destroy(&thread_lock); =20 for (i =3D 0; i < params.nthreads; i++) { unsigned long t =3D bench__runtime.tv_sec > 0 ? diff --git a/tools/perf/bench/futex-requeue.c b/tools/perf/bench/futex-requ= eue.c index b6faabfafb8e..69ad896f556c 100644 --- a/tools/perf/bench/futex-requeue.c +++ b/tools/perf/bench/futex-requeue.c @@ -15,6 +15,7 @@ #include =20 #include +#include "../util/mutex.h" #include "../util/stat.h" #include #include @@ -34,8 +35,8 @@ static u_int32_t futex1 =3D 0, futex2 =3D 0; =20 static pthread_t *worker; static bool done =3D false; -static pthread_mutex_t thread_lock; -static pthread_cond_t thread_parent, thread_worker; +static struct mutex thread_lock; +static struct cond thread_parent, thread_worker; static struct stats requeuetime_stats, requeued_stats; static unsigned int threads_starting; static int futex_flag =3D 0; @@ -82,12 +83,12 @@ static void *workerfn(void *arg __maybe_unused) { int ret; =20 - pthread_mutex_lock(&thread_lock); + mutex_lock(&thread_lock); threads_starting--; if (!threads_starting) - pthread_cond_signal(&thread_parent); - pthread_cond_wait(&thread_worker, &thread_lock); - pthread_mutex_unlock(&thread_lock); + cond_signal(&thread_parent); + cond_wait(&thread_worker, &thread_lock); + mutex_unlock(&thread_lock); =20 while (1) { if (!params.pi) { @@ -209,9 +210,9 @@ int bench_futex_requeue(int argc, const char **argv) init_stats(&requeued_stats); init_stats(&requeuetime_stats); pthread_attr_init(&thread_attr); - pthread_mutex_init(&thread_lock, NULL); - pthread_cond_init(&thread_parent, NULL); - pthread_cond_init(&thread_worker, NULL); + mutex_init(&thread_lock); + cond_init(&thread_parent); + cond_init(&thread_worker); =20 for (j =3D 0; j < bench_repeat && !done; j++) { unsigned int nrequeued =3D 0, wakeups =3D 0; @@ -221,11 +222,11 @@ int bench_futex_requeue(int argc, const char **argv) block_threads(worker, thread_attr, cpu); =20 /* make sure all threads are already blocked */ - pthread_mutex_lock(&thread_lock); + mutex_lock(&thread_lock); while (threads_starting) - pthread_cond_wait(&thread_parent, &thread_lock); - pthread_cond_broadcast(&thread_worker); - pthread_mutex_unlock(&thread_lock); + cond_wait(&thread_parent, &thread_lock); + cond_broadcast(&thread_worker); + mutex_unlock(&thread_lock); =20 usleep(100000); =20 @@ -297,9 +298,9 @@ int bench_futex_requeue(int argc, const char **argv) } =20 /* cleanup & report results */ - pthread_cond_destroy(&thread_parent); - pthread_cond_destroy(&thread_worker); - pthread_mutex_destroy(&thread_lock); + cond_destroy(&thread_parent); + cond_destroy(&thread_worker); + mutex_destroy(&thread_lock); pthread_attr_destroy(&thread_attr); =20 print_summary(); diff --git a/tools/perf/bench/futex-wake-parallel.c b/tools/perf/bench/fute= x-wake-parallel.c index e47f46a3a47e..6682e49d0ee0 100644 --- a/tools/perf/bench/futex-wake-parallel.c +++ b/tools/perf/bench/futex-wake-parallel.c @@ -10,6 +10,7 @@ #include "bench.h" #include #include "../util/debug.h" +#include "../util/mutex.h" =20 #ifndef HAVE_PTHREAD_BARRIER int bench_futex_wake_parallel(int argc __maybe_unused, const char **argv _= _maybe_unused) @@ -49,8 +50,8 @@ static u_int32_t futex =3D 0; =20 static pthread_t *blocked_worker; static bool done =3D false; -static pthread_mutex_t thread_lock; -static pthread_cond_t thread_parent, thread_worker; +static struct mutex thread_lock; +static struct cond thread_parent, thread_worker; static pthread_barrier_t barrier; static struct stats waketime_stats, wakeup_stats; static unsigned int threads_starting; @@ -125,12 +126,12 @@ static void wakeup_threads(struct thread_data *td, pt= hread_attr_t thread_attr) =20 static void *blocked_workerfn(void *arg __maybe_unused) { - pthread_mutex_lock(&thread_lock); + mutex_lock(&thread_lock); threads_starting--; if (!threads_starting) - pthread_cond_signal(&thread_parent); - pthread_cond_wait(&thread_worker, &thread_lock); - pthread_mutex_unlock(&thread_lock); + cond_signal(&thread_parent); + cond_wait(&thread_worker, &thread_lock); + mutex_unlock(&thread_lock); =20 while (1) { /* handle spurious wakeups */ if (futex_wait(&futex, 0, NULL, futex_flag) !=3D EINTR) @@ -294,9 +295,9 @@ int bench_futex_wake_parallel(int argc, const char **ar= gv) init_stats(&waketime_stats); =20 pthread_attr_init(&thread_attr); - pthread_mutex_init(&thread_lock, NULL); - pthread_cond_init(&thread_parent, NULL); - pthread_cond_init(&thread_worker, NULL); + mutex_init(&thread_lock); + cond_init(&thread_parent); + cond_init(&thread_worker); =20 for (j =3D 0; j < bench_repeat && !done; j++) { waking_worker =3D calloc(params.nwakes, sizeof(*waking_worker)); @@ -307,11 +308,11 @@ int bench_futex_wake_parallel(int argc, const char **= argv) block_threads(blocked_worker, thread_attr, cpu); =20 /* make sure all threads are already blocked */ - pthread_mutex_lock(&thread_lock); + mutex_lock(&thread_lock); while (threads_starting) - pthread_cond_wait(&thread_parent, &thread_lock); - pthread_cond_broadcast(&thread_worker); - pthread_mutex_unlock(&thread_lock); + cond_wait(&thread_parent, &thread_lock); + cond_broadcast(&thread_worker); + mutex_unlock(&thread_lock); =20 usleep(100000); =20 @@ -332,9 +333,9 @@ int bench_futex_wake_parallel(int argc, const char **ar= gv) } =20 /* cleanup & report results */ - pthread_cond_destroy(&thread_parent); - pthread_cond_destroy(&thread_worker); - pthread_mutex_destroy(&thread_lock); + cond_destroy(&thread_parent); + cond_destroy(&thread_worker); + mutex_destroy(&thread_lock); pthread_attr_destroy(&thread_attr); =20 print_summary(); diff --git a/tools/perf/bench/futex-wake.c b/tools/perf/bench/futex-wake.c index 201a3555f09a..9ecab6620a87 100644 --- a/tools/perf/bench/futex-wake.c +++ b/tools/perf/bench/futex-wake.c @@ -14,6 +14,7 @@ #include =20 #include +#include "../util/mutex.h" #include "../util/stat.h" #include #include @@ -34,8 +35,8 @@ static u_int32_t futex1 =3D 0; =20 static pthread_t *worker; static bool done =3D false; -static pthread_mutex_t thread_lock; -static pthread_cond_t thread_parent, thread_worker; +static struct mutex thread_lock; +static struct cond thread_parent, thread_worker; static struct stats waketime_stats, wakeup_stats; static unsigned int threads_starting; static int futex_flag =3D 0; @@ -65,12 +66,12 @@ static const char * const bench_futex_wake_usage[] =3D { =20 static void *workerfn(void *arg __maybe_unused) { - pthread_mutex_lock(&thread_lock); + mutex_lock(&thread_lock); threads_starting--; if (!threads_starting) - pthread_cond_signal(&thread_parent); - pthread_cond_wait(&thread_worker, &thread_lock); - pthread_mutex_unlock(&thread_lock); + cond_signal(&thread_parent); + cond_wait(&thread_worker, &thread_lock); + mutex_unlock(&thread_lock); =20 while (1) { if (futex_wait(&futex1, 0, NULL, futex_flag) !=3D EINTR) @@ -178,9 +179,9 @@ int bench_futex_wake(int argc, const char **argv) init_stats(&wakeup_stats); init_stats(&waketime_stats); pthread_attr_init(&thread_attr); - pthread_mutex_init(&thread_lock, NULL); - pthread_cond_init(&thread_parent, NULL); - pthread_cond_init(&thread_worker, NULL); + mutex_init(&thread_lock); + cond_init(&thread_parent); + cond_init(&thread_worker); =20 for (j =3D 0; j < bench_repeat && !done; j++) { unsigned int nwoken =3D 0; @@ -190,11 +191,11 @@ int bench_futex_wake(int argc, const char **argv) block_threads(worker, thread_attr, cpu); =20 /* make sure all threads are already blocked */ - pthread_mutex_lock(&thread_lock); + mutex_lock(&thread_lock); while (threads_starting) - pthread_cond_wait(&thread_parent, &thread_lock); - pthread_cond_broadcast(&thread_worker); - pthread_mutex_unlock(&thread_lock); + cond_wait(&thread_parent, &thread_lock); + cond_broadcast(&thread_worker); + mutex_unlock(&thread_lock); =20 usleep(100000); =20 @@ -224,9 +225,9 @@ int bench_futex_wake(int argc, const char **argv) } =20 /* cleanup & report results */ - pthread_cond_destroy(&thread_parent); - pthread_cond_destroy(&thread_worker); - pthread_mutex_destroy(&thread_lock); + cond_destroy(&thread_parent); + cond_destroy(&thread_worker); + mutex_destroy(&thread_lock); pthread_attr_destroy(&thread_attr); =20 print_summary(); diff --git a/tools/perf/bench/numa.c b/tools/perf/bench/numa.c index 20eed1e53f80..e78dedf9e682 100644 --- a/tools/perf/bench/numa.c +++ b/tools/perf/bench/numa.c @@ -6,8 +6,6 @@ */ =20 #include -/* For the CLR_() macros */ -#include =20 #include #include "../util/cloexec.h" @@ -35,6 +33,7 @@ #include =20 #include "../util/header.h" +#include "../util/mutex.h" #include #include =20 @@ -67,7 +66,7 @@ struct thread_data { u64 system_time_ns; u64 user_time_ns; double speed_gbs; - pthread_mutex_t *process_lock; + struct mutex *process_lock; }; =20 /* Parameters set by options: */ @@ -137,16 +136,16 @@ struct params { struct global_info { u8 *data; =20 - pthread_mutex_t startup_mutex; - pthread_cond_t startup_cond; + struct mutex startup_mutex; + struct cond startup_cond; int nr_tasks_started; =20 - pthread_mutex_t start_work_mutex; - pthread_cond_t start_work_cond; + struct mutex start_work_mutex; + struct cond start_work_cond; int nr_tasks_working; bool start_work; =20 - pthread_mutex_t stop_work_mutex; + struct mutex stop_work_mutex; u64 bytes_done; =20 struct thread_data *threads; @@ -524,30 +523,6 @@ static void * setup_private_data(ssize_t bytes) return alloc_data(bytes, MAP_PRIVATE, 0, g->p.init_cpu0, g->p.thp, g->p.= init_random); } =20 -/* - * Return a process-shared (global) mutex: - */ -static void init_global_mutex(pthread_mutex_t *mutex) -{ - pthread_mutexattr_t attr; - - pthread_mutexattr_init(&attr); - pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); - pthread_mutex_init(mutex, &attr); -} - -/* - * Return a process-shared (global) condition variable: - */ -static void init_global_cond(pthread_cond_t *cond) -{ - pthread_condattr_t attr; - - pthread_condattr_init(&attr); - pthread_condattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); - pthread_cond_init(cond, &attr); -} - static int parse_cpu_list(const char *arg) { p0.cpu_list_str =3D strdup(arg); @@ -1220,22 +1195,22 @@ static void *worker_thread(void *__tdata) } =20 if (g->p.serialize_startup) { - pthread_mutex_lock(&g->startup_mutex); + mutex_lock(&g->startup_mutex); g->nr_tasks_started++; /* The last thread wakes the main process. */ if (g->nr_tasks_started =3D=3D g->p.nr_tasks) - pthread_cond_signal(&g->startup_cond); + cond_signal(&g->startup_cond); =20 - pthread_mutex_unlock(&g->startup_mutex); + mutex_unlock(&g->startup_mutex); =20 /* Here we will wait for the main process to start us all at once: */ - pthread_mutex_lock(&g->start_work_mutex); + mutex_lock(&g->start_work_mutex); g->start_work =3D false; g->nr_tasks_working++; while (!g->start_work) - pthread_cond_wait(&g->start_work_cond, &g->start_work_mutex); + cond_wait(&g->start_work_cond, &g->start_work_mutex); =20 - pthread_mutex_unlock(&g->start_work_mutex); + mutex_unlock(&g->start_work_mutex); } =20 gettimeofday(&start0, NULL); @@ -1254,17 +1229,17 @@ static void *worker_thread(void *__tdata) val +=3D do_work(thread_data, g->p.bytes_thread, 0, 1, l, va= l); =20 if (g->p.sleep_usecs) { - pthread_mutex_lock(td->process_lock); + mutex_lock(td->process_lock); usleep(g->p.sleep_usecs); - pthread_mutex_unlock(td->process_lock); + mutex_unlock(td->process_lock); } /* * Amount of work to be done under a process-global lock: */ if (g->p.bytes_process_locked) { - pthread_mutex_lock(td->process_lock); + mutex_lock(td->process_lock); val +=3D do_work(process_data, g->p.bytes_process_locked, thread_nr, g= ->p.nr_threads, l, val); - pthread_mutex_unlock(td->process_lock); + mutex_unlock(td->process_lock); } =20 work_done =3D g->p.bytes_global + g->p.bytes_process + @@ -1361,9 +1336,9 @@ static void *worker_thread(void *__tdata) =20 free_data(thread_data, g->p.bytes_thread); =20 - pthread_mutex_lock(&g->stop_work_mutex); + mutex_lock(&g->stop_work_mutex); g->bytes_done +=3D bytes_done; - pthread_mutex_unlock(&g->stop_work_mutex); + mutex_unlock(&g->stop_work_mutex); =20 return NULL; } @@ -1373,7 +1348,7 @@ static void *worker_thread(void *__tdata) */ static void worker_process(int process_nr) { - pthread_mutex_t process_lock; + struct mutex process_lock; struct thread_data *td; pthread_t *pthreads; u8 *process_data; @@ -1381,7 +1356,7 @@ static void worker_process(int process_nr) int ret; int t; =20 - pthread_mutex_init(&process_lock, NULL); + mutex_init(&process_lock); set_taskname("process %d", process_nr); =20 /* @@ -1540,11 +1515,11 @@ static int init(void) g->data =3D setup_shared_data(g->p.bytes_global); =20 /* Startup serialization: */ - init_global_mutex(&g->start_work_mutex); - init_global_cond(&g->start_work_cond); - init_global_mutex(&g->startup_mutex); - init_global_cond(&g->startup_cond); - init_global_mutex(&g->stop_work_mutex); + mutex_init_pshared(&g->start_work_mutex); + cond_init_pshared(&g->start_work_cond); + mutex_init_pshared(&g->startup_mutex); + cond_init_pshared(&g->startup_cond); + mutex_init_pshared(&g->stop_work_mutex); =20 init_thread_data(); =20 @@ -1633,17 +1608,17 @@ static int __bench_numa(const char *name) * Wait for all the threads to start up. The last thread will * signal this process. */ - pthread_mutex_lock(&g->startup_mutex); + mutex_lock(&g->startup_mutex); while (g->nr_tasks_started !=3D g->p.nr_tasks) - pthread_cond_wait(&g->startup_cond, &g->startup_mutex); + cond_wait(&g->startup_cond, &g->startup_mutex); =20 - pthread_mutex_unlock(&g->startup_mutex); + mutex_unlock(&g->startup_mutex); =20 /* Wait for all threads to be at the start_work_cond. */ while (!threads_ready) { - pthread_mutex_lock(&g->start_work_mutex); + mutex_lock(&g->start_work_mutex); threads_ready =3D (g->nr_tasks_working =3D=3D g->p.nr_tasks); - pthread_mutex_unlock(&g->start_work_mutex); + mutex_unlock(&g->start_work_mutex); if (!threads_ready) usleep(1); } @@ -1661,10 +1636,10 @@ static int __bench_numa(const char *name) =20 start =3D stop; /* Start all threads running. */ - pthread_mutex_lock(&g->start_work_mutex); + mutex_lock(&g->start_work_mutex); g->start_work =3D true; - pthread_mutex_unlock(&g->start_work_mutex); - pthread_cond_broadcast(&g->start_work_cond); + mutex_unlock(&g->start_work_mutex); + cond_broadcast(&g->start_work_cond); } else { gettimeofday(&start, NULL); } --=20 2.37.2.672.g94769d06f0-goog From nobody Tue Apr 7 14:52:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C576ECAAA6 for ; Fri, 26 Aug 2022 16:43:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241806AbiHZQnp (ORCPT ); Fri, 26 Aug 2022 12:43:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344596AbiHZQnS (ORCPT ); Fri, 26 Aug 2022 12:43:18 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9839DFB5A for ; Fri, 26 Aug 2022 09:43:15 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-340ae84fb7dso1264857b3.17 for ; Fri, 26 Aug 2022 09:43:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=Rgaq1z5LOjS10FPCONzKodXjmm6pDD9DpzwInFEM770=; b=nl+Qh97XZk1KJ88OfXW9aPzIUNFMYSiDtZHMv5SvJstTLcntVJ2oztHnY+KiRHT3kT kxGubUgo9pIyre3cM28oumxGadAhesrLufKNV1+HtDxEgNUhRpm4iN7xGRfPUl4cu7jk ak7a9kqiKgvE60a2HYuzHY/wd6xhkb42GJM+0/6r9Xu9UBtFowN98FQkkedSH/sLywPk gd9Z5Iw7DYOeow252llFAVKTfJkJVWPUSR6mW6LXHwnLl2obc6JW8y8d/qAkWUt0IUIL Kyv4xDs+CIsRZl65hn6ylB3VKdry3X7THPwDevdSrKWj9BtbykigQ01iMx2KWt//AO0s c5dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=Rgaq1z5LOjS10FPCONzKodXjmm6pDD9DpzwInFEM770=; b=yg8YzvPi40Ddh8m/zHSlZ3N6FX3YOpAZy82yDzZaKu5zoSNQPgQBotMcSqnhCIOIhw 1hHpmEesFM+bThoXYU1x3o54NQ+LKwUVFrPE+BnxAglqtP6hz3tmAtybkz4TSBe7UTBK ne5BMU2v8b0rsz79Xo96QdKIslfO3XVMB0XSFaG8Md3t3X9na3fuXAb3BrOR+lRC5Suh ja+M9JF+TdKCeiRMOU8anhIPZOLt9/RqRsMMS4H8sZGYvZnywmYmKIZUrk8uJEfVZj6L 1FlythiaDLERJgNodzx5p4dL6hieWfikcftRKzkMz1UX2sDSX1ffzI0+6oSnoxiIuAkh uiqw== X-Gm-Message-State: ACgBeo3JfAIKNre2OFKWwe5weTyzcWZCMferUi7gv4qNF9FcAmk9Zk+v JqLK23EJTuAf7zrfHBGprxS9DAjezgOG X-Google-Smtp-Source: AA6agR7rr4cAm33WV7u+4zxKPqfDoUFhcdJ/w+TdWr0NJw63hF42lS3uIKi5UTfG/JnaYn5DASu62tOLWAIv X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:ccb1:c46b:7044:2508]) (user=irogers job=sendgmr) by 2002:a05:6902:1449:b0:67b:3ea:e49d with SMTP id a9-20020a056902144900b0067b03eae49dmr480144ybv.511.1661532194250; Fri, 26 Aug 2022 09:43:14 -0700 (PDT) Date: Fri, 26 Aug 2022 09:42:27 -0700 In-Reply-To: <20220826164242.43412-1-irogers@google.com> Message-Id: <20220826164242.43412-4-irogers@google.com> Mime-Version: 1.0 References: <20220826164242.43412-1-irogers@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 03/18] perf tests: Avoid pthread.h inclusion From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Weiguo Li , Athira Rajeev , Thomas Richter , Ravi Bangoria , Dario Petrillo , Hewenliang , yaowenbin , Wenyu Liu , Song Liu , Andrii Nakryiko , Dave Marchevsky , Leo Yan , Kim Phillips , Pavithra Gurushankar , Alexandre Truong , Quentin Monnet , William Cohen , Andres Freund , Adrian Hunter , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Colin Ian King , James Clark , Fangrui Song , Stephane Eranian , Kajol Jain , Alexey Bayduraev , Riccardo Mancini , Andi Kleen , Masami Hiramatsu , Zechuan Chen , Jason Wang , Christophe JAILLET , Remi Bernon , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Cc: Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" pthread.h is being included for the side-effect of getting sched.h and macros like CPU_CLR. Switch to directly using sched.h, or if that is already present, just remove the pthread.h inclusion entirely. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/tests/mmap-basic.c | 2 -- tools/perf/tests/openat-syscall-all-cpus.c | 2 +- tools/perf/tests/perf-record.c | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c index dfb6173b2a82..21b5e68179d7 100644 --- a/tools/perf/tests/mmap-basic.c +++ b/tools/perf/tests/mmap-basic.c @@ -1,8 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include #include -/* For the CLR_() macros */ -#include #include #include =20 diff --git a/tools/perf/tests/openat-syscall-all-cpus.c b/tools/perf/tests/= openat-syscall-all-cpus.c index 90828ae03ef5..f3275be83a33 100644 --- a/tools/perf/tests/openat-syscall-all-cpus.c +++ b/tools/perf/tests/openat-syscall-all-cpus.c @@ -2,7 +2,7 @@ #include #include /* For the CPU_* macros */ -#include +#include =20 #include #include diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c index 6a001fcfed68..b386ade9ed06 100644 --- a/tools/perf/tests/perf-record.c +++ b/tools/perf/tests/perf-record.c @@ -2,8 +2,6 @@ #include #include #include -/* For the CLR_() macros */ -#include =20 #include #include --=20 2.37.2.672.g94769d06f0-goog From nobody Tue Apr 7 14:52:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20988ECAAA3 for ; Fri, 26 Aug 2022 16:44:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344385AbiHZQoH (ORCPT ); Fri, 26 Aug 2022 12:44:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344687AbiHZQnZ (ORCPT ); Fri, 26 Aug 2022 12:43:25 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2330E01F4 for ; Fri, 26 Aug 2022 09:43:21 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-33dd097f993so33823497b3.10 for ; Fri, 26 Aug 2022 09:43:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=piFbI+N6ifodUssf6WWN9myKJ56nTyFL5MKGVcy1SIc=; b=oOTDnYkPox9n4dsRhelTrPGHGRLMEt6deTizLhz5ofmR+ooyIHLjFb758aN7XxeLyG mHElOGWQf3BuNkN8x3H2oZCTNs1m0D6ZX+FU1E5wVWKdsYEUf2kRi8EjLcXbLirQ4gHK Uoc+jySNEJmZFEgzlg0UTdE0K6mfDjJqyRoIoA61S7cXRsPHKutQMrUK1qSYhqfDVO+u GLZ4Tju4FfrS8seygSJX/JA23Htiq/BHSZYMK0UF5tZfbRCGBv1YJ8G0ieGtqTsD4PsB YsBRKb+kvtauhwZ+C6VHGIRgAdS0MuDIdx85It4XvLwuyCs91J2ETHROY0bsF8xzey5A qtUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=piFbI+N6ifodUssf6WWN9myKJ56nTyFL5MKGVcy1SIc=; b=Zq+kfcorPt2gZ5IAXp81pft5zVWi876X7vz6R8ht/nW5Xh8g17uY1Tdq1i3CsruW6v P7rlc6JN1en8rSnTipAb4FyhrwTxGrDjntvSfijbCcfJD4tigp84CIPZWFQH5ji85Imv 866UP2tday8ZproLwZMIBZJcS8yWN6D3gJjVbWCZqLI73sLnw4sma9LVxMkrsG9A9xrK 4HVAERqxffqAUIVJGfudK3JcZ1wCtNqtQSz59+j1Z72JXtuslLv+7tXCZk79UYwJdlvm jWoQlYlwGE76mHIOvoG9JoVZKt3G6zFC+qtsOD5duqiGjisus3atedKmMZRoyCpbNlfU Unvg== X-Gm-Message-State: ACgBeo0a8JoAr7dSh39g+/b2XJzaWozC2OzWqXSs1pjtozAGEk05lzdg Jl/TwczvqNRuc6qy/LWziS2hE/7r+QXj X-Google-Smtp-Source: AA6agR79l5tuhoTcDP4BLbWyfZ0xNMgzVMVpetYezd/5Wb9TiKNEL9VdQKZl8bhay/NuyiZiUoNpISpBNc4U X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:ccb1:c46b:7044:2508]) (user=irogers job=sendgmr) by 2002:a81:6103:0:b0:333:67b3:3558 with SMTP id v3-20020a816103000000b0033367b33558mr592131ywb.128.1661532199972; Fri, 26 Aug 2022 09:43:19 -0700 (PDT) Date: Fri, 26 Aug 2022 09:42:28 -0700 In-Reply-To: <20220826164242.43412-1-irogers@google.com> Message-Id: <20220826164242.43412-5-irogers@google.com> Mime-Version: 1.0 References: <20220826164242.43412-1-irogers@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 04/18] perf hist: Update use of pthread mutex From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Weiguo Li , Athira Rajeev , Thomas Richter , Ravi Bangoria , Dario Petrillo , Hewenliang , yaowenbin , Wenyu Liu , Song Liu , Andrii Nakryiko , Dave Marchevsky , Leo Yan , Kim Phillips , Pavithra Gurushankar , Alexandre Truong , Quentin Monnet , William Cohen , Andres Freund , Adrian Hunter , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Colin Ian King , James Clark , Fangrui Song , Stephane Eranian , Kajol Jain , Alexey Bayduraev , Riccardo Mancini , Andi Kleen , Masami Hiramatsu , Zechuan Chen , Jason Wang , Christophe JAILLET , Remi Bernon , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Cc: Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch to the use of mutex wrappers that provide better error checking. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-top.c | 8 ++++---- tools/perf/util/hist.c | 6 +++--- tools/perf/util/hist.h | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index fd8fd913c533..14e60f6f219c 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -220,7 +220,7 @@ static void perf_top__record_precise_ip(struct perf_top= *top, * This function is now called with he->hists->lock held. * Release it before going to sleep. */ - pthread_mutex_unlock(&he->hists->lock); + mutex_unlock(&he->hists->lock); =20 if (err =3D=3D -ERANGE && !he->ms.map->erange_warned) ui__warn_map_erange(he->ms.map, sym, ip); @@ -230,7 +230,7 @@ static void perf_top__record_precise_ip(struct perf_top= *top, sleep(1); } =20 - pthread_mutex_lock(&he->hists->lock); + mutex_lock(&he->hists->lock); } } =20 @@ -836,12 +836,12 @@ static void perf_event__process_sample(struct perf_to= ol *tool, else iter.ops =3D &hist_iter_normal; =20 - pthread_mutex_lock(&hists->lock); + mutex_lock(&hists->lock); =20 if (hist_entry_iter__add(&iter, &al, top->max_stack, top) < 0) pr_err("Problem incrementing symbol period, skipping event\n"); =20 - pthread_mutex_unlock(&hists->lock); + mutex_unlock(&hists->lock); } =20 addr_location__put(&al); diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 1c085ab56534..698add038cec 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -1622,13 +1622,13 @@ struct rb_root_cached *hists__get_rotate_entries_in= (struct hists *hists) { struct rb_root_cached *root; =20 - pthread_mutex_lock(&hists->lock); + mutex_lock(&hists->lock); =20 root =3D hists->entries_in; if (++hists->entries_in > &hists->entries_in_array[1]) hists->entries_in =3D &hists->entries_in_array[0]; =20 - pthread_mutex_unlock(&hists->lock); + mutex_unlock(&hists->lock); =20 return root; } @@ -2805,7 +2805,7 @@ int __hists__init(struct hists *hists, struct perf_hp= p_list *hpp_list) hists->entries_in =3D &hists->entries_in_array[0]; hists->entries_collapsed =3D RB_ROOT_CACHED; hists->entries =3D RB_ROOT_CACHED; - pthread_mutex_init(&hists->lock, NULL); + mutex_init(&hists->lock); hists->socket_filter =3D -1; hists->hpp_list =3D hpp_list; INIT_LIST_HEAD(&hists->hpp_formats); diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 7ed4648d2fc2..508428b2c1b2 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -4,10 +4,10 @@ =20 #include #include -#include #include "evsel.h" #include "color.h" #include "events_stats.h" +#include "mutex.h" =20 struct hist_entry; struct hist_entry_ops; @@ -98,7 +98,7 @@ struct hists { const struct dso *dso_filter; const char *uid_filter_str; const char *symbol_filter_str; - pthread_mutex_t lock; + struct mutex lock; struct hists_stats stats; u64 event_stream; u16 col_len[HISTC_NR_COLS]; --=20 2.37.2.672.g94769d06f0-goog From nobody Tue Apr 7 14:52:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA409ECAAD6 for ; Fri, 26 Aug 2022 16:44:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344744AbiHZQoX (ORCPT ); Fri, 26 Aug 2022 12:44:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344437AbiHZQn6 (ORCPT ); Fri, 26 Aug 2022 12:43:58 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC9F5E0965 for ; Fri, 26 Aug 2022 09:43:29 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-33dbe61eed8so33711017b3.1 for ; Fri, 26 Aug 2022 09:43:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=byVpB80TV/x11qGZZj1V9Hbrrk6J+Ff/Bi0KHWzM1Uo=; b=ROEzNU2vLJMBQ/ebGwfQ6eGsi2A4XeOX0z4/AtBTW7uH+wvBDbvD9U7dJUuGUu0/t/ RG9SYRmEyQo81EQ6zm3BjTZyRAd/U+mfJ7acDyId27JWIUA+paGfqTwDijvDB5d96jS4 0Evlu4LK9nXucMq0urv221+RSew0RsqU7Avx7QFSET/cxIFWkyK8hulDJfmqHHoDNT5d xzKrx5b6n0zWGgGV0Vid5qk43WAwDqZ2pDO3Z9r3V/WssKhdPELqolGKQo+4CFfR2Ggh H3RSQhX3uRz8yinHvLoTXXd77gH0H5rzVUCKfgzHXTupkv1hVDBVI3XndkxCFQPKiQVA mRTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=byVpB80TV/x11qGZZj1V9Hbrrk6J+Ff/Bi0KHWzM1Uo=; b=qEbSXatQC/V1vsEZIaYxQdU+m9RX7laQMBg1SwEYZmqMFg2bSTPpK7xO184QDT0Pxd f2V1eMbxlPMPviIZqqt79vnKyhWctwdLxb1P/kpRxE3e++HrrlDhJIARFynzwvC9GKYh FxKfzoqc8f3Ks/5WHbCYSvLhKS86VM4cwvoc4UjYo82KMPFjh98CDC4OvnBaUsx9xDFx tMDwmiWkcWro/xxS03Cny3tt56XZWI1abUt627NlvxogZY2d2BuVdJQ8fYUQOJMoPKfZ sSA2y1LpsR+A+ALtiD6Q90iPPzfs3ZcOzPY2FK5AxGrmnu6FqXH2h/TNpm0+UHtVjvAM GrFg== X-Gm-Message-State: ACgBeo1pj/Be5wSQlDUScxCr8PJtzBzsM/hd+h0l2vWGnkb1/uvapGcv +Jc2hROVU8j61BmBuxCkHZJkvlWrhtnf X-Google-Smtp-Source: AA6agR6+TnZFZIJcRd/XLNKJvnwoJOukG+FHhTf/+Ns3Gs61SwVZyHKl1Nu9OjgbFxM6njZlSR8C8NrDOQey X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:ccb1:c46b:7044:2508]) (user=irogers job=sendgmr) by 2002:a25:afc6:0:b0:695:8a28:1dc6 with SMTP id d6-20020a25afc6000000b006958a281dc6mr494579ybj.500.1661532207957; Fri, 26 Aug 2022 09:43:27 -0700 (PDT) Date: Fri, 26 Aug 2022 09:42:29 -0700 In-Reply-To: <20220826164242.43412-1-irogers@google.com> Message-Id: <20220826164242.43412-6-irogers@google.com> Mime-Version: 1.0 References: <20220826164242.43412-1-irogers@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 05/18] perf bpf: Remove unused pthread.h include From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Weiguo Li , Athira Rajeev , Thomas Richter , Ravi Bangoria , Dario Petrillo , Hewenliang , yaowenbin , Wenyu Liu , Song Liu , Andrii Nakryiko , Dave Marchevsky , Leo Yan , Kim Phillips , Pavithra Gurushankar , Alexandre Truong , Quentin Monnet , William Cohen , Andres Freund , Adrian Hunter , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Colin Ian King , James Clark , Fangrui Song , Stephane Eranian , Kajol Jain , Alexey Bayduraev , Riccardo Mancini , Andi Kleen , Masami Hiramatsu , Zechuan Chen , Jason Wang , Christophe JAILLET , Remi Bernon , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Cc: Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" No pthread usage in bpf-event.h. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/bpf-event.h | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/perf/util/bpf-event.h b/tools/perf/util/bpf-event.h index 144a8a24cc69..1bcbd4fb6c66 100644 --- a/tools/perf/util/bpf-event.h +++ b/tools/perf/util/bpf-event.h @@ -4,7 +4,6 @@ =20 #include #include -#include #include #include =20 --=20 2.37.2.672.g94769d06f0-goog From nobody Tue Apr 7 14:52:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25F07ECAAD6 for ; Fri, 26 Aug 2022 16:45:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244912AbiHZQpF (ORCPT ); Fri, 26 Aug 2022 12:45:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344392AbiHZQom (ORCPT ); Fri, 26 Aug 2022 12:44:42 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71027E01C6 for ; Fri, 26 Aug 2022 09:43:58 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-31f5960500bso33297157b3.14 for ; Fri, 26 Aug 2022 09:43:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=ACInBWBwNvRh9+ZIkz7xZW+D59fAbxI1HNUoQj5EwTw=; b=A0ERzChba5qfQmN7t7ZnM+aWwRGaH2/CrJK4ga0h0ake/rNiQ1IkyR3JmXhJrMT9a2 KnHqRjX6PAnDpWoIkW8DOomTPRLzc1TyRbC3t+/4APWQ++yOkmcb7vZpIh864xKc8YkK TXueOMvwyqUW3p/H3jsDEaZeJ+ManaFKIw162zxrEZglv7KFe53adPbLvLotwONtq3m/ VkC4OmR/ajX51K4DFiENSlLRlXTjnnPJs3yS3cx54uVvE0IWijCmALy9ppEdFbi335dQ oYkX423X1tMjhhM+hPZBMshXdSCABfYwEL8duHu/C0YW0phgba8d6AjJngM2mSDJoJtU Qqcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=ACInBWBwNvRh9+ZIkz7xZW+D59fAbxI1HNUoQj5EwTw=; b=aj4a5XQYmElBMDUdGk35HOWhnpRPHfGDgNvUXpwScIMrIxCuPWA/6vs/y+IDhIbanB yTxAZ/83dhMKprlnMTebyUCOwF+KAq1NPkoPDlZG1pYhyY4e2NrNUsVpe7Z975z0anpe Vlc88vyKDpcgURYhid6rYMmTGX68wz19dBnaKWIHyQW+lxxJ9bviTAPE0osylcdvFkDT oLN4EeBJh2emkNwBkBQTYJFM2yHJbDVKqlGKbRu8M6DOmvQ8aKMIgwlxKG0LEkK492QA 9a/v524An2Ku1/ZCM6iWFn+JyNvtEo7qgausY1cG/oHcOhKm9i+tMbkLyDxtz6jEvG52 AI2Q== X-Gm-Message-State: ACgBeo0E4oQTNMOQbYibs/RQXeLOD8gXEr3vyQrenMqJnHMKYahlg4XH 8U07X3xhb18NcKR3BrFcrrnsrZSpCn/V X-Google-Smtp-Source: AA6agR674nFvhyZ8kZZpDZ9P2qEjEXJiLqOtFWE4EU1fMUMemGrNgewnTe7bwqftGS+iFizSaZUFrMd6XEEw X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:ccb1:c46b:7044:2508]) (user=irogers job=sendgmr) by 2002:a5b:6c7:0:b0:66e:3713:9929 with SMTP id r7-20020a5b06c7000000b0066e37139929mr535950ybq.34.1661532237966; Fri, 26 Aug 2022 09:43:57 -0700 (PDT) Date: Fri, 26 Aug 2022 09:42:30 -0700 In-Reply-To: <20220826164242.43412-1-irogers@google.com> Message-Id: <20220826164242.43412-7-irogers@google.com> Mime-Version: 1.0 References: <20220826164242.43412-1-irogers@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 06/18] perf lock: Remove unused pthread.h include From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Weiguo Li , Athira Rajeev , Thomas Richter , Ravi Bangoria , Dario Petrillo , Hewenliang , yaowenbin , Wenyu Liu , Song Liu , Andrii Nakryiko , Dave Marchevsky , Leo Yan , Kim Phillips , Pavithra Gurushankar , Alexandre Truong , Quentin Monnet , William Cohen , Andres Freund , Adrian Hunter , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Colin Ian King , James Clark , Fangrui Song , Stephane Eranian , Kajol Jain , Alexey Bayduraev , Riccardo Mancini , Andi Kleen , Masami Hiramatsu , Zechuan Chen , Jason Wang , Christophe JAILLET , Remi Bernon , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Cc: Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" No pthread usage in builtin-lock.c. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-lock.c | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index dd11d3471baf..70197c0593b1 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include =20 --=20 2.37.2.672.g94769d06f0-goog From nobody Tue Apr 7 14:52:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1AF8ECAAA6 for ; Fri, 26 Aug 2022 16:45:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344461AbiHZQpU (ORCPT ); Fri, 26 Aug 2022 12:45:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344438AbiHZQot (ORCPT ); Fri, 26 Aug 2022 12:44:49 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57AC5E01F7 for ; Fri, 26 Aug 2022 09:44:10 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-33dc390f26cso33306977b3.9 for ; Fri, 26 Aug 2022 09:44:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=KW1wjZhQOylJAM8dFCUuUgsNn9wynC6cGB5CBRkTkjU=; b=DLT7CNCPFxgWp4tw+x/BQspqZDpc1UMezv684sA8Gl8TsHyYXrhbYfV0Qr+PfXH6sE WyZe8OnzJaU/1Ef8NA1auGJ2hDrBVFrWmQe6C1c75RmFWI5JgK2QkInaC0PFH357sUBK iccm1taYoFpVQWHE0/CEbyO9NCebkdSo/fQeYsuY6lmfBq5fUmtl3rMLeYJ8QGma+I+K RnmZ6nmyKMDdXUQmHGCIdUIKetMz8UzgX1QFuI8iXW62hCKyDldFPgyV+eyEhCw0AA+N ocvsSYMFTlAfmg7rbbu/rnHYvg+mfLX25WZwKcDLZgrttSfeE/17xTn3w2Z+r4BptWl2 C1EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=KW1wjZhQOylJAM8dFCUuUgsNn9wynC6cGB5CBRkTkjU=; b=dA2rvcDRJYSb8TKe6ag5FDYxeRZL/neyRlbZ8Ii0Ckf8ClYyJTb8erwb7suatp/mmE Ug9YffhaqGWLbMw+mwbGwKVG+77w6lGJYRhovalbWmYoBYwqh5EbwK+vuDhhuXMUUUT8 uB3O2YtMSZd5xKlbAo77NeUaCbU28uOvpZ9JzaHYbi/4X4EqTNHhzGwGcBLbt0k3MjPS RINl0GtUbKOdk8aO57wsiiN0b71+WMB/H/AEXQTh5TmF5pmAsMrIhJ8/ffDki/807M/9 8Z3PcA64Wa9ms1d9ufSIAINRJyD29lLSnYB8CJjQhlFrjN4h/JeVlADjxeF/Lwu+Lx5p CZpw== X-Gm-Message-State: ACgBeo08LShf269a/KW83Mdk76/8MxfwrtZEdr3M2gQCpZOFy5fKhgEH 4jaZbbi54TlhKgUu7bRWDKxMeOZQmVKF X-Google-Smtp-Source: AA6agR5ECIO+GHRI3XC9wpQWiTgzeGBhIlpvn15OMBLt2Eu4HKggVRe/TElALFWz/W+OT2LnRb3f7F9dYoKl X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:ccb1:c46b:7044:2508]) (user=irogers job=sendgmr) by 2002:a05:6902:110d:b0:670:b10b:d16e with SMTP id o13-20020a056902110d00b00670b10bd16emr494541ybu.259.1661532248866; Fri, 26 Aug 2022 09:44:08 -0700 (PDT) Date: Fri, 26 Aug 2022 09:42:31 -0700 In-Reply-To: <20220826164242.43412-1-irogers@google.com> Message-Id: <20220826164242.43412-8-irogers@google.com> Mime-Version: 1.0 References: <20220826164242.43412-1-irogers@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 07/18] perf record: Update use of pthread mutex From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Weiguo Li , Athira Rajeev , Thomas Richter , Ravi Bangoria , Dario Petrillo , Hewenliang , yaowenbin , Wenyu Liu , Song Liu , Andrii Nakryiko , Dave Marchevsky , Leo Yan , Kim Phillips , Pavithra Gurushankar , Alexandre Truong , Quentin Monnet , William Cohen , Andres Freund , Adrian Hunter , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Colin Ian King , James Clark , Fangrui Song , Stephane Eranian , Kajol Jain , Alexey Bayduraev , Riccardo Mancini , Andi Kleen , Masami Hiramatsu , Zechuan Chen , Jason Wang , Christophe JAILLET , Remi Bernon , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Cc: Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch to the use of mutex wrappers that provide better error checking for synth_lock. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-record.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 4713f0f3a6cf..a7b7a317d81b 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -21,6 +21,7 @@ #include "util/evsel.h" #include "util/debug.h" #include "util/mmap.h" +#include "util/mutex.h" #include "util/target.h" #include "util/session.h" #include "util/tool.h" @@ -608,17 +609,18 @@ static int process_synthesized_event(struct perf_tool= *tool, return record__write(rec, NULL, event, event->header.size); } =20 +static struct mutex synth_lock; + static int process_locked_synthesized_event(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample __maybe_unused, struct machine *machine __maybe_unused) { - static pthread_mutex_t synth_lock =3D PTHREAD_MUTEX_INITIALIZER; int ret; =20 - pthread_mutex_lock(&synth_lock); + mutex_lock(&synth_lock); ret =3D process_synthesized_event(tool, event, sample, machine); - pthread_mutex_unlock(&synth_lock); + mutex_unlock(&synth_lock); return ret; } =20 @@ -1917,6 +1919,7 @@ static int record__synthesize(struct record *rec, boo= l tail) } =20 if (rec->opts.nr_threads_synthesize > 1) { + mutex_init(&synth_lock); perf_set_multithreaded(); f =3D process_locked_synthesized_event; } @@ -1930,8 +1933,10 @@ static int record__synthesize(struct record *rec, bo= ol tail) rec->opts.nr_threads_synthesize); } =20 - if (rec->opts.nr_threads_synthesize > 1) + if (rec->opts.nr_threads_synthesize > 1) { perf_set_singlethreaded(); + mutex_destroy(&synth_lock); + } =20 out: return err; --=20 2.37.2.672.g94769d06f0-goog From nobody Tue Apr 7 14:52:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27255ECAAA6 for ; Fri, 26 Aug 2022 16:45:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344779AbiHZQpZ (ORCPT ); Fri, 26 Aug 2022 12:45:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343587AbiHZQow (ORCPT ); Fri, 26 Aug 2022 12:44:52 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF251E0940 for ; Fri, 26 Aug 2022 09:44:15 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-3360c0f0583so33706547b3.2 for ; Fri, 26 Aug 2022 09:44:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=GgD+6zwqra9gOnSqGkAieKztoRTvvP9XXeeW7MuBWMo=; b=VIOXaOsl5Ybq3F+Ya1f+q2xUAralWPCk+yRASBaGpkAZo2gq+PuQ8qUI43ZsErEeOH /CIpkUnC/fPPIvNZc8OZ+ruKlZtSG2o2A/oWHwmTw0JDQ5dVFhR5r9jph9vsjHAu5rjy b8FfJMPNyzWfnufYso4NpxZsAhdfdtxadODqdMFXDGWw8FOI2L5YX5empRcw86z5P6zr 0UU4aDlCYr/D+stU/r5ELtfgESrfXDTUnf+eJWFEOL5qHCkiVa78QX7cfdkTfhetqfu6 p5xsZkN1LJt/vVStBCS9F/BhaShHR1jB5IWv91GNdQ5GaiyJdJSO/QotIlOBIsaQ/abH uu3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=GgD+6zwqra9gOnSqGkAieKztoRTvvP9XXeeW7MuBWMo=; b=Y992ilLttjR0iEE2lfySwKrEP5hnB4gFSQPMTj2Nl1pvZdojEjmWo1QzQ+2LO0UMlc VOLIiuUCCzmdxZ5aOOj6L7OIZJLJu0EvtJaC9Z5+hUzZgg1a3Jq2RtPvdY8R/YT7kX80 +WuMsR+aSozCA2+SfX9DtevwpcViBm/1uwiRtR5tXm3Qt6sZKCNgAlkugnhkZ/7Nj+51 0nkgns/cy4Opa5Rj8OPpE1oxxRDkXtanVEymL4ljWFm4cYqsolzXBq5zwBCmHrxfnW89 c1u534MKGM0sjleVK6qBZbBHKCEr8HObd95QZiKHvXLWZ+tp2iFpCchmYXq2QuUa4OrC gmFQ== X-Gm-Message-State: ACgBeo28CclvnRuaB6VI+GIPdFzhtVZTHraMHoe3ug3DHbPXGMk/AwEv 8bJXKON7+dO5ieHpohw0YI+BrC8qfAjM X-Google-Smtp-Source: AA6agR6lqr3Mf/yq4gHfai7EoCGqdkPDaQRC0WWlRD459eEHKC2xzEVghJ668HwLSNkBvHYMTAZPI224F5d7 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:ccb1:c46b:7044:2508]) (user=irogers job=sendgmr) by 2002:a25:b983:0:b0:695:d8b4:a5a3 with SMTP id r3-20020a25b983000000b00695d8b4a5a3mr488819ybg.553.1661532254499; Fri, 26 Aug 2022 09:44:14 -0700 (PDT) Date: Fri, 26 Aug 2022 09:42:32 -0700 In-Reply-To: <20220826164242.43412-1-irogers@google.com> Message-Id: <20220826164242.43412-9-irogers@google.com> Mime-Version: 1.0 References: <20220826164242.43412-1-irogers@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 08/18] perf sched: Update use of pthread mutex From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Weiguo Li , Athira Rajeev , Thomas Richter , Ravi Bangoria , Dario Petrillo , Hewenliang , yaowenbin , Wenyu Liu , Song Liu , Andrii Nakryiko , Dave Marchevsky , Leo Yan , Kim Phillips , Pavithra Gurushankar , Alexandre Truong , Quentin Monnet , William Cohen , Andres Freund , Adrian Hunter , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Colin Ian King , James Clark , Fangrui Song , Stephane Eranian , Kajol Jain , Alexey Bayduraev , Riccardo Mancini , Andi Kleen , Masami Hiramatsu , Zechuan Chen , Jason Wang , Christophe JAILLET , Remi Bernon , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Cc: Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch to the use of mutex wrappers that provide better error checking. Update cmd_sched so that we always explicitly destroy the mutexes. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-sched.c | 67 ++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 2f6cd1b8b662..7e4006d6b8bc 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -7,6 +7,7 @@ #include "util/evlist.h" #include "util/evsel.h" #include "util/evsel_fprintf.h" +#include "util/mutex.h" #include "util/symbol.h" #include "util/thread.h" #include "util/header.h" @@ -184,8 +185,8 @@ struct perf_sched { struct task_desc **pid_to_task; struct task_desc **tasks; const struct trace_sched_handler *tp_handler; - pthread_mutex_t start_work_mutex; - pthread_mutex_t work_done_wait_mutex; + struct mutex start_work_mutex; + struct mutex work_done_wait_mutex; int profile_cpu; /* * Track the current task - that way we can know whether there's any @@ -635,10 +636,8 @@ static void *thread_func(void *ctx) again: ret =3D sem_post(&this_task->ready_for_work); BUG_ON(ret); - ret =3D pthread_mutex_lock(&sched->start_work_mutex); - BUG_ON(ret); - ret =3D pthread_mutex_unlock(&sched->start_work_mutex); - BUG_ON(ret); + mutex_lock(&sched->start_work_mutex); + mutex_unlock(&sched->start_work_mutex); =20 cpu_usage_0 =3D get_cpu_usage_nsec_self(fd); =20 @@ -652,10 +651,8 @@ static void *thread_func(void *ctx) ret =3D sem_post(&this_task->work_done_sem); BUG_ON(ret); =20 - ret =3D pthread_mutex_lock(&sched->work_done_wait_mutex); - BUG_ON(ret); - ret =3D pthread_mutex_unlock(&sched->work_done_wait_mutex); - BUG_ON(ret); + mutex_lock(&sched->work_done_wait_mutex); + mutex_unlock(&sched->work_done_wait_mutex); =20 goto again; } @@ -672,10 +669,8 @@ static void create_tasks(struct perf_sched *sched) err =3D pthread_attr_setstacksize(&attr, (size_t) max(16 * 1024, (int)PTHREAD_STACK_MIN)); BUG_ON(err); - err =3D pthread_mutex_lock(&sched->start_work_mutex); - BUG_ON(err); - err =3D pthread_mutex_lock(&sched->work_done_wait_mutex); - BUG_ON(err); + mutex_lock(&sched->start_work_mutex); + mutex_lock(&sched->work_done_wait_mutex); for (i =3D 0; i < sched->nr_tasks; i++) { struct sched_thread_parms *parms =3D malloc(sizeof(*parms)); BUG_ON(parms =3D=3D NULL); @@ -699,7 +694,7 @@ static void wait_for_tasks(struct perf_sched *sched) =20 sched->start_time =3D get_nsecs(); sched->cpu_usage =3D 0; - pthread_mutex_unlock(&sched->work_done_wait_mutex); + mutex_unlock(&sched->work_done_wait_mutex); =20 for (i =3D 0; i < sched->nr_tasks; i++) { task =3D sched->tasks[i]; @@ -707,12 +702,11 @@ static void wait_for_tasks(struct perf_sched *sched) BUG_ON(ret); sem_init(&task->ready_for_work, 0, 0); } - ret =3D pthread_mutex_lock(&sched->work_done_wait_mutex); - BUG_ON(ret); + mutex_lock(&sched->work_done_wait_mutex); =20 cpu_usage_0 =3D get_cpu_usage_nsec_parent(); =20 - pthread_mutex_unlock(&sched->start_work_mutex); + mutex_unlock(&sched->start_work_mutex); =20 for (i =3D 0; i < sched->nr_tasks; i++) { task =3D sched->tasks[i]; @@ -734,8 +728,7 @@ static void wait_for_tasks(struct perf_sched *sched) sched->runavg_parent_cpu_usage =3D (sched->runavg_parent_cpu_usage * (sch= ed->replay_repeat - 1) + sched->parent_cpu_usage)/sched->replay_repeat; =20 - ret =3D pthread_mutex_lock(&sched->start_work_mutex); - BUG_ON(ret); + mutex_lock(&sched->start_work_mutex); =20 for (i =3D 0; i < sched->nr_tasks; i++) { task =3D sched->tasks[i]; @@ -3430,8 +3423,6 @@ int cmd_sched(int argc, const char **argv) }, .cmp_pid =3D LIST_HEAD_INIT(sched.cmp_pid), .sort_list =3D LIST_HEAD_INIT(sched.sort_list), - .start_work_mutex =3D PTHREAD_MUTEX_INITIALIZER, - .work_done_wait_mutex =3D PTHREAD_MUTEX_INITIALIZER, .sort_order =3D default_sort_order, .replay_repeat =3D 10, .profile_cpu =3D -1, @@ -3545,8 +3536,10 @@ int cmd_sched(int argc, const char **argv) .fork_event =3D replay_fork_event, }; unsigned int i; - int ret; + int ret =3D 0; =20 + mutex_init(&sched.start_work_mutex); + mutex_init(&sched.work_done_wait_mutex); for (i =3D 0; i < ARRAY_SIZE(sched.curr_pid); i++) sched.curr_pid[i] =3D -1; =20 @@ -3558,11 +3551,10 @@ int cmd_sched(int argc, const char **argv) /* * Aliased to 'perf script' for now: */ - if (!strcmp(argv[0], "script")) - return cmd_script(argc, argv); - - if (strlen(argv[0]) > 2 && strstarts("record", argv[0])) { - return __cmd_record(argc, argv); + if (!strcmp(argv[0], "script")) { + ret =3D cmd_script(argc, argv); + } else if (strlen(argv[0]) > 2 && strstarts("record", argv[0])) { + ret =3D __cmd_record(argc, argv); } else if (strlen(argv[0]) > 2 && strstarts("latency", argv[0])) { sched.tp_handler =3D &lat_ops; if (argc > 1) { @@ -3571,7 +3563,7 @@ int cmd_sched(int argc, const char **argv) usage_with_options(latency_usage, latency_options); } setup_sorting(&sched, latency_options, latency_usage); - return perf_sched__lat(&sched); + ret =3D perf_sched__lat(&sched); } else if (!strcmp(argv[0], "map")) { if (argc) { argc =3D parse_options(argc, argv, map_options, map_usage, 0); @@ -3580,7 +3572,7 @@ int cmd_sched(int argc, const char **argv) } sched.tp_handler =3D &map_ops; setup_sorting(&sched, latency_options, latency_usage); - return perf_sched__map(&sched); + ret =3D perf_sched__map(&sched); } else if (strlen(argv[0]) > 2 && strstarts("replay", argv[0])) { sched.tp_handler =3D &replay_ops; if (argc) { @@ -3588,7 +3580,7 @@ int cmd_sched(int argc, const char **argv) if (argc) usage_with_options(replay_usage, replay_options); } - return perf_sched__replay(&sched); + ret =3D perf_sched__replay(&sched); } else if (!strcmp(argv[0], "timehist")) { if (argc) { argc =3D parse_options(argc, argv, timehist_options, @@ -3604,16 +3596,21 @@ int cmd_sched(int argc, const char **argv) parse_options_usage(NULL, timehist_options, "w", true); if (sched.show_next) parse_options_usage(NULL, timehist_options, "n", true); - return -EINVAL; + ret =3D -EINVAL; + goto out; } ret =3D symbol__validate_sym_arguments(); if (ret) - return ret; + goto out; =20 - return perf_sched__timehist(&sched); + ret =3D perf_sched__timehist(&sched); } else { usage_with_options(sched_usage, sched_options); } =20 - return 0; +out: + mutex_destroy(&sched.start_work_mutex); + mutex_destroy(&sched.work_done_wait_mutex); + + return ret; } --=20 2.37.2.672.g94769d06f0-goog From nobody Tue Apr 7 14:52:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20A0BECAAA6 for ; Fri, 26 Aug 2022 16:45:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344687AbiHZQpl (ORCPT ); Fri, 26 Aug 2022 12:45:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344701AbiHZQpD (ORCPT ); Fri, 26 Aug 2022 12:45:03 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4458EE117A for ; Fri, 26 Aug 2022 09:44:25 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-335420c7bfeso33323447b3.16 for ; Fri, 26 Aug 2022 09:44:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=kEA3RGEE+trfjZ+Bvxe855U6hLue5xmX2s3z8WCGKoA=; b=B3DLVwoTcBSsYIR9M59Sbjonq2y7EfsZSj7+/4RAcSpsIj2lRUdIPGG2QLQT3i2u1G MR3THKclDz4vmJtB6DbCfmBDw+yCSTOwLKTKojy29qSiCuqRwrwTYRV6k1bitPhnoIrC wX0VE3HXX+sTZt9AY9n9bf9RnQ20Anz3HkjkxmHg/5V9Q7nl815KZkR40kMND964DUNZ LTX1zlhRQ57cAjWn4n/9Ni7kfQUxZFC2rHXYLxhlHLwDzveeIoWEtcpENFr/HCWwwB2M Hu/BtnGOROV9IXWzr+8KfQsryJmczI7u3mVdy1WIGmAU5sbDDDMYHXePMVws/YKJiDnz ax7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=kEA3RGEE+trfjZ+Bvxe855U6hLue5xmX2s3z8WCGKoA=; b=cFT1ZzCigaa/kyG/asqCU1Op3fSKsSSSSKpHLiYb2gGIJfH5Tmav5lJ0ICLSd/ZUOf NKvCfQOD5sS39LMgXs0j/iYTGMZ0kvelmP3hioD1FZpYA2niB2hVQbKiPt6o0dpy0C93 pXiaH9UWR7ZM1lhFssj3p0YwmfbPHzi4HuyuZmfHnIxJw8gC4uqkBZ8rr+fb7YJpqYFl 0E2h2vYzo3XonT63CoDPcuxGJpGHodVAhoydXEItO8Gdok3gX2DksOaa3M66c3UOTGSG Q65qBNxQHxE34d6Gm2IK5jMidJtNqYKQVOTkLVqCHY7dWXZ6rOrb0M1Pj3QpNaJay1J3 Aosw== X-Gm-Message-State: ACgBeo39P6v7lx2MOxaFBKYKaEBZPmNEEtSGQYh/PNZuTcooKhwId9Ph +fmbPVEM44eT3MJ6cKw1gbkmgaWr60u1 X-Google-Smtp-Source: AA6agR5kUjXh6ZMxinVHjdTeROCTYuj37y/w9zOInuu1hgQP/cx25WyO6FwqFwCplppsFPykfzYaq38BbU/T X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:ccb1:c46b:7044:2508]) (user=irogers job=sendgmr) by 2002:a0d:df0a:0:b0:33d:ab83:e816 with SMTP id i10-20020a0ddf0a000000b0033dab83e816mr548337ywe.187.1661532264167; Fri, 26 Aug 2022 09:44:24 -0700 (PDT) Date: Fri, 26 Aug 2022 09:42:33 -0700 In-Reply-To: <20220826164242.43412-1-irogers@google.com> Message-Id: <20220826164242.43412-10-irogers@google.com> Mime-Version: 1.0 References: <20220826164242.43412-1-irogers@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 09/18] perf ui: Update use of pthread mutex From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Weiguo Li , Athira Rajeev , Thomas Richter , Ravi Bangoria , Dario Petrillo , Hewenliang , yaowenbin , Wenyu Liu , Song Liu , Andrii Nakryiko , Dave Marchevsky , Leo Yan , Kim Phillips , Pavithra Gurushankar , Alexandre Truong , Quentin Monnet , William Cohen , Andres Freund , Adrian Hunter , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Colin Ian King , James Clark , Fangrui Song , Stephane Eranian , Kajol Jain , Alexey Bayduraev , Riccardo Mancini , Andi Kleen , Masami Hiramatsu , Zechuan Chen , Jason Wang , Christophe JAILLET , Remi Bernon , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Cc: Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch to the use of mutex wrappers that provide better error checking. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/ui/browser.c | 20 ++++++++++---------- tools/perf/ui/browsers/annotate.c | 2 +- tools/perf/ui/setup.c | 5 +++-- tools/perf/ui/tui/helpline.c | 5 ++--- tools/perf/ui/tui/progress.c | 8 ++++---- tools/perf/ui/tui/setup.c | 8 ++++---- tools/perf/ui/tui/util.c | 18 +++++++++--------- tools/perf/ui/ui.h | 4 ++-- 8 files changed, 35 insertions(+), 35 deletions(-) diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c index fa5bd5c20e96..78fb01d6ad63 100644 --- a/tools/perf/ui/browser.c +++ b/tools/perf/ui/browser.c @@ -268,9 +268,9 @@ void __ui_browser__show_title(struct ui_browser *browse= r, const char *title) =20 void ui_browser__show_title(struct ui_browser *browser, const char *title) { - pthread_mutex_lock(&ui__lock); + mutex_lock(&ui__lock); __ui_browser__show_title(browser, title); - pthread_mutex_unlock(&ui__lock); + mutex_unlock(&ui__lock); } =20 int ui_browser__show(struct ui_browser *browser, const char *title, @@ -284,7 +284,7 @@ int ui_browser__show(struct ui_browser *browser, const = char *title, =20 browser->refresh_dimensions(browser); =20 - pthread_mutex_lock(&ui__lock); + mutex_lock(&ui__lock); __ui_browser__show_title(browser, title); =20 browser->title =3D title; @@ -295,16 +295,16 @@ int ui_browser__show(struct ui_browser *browser, cons= t char *title, va_end(ap); if (err > 0) ui_helpline__push(browser->helpline); - pthread_mutex_unlock(&ui__lock); + mutex_unlock(&ui__lock); return err ? 0 : -1; } =20 void ui_browser__hide(struct ui_browser *browser) { - pthread_mutex_lock(&ui__lock); + mutex_lock(&ui__lock); ui_helpline__pop(); zfree(&browser->helpline); - pthread_mutex_unlock(&ui__lock); + mutex_unlock(&ui__lock); } =20 static void ui_browser__scrollbar_set(struct ui_browser *browser) @@ -352,9 +352,9 @@ static int __ui_browser__refresh(struct ui_browser *bro= wser) =20 int ui_browser__refresh(struct ui_browser *browser) { - pthread_mutex_lock(&ui__lock); + mutex_lock(&ui__lock); __ui_browser__refresh(browser); - pthread_mutex_unlock(&ui__lock); + mutex_unlock(&ui__lock); =20 return 0; } @@ -390,10 +390,10 @@ int ui_browser__run(struct ui_browser *browser, int d= elay_secs) while (1) { off_t offset; =20 - pthread_mutex_lock(&ui__lock); + mutex_lock(&ui__lock); err =3D __ui_browser__refresh(browser); SLsmg_refresh(); - pthread_mutex_unlock(&ui__lock); + mutex_unlock(&ui__lock); if (err < 0) break; =20 diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/ann= otate.c index 44ba900828f6..b8747e8dd9ea 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -8,11 +8,11 @@ #include "../../util/hist.h" #include "../../util/sort.h" #include "../../util/map.h" +#include "../../util/mutex.h" #include "../../util/symbol.h" #include "../../util/evsel.h" #include "../../util/evlist.h" #include -#include #include #include #include diff --git a/tools/perf/ui/setup.c b/tools/perf/ui/setup.c index 700335cde618..25ded88801a3 100644 --- a/tools/perf/ui/setup.c +++ b/tools/perf/ui/setup.c @@ -1,5 +1,4 @@ // SPDX-License-Identifier: GPL-2.0 -#include #include #include =20 @@ -8,7 +7,7 @@ #include "../util/hist.h" #include "ui.h" =20 -pthread_mutex_t ui__lock =3D PTHREAD_MUTEX_INITIALIZER; +struct mutex ui__lock; void *perf_gtk_handle; int use_browser =3D -1; =20 @@ -76,6 +75,7 @@ int stdio__config_color(const struct option *opt __maybe_= unused, =20 void setup_browser(bool fallback_to_pager) { + mutex_init(&ui__lock); if (use_browser < 2 && (!isatty(1) || dump_trace)) use_browser =3D 0; =20 @@ -118,4 +118,5 @@ void exit_browser(bool wait_for_ok) default: break; } + mutex_destroy(&ui__lock); } diff --git a/tools/perf/ui/tui/helpline.c b/tools/perf/ui/tui/helpline.c index 298d6af82fdd..db4952f5990b 100644 --- a/tools/perf/ui/tui/helpline.c +++ b/tools/perf/ui/tui/helpline.c @@ -2,7 +2,6 @@ #include #include #include -#include #include #include =20 @@ -33,7 +32,7 @@ static int tui_helpline__show(const char *format, va_list= ap) int ret; static int backlog; =20 - pthread_mutex_lock(&ui__lock); + mutex_lock(&ui__lock); ret =3D vscnprintf(ui_helpline__last_msg + backlog, sizeof(ui_helpline__last_msg) - backlog, format, ap); backlog +=3D ret; @@ -45,7 +44,7 @@ static int tui_helpline__show(const char *format, va_list= ap) SLsmg_refresh(); backlog =3D 0; } - pthread_mutex_unlock(&ui__lock); + mutex_unlock(&ui__lock); =20 return ret; } diff --git a/tools/perf/ui/tui/progress.c b/tools/perf/ui/tui/progress.c index 3d74af5a7ece..71b6c8d9474f 100644 --- a/tools/perf/ui/tui/progress.c +++ b/tools/perf/ui/tui/progress.c @@ -45,7 +45,7 @@ static void tui_progress__update(struct ui_progress *p) } =20 ui__refresh_dimensions(false); - pthread_mutex_lock(&ui__lock); + mutex_lock(&ui__lock); y =3D SLtt_Screen_Rows / 2 - 2; SLsmg_set_color(0); SLsmg_draw_box(y, 0, 3, SLtt_Screen_Cols); @@ -56,7 +56,7 @@ static void tui_progress__update(struct ui_progress *p) bar =3D ((SLtt_Screen_Cols - 2) * p->curr) / p->total; SLsmg_fill_region(y, 1, 1, bar, ' '); SLsmg_refresh(); - pthread_mutex_unlock(&ui__lock); + mutex_unlock(&ui__lock); } =20 static void tui_progress__finish(void) @@ -67,12 +67,12 @@ static void tui_progress__finish(void) return; =20 ui__refresh_dimensions(false); - pthread_mutex_lock(&ui__lock); + mutex_lock(&ui__lock); y =3D SLtt_Screen_Rows / 2 - 2; SLsmg_set_color(0); SLsmg_fill_region(y, 0, 3, SLtt_Screen_Cols, ' '); SLsmg_refresh(); - pthread_mutex_unlock(&ui__lock); + mutex_unlock(&ui__lock); } =20 static struct ui_progress_ops tui_progress__ops =3D { diff --git a/tools/perf/ui/tui/setup.c b/tools/perf/ui/tui/setup.c index b1be59b4e2a4..a3b8c397c24d 100644 --- a/tools/perf/ui/tui/setup.c +++ b/tools/perf/ui/tui/setup.c @@ -29,10 +29,10 @@ void ui__refresh_dimensions(bool force) { if (force || ui__need_resize) { ui__need_resize =3D 0; - pthread_mutex_lock(&ui__lock); + mutex_lock(&ui__lock); SLtt_get_screen_size(); SLsmg_reinit_smg(); - pthread_mutex_unlock(&ui__lock); + mutex_unlock(&ui__lock); } } =20 @@ -170,10 +170,10 @@ void ui__exit(bool wait_for_ok) "Press any key...", 0); =20 SLtt_set_cursor_visibility(1); - if (!pthread_mutex_trylock(&ui__lock)) { + if (mutex_trylock(&ui__lock)) { SLsmg_refresh(); SLsmg_reset_smg(); - pthread_mutex_unlock(&ui__lock); + mutex_unlock(&ui__lock); } SLang_reset_tty(); perf_error__unregister(&perf_tui_eops); diff --git a/tools/perf/ui/tui/util.c b/tools/perf/ui/tui/util.c index 0f562e2cb1e8..3c5174854ac8 100644 --- a/tools/perf/ui/tui/util.c +++ b/tools/perf/ui/tui/util.c @@ -95,7 +95,7 @@ int ui_browser__input_window(const char *title, const cha= r *text, char *input, t =3D sep + 1; } =20 - pthread_mutex_lock(&ui__lock); + mutex_lock(&ui__lock); =20 max_len +=3D 2; nr_lines +=3D 8; @@ -125,17 +125,17 @@ int ui_browser__input_window(const char *title, const= char *text, char *input, SLsmg_write_nstring((char *)exit_msg, max_len); SLsmg_refresh(); =20 - pthread_mutex_unlock(&ui__lock); + mutex_unlock(&ui__lock); =20 x +=3D 2; len =3D 0; key =3D ui__getch(delay_secs); while (key !=3D K_TIMER && key !=3D K_ENTER && key !=3D K_ESC) { - pthread_mutex_lock(&ui__lock); + mutex_lock(&ui__lock); =20 if (key =3D=3D K_BKSPC) { if (len =3D=3D 0) { - pthread_mutex_unlock(&ui__lock); + mutex_unlock(&ui__lock); goto next_key; } SLsmg_gotorc(y, x + --len); @@ -147,7 +147,7 @@ int ui_browser__input_window(const char *title, const c= har *text, char *input, } SLsmg_refresh(); =20 - pthread_mutex_unlock(&ui__lock); + mutex_unlock(&ui__lock); =20 /* XXX more graceful overflow handling needed */ if (len =3D=3D sizeof(buf) - 1) { @@ -215,19 +215,19 @@ void __ui__info_window(const char *title, const char = *text, const char *exit_msg =20 void ui__info_window(const char *title, const char *text) { - pthread_mutex_lock(&ui__lock); + mutex_lock(&ui__lock); __ui__info_window(title, text, NULL); SLsmg_refresh(); - pthread_mutex_unlock(&ui__lock); + mutex_unlock(&ui__lock); } =20 int ui__question_window(const char *title, const char *text, const char *exit_msg, int delay_secs) { - pthread_mutex_lock(&ui__lock); + mutex_lock(&ui__lock); __ui__info_window(title, text, exit_msg); SLsmg_refresh(); - pthread_mutex_unlock(&ui__lock); + mutex_unlock(&ui__lock); return ui__getch(delay_secs); } =20 diff --git a/tools/perf/ui/ui.h b/tools/perf/ui/ui.h index 9b6fdf06e1d2..99f8d2fe9bc5 100644 --- a/tools/perf/ui/ui.h +++ b/tools/perf/ui/ui.h @@ -2,11 +2,11 @@ #ifndef _PERF_UI_H_ #define _PERF_UI_H_ 1 =20 -#include +#include "../util/mutex.h" #include #include =20 -extern pthread_mutex_t ui__lock; +extern struct mutex ui__lock; extern void *perf_gtk_handle; =20 extern int use_browser; --=20 2.37.2.672.g94769d06f0-goog From nobody Tue Apr 7 14:52:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55DEDECAAA3 for ; Fri, 26 Aug 2022 16:45:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344727AbiHZQpv (ORCPT ); Fri, 26 Aug 2022 12:45:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344599AbiHZQpP (ORCPT ); Fri, 26 Aug 2022 12:45:15 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEA032D1C2 for ; Fri, 26 Aug 2022 09:44:32 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-33dbe61eed8so33749067b3.1 for ; Fri, 26 Aug 2022 09:44:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=qbxmvtg31vAuyTVNdQtLAo3hOGlbGiTSIFXCXMg0luQ=; b=YiNeHiEQB7ZT+byLDsP6gzhAxj4qOcjGxn/TRpfE7J5uDFuiRDDfDWXwSNYZMf71ii A042tDGS3mpdCbthoHOppHcp8csVsnoDFYj8uc6vICZfkDKq6ExaozYty4czWI7Od2rm rqqyt4D2tilfzdIguqYFmEmgMQUSCyrZllDJTNi1x6gPLiUh8K3O6SXJ6cPf3yMWidsQ IITf4xjJM6BQNoO8wUGCfIeOHnAxA4zzC9sC3gH0blsa/anyMgCupQSLxprb9f+dw9kP H8qSSU3Gwc46qrepxa0bpb552AkXWP7nh6/fTVf57pE2JAc0X2yzdujYaGSYq+iMD4No Ev3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=qbxmvtg31vAuyTVNdQtLAo3hOGlbGiTSIFXCXMg0luQ=; b=Wn9pnDm9eGh998ZqAC5ohEVC2aYoizIXBcx8JWMxCn4rU8/grJBZi0mAfmCoc7v0A/ mqdL64aVMxH3FYjRNWkflgn4ORZ21VE7SgU/Jvt28u/C7EO1WYeKeuQqMtHIZTWPYIe7 JnVJ3FavI9AxBWc/aNuMEKj4IaRlXtpX6wmFA0LlXog8IWu/QY/2Uw523DUpq19GaVYB y5vMFBP6Vmz/C+A67W6MD5K/V3IL4BA8QzCFqntGjVBiPQqiPbTQFVZJ4fkNeeoM4/8a m6JVwD8HnpWw1i5uHru+hpXvzsKx+GgqxtUOxYRz0oTU7jEQhYNGtoDIWDQyqkFBEgtd ClPA== X-Gm-Message-State: ACgBeo1Z4O/ZaAaoA8UNxdioeV+ZLkV3RDsJAQD9mxExIH6Lgs6cn7cX 5yLHLY2zU39uh9fXqEs9EJFyR0Xq1WqZ X-Google-Smtp-Source: AA6agR6GfpMi/GILI+QpU1U4bPsd6a35OdbU6xCyVP9TE8SbGO9dQ/L4McelKKt6Ipqvg8tKYdc1sXGi3MSG X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:ccb1:c46b:7044:2508]) (user=irogers job=sendgmr) by 2002:a25:198b:0:b0:690:65bb:9416 with SMTP id 133-20020a25198b000000b0069065bb9416mr510164ybz.142.1661532272130; Fri, 26 Aug 2022 09:44:32 -0700 (PDT) Date: Fri, 26 Aug 2022 09:42:34 -0700 In-Reply-To: <20220826164242.43412-1-irogers@google.com> Message-Id: <20220826164242.43412-11-irogers@google.com> Mime-Version: 1.0 References: <20220826164242.43412-1-irogers@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 10/18] perf mmap: Remove unnecessary pthread.h include From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Weiguo Li , Athira Rajeev , Thomas Richter , Ravi Bangoria , Dario Petrillo , Hewenliang , yaowenbin , Wenyu Liu , Song Liu , Andrii Nakryiko , Dave Marchevsky , Leo Yan , Kim Phillips , Pavithra Gurushankar , Alexandre Truong , Quentin Monnet , William Cohen , Andres Freund , Adrian Hunter , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Colin Ian King , James Clark , Fangrui Song , Stephane Eranian , Kajol Jain , Alexey Bayduraev , Riccardo Mancini , Andi Kleen , Masami Hiramatsu , Zechuan Chen , Jason Wang , Christophe JAILLET , Remi Bernon , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Cc: Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The comment says it is for cpu_set_t which isn't used in the header. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/mmap.h | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h index cd8b0777473b..cd4ccec7f361 100644 --- a/tools/perf/util/mmap.h +++ b/tools/perf/util/mmap.h @@ -9,7 +9,6 @@ #include #include #include -#include // for cpu_set_t #ifdef HAVE_AIO_SUPPORT #include #endif --=20 2.37.2.672.g94769d06f0-goog From nobody Tue Apr 7 14:52:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D253ECAAD7 for ; Fri, 26 Aug 2022 16:46:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344833AbiHZQqY (ORCPT ); Fri, 26 Aug 2022 12:46:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344421AbiHZQpr (ORCPT ); Fri, 26 Aug 2022 12:45:47 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B36712AEB for ; Fri, 26 Aug 2022 09:44:54 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-335ff2ef600so33235747b3.18 for ; Fri, 26 Aug 2022 09:44:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=oUmOqsD5kNY3uiPBG3PIXYxy0Y1/hD+f3VoRJWg9Hxo=; b=l/qcbZC3RAYS3zFxyNjj12e+O4lcrnJ7FV4xL7kvxiHF8Mx2n3ltWCkXys/11dJGt1 ZtiUxresfuHCdlis/U5NZwCCkzDNg0/Hv2cny+WESdnGvvgCEfYe3x6jQ4dLnRR6bq1j ACcmaYPV3BGgwcp3616UOPVQmhwjCsvNK4hIKe5IM33LgXZeCFzT9f2I680xt43MkmGd I94cqzVZ31/U8I2k/8DGZcC2ePOaSWILMAP1/8YraEkEtg7WGDRTvas1iqlPTezPmt1B CgtD6rFxz42PxG8sZJiLdGA+qbsNV5SNGqePaqtEq0vEj7gxVeOxLKrb+hti3xPiYmBv PYrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=oUmOqsD5kNY3uiPBG3PIXYxy0Y1/hD+f3VoRJWg9Hxo=; b=ZylCASXG47PMK/PElNfw5IsFGdn1kvUJQsiBcaVdwZDmUpWCOyqDE7PHmEkAU5d21b S0/c81ARZ/F8uNJ+nsidR40xaNW51GfscR3/jLCVWuUH6a6Vyq4LsI7xcK4o2opEyrmi YDZBJ9XXi/EtcBBEBZisAqFo+Y6P2KNc1v2iMJUXIGeA+PpCOD8Ogrt4TbGb/hmtXt+E 4ALIwHHgwKAwPxH836L3IotG9/As69IBvDfRVeaUYDDBsQRA/ZNIlvbUVfDUwfdkXcPV qbvFKScMTPLzNu54nMSnrq9ZcrkRkc3yrFrbSLjtE+0oI3cb9KwtgfJbN57zxYNGCrUH 8iQg== X-Gm-Message-State: ACgBeo1ecipKev9Q/3Eu6pg86bsolJhIBYx02ef6jhsOjn1sixXYhZQK o8P13nJ9/noL4tUVWIdcHD38O4tWRih8 X-Google-Smtp-Source: AA6agR5vPhlcXqUl7fZdTgvl9EUqkClaIWVlom6e43OfIEN+lpPk+r9wbUuWqYy6Bba8U5JO6BpI/71vkiYR X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:ccb1:c46b:7044:2508]) (user=irogers job=sendgmr) by 2002:a25:cc4:0:b0:67c:228d:284 with SMTP id 187-20020a250cc4000000b0067c228d0284mr480023ybm.247.1661532293697; Fri, 26 Aug 2022 09:44:53 -0700 (PDT) Date: Fri, 26 Aug 2022 09:42:35 -0700 In-Reply-To: <20220826164242.43412-1-irogers@google.com> Message-Id: <20220826164242.43412-12-irogers@google.com> Mime-Version: 1.0 References: <20220826164242.43412-1-irogers@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 11/18] perf dso: Update use of pthread mutex From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Weiguo Li , Athira Rajeev , Thomas Richter , Ravi Bangoria , Dario Petrillo , Hewenliang , yaowenbin , Wenyu Liu , Song Liu , Andrii Nakryiko , Dave Marchevsky , Leo Yan , Kim Phillips , Pavithra Gurushankar , Alexandre Truong , Quentin Monnet , William Cohen , Andres Freund , Adrian Hunter , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Colin Ian King , James Clark , Fangrui Song , Stephane Eranian , Kajol Jain , Alexey Bayduraev , Riccardo Mancini , Andi Kleen , Masami Hiramatsu , Zechuan Chen , Jason Wang , Christophe JAILLET , Remi Bernon , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Cc: Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch to the use of mutex wrappers that provide better error checking. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/dso.c | 12 ++++++------ tools/perf/util/dso.h | 4 ++-- tools/perf/util/symbol.c | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 5ac13958d1bd..a9789a955403 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -795,7 +795,7 @@ dso_cache__free(struct dso *dso) struct rb_root *root =3D &dso->data.cache; struct rb_node *next =3D rb_first(root); =20 - pthread_mutex_lock(&dso->lock); + mutex_lock(&dso->lock); while (next) { struct dso_cache *cache; =20 @@ -804,7 +804,7 @@ dso_cache__free(struct dso *dso) rb_erase(&cache->rb_node, root); free(cache); } - pthread_mutex_unlock(&dso->lock); + mutex_unlock(&dso->lock); } =20 static struct dso_cache *__dso_cache__find(struct dso *dso, u64 offset) @@ -841,7 +841,7 @@ dso_cache__insert(struct dso *dso, struct dso_cache *ne= w) struct dso_cache *cache; u64 offset =3D new->offset; =20 - pthread_mutex_lock(&dso->lock); + mutex_lock(&dso->lock); while (*p !=3D NULL) { u64 end; =20 @@ -862,7 +862,7 @@ dso_cache__insert(struct dso *dso, struct dso_cache *ne= w) =20 cache =3D NULL; out: - pthread_mutex_unlock(&dso->lock); + mutex_unlock(&dso->lock); return cache; } =20 @@ -1297,7 +1297,7 @@ struct dso *dso__new_id(const char *name, struct dso_= id *id) dso->root =3D NULL; INIT_LIST_HEAD(&dso->node); INIT_LIST_HEAD(&dso->data.open_entry); - pthread_mutex_init(&dso->lock, NULL); + mutex_init(&dso->lock); refcount_set(&dso->refcnt, 1); } =20 @@ -1336,7 +1336,7 @@ void dso__delete(struct dso *dso) dso__free_a2l(dso); zfree(&dso->symsrc_filename); nsinfo__zput(dso->nsinfo); - pthread_mutex_destroy(&dso->lock); + mutex_destroy(&dso->lock); free(dso); } =20 diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index 66981c7a9a18..58d94175e714 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -2,7 +2,6 @@ #ifndef __PERF_DSO #define __PERF_DSO =20 -#include #include #include #include @@ -11,6 +10,7 @@ #include #include #include "build-id.h" +#include "mutex.h" =20 struct machine; struct map; @@ -145,7 +145,7 @@ struct dso_cache { struct auxtrace_cache; =20 struct dso { - pthread_mutex_t lock; + struct mutex lock; struct list_head node; struct rb_node rb_node; /* rbtree node sorted by long name */ struct rb_root *root; /* root of rbtree that rb_node is in */ diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index a4b22caa7c24..656d9b4dd456 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -1800,7 +1800,7 @@ int dso__load(struct dso *dso, struct map *map) } =20 nsinfo__mountns_enter(dso->nsinfo, &nsc); - pthread_mutex_lock(&dso->lock); + mutex_lock(&dso->lock); =20 /* check again under the dso->lock */ if (dso__loaded(dso)) { @@ -1964,7 +1964,7 @@ int dso__load(struct dso *dso, struct map *map) ret =3D 0; out: dso__set_loaded(dso); - pthread_mutex_unlock(&dso->lock); + mutex_unlock(&dso->lock); nsinfo__mountns_exit(&nsc); =20 return ret; --=20 2.37.2.672.g94769d06f0-goog From nobody Tue Apr 7 14:52:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1DA8ECAAA3 for ; Fri, 26 Aug 2022 16:46:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344496AbiHZQq1 (ORCPT ); Fri, 26 Aug 2022 12:46:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344675AbiHZQpu (ORCPT ); Fri, 26 Aug 2022 12:45:50 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBF9A1E3F3 for ; Fri, 26 Aug 2022 09:45:00 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-31f5960500bso33334347b3.14 for ; Fri, 26 Aug 2022 09:45:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=2S7UT5klKL+i22GMRfPejXX+Bef4p1fHRoH4GKdgyNQ=; b=YkhiZa0pWZXRusE/b3eH0WoJgNWCGi3fXEuKFR4e90ik60KaCLecXSjB/YVdsMwIYg cYxK7fVJ01yjdgsp47t+cgSx+T3djmwoDiJGQJQOHVAcQW7i/D3//qL8uynnF3EjeStm q1swoyHFJlxv9Vqu2vXs/tYgR/kqBAvRlWcOiDfmPBC2zGAF1QvnEEniMYp5BG237Bhk D1RHbx+SIN/4N619OHEeCwhqVtx5iGWl/8JqhSkroDfqajFQQk6KwwPnTVKGyFkW0SBP 1uXM1IRMKm13rkI3/VA925XJkI4J2pmuOqj50fDsPcmN8sGuOw4H9spZnl0KsC8eLzs8 QkBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=2S7UT5klKL+i22GMRfPejXX+Bef4p1fHRoH4GKdgyNQ=; b=tsFQG9M4b1RygcHPpk/8ft0dHoDr9umD8DQ7ABxyfcOVpW90lX8lHpDUAYyCSCkiWU 576G6YA+AGi7g7wVWklLMGJDCLL3z3WSiqgUCFLEiIyQLnvgooH4mplkaJw5Z/Yt/bFe BRMD9XFZ+yZCRA0qj8NTeaOnagGyoEeFktuGGGmhM8xboIoVJmph4FN2xnaYdK0h0GDt X2/Q93o8xeWnJlaJd8TqtVUxIW4+S2DLJuXCM/4ihCGVeGRMzJKNz4tSPvbubaiwInXY ORSzamQSnm0bXR5JU7ncjrdLIa5zbKOrnBdChqFp2vU9lpv/ZJvCL81GCzuyOfOrM9fH uzgw== X-Gm-Message-State: ACgBeo1OIagh3PuoNzvNkBhKsLc355C5xjQe+t9Z0nAVnU/85kup3akE E1kyAUOsu7Q0Et3kBZaNDDJ1SA2Ol/CM X-Google-Smtp-Source: AA6agR7UD/JdAmCneWRO1XmdXG2XoA5tH3E9OhQDE0HhMxCRaY0s7EW7z6ZkScb+6Cjfq3E+pKoad5NqTcCN X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:ccb1:c46b:7044:2508]) (user=irogers job=sendgmr) by 2002:a25:e783:0:b0:696:45e0:2490 with SMTP id e125-20020a25e783000000b0069645e02490mr475414ybh.593.1661532299511; Fri, 26 Aug 2022 09:44:59 -0700 (PDT) Date: Fri, 26 Aug 2022 09:42:36 -0700 In-Reply-To: <20220826164242.43412-1-irogers@google.com> Message-Id: <20220826164242.43412-13-irogers@google.com> Mime-Version: 1.0 References: <20220826164242.43412-1-irogers@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 12/18] perf annotate: Update use of pthread mutex From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Weiguo Li , Athira Rajeev , Thomas Richter , Ravi Bangoria , Dario Petrillo , Hewenliang , yaowenbin , Wenyu Liu , Song Liu , Andrii Nakryiko , Dave Marchevsky , Leo Yan , Kim Phillips , Pavithra Gurushankar , Alexandre Truong , Quentin Monnet , William Cohen , Andres Freund , Adrian Hunter , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Colin Ian King , James Clark , Fangrui Song , Stephane Eranian , Kajol Jain , Alexey Bayduraev , Riccardo Mancini , Andi Kleen , Masami Hiramatsu , Zechuan Chen , Jason Wang , Christophe JAILLET , Remi Bernon , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Cc: Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch to the use of mutex wrappers that provide better error checking. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-top.c | 14 +++++++------- tools/perf/ui/browsers/annotate.c | 10 +++++----- tools/perf/util/annotate.c | 13 ++++++------- tools/perf/util/annotate.h | 4 ++-- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 14e60f6f219c..b96bb9a23ac0 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -136,10 +136,10 @@ static int perf_top__parse_source(struct perf_top *to= p, struct hist_entry *he) } =20 notes =3D symbol__annotation(sym); - pthread_mutex_lock(¬es->lock); + mutex_lock(¬es->lock); =20 if (!symbol__hists(sym, top->evlist->core.nr_entries)) { - pthread_mutex_unlock(¬es->lock); + mutex_unlock(¬es->lock); pr_err("Not enough memory for annotating '%s' symbol!\n", sym->name); sleep(1); @@ -155,7 +155,7 @@ static int perf_top__parse_source(struct perf_top *top,= struct hist_entry *he) pr_err("Couldn't annotate %s: %s\n", sym->name, msg); } =20 - pthread_mutex_unlock(¬es->lock); + mutex_unlock(¬es->lock); return err; } =20 @@ -208,12 +208,12 @@ static void perf_top__record_precise_ip(struct perf_t= op *top, =20 notes =3D symbol__annotation(sym); =20 - if (pthread_mutex_trylock(¬es->lock)) + if (!mutex_trylock(¬es->lock)) return; =20 err =3D hist_entry__inc_addr_samples(he, sample, evsel, ip); =20 - pthread_mutex_unlock(¬es->lock); + mutex_unlock(¬es->lock); =20 if (unlikely(err)) { /* @@ -250,7 +250,7 @@ static void perf_top__show_details(struct perf_top *top) symbol =3D he->ms.sym; notes =3D symbol__annotation(symbol); =20 - pthread_mutex_lock(¬es->lock); + mutex_lock(¬es->lock); =20 symbol__calc_percent(symbol, evsel); =20 @@ -271,7 +271,7 @@ static void perf_top__show_details(struct perf_top *top) if (more !=3D 0) printf("%d lines not displayed, maybe increase display entries [e]\n", m= ore); out_unlock: - pthread_mutex_unlock(¬es->lock); + mutex_unlock(¬es->lock); } =20 static void perf_top__resort_hists(struct perf_top *t) diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/ann= otate.c index b8747e8dd9ea..9bc1076374ff 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -319,7 +319,7 @@ static void annotate_browser__calc_percent(struct annot= ate_browser *browser, =20 browser->entries =3D RB_ROOT; =20 - pthread_mutex_lock(¬es->lock); + mutex_lock(¬es->lock); =20 symbol__calc_percent(sym, evsel); =20 @@ -348,7 +348,7 @@ static void annotate_browser__calc_percent(struct annot= ate_browser *browser, } disasm_rb_tree__insert(browser, &pos->al); } - pthread_mutex_unlock(¬es->lock); + mutex_unlock(¬es->lock); =20 browser->curr_hot =3D rb_last(&browser->entries); } @@ -474,10 +474,10 @@ static bool annotate_browser__callq(struct annotate_b= rowser *browser, } =20 notes =3D symbol__annotation(dl->ops.target.sym); - pthread_mutex_lock(¬es->lock); + mutex_lock(¬es->lock); =20 if (!symbol__hists(dl->ops.target.sym, evsel->evlist->core.nr_entries)) { - pthread_mutex_unlock(¬es->lock); + mutex_unlock(¬es->lock); ui__warning("Not enough memory for annotating '%s' symbol!\n", dl->ops.target.sym->name); return true; @@ -486,7 +486,7 @@ static bool annotate_browser__callq(struct annotate_bro= wser *browser, target_ms.maps =3D ms->maps; target_ms.map =3D ms->map; target_ms.sym =3D dl->ops.target.sym; - pthread_mutex_unlock(¬es->lock); + mutex_unlock(¬es->lock); symbol__tui_annotate(&target_ms, evsel, hbt, browser->opts); sym_title(ms->sym, ms->map, title, sizeof(title), browser->opts->percent_= type); ui_browser__show_title(&browser->b, title); diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 2c6a485c3de5..9d7dd6489a05 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -35,7 +35,6 @@ #include "arch/common.h" #include "namespaces.h" #include -#include #include #include #include @@ -821,7 +820,7 @@ void symbol__annotate_zero_histograms(struct symbol *sy= m) { struct annotation *notes =3D symbol__annotation(sym); =20 - pthread_mutex_lock(¬es->lock); + mutex_lock(¬es->lock); if (notes->src !=3D NULL) { memset(notes->src->histograms, 0, notes->src->nr_histograms * notes->src->sizeof_sym_hist); @@ -829,7 +828,7 @@ void symbol__annotate_zero_histograms(struct symbol *sy= m) memset(notes->src->cycles_hist, 0, symbol__size(sym) * sizeof(struct cyc_hist)); } - pthread_mutex_unlock(¬es->lock); + mutex_unlock(¬es->lock); } =20 static int __symbol__account_cycles(struct cyc_hist *ch, @@ -1086,7 +1085,7 @@ void annotation__compute_ipc(struct annotation *notes= , size_t size) notes->hit_insn =3D 0; notes->cover_insn =3D 0; =20 - pthread_mutex_lock(¬es->lock); + mutex_lock(¬es->lock); for (offset =3D size - 1; offset >=3D 0; --offset) { struct cyc_hist *ch; =20 @@ -1105,7 +1104,7 @@ void annotation__compute_ipc(struct annotation *notes= , size_t size) notes->have_cycles =3D true; } } - pthread_mutex_unlock(¬es->lock); + mutex_unlock(¬es->lock); } =20 int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_= sample *sample, @@ -1258,13 +1257,13 @@ int disasm_line__scnprintf(struct disasm_line *dl, = char *bf, size_t size, bool r =20 void annotation__init(struct annotation *notes) { - pthread_mutex_init(¬es->lock, NULL); + mutex_init(¬es->lock); } =20 void annotation__exit(struct annotation *notes) { annotated_source__delete(notes->src); - pthread_mutex_destroy(¬es->lock); + mutex_destroy(¬es->lock); } =20 static void annotation_line__add(struct annotation_line *al, struct list_h= ead *head) diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 986f2bbe4870..3cbd883e4d7a 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -8,9 +8,9 @@ #include #include #include -#include #include #include "symbol_conf.h" +#include "mutex.h" #include "spark.h" =20 struct hist_browser_timer; @@ -273,7 +273,7 @@ struct annotated_source { }; =20 struct annotation { - pthread_mutex_t lock; + struct mutex lock; u64 max_coverage; u64 start; u64 hit_cycles; --=20 2.37.2.672.g94769d06f0-goog From nobody Tue Apr 7 14:52:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E93EECAAA3 for ; Fri, 26 Aug 2022 16:46:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344802AbiHZQqn (ORCPT ); Fri, 26 Aug 2022 12:46:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344831AbiHZQp7 (ORCPT ); Fri, 26 Aug 2022 12:45:59 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E5B4248D7 for ; Fri, 26 Aug 2022 09:45:07 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-32a115757b6so33662487b3.13 for ; Fri, 26 Aug 2022 09:45:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=P+FyhU2B/YN3/TrA4dmeuxuHGACyeB5O/ib05glm4b0=; b=medTLeaDsm5+Opq4aXiy32t1/beJm7t0X/USeUrahXOriOH3gsk4fG41vEQW4R2/AM byjizPt/bfKhoaDGijCt0LUaz7PbUQVv5y9flJKZOEVELXd3TIPjdCHMSnI8DL15HUKJ gzieyUfBzTDegVhgcQtGOfHHdVdsLrnkDUZHYOoJP/r0RzdO/8F4Fdy0H8usgOhXVOwf FJf1oIRukKfZ9sOSXvqN3LazFyXSns+slySkXXUxzf/m3mPoDzd7W+PJ9nZ9WBmY//oa FKGGze/1yR5mZNZ6T3H5l9nStvUd/69g5wdh/alCD166DSnvVTK0Epw9AZkYcuC7JI18 ylIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=P+FyhU2B/YN3/TrA4dmeuxuHGACyeB5O/ib05glm4b0=; b=meMlnejjoj52V8ZGBxzQTaqZS9wTw+nX+eMHYA0+DjRGOkYBU/MmcNRK2R048B9T7U AA4IAcg/fBYxpgUJR5qt4MxUqGduIoSwgmAzKG1CAUq+1Mwj5eU/VmQXCz70lbyFrN0V FZAIQ2kKMnuDgB80FJfhdcSTsUiPy9opNJmtFtMDVMDTV9L2wIeoqgUd7PSxjTlakne1 N5r91NZiwAK/R2Sz68+ybCZP5zrZJ8G89J+bicJpipIkasxBC/8wt4k74JmIYoQQm98X qUVSNOAbydEjjbMCI6KevYBQ3LT8mr5CJRJ+XOfujDAl2fJtLBsDKlC/58e8HUxMcQt6 dpuQ== X-Gm-Message-State: ACgBeo0cwhQrCE7xKeiLMey/vfu5bLKcd7mLd+eracAR2btvY491ku7M kbzR15RdV5qweiLlRXY+0+fSOPGk7ZCa X-Google-Smtp-Source: AA6agR4XN14X3kZFhyH9PFbRRm71ehh2clkMuysFZbGu+P2MvUHCWkzVymsk8OFWxzJ5tiSlZECqk9i1UQQc X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:ccb1:c46b:7044:2508]) (user=irogers job=sendgmr) by 2002:a05:6902:1442:b0:696:4962:a73 with SMTP id a2-20020a056902144200b0069649620a73mr513913ybv.386.1661532306375; Fri, 26 Aug 2022 09:45:06 -0700 (PDT) Date: Fri, 26 Aug 2022 09:42:37 -0700 In-Reply-To: <20220826164242.43412-1-irogers@google.com> Message-Id: <20220826164242.43412-14-irogers@google.com> Mime-Version: 1.0 References: <20220826164242.43412-1-irogers@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 13/18] perf top: Update use of pthread mutex From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Weiguo Li , Athira Rajeev , Thomas Richter , Ravi Bangoria , Dario Petrillo , Hewenliang , yaowenbin , Wenyu Liu , Song Liu , Andrii Nakryiko , Dave Marchevsky , Leo Yan , Kim Phillips , Pavithra Gurushankar , Alexandre Truong , Quentin Monnet , William Cohen , Andres Freund , Adrian Hunter , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Colin Ian King , James Clark , Fangrui Song , Stephane Eranian , Kajol Jain , Alexey Bayduraev , Riccardo Mancini , Andi Kleen , Masami Hiramatsu , Zechuan Chen , Jason Wang , Christophe JAILLET , Remi Bernon , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Cc: Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch to the use of mutex wrappers that provide better error checking. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-top.c | 18 +++++++++--------- tools/perf/util/top.h | 5 +++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index b96bb9a23ac0..5af3347eedc1 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -893,10 +893,10 @@ static void perf_top__mmap_read_idx(struct perf_top *= top, int idx) perf_mmap__consume(&md->core); =20 if (top->qe.rotate) { - pthread_mutex_lock(&top->qe.mutex); + mutex_lock(&top->qe.mutex); top->qe.rotate =3D false; - pthread_cond_signal(&top->qe.cond); - pthread_mutex_unlock(&top->qe.mutex); + cond_signal(&top->qe.cond); + mutex_unlock(&top->qe.mutex); } } =20 @@ -1100,10 +1100,10 @@ static void *process_thread(void *arg) =20 out =3D rotate_queues(top); =20 - pthread_mutex_lock(&top->qe.mutex); + mutex_lock(&top->qe.mutex); top->qe.rotate =3D true; - pthread_cond_wait(&top->qe.cond, &top->qe.mutex); - pthread_mutex_unlock(&top->qe.mutex); + cond_wait(&top->qe.cond, &top->qe.mutex); + mutex_unlock(&top->qe.mutex); =20 if (ordered_events__flush(out, OE_FLUSH__TOP)) pr_err("failed to process events\n"); @@ -1217,8 +1217,8 @@ static void init_process_thread(struct perf_top *top) ordered_events__set_copy_on_queue(&top->qe.data[0], true); ordered_events__set_copy_on_queue(&top->qe.data[1], true); top->qe.in =3D &top->qe.data[0]; - pthread_mutex_init(&top->qe.mutex, NULL); - pthread_cond_init(&top->qe.cond, NULL); + mutex_init(&top->qe.mutex); + cond_init(&top->qe.cond); } =20 static int __cmd_top(struct perf_top *top) @@ -1349,7 +1349,7 @@ static int __cmd_top(struct perf_top *top) out_join: pthread_join(thread, NULL); out_join_thread: - pthread_cond_signal(&top->qe.cond); + cond_signal(&top->qe.cond); pthread_join(thread_process, NULL); return ret; } diff --git a/tools/perf/util/top.h b/tools/perf/util/top.h index 1c2c0a838430..a8b0d79bd96c 100644 --- a/tools/perf/util/top.h +++ b/tools/perf/util/top.h @@ -5,6 +5,7 @@ #include "tool.h" #include "evswitch.h" #include "annotate.h" +#include "mutex.h" #include "ordered-events.h" #include "record.h" #include @@ -53,8 +54,8 @@ struct perf_top { struct ordered_events *in; struct ordered_events data[2]; bool rotate; - pthread_mutex_t mutex; - pthread_cond_t cond; + struct mutex mutex; + struct cond cond; } qe; }; =20 --=20 2.37.2.672.g94769d06f0-goog From nobody Tue Apr 7 14:52:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74525ECAAA3 for ; Fri, 26 Aug 2022 16:46:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344821AbiHZQqs (ORCPT ); Fri, 26 Aug 2022 12:46:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344816AbiHZQqR (ORCPT ); Fri, 26 Aug 2022 12:46:17 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E50A6275DC for ; Fri, 26 Aug 2022 09:45:16 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-33dce8cae71so33596497b3.8 for ; Fri, 26 Aug 2022 09:45:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=P/ieWH4vlM/8h5LESv9iguXPsGFEK+Ic1rlbsC/GugE=; b=izKuMNaT1OBd/uCYzdvuUjEkJFXVDOPZrd+ZHfYyTXDR6ldY/aTFaM75nG8Au/gJ+u OsVKLUHvG+lUblgaeDbJ7FVInI7L97a5Ib6F/c9+0jFbMPFgX6UeMhdPNtETwMs6viDN UpY6+LLumhbuz0Ek634XZr+0Qm4MUyir30u7J/RS7aY0eSB/W2JBOrkhXvFDaNAfoKED Tt2LRLvbbqGMP3oSv8JDOjEy+H17r9Z2ESnpevGbPit+QwL1+dcAW4UZvkhNMZF6wUq/ cLcEpuNESV++aK0Pl9SVropz/2tqIC4F4t0CKWrS8cYnCShWDEAnhsTu2VCXoaq5W+qU Hytw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=P/ieWH4vlM/8h5LESv9iguXPsGFEK+Ic1rlbsC/GugE=; b=cPJVTkhz2cpsDlTKjvzwYNLNCLqAIEzH9sEotVRezGXJ1E28kF6ZSoEABWWqEcyQjP DNrmuVRvfqwyvI5loWjOd9iWvg7svpH962IHFaU6jSka+kShcCFv467mK9aAX3IbKL+E 64VScfHQqPxu/JwOJ90Z/EvY6/CXOljC8cp+97GYj3PctBr5dO4J4V4XrvWkvIKBKwdV RmRXTh0sFSBqlTSx7egaENrEQlLR0Wh8rsPne+IHg4wdO3gmf5ujV+cm1qiuACkelGtR rKQMkt6DpJhZREUVhqm6EZRxpKUcdHA1k3ug4D2Hd5M1o279x9N43n1Us10q4m2bEoDD dHvw== X-Gm-Message-State: ACgBeo1IxgIswjyAIrPPJC4VN+f6+5VcF/scnEChjDAsh48YD/Ts3QgP ydXG9DCJEK8oX6HagB2zYP2EoXn4XuJl X-Google-Smtp-Source: AA6agR7np94rG4awV3eXa8XCOc67AhRQf42xpkRPMpvE1bBB9l7bmkbyLJ+5gTzEUA3V38h3QZFbnPKhuX5X X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:ccb1:c46b:7044:2508]) (user=irogers job=sendgmr) by 2002:a05:6902:1544:b0:696:69c7:2431 with SMTP id r4-20020a056902154400b0069669c72431mr469630ybu.385.1661532315319; Fri, 26 Aug 2022 09:45:15 -0700 (PDT) Date: Fri, 26 Aug 2022 09:42:38 -0700 In-Reply-To: <20220826164242.43412-1-irogers@google.com> Message-Id: <20220826164242.43412-15-irogers@google.com> Mime-Version: 1.0 References: <20220826164242.43412-1-irogers@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 14/18] perf dso: Hold lock when accessing nsinfo From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Weiguo Li , Athira Rajeev , Thomas Richter , Ravi Bangoria , Dario Petrillo , Hewenliang , yaowenbin , Wenyu Liu , Song Liu , Andrii Nakryiko , Dave Marchevsky , Leo Yan , Kim Phillips , Pavithra Gurushankar , Alexandre Truong , Quentin Monnet , William Cohen , Andres Freund , Adrian Hunter , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Colin Ian King , James Clark , Fangrui Song , Stephane Eranian , Kajol Jain , Alexey Bayduraev , Riccardo Mancini , Andi Kleen , Masami Hiramatsu , Zechuan Chen , Jason Wang , Christophe JAILLET , Remi Bernon , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Cc: Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There may be threads racing to update dso->nsinfo: https://lore.kernel.org/linux-perf-users/CAP-5=3DfWZH20L4kv-BwVtGLwR=3DEm3A= OOT+Q4QGivvQuYn5AsPRg@mail.gmail.com/ Holding the dso->lock avoids use-after-free, memory leaks and other such bugs. Apply the fix in: https://lore.kernel.org/linux-perf-users/20211118193714.2293728-1-irogers@g= oogle.com/ of there being a missing nsinfo__put now that the accesses are data race free. Fixes test "Lookup mmap thread" when compiled with address sanitizer. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-inject.c | 4 ++++ tools/perf/util/annotate.c | 2 ++ tools/perf/util/build-id.c | 12 +++++++++--- tools/perf/util/dso.c | 7 ++++++- tools/perf/util/map.c | 3 +++ tools/perf/util/probe-event.c | 3 +++ tools/perf/util/symbol.c | 2 +- 7 files changed, 28 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 8ec955402488..e254f18986f7 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -436,8 +436,10 @@ static struct dso *findnew_dso(int pid, int tid, const= char *filename, } =20 if (dso) { + mutex_lock(&dso->lock); nsinfo__put(dso->nsinfo); dso->nsinfo =3D nsi; + mutex_unlock(&dso->lock); } else nsinfo__put(nsi); =20 @@ -620,6 +622,7 @@ static int dso__read_build_id(struct dso *dso) if (dso->has_build_id) return 0; =20 + mutex_lock(&dso->lock); nsinfo__mountns_enter(dso->nsinfo, &nsc); if (filename__read_build_id(dso->long_name, &dso->bid) > 0) dso->has_build_id =3D true; @@ -633,6 +636,7 @@ static int dso__read_build_id(struct dso *dso) free(new_name); } nsinfo__mountns_exit(&nsc); + mutex_unlock(&dso->lock); =20 return dso->has_build_id ? 0 : -1; } diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 9d7dd6489a05..5bc63c9e0324 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1697,6 +1697,7 @@ static int dso__disassemble_filename(struct dso *dso,= char *filename, size_t fil */ __symbol__join_symfs(filename, filename_size, dso->long_name); =20 + mutex_lock(&dso->lock); if (access(filename, R_OK) && errno =3D=3D ENOENT && dso->nsinfo) { char *new_name =3D filename_with_chroot(dso->nsinfo->pid, filename); @@ -1705,6 +1706,7 @@ static int dso__disassemble_filename(struct dso *dso,= char *filename, size_t fil free(new_name); } } + mutex_unlock(&dso->lock); } =20 free(build_id_path); diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index ec18ed5caf3e..a839b30c981b 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -898,11 +898,15 @@ static int filename__read_build_id_ns(const char *fil= ename, static bool dso__build_id_mismatch(struct dso *dso, const char *name) { struct build_id bid; + bool ret =3D false; =20 - if (filename__read_build_id_ns(name, &bid, dso->nsinfo) < 0) - return false; + mutex_lock(&dso->lock); + if (filename__read_build_id_ns(name, &bid, dso->nsinfo) >=3D 0) + ret =3D !dso__build_id_equal(dso, &bid); =20 - return !dso__build_id_equal(dso, &bid); + mutex_unlock(&dso->lock); + + return ret; } =20 static int dso__cache_build_id(struct dso *dso, struct machine *machine, @@ -941,8 +945,10 @@ static int dso__cache_build_id(struct dso *dso, struct= machine *machine, if (!is_kallsyms && dso__build_id_mismatch(dso, name)) goto out_free; =20 + mutex_lock(&dso->lock); ret =3D build_id_cache__add_b(&dso->bid, name, dso->nsinfo, is_kallsyms, is_vdso, proper_name, root_dir); + mutex_unlock(&dso->lock); out_free: free(allocated_name); return ret; diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index a9789a955403..f1a14c0ad26d 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -501,6 +501,7 @@ static int __open_dso(struct dso *dso, struct machine *= machine) if (!name) return -ENOMEM; =20 + mutex_lock(&dso->lock); if (machine) root_dir =3D machine->root_dir; =20 @@ -541,6 +542,7 @@ static int __open_dso(struct dso *dso, struct machine *= machine) unlink(name); =20 out: + mutex_unlock(&dso->lock); free(name); return fd; } @@ -559,8 +561,11 @@ static int open_dso(struct dso *dso, struct machine *m= achine) int fd; struct nscookie nsc; =20 - if (dso->binary_type !=3D DSO_BINARY_TYPE__BUILD_ID_CACHE) + if (dso->binary_type !=3D DSO_BINARY_TYPE__BUILD_ID_CACHE) { + mutex_lock(&dso->lock); nsinfo__mountns_enter(dso->nsinfo, &nsc); + mutex_unlock(&dso->lock); + } fd =3D __open_dso(dso, machine); if (dso->binary_type !=3D DSO_BINARY_TYPE__BUILD_ID_CACHE) nsinfo__mountns_exit(&nsc); diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index e0aa4a254583..f3a3d9b3a40d 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -181,7 +181,10 @@ struct map *map__new(struct machine *machine, u64 star= t, u64 len, if (!(prot & PROT_EXEC)) dso__set_loaded(dso); } + mutex_lock(&dso->lock); + nsinfo__put(dso->nsinfo); dso->nsinfo =3D nsi; + mutex_unlock(&dso->lock); =20 if (build_id__is_defined(bid)) { dso__set_build_id(dso, bid); diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 785246ff4179..0c24bc7afbca 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -29,6 +29,7 @@ #include "color.h" #include "map.h" #include "maps.h" +#include "mutex.h" #include "symbol.h" #include #include "trace-event.h" /* For __maybe_unused */ @@ -180,8 +181,10 @@ struct map *get_target_map(const char *target, struct = nsinfo *nsi, bool user) =20 map =3D dso__new_map(target); if (map && map->dso) { + mutex_lock(&map->dso->lock); nsinfo__put(map->dso->nsinfo); map->dso->nsinfo =3D nsinfo__get(nsi); + mutex_unlock(&map->dso->lock); } return map; } else { diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 656d9b4dd456..a3a165ae933a 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -1791,6 +1791,7 @@ int dso__load(struct dso *dso, struct map *map) char newmapname[PATH_MAX]; const char *map_path =3D dso->long_name; =20 + mutex_lock(&dso->lock); perfmap =3D strncmp(dso->name, "/tmp/perf-", 10) =3D=3D 0; if (perfmap) { if (dso->nsinfo && (dso__find_perf_map(newmapname, @@ -1800,7 +1801,6 @@ int dso__load(struct dso *dso, struct map *map) } =20 nsinfo__mountns_enter(dso->nsinfo, &nsc); - mutex_lock(&dso->lock); =20 /* check again under the dso->lock */ if (dso__loaded(dso)) { --=20 2.37.2.672.g94769d06f0-goog From nobody Tue Apr 7 14:52:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DC2BECAAD6 for ; Fri, 26 Aug 2022 16:47:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344842AbiHZQrF (ORCPT ); Fri, 26 Aug 2022 12:47:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344717AbiHZQqU (ORCPT ); Fri, 26 Aug 2022 12:46:20 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7FC527CE4 for ; Fri, 26 Aug 2022 09:45:22 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-33f8988daecso24994937b3.12 for ; Fri, 26 Aug 2022 09:45:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=O8Qr4u2Ex+vGQYNxrAO3WvQT1T8a47855lT6UekNsbk=; b=akb+9dSb467cjd2G9Apq4JRbepx097HVchmRbRbAH+zwl1beW1vL1eBXVIRJ+8ulQl z61OTSCYkQBJJuGHOX/DqMTSBgtjdvdFPWd6NxEV8vQMKPDmE1zLMCBiMFgYpbUKyH++ rQCbXuxVP2vPL8CBkwM+4+bvtsGbU61t7t5I0uXChM8FaAOyeGk8mwYEO5hwOsksI2MP ywmrudXhK4qZAXgs92mlQq8hxj5ZR2rwyfLIvFtCWWBLNMFWoL2K05OQaIuuJ1zgWjPH HL2TNXtvTFmZIL4XVHJRMFdVwQfwY4yDaj/dtqUl89/DWhIUq9ln4SjNwBmXPBB1aoZB G1MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=O8Qr4u2Ex+vGQYNxrAO3WvQT1T8a47855lT6UekNsbk=; b=omwSu8wj+qw5Y+K4fW/RMdrWfBhsFYpW7rxkzI7OAQP6leq1CXWwnuffy1SDYMEj7g GKQ5yp1iLRtu+8wnqMSYwXJHHBbaiWhpQ8rg0xl2ACxU/LTgzXpoB4WeMZmgoU4+ZaYW tuFm28A1wLyx2gckRh3CuMk+wAkSlQekOLTfrJUZWpQJlYtoWU9PmnxQdblOWWsnJ3G6 2LtYseixOdPAcak3mo4Ua0o0BrRujCTPKaEEgB8t1vXJ8oHA2sh/HaxMC3Ct3ibi0Zrj iWJQnkpCuQ+fcOzJsE2eCoRTOwrxRd6NtUgH+k1WC5rPyPNYz9qMmCxOviqb7mfO+A/V 88cg== X-Gm-Message-State: ACgBeo3uOpugPuLoKVOKETPErAPAsuOdmaRTtxwjxVVz5yoYeZQbxOpc FOsg1vNu4leECQnNZa1rsU6KM8G6tOv1 X-Google-Smtp-Source: AA6agR5R064ML6FigNicUfVaFAIqgVvCzSA3QYsjZDwwqZufirr829wsg6kAlryDwTanAFH/voDz0TZVwXeo X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:ccb1:c46b:7044:2508]) (user=irogers job=sendgmr) by 2002:a81:4507:0:b0:33d:d0a5:aaf4 with SMTP id s7-20020a814507000000b0033dd0a5aaf4mr621623ywa.150.1661532321892; Fri, 26 Aug 2022 09:45:21 -0700 (PDT) Date: Fri, 26 Aug 2022 09:42:39 -0700 In-Reply-To: <20220826164242.43412-1-irogers@google.com> Message-Id: <20220826164242.43412-16-irogers@google.com> Mime-Version: 1.0 References: <20220826164242.43412-1-irogers@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 15/18] perf mutex: Add thread safety annotations From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Weiguo Li , Athira Rajeev , Thomas Richter , Ravi Bangoria , Dario Petrillo , Hewenliang , yaowenbin , Wenyu Liu , Song Liu , Andrii Nakryiko , Dave Marchevsky , Leo Yan , Kim Phillips , Pavithra Gurushankar , Alexandre Truong , Quentin Monnet , William Cohen , Andres Freund , Adrian Hunter , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Colin Ian King , James Clark , Fangrui Song , Stephane Eranian , Kajol Jain , Alexey Bayduraev , Riccardo Mancini , Andi Kleen , Masami Hiramatsu , Zechuan Chen , Jason Wang , Christophe JAILLET , Remi Bernon , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Cc: Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add thread safety annotations to struct mutex so that when compiled with clang's -Wthread-safety warnings are generated for erroneous lock patterns. NO_THREAD_SAFETY_ANALYSIS is needed for mutex_lock/mutex_unlock as the analysis doesn't under pthread calls. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/mutex.c | 2 ++ tools/perf/util/mutex.h | 70 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 67 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/mutex.c b/tools/perf/util/mutex.c index 5029237164e5..bca7f0717f35 100644 --- a/tools/perf/util/mutex.c +++ b/tools/perf/util/mutex.c @@ -50,11 +50,13 @@ void mutex_destroy(struct mutex *mtx) } =20 void mutex_lock(struct mutex *mtx) + NO_THREAD_SAFETY_ANALYSIS { CHECK_ERR(pthread_mutex_lock(&mtx->lock)); } =20 void mutex_unlock(struct mutex *mtx) + NO_THREAD_SAFETY_ANALYSIS { CHECK_ERR(pthread_mutex_unlock(&mtx->lock)); } diff --git a/tools/perf/util/mutex.h b/tools/perf/util/mutex.h index cfff32a902d9..5677f92ca6ed 100644 --- a/tools/perf/util/mutex.h +++ b/tools/perf/util/mutex.h @@ -5,11 +5,71 @@ #include #include =20 +/* + * A function-like feature checking macro that is a wrapper around + * `__has_attribute`, which is defined by GCC 5+ and Clang and evaluates t= o a + * nonzero constant integer if the attribute is supported or 0 if not. + */ +#ifdef __has_attribute +#define HAVE_ATTRIBUTE(x) __has_attribute(x) +#else +#define HAVE_ATTRIBUTE(x) 0 +#endif + +#if HAVE_ATTRIBUTE(guarded_by) && HAVE_ATTRIBUTE(pt_guarded_by) && \ + HAVE_ATTRIBUTE(lockable) && HAVE_ATTRIBUTE(exclusive_lock_function) && \ + HAVE_ATTRIBUTE(exclusive_trylock_function) && HAVE_ATTRIBUTE(exclusive_lo= cks_required) && \ + HAVE_ATTRIBUTE(no_thread_safety_analysis) + +/* Documents if a shared field or global variable needs to be protected by= a mutex. */ +#define GUARDED_BY(x) __attribute__((guarded_by(x))) + +/* + * Documents if the memory location pointed to by a pointer should be guar= ded by + * a mutex when dereferencing the pointer. + */ +#define PT_GUARDED_BY(x) __attribute__((pt_guarded_by(x))) + +/* Documents if a type is a lockable type. */ +#define LOCKABLE __attribute__((capability("lockable"))) + +/* Documents functions that acquire a lock in the body of a function, and = do not release it. */ +#define EXCLUSIVE_LOCK_FUNCTION(...) __attribute__((exclusive_lock_functi= on(__VA_ARGS__))) + +/* + * Documents functions that expect a lock to be held on entry to the funct= ion, + * and release it in the body of the function. + */ +#define UNLOCK_FUNCTION(...) __attribute__((unlock_function(__VA_ARGS__))) + +/* Documents functions that try to acquire a lock, and return success or f= ailure. */ +#define EXCLUSIVE_TRYLOCK_FUNCTION(...) \ + __attribute__((exclusive_trylock_function(__VA_ARGS__))) + +/* Documents a function that expects a mutex to be held prior to entry. */ +#define EXCLUSIVE_LOCKS_REQUIRED(...) __attribute__((exclusive_locks_requi= red(__VA_ARGS__))) + +/* Turns off thread safety checking within the body of a particular functi= on. */ +#define NO_THREAD_SAFETY_ANALYSIS __attribute__((no_thread_safety_analysis= )) + +#else + +#define GUARDED_BY(x) +#define PT_GUARDED_BY(x) +#define LOCKABLE +#define EXCLUSIVE_LOCK_FUNCTION(...) +#define UNLOCK_FUNCTION(...) +#define EXCLUSIVE_TRYLOCK_FUNCTION(...) +#define EXCLUSIVE_LOCKS_REQUIRED(...) +#define NO_THREAD_SAFETY_ANALYSIS + +#endif + /* * A wrapper around the mutex implementation that allows perf to error che= ck * usage, etc. */ -struct mutex { +struct LOCKABLE mutex { pthread_mutex_t lock; }; =20 @@ -27,10 +87,10 @@ void mutex_init(struct mutex *mtx); void mutex_init_pshared(struct mutex *mtx); void mutex_destroy(struct mutex *mtx); =20 -void mutex_lock(struct mutex *mtx); -void mutex_unlock(struct mutex *mtx); +void mutex_lock(struct mutex *mtx) EXCLUSIVE_LOCK_FUNCTION(*mtx); +void mutex_unlock(struct mutex *mtx) UNLOCK_FUNCTION(*mtx); /* Tries to acquire the lock and returns true on success. */ -bool mutex_trylock(struct mutex *mtx); +bool mutex_trylock(struct mutex *mtx) EXCLUSIVE_TRYLOCK_FUNCTION(true, *mt= x); =20 /* Default initialize the cond struct. */ void cond_init(struct cond *cnd); @@ -41,7 +101,7 @@ void cond_init(struct cond *cnd); void cond_init_pshared(struct cond *cnd); void cond_destroy(struct cond *cnd); =20 -void cond_wait(struct cond *cnd, struct mutex *mtx); +void cond_wait(struct cond *cnd, struct mutex *mtx) EXCLUSIVE_LOCKS_REQUIR= ED(mtx); void cond_signal(struct cond *cnd); void cond_broadcast(struct cond *cnd); =20 --=20 2.37.2.672.g94769d06f0-goog From nobody Tue Apr 7 14:52:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71FEBECAAA6 for ; Fri, 26 Aug 2022 16:47:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344835AbiHZQrM (ORCPT ); Fri, 26 Aug 2022 12:47:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344740AbiHZQqX (ORCPT ); Fri, 26 Aug 2022 12:46:23 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D93803340D for ; Fri, 26 Aug 2022 09:45:28 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-33dc390f26cso33356427b3.9 for ; Fri, 26 Aug 2022 09:45:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=qVZGUrjNaf+uaIklV22hg50RBgn+7V45ToWO7LHu6z0=; b=KHJFy5APhi23hCB5yhBJbIt9QnW9DPxdVtwh9gL5fbHIYRHK3POGYS46+q2HkyOStC 76K6TkDIM4sJYciYCZapgV+g78ZVpk+J4MwS4SdpMuSUyUj1+4fLMR5afhfyFuWXTpmU ZDI89zMH1X54UbxfpgRHoJ8NKFjReW0C17bEAFMiD2YuZo9/MlfTIgj6OoCs0J/6Qs9v Pvk6mvDm/iNVPGZ6P+HTAHuE75ABfGTMz4NSGJZyWLpb+bOxLLiomAK2i4UP5IPDIORg 2nD82jqta63p0XiFw5/8qAyBlH+7+B9IyCPQLmSFDJElrJtkcY+fpxPVGMM09tEFQx7F DJ1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=qVZGUrjNaf+uaIklV22hg50RBgn+7V45ToWO7LHu6z0=; b=PK6Qftd1dDj4uI6o1OSfe0RaOzR4Bb75lGm9Vxz889AtL4hXo/2unRNAy93lAMqn02 UFRjRfmRHzleY0av+nHRgU9AnJnSi3dQzgH/+bIzJTPAAvYi2vm+Ut+EfyJ8WEMkjxJ9 Hi9OLbTpY7dWIEApae6f7zacVmFxbDk4aroWRLMrfuj7WUIEdo1FPOH4r8tDTe7FEE8n i7RkqXdHa9U+7Srznr8NcMlZPl7ZsfrgkEgbHpjEYGH3T7VkJ40RTDtdPpwjZvc7oSOu cHxHvey0wksYAGIg/F45nXlSbMu49+f+DljvLx5zzJycq4Ws1AfKKeYxyAYyoGx4V22B 4YSQ== X-Gm-Message-State: ACgBeo1tJ2RLeMZZxd74NIcGgS4w6PL0cOQ+FPdFDcoDi9PMvZNBGizx E/BVYArUYjzaGNJ3BNrQCxpzCt2eQv5v X-Google-Smtp-Source: AA6agR6J0Hznz0vPOdzwS6MMpPQI4D+kQEceU90qKk0iVhgT86mCXFGZ9ZRvq5vU8WGX7k2j0+P8PXMbYM+2 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:ccb1:c46b:7044:2508]) (user=irogers job=sendgmr) by 2002:a25:b901:0:b0:682:66a2:f714 with SMTP id x1-20020a25b901000000b0068266a2f714mr428844ybj.577.1661532327823; Fri, 26 Aug 2022 09:45:27 -0700 (PDT) Date: Fri, 26 Aug 2022 09:42:40 -0700 In-Reply-To: <20220826164242.43412-1-irogers@google.com> Message-Id: <20220826164242.43412-17-irogers@google.com> Mime-Version: 1.0 References: <20220826164242.43412-1-irogers@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 16/18] perf sched: Fixes for thread safety analysis From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Weiguo Li , Athira Rajeev , Thomas Richter , Ravi Bangoria , Dario Petrillo , Hewenliang , yaowenbin , Wenyu Liu , Song Liu , Andrii Nakryiko , Dave Marchevsky , Leo Yan , Kim Phillips , Pavithra Gurushankar , Alexandre Truong , Quentin Monnet , William Cohen , Andres Freund , Adrian Hunter , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Colin Ian King , James Clark , Fangrui Song , Stephane Eranian , Kajol Jain , Alexey Bayduraev , Riccardo Mancini , Andi Kleen , Masami Hiramatsu , Zechuan Chen , Jason Wang , Christophe JAILLET , Remi Bernon , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Cc: Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add annotations to describe lock behavior. Add unlocks so that mutexes aren't conditionally held on exit from perf_sched__replay. Add an exit variable so that thread_func can terminate, rather than leaving the threads blocked on mutexes. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-sched.c | 46 ++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 7e4006d6b8bc..b483ff0d432e 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -246,6 +246,7 @@ struct perf_sched { const char *time_str; struct perf_time_interval ptime; struct perf_time_interval hist_time; + volatile bool thread_funcs_exit; }; =20 /* per thread run time data */ @@ -633,31 +634,34 @@ static void *thread_func(void *ctx) prctl(PR_SET_NAME, comm2); if (fd < 0) return NULL; -again: - ret =3D sem_post(&this_task->ready_for_work); - BUG_ON(ret); - mutex_lock(&sched->start_work_mutex); - mutex_unlock(&sched->start_work_mutex); =20 - cpu_usage_0 =3D get_cpu_usage_nsec_self(fd); + while (!sched->thread_funcs_exit) { + ret =3D sem_post(&this_task->ready_for_work); + BUG_ON(ret); + mutex_lock(&sched->start_work_mutex); + mutex_unlock(&sched->start_work_mutex); =20 - for (i =3D 0; i < this_task->nr_events; i++) { - this_task->curr_event =3D i; - perf_sched__process_event(sched, this_task->atoms[i]); - } + cpu_usage_0 =3D get_cpu_usage_nsec_self(fd); =20 - cpu_usage_1 =3D get_cpu_usage_nsec_self(fd); - this_task->cpu_usage =3D cpu_usage_1 - cpu_usage_0; - ret =3D sem_post(&this_task->work_done_sem); - BUG_ON(ret); + for (i =3D 0; i < this_task->nr_events; i++) { + this_task->curr_event =3D i; + perf_sched__process_event(sched, this_task->atoms[i]); + } =20 - mutex_lock(&sched->work_done_wait_mutex); - mutex_unlock(&sched->work_done_wait_mutex); + cpu_usage_1 =3D get_cpu_usage_nsec_self(fd); + this_task->cpu_usage =3D cpu_usage_1 - cpu_usage_0; + ret =3D sem_post(&this_task->work_done_sem); + BUG_ON(ret); =20 - goto again; + mutex_lock(&sched->work_done_wait_mutex); + mutex_unlock(&sched->work_done_wait_mutex); + } + return NULL; } =20 static void create_tasks(struct perf_sched *sched) + EXCLUSIVE_LOCK_FUNCTION(sched->start_work_mutex) + EXCLUSIVE_LOCK_FUNCTION(sched->work_done_wait_mutex) { struct task_desc *task; pthread_attr_t attr; @@ -687,6 +691,8 @@ static void create_tasks(struct perf_sched *sched) } =20 static void wait_for_tasks(struct perf_sched *sched) + EXCLUSIVE_LOCKS_REQUIRED(sched->work_done_wait_mutex) + EXCLUSIVE_LOCKS_REQUIRED(sched->start_work_mutex) { u64 cpu_usage_0, cpu_usage_1; struct task_desc *task; @@ -738,6 +744,8 @@ static void wait_for_tasks(struct perf_sched *sched) } =20 static void run_one_test(struct perf_sched *sched) + EXCLUSIVE_LOCKS_REQUIRED(sched->work_done_wait_mutex) + EXCLUSIVE_LOCKS_REQUIRED(sched->start_work_mutex) { u64 T0, T1, delta, avg_delta, fluct; =20 @@ -3309,11 +3317,15 @@ static int perf_sched__replay(struct perf_sched *sc= hed) print_task_traces(sched); add_cross_task_wakeups(sched); =20 + sched->thread_funcs_exit =3D false; create_tasks(sched); printf("------------------------------------------------------------\n"); for (i =3D 0; i < sched->replay_repeat; i++) run_one_test(sched); =20 + sched->thread_funcs_exit =3D true; + mutex_unlock(&sched->start_work_mutex); + mutex_unlock(&sched->work_done_wait_mutex); return 0; } =20 --=20 2.37.2.672.g94769d06f0-goog From nobody Tue Apr 7 14:52:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4ABFCECAAA6 for ; Fri, 26 Aug 2022 16:47:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344868AbiHZQrT (ORCPT ); Fri, 26 Aug 2022 12:47:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344760AbiHZQq0 (ORCPT ); Fri, 26 Aug 2022 12:46:26 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B25F44454C for ; Fri, 26 Aug 2022 09:45:36 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-33daeaa6b8eso33411427b3.7 for ; Fri, 26 Aug 2022 09:45:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=taa3AgrUGklZBinkwVt0bQeh1ht8ynjIrx3kuUJRxJw=; b=RCSICxAMM6hk3ItMYtco0m9Sf6jGuFwmDEqz3qYYgbJ5Y6hKFjHIWnsaPtK2ZlXWFf GPwzXBHgxMvQkOEwxAPDe7t3hFITeGDkOPPmm/iJPxvDVVe1NwUHVvBMg9dJYHkgzuHJ gRuZAGzuxm5KQuJgcZ3b0xNoLUy2rDHQ/o767HC22XYfGYRdLMrgNzreWhw88pdnW/sh 0mhfBarjKntwWqB7xZMoDTvvX7J9uPYAe2mIL+9O7YcLs/JHel+EtttxKzxYoLskXfcZ bBpcjMu4Bb/kLPmMIXlYgVvpsYlYdc8It4TMkF27UNF0Tc7IGyTfDZSkXy3KvaZQze2+ xvTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=taa3AgrUGklZBinkwVt0bQeh1ht8ynjIrx3kuUJRxJw=; b=Ccleithd7iry/NYS+lwnIQZwrnrxhRpLAMGTKFawfWe58epkZZ8nQOlFhQSmoc/VOZ IH+lBhpX98pFpIeneeefXFMTEBMeJYJsZd6YreP/OjTlCZd6z7Rb8duslUck8zzweypz Xr7l3WS7vNiHqiOrGLLi5bkiHE+aQRnX/ETPCAUu0Bja4/DEWK0zS57hbavOQWfaWZ6S mOyNFz2nnRqTJvTkpkxoCCOfmofkn+Dx/oNIVwHT4+ND29lhyrFZozbIRbBA5qF3lBYh V5PwgImemu9YkI5Wlutj9GVw3kyWwss5fXwpC1/Vy+QZ5WBdGDc/JdN8l9n26ipYnruN 8xzQ== X-Gm-Message-State: ACgBeo0EEddrQ8MaT5G+iE5RB5BpM3npWT+BLIPH+gaTiigkmrnox/Wf Td5rzluW0E/zXnpm7ZK0Lnl47fKEs3bY X-Google-Smtp-Source: AA6agR7ev6SqhADqDt5uLWdJHobeI3O4tugxHnBnZzIqU9aNAwe8a818CmiT0W42Jhsf3qgC2JcEr6Zr1uz9 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:ccb1:c46b:7044:2508]) (user=irogers job=sendgmr) by 2002:a05:6902:549:b0:696:42fd:60aa with SMTP id z9-20020a056902054900b0069642fd60aamr464473ybs.575.1661532335547; Fri, 26 Aug 2022 09:45:35 -0700 (PDT) Date: Fri, 26 Aug 2022 09:42:41 -0700 In-Reply-To: <20220826164242.43412-1-irogers@google.com> Message-Id: <20220826164242.43412-18-irogers@google.com> Mime-Version: 1.0 References: <20220826164242.43412-1-irogers@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 17/18] perf top: Fixes for thread safety analysis From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Weiguo Li , Athira Rajeev , Thomas Richter , Ravi Bangoria , Dario Petrillo , Hewenliang , yaowenbin , Wenyu Liu , Song Liu , Andrii Nakryiko , Dave Marchevsky , Leo Yan , Kim Phillips , Pavithra Gurushankar , Alexandre Truong , Quentin Monnet , William Cohen , Andres Freund , Adrian Hunter , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Colin Ian King , James Clark , Fangrui Song , Stephane Eranian , Kajol Jain , Alexey Bayduraev , Riccardo Mancini , Andi Kleen , Masami Hiramatsu , Zechuan Chen , Jason Wang , Christophe JAILLET , Remi Bernon , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Cc: Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add annotations to describe lock behavior. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-top.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 5af3347eedc1..e89208b4ad4b 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -196,6 +196,7 @@ static void perf_top__record_precise_ip(struct perf_top= *top, struct hist_entry *he, struct perf_sample *sample, struct evsel *evsel, u64 ip) + EXCLUSIVE_LOCKS_REQUIRED(he->hists->lock) { struct annotation *notes; struct symbol *sym =3D he->ms.sym; @@ -724,13 +725,13 @@ static void *display_thread(void *arg) static int hist_iter__top_callback(struct hist_entry_iter *iter, struct addr_location *al, bool single, void *arg) + EXCLUSIVE_LOCKS_REQUIRED(iter->he->hists->lock) { struct perf_top *top =3D arg; - struct hist_entry *he =3D iter->he; struct evsel *evsel =3D iter->evsel; =20 if (perf_hpp_list.sym && single) - perf_top__record_precise_ip(top, he, iter->sample, evsel, al->addr); + perf_top__record_precise_ip(top, iter->he, iter->sample, evsel, al->addr= ); =20 hist__account_cycles(iter->sample->branch_stack, al, iter->sample, !(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY), --=20 2.37.2.672.g94769d06f0-goog From nobody Tue Apr 7 14:52:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B34BECAAA3 for ; Fri, 26 Aug 2022 16:47:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344823AbiHZQr3 (ORCPT ); Fri, 26 Aug 2022 12:47:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343731AbiHZQqj (ORCPT ); Fri, 26 Aug 2022 12:46:39 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D04894505A for ; Fri, 26 Aug 2022 09:45:43 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id i16-20020a170902c95000b00172c39b3fb0so1400715pla.22 for ; Fri, 26 Aug 2022 09:45:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=LEHDHxAnksEJke5uXEgC/4fvlBz/SQBsppkh6XDSNgM=; b=VOV3ZeQLK7insFX0lmDaq/k7r0x4+Jx+0drlOcZW9Pv6LP/mYzLvuK0V5gHu4IDPNg 7ScpP6ajmkx53bfkRHgW9E2eOmJonRICOVsrLq7phuLXrvQsXxvCn+Puthlbd0RbbYnS zpuYddmMpBGNF/36MnFOzr/XVqqv0mqIiQ7DrweQEyg705qhnfMhxDoIXe+y9LqU/2TH ypL7V8lMnlmDV6NGRaelq3C61ouifEjuRGuLYlI9pRk2DoqvtywHxYi0GRIO6RNQBOJ4 vskiabGPN8iVem8p4lLLKFvfz7Za7a3SyeSXLmXq254dQDpKjmOfkLTri5SUDF4IUI7M j56Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=LEHDHxAnksEJke5uXEgC/4fvlBz/SQBsppkh6XDSNgM=; b=C9pUkTdwscUAwsjdUrUCeuz5eLmFqtC/YG0w+VBObcZhpY2/UyYtOWDiY6MA/DQRh5 FYUC0NkzzKc8CoLzGltdM80PavAV1xqbR+/+4IP230OsYWbJVaIFGkG7pXR3f6TEzTAK SuMyxcwJZmadh2xhH8zYs4A066WQVQJzLbYSp0PjUXQbNrw8WShS06csEeLx7Z3E+Klm mX/icpagJSasOhev8wNiDcMN5dKqYaf9SCo4J6cJ3Vh7K9rFPWi64d/9RWWkfnTsEZoL gZ1/XcljEj+PRbQAarqtPoQL29QUkcUXL7WdV/SqEgDWqolK9w95lNE8xM0M0LKA9Opu T8AA== X-Gm-Message-State: ACgBeo1ZJTfNofHnEqjnPrdIeF00rJQrtJddgqemanKhMN8WmGPhcLw6 6OjVOGQYxBqrRnnLha5OdKrKbsDv47t0 X-Google-Smtp-Source: AA6agR7L6xHhqF8ShRu0uc83vM8zveOXqQ0A0Wg+4L4tk7yuhmGODVT7+yJjTn80JIeNUZ0kDT90cFuI9sjc X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:ccb1:c46b:7044:2508]) (user=irogers job=sendgmr) by 2002:a17:90a:bf01:b0:1fb:c6c4:7dfd with SMTP id c1-20020a17090abf0100b001fbc6c47dfdmr5118986pjs.134.1661532343199; Fri, 26 Aug 2022 09:45:43 -0700 (PDT) Date: Fri, 26 Aug 2022 09:42:42 -0700 In-Reply-To: <20220826164242.43412-1-irogers@google.com> Message-Id: <20220826164242.43412-19-irogers@google.com> Mime-Version: 1.0 References: <20220826164242.43412-1-irogers@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 18/18] perf build: Enable -Wthread-safety with clang From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Weiguo Li , Athira Rajeev , Thomas Richter , Ravi Bangoria , Dario Petrillo , Hewenliang , yaowenbin , Wenyu Liu , Song Liu , Andrii Nakryiko , Dave Marchevsky , Leo Yan , Kim Phillips , Pavithra Gurushankar , Alexandre Truong , Quentin Monnet , William Cohen , Andres Freund , Adrian Hunter , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Colin Ian King , James Clark , Fangrui Song , Stephane Eranian , Kajol Jain , Alexey Bayduraev , Riccardo Mancini , Andi Kleen , Masami Hiramatsu , Zechuan Chen , Jason Wang , Christophe JAILLET , Remi Bernon , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Cc: Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If building with clang then enable -Wthread-safety warnings. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/Makefile.config | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index c41a090c0652..72dadafdbad9 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -19,6 +19,11 @@ detected_var =3D $(shell echo "$(1)=3D$($(1))" >> $(OUTP= UT).config-detected) CFLAGS :=3D $(EXTRA_CFLAGS) $(filter-out -Wnested-externs,$(EXTRA_WARNINGS= )) HOSTCFLAGS :=3D $(filter-out -Wnested-externs,$(EXTRA_WARNINGS)) =20 +# Enabled Wthread-safety analysis for clang builds. +ifeq ($(CC_NO_CLANG), 0) + CFLAGS +=3D -Wthread-safety +endif + include $(srctree)/tools/scripts/Makefile.arch =20 $(call detected_var,SRCARCH) --=20 2.37.2.672.g94769d06f0-goog