From mboxrd@z Thu Jan 1 00:00:00 1970 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 295DDC32789 for ; Tue, 23 Aug 2022 22:12:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233085AbiHWWMI (ORCPT ); Tue, 23 Aug 2022 18:12:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232882AbiHWWLZ (ORCPT ); Tue, 23 Aug 2022 18:11: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 9BF5D792EF for ; Tue, 23 Aug 2022 15:10:48 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-334370e5ab9so262805587b3.22 for ; Tue, 23 Aug 2022 15:10:48 -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=arpz1x4wRB6/QNxRP3dkfAc2/txeMiNYmprTIBVUU+o=; b=Lcngrn9oCl+hI8knJyVxJa01Zj/XUqMyM00L3enlNUWFOQaV5c7f+jWKUKP401YcoR 8+rsFImJkb6xicnZAcBiL/fnxVDDr9OmN4yqwUyKemZ2yRGruoH2O5rQaytqfZ01p80A WvcNF9ceSAqsIQt/9vdGPYhAGmn8imRm1T0lGBbGySYZpObNgQBdzN0oQCt8PLhktXNB +FOppc5FXbLCWS9wP3dpt04f7xAS4Us5RbB7Exck2lSdEViTRrSLA7utLf5vK+4GO0JL gn2r35hBP1EuNzw/Yd5KkL7F/A5sAYGL46hUlkQ1SqTLi3cTzQhBQ2kciKeylzgbzlHP zPBQ== 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=arpz1x4wRB6/QNxRP3dkfAc2/txeMiNYmprTIBVUU+o=; b=JmdjYjbcookA2Pkro6qpimd0/wV72cyU02dDFV/N10yBjbO+eCzdxMGJOnx8iCcM6e D9fIF0Q+wBL/Om/4f7h/rnD/rxG7zQgDM6682/571LvUOy9rOjozSjb/cy29ZKlR3fmM l6RqAjx+CFK9ipATtu4QXHIWnfhQag2JmHoZywjAUF6JpYRFIzG0igr8SMrMJAza5a2j az9A7lWHGwLyANceQKnAW1d41A2JPOJLSRC60/vW3XgsR/TG4HEXZp+Bg7Bf9bw9HuqU 94JbXFFdDFTsBcBnnLPaLGS4juHued0exyrOtHH48WhbIMQFHLNk/lvbtcw4zQfFShP9 ku7g== X-Gm-Message-State: ACgBeo29aXc4JLTQWwCrp+fFqSfZmpSoWp0nk230kf4NJjhaBwnnf6+l MrHCT0lehJvxCiSyQZjDSRwKLuQVGd0a X-Google-Smtp-Source: AA6agR7eIYIOCFyqOpz14ZguJ/5cNVPSssWyoD3gTfA0QBKYmaULVXXkeowKHq/vD/xDBhmaKFfg43GneYK0 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7dbd:c08f:de81:c2a3]) (user=irogers job=sendgmr) by 2002:a5b:24c:0:b0:68f:b0d7:79d9 with SMTP id g12-20020a5b024c000000b0068fb0d779d9mr24806647ybp.26.1661292647538; Tue, 23 Aug 2022 15:10:47 -0700 (PDT) Date: Tue, 23 Aug 2022 15:09:17 -0700 In-Reply-To: <20220823220922.256001-1-irogers@google.com> Message-Id: <20220823220922.256001-14-irogers@google.com> Mime-Version: 1.0 References: <20220823220922.256001-1-irogers@google.com> X-Mailer: git-send-email 2.37.2.609.g9ff673ca1a-goog Subject: [PATCH v2 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: bpf@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 | 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..3757292bfe86 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); if (top->qe.rotate) { - pthread_mutex_lock(&top->qe.mutex); + mutex_lock(&top->qe.mutex); top->qe.rotate = false; - pthread_cond_signal(&top->qe.cond); - pthread_mutex_unlock(&top->qe.mutex); + cond_signal(&top->qe.cond); + mutex_unlock(&top->qe.mutex); } } @@ -1100,10 +1100,10 @@ static void *process_thread(void *arg) out = rotate_queues(top); - pthread_mutex_lock(&top->qe.mutex); + mutex_lock(&top->qe.mutex); top->qe.rotate = 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); 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 = &top->qe.data[0]; - pthread_mutex_init(&top->qe.mutex, NULL); - pthread_cond_init(&top->qe.cond, NULL); + mutex_init(&top->qe.mutex, /*pshared=*/false); + cond_init(&top->qe.cond, /*pshared=*/false); } 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; }; -- 2.37.2.609.g9ff673ca1a-goog