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 B1823ECAAA6 for ; Fri, 26 Aug 2022 16:42:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343842AbiHZQm2 (ORCPT ); Fri, 26 Aug 2022 12:42:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344217AbiHZQmN (ORCPT ); Fri, 26 Aug 2022 12:42:13 -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 6E21ADFB54 for ; Fri, 26 Aug 2022 09:42:04 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-33dbe61eed8so33658697b3.1 for ; Fri, 26 Aug 2022 09:42:04 -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=e+9l/h95UMRaaxW+Q0FvduJHKlIu2RqOW+G9E5iQPCR1/TgIjGoCI92Rf7Ru8B/N34 QGL+JNyV+nwbT2QUmgkHAVbI1xUl6vMY1ghlmedSUj5gYgPc89boswfZmuo0siLUM8rJ QWxeJiNN6jacj4imgJcvu3wnf72rWde2vzo9VXE8c2GTv6T4qwuCxyvvKbTKdV0itnWT u53BJGoqHbDW/y3+admPuoaISu9FCben2RpfwJx9f94i82KR/HXIdcFlRyfvkoy+fmTI g+dMt5/eur5upAe/Vs4x7ATn8U57pqmUlxJ8VIb9bh3Nc/KHgaHhdmigyarYFzeHDFVD UgEw== 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=u69+PCWo5Y+U2JbQ5gHjkFhhhsAAaqoIPq/NqcTr72XsSDoNmSt3bkNCC+kD0Jl17K FVN0SWH8MglRxfrVUcSaRE3j1/+uNLMfJUGF4bBHRtcZNoXNAvsm+NXt4aqwdvA9UeRm QkqGgCUJ7cupKLzPs9sw7E14yJGqP2XVTLq74w0JTh4EhYy+k5Cd520NH2ycrVF2ewB0 ewlqJGzxtLOnJPnxhg+8ACiP3FpbzupTcfj0dB8YVgRYiJUNjGM28B36tptqKudB7LQu rjFOHguFlGnN1mI7ACYTJ8bULflLR0cX91/7+YLS1QEcH3VU0FPOla0wjglAwZgKblhm 2Mxw== X-Gm-Message-State: ACgBeo3ZYG+o4yRodEQQTtDw/cUWv2UoyqmXbORtA8tV1mnPTUEvOsmN APTgfRc/iarSm+uJuo3XFoEhbPiv3bsr X-Google-Smtp-Source: AA6agR5816c2dpkxg9aZqV5OldbW9+MmZNvBW5CmhhISAlMC36z7gJwcR4f7iYfgONNnqBFfJ/Ibv/YohkRR X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:ccb1:c46b:7044:2508]) (user=irogers job=sendgmr) by 2002:a05:6902:722:b0:699:63c9:7622 with SMTP id l2-20020a056902072200b0069963c97622mr507062ybt.83.1661532123608; Fri, 26 Aug 2022 09:42:03 -0700 (PDT) Date: Fri, 26 Aug 2022 09:40:13 -0700 In-Reply-To: <20220826164027.42929-1-irogers@google.com> Message-Id: <20220826164027.42929-5-irogers@google.com> Mime-Version: 1.0 References: <20220826164027.42929-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 --- 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