Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp569205rwe; Fri, 26 Aug 2022 10:01:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR4My6Ybzh0D3ea8PZzfS4JNd61+2RJnTDYm6d+0do8hzCgBKgEebvL5BZJaSdcAl8bzJvOR X-Received: by 2002:a63:1c23:0:b0:421:a0a1:696d with SMTP id c35-20020a631c23000000b00421a0a1696dmr3992523pgc.275.1661533294659; Fri, 26 Aug 2022 10:01:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661533294; cv=none; d=google.com; s=arc-20160816; b=LSL1UnNcZGOrQUvkRx6ipx72f/ETq/fUeFuQesuz313K5aIEk8JaLl6tUKFIpOrIGK e5wdcF2q43grZ6Mvbo2RJl12GHap0+dEU152VNifyop9ZwFNEn+l3OyEZtzbweSPU6ve iMk9m9zhM+0vMIDHB3BPf+QcMmGKH692lNzHEao0BSP1Gp5og9UlnRmVjl/JHitU7h2Q bHXqcvI+cNO0a/jy0zIkMCtSVJf//tA2wTzgZFxtjKSuCya1kb1opPS5TAlW8fTwTCsI nY2NjkNO5p9imRQs8AFKNsmVSC5zNTgTcv/DK3ro3zO2v4giuKRm/Mw+MlCz0Ox+D8V5 NboQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=2S7UT5klKL+i22GMRfPejXX+Bef4p1fHRoH4GKdgyNQ=; b=ZWyVkUiP4WMLIPePGBQ9BuSfkpWkOvpGcGRptn7ggM6vAkebfzTMhalMNw8uD3BVkQ D1+vVufr6wpFstYzDAEfybG208cXwexo6fnfufc34h5+SEMn7lETmlaL0wnoOmrBT7SQ bqJh1y7uRRJRAGp32Bb0r/jdZnq/LAVH3GFgCDPidxAQSkVtyaQJux5d1lEpIJuHHkFX R71EGtmkqLSkZ1Aqy5sQ02eAjqLKFAG4F+PCnCg20FWdkSCsyQl6cHsjhy0GaQhmt5ze ToLVFuwqE6/l7QoHLs1zzf7Ntux7cu42H3/VP+zbqgewkR1fQw+R0zC5f/JG2HvD7BLg xYvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=YkhiZa0p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id on17-20020a17090b1d1100b001fa5ea8e65bsi2523127pjb.19.2022.08.26.10.01.22; Fri, 26 Aug 2022 10:01:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=YkhiZa0p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344437AbiHZQq0 (ORCPT + 99 others); Fri, 26 Aug 2022 12:46:26 -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-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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 *top, struct hist_entry *he) } notes = symbol__annotation(sym); - pthread_mutex_lock(¬es->lock); + mutex_lock(¬es->lock); 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); } - pthread_mutex_unlock(¬es->lock); + mutex_unlock(¬es->lock); return err; } @@ -208,12 +208,12 @@ static void perf_top__record_precise_ip(struct perf_top *top, notes = symbol__annotation(sym); - if (pthread_mutex_trylock(¬es->lock)) + if (!mutex_trylock(¬es->lock)) return; err = hist_entry__inc_addr_samples(he, sample, evsel, ip); - pthread_mutex_unlock(¬es->lock); + mutex_unlock(¬es->lock); if (unlikely(err)) { /* @@ -250,7 +250,7 @@ static void perf_top__show_details(struct perf_top *top) symbol = he->ms.sym; notes = symbol__annotation(symbol); - pthread_mutex_lock(¬es->lock); + mutex_lock(¬es->lock); symbol__calc_percent(symbol, evsel); @@ -271,7 +271,7 @@ static void perf_top__show_details(struct perf_top *top) if (more != 0) printf("%d lines not displayed, maybe increase display entries [e]\n", more); out_unlock: - pthread_mutex_unlock(¬es->lock); + mutex_unlock(¬es->lock); } static void perf_top__resort_hists(struct perf_top *t) diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.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 annotate_browser *browser, browser->entries = RB_ROOT; - pthread_mutex_lock(¬es->lock); + mutex_lock(¬es->lock); symbol__calc_percent(sym, evsel); @@ -348,7 +348,7 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser, } disasm_rb_tree__insert(browser, &pos->al); } - pthread_mutex_unlock(¬es->lock); + mutex_unlock(¬es->lock); browser->curr_hot = rb_last(&browser->entries); } @@ -474,10 +474,10 @@ static bool annotate_browser__callq(struct annotate_browser *browser, } notes = symbol__annotation(dl->ops.target.sym); - pthread_mutex_lock(¬es->lock); + mutex_lock(¬es->lock); 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_browser *browser, target_ms.maps = ms->maps; target_ms.map = ms->map; target_ms.sym = 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 *sym) { struct annotation *notes = symbol__annotation(sym); - pthread_mutex_lock(¬es->lock); + mutex_lock(¬es->lock); if (notes->src != 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 *sym) memset(notes->src->cycles_hist, 0, symbol__size(sym) * sizeof(struct cyc_hist)); } - pthread_mutex_unlock(¬es->lock); + mutex_unlock(¬es->lock); } 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 = 0; notes->cover_insn = 0; - pthread_mutex_lock(¬es->lock); + mutex_lock(¬es->lock); for (offset = size - 1; offset >= 0; --offset) { struct cyc_hist *ch; @@ -1105,7 +1104,7 @@ void annotation__compute_ipc(struct annotation *notes, size_t size) notes->have_cycles = true; } } - pthread_mutex_unlock(¬es->lock); + mutex_unlock(¬es->lock); } 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 void annotation__init(struct annotation *notes) { - pthread_mutex_init(¬es->lock, NULL); + mutex_init(¬es->lock); } void annotation__exit(struct annotation *notes) { annotated_source__delete(notes->src); - pthread_mutex_destroy(¬es->lock); + mutex_destroy(¬es->lock); } static void annotation_line__add(struct annotation_line *al, struct list_head *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" struct hist_browser_timer; @@ -273,7 +273,7 @@ struct annotated_source { }; struct annotation { - pthread_mutex_t lock; + struct mutex lock; u64 max_coverage; u64 start; u64 hit_cycles; -- 2.37.2.672.g94769d06f0-goog