From nobody Tue Apr 7 16:29:03 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 --- 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