Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp802804rwe; Wed, 24 Aug 2022 09:10:56 -0700 (PDT) X-Google-Smtp-Source: AA6agR4q/22sxeHidV64z11iTYN7s4djq1/gXQAN9DSzUNj7SNgGv7egbs4brnao6aWDBQdtNrpn X-Received: by 2002:a65:494b:0:b0:428:d68c:35bf with SMTP id q11-20020a65494b000000b00428d68c35bfmr23899603pgs.509.1661357455639; Wed, 24 Aug 2022 09:10:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661357455; cv=none; d=google.com; s=arc-20160816; b=WNXshWyPqVTU69/GCj1DQs34z8gGmv7Ty/zvU6DVkugc1rqlR1CYuqbkJvWgLOrQ21 +gWPC/9A8xNrq+Tjdr2k/gz/9dKEunhtqEC356g24pATzdD2uGWsum1XWURgKxOZHMGj nCHxo2dTuMYLWH9f8F/DvGqnjHdslLPb5o2CSfzoFJSABf8fq2v6br7gnoa4sxAc+UbO /+q+nAMP+by3toCPSmQGwwV58XgIEhHh7gY6F2cIcbLHhfpJh1KYazsJqAX5ujZVi+u0 vyRad/HPHqD+BdHcAa9ftbq2Ugm/VgljVpo5Yext/aRwaDRhUhGF03HSs1kui1TTS6vo g89Q== 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=E+v8EG42HRikeSNXbmnFQC/dENrnMCWWyvKN9u3QR5M=; b=Y+38kjlYtO6gvJv7WmW/Vgf2U3KqLwO7glSA3uvkL/BZCG+f2uEoeYxaFp1vCLRPT+ 3VrvWsIAdpTxy+hklZmCDAGbQ8BhR2U+f8lw3H1d3Lx/n7nPyP3xK3xO/fyxpiusb4PL lbtCl4qwwy7M1kJrWFwx4y2YpxFViCmw6dRliwBj4QL5xybn/2XsOqs/FMJ/orGzoWIR ZIRMv0IfrkW8BS6khIRlM2/M1nR8x3gw9MQv2+VkcVNtxeKZf+DlAxjjkP7f37Z1cRiW 1p1UwSIXIt+whN445pX09ycnSQnnVNwfYtpzjFDjrXaH48j1UKtdILNnM5aRH8Kxxm+g FgyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=kk7GHJbl; 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 y6-20020a626406000000b00535ed30d44esi16387361pfb.78.2022.08.24.09.10.43; Wed, 24 Aug 2022 09:10:55 -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=kk7GHJbl; 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 S239783AbiHXPlP (ORCPT + 99 others); Wed, 24 Aug 2022 11:41:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239709AbiHXPk5 (ORCPT ); Wed, 24 Aug 2022 11:40:57 -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 3DEE852469 for ; Wed, 24 Aug 2022 08:40:43 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-33daeaa6b8eso6693427b3.7 for ; Wed, 24 Aug 2022 08:40: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=E+v8EG42HRikeSNXbmnFQC/dENrnMCWWyvKN9u3QR5M=; b=kk7GHJbl10t2LSP2yw9VaKovZEQR44FQrddt7kqK2Ys6J5SQGwWPEL95ziuQIQ8pfY msoCOGNgKQw3P8by/o3IgN4F355tvlqYg64SDIzCtmbJXrbznmJmBM+FShGoc39SFXK0 aPMlYh5ctAS+GDcW9uQFfAyJLq1cf+ud97K0xtS/MA3S+4RbtkwiOm13ikVpmk9ieanQ dpf2Kr0wCOwf3nIodSr/ULuOzOgNOwMOm5Ixk+OuwDMunBOO/ZC7fadZUmBkePH6MUM8 jRmZW2WN0+p56IyrkOuWtjUysotivr4ObMwuWqIWMhStgXBBZWhSkWyuJTXPsaH7Vb8K JuKQ== 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=E+v8EG42HRikeSNXbmnFQC/dENrnMCWWyvKN9u3QR5M=; b=A6Unlen72YZStp82eAWOB+fsiw6zFRZtuZvYCwS2l+udx+lTEsrSybZ3kaFDixSgU/ qAOynWL6n93YQaCXF2c9jUjoRi0dh180VOS/pbFYZQ5SMbSl9xZN67csrHUhvQdxbIFA hXFNddgcL5CzOf+T23dZKgTa4clIpVwm4VC+XrDaUeNnWL4JexFsMjZ07GLHuzD7I6PA 90KaAHCi5j/PWukCLqbOaorLAw0Geg2NC6FlFYjeD+lvGlrquuax8O7cm9RHqkt0swXz VIWyVzbadP7IZuPOQ//Tn4FVTDGCeOqIlX4vaTwV5IQhlF4OKwg5V2uPNHF75KtBz95F EHaQ== X-Gm-Message-State: ACgBeo0EsblKOi0KXmDJm/OYgaX61lkuw/7V4vyTc4g7MJ6HkvVmvtE7 OLsy2my8YC0dZSHm+wG2B4uI2fTCq2wD X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:ab82:a348:500d:1fc4]) (user=irogers job=sendgmr) by 2002:a25:41c5:0:b0:690:18a0:c7ee with SMTP id o188-20020a2541c5000000b0069018a0c7eemr30626984yba.1.1661355641946; Wed, 24 Aug 2022 08:40:41 -0700 (PDT) Date: Wed, 24 Aug 2022 08:38:55 -0700 In-Reply-To: <20220824153901.488576-1-irogers@google.com> Message-Id: <20220824153901.488576-13-irogers@google.com> Mime-Version: 1.0 References: <20220824153901.488576-1-irogers@google.com> X-Mailer: git-send-email 2.37.2.609.g9ff673ca1a-goog Subject: [PATCH v3 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.609.g9ff673ca1a-goog