From patchwork Wed Aug 24 15:38:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12953751 X-Patchwork-Delegate: bpf@iogearbox.net 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 9C5C6C3F6B0 for ; Wed, 24 Aug 2022 15:40:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235526AbiHXPkg (ORCPT ); Wed, 24 Aug 2022 11:40:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239521AbiHXPkK (ORCPT ); Wed, 24 Aug 2022 11:40:10 -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 159D014D12 for ; Wed, 24 Aug 2022 08:40:08 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-33580e26058so296925067b3.4 for ; Wed, 24 Aug 2022 08:40:08 -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=3BrhFwUG/qTzyva+786rSer4lbcXLx6c2fnZFduSMeE=; b=nUqCJ+/IRCQa4bu7dz0dSGIz/D7e0XuB2olt28nTD731WTDPqVr0S6sKDVwQSrWR8J fPJjjnLAlM3ZnyhrUxJW8QWkf9ybZcXdr+vofJfqdMVEuCYFbFyR49gKLPi1h3U1OLbj f46LVv1unEu3AVYvRY2uBWrWc2ydFujyogOSwB5lRKzlhv9mJFWPFn0i4Umx7sVXersq 9J0SxHak8/+FaPwrkNQcXsQbO8kzdXinisrv9M14dEWWQj16d85KwvOG0lCbwKOw4aHw K7o19LdkgFlHKFo5qpIBCtZYRL1BgeXXY891Sma/BdhvG+nQVI2kAwVaoJVe7ON1U/HN D5Nw== 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=3BrhFwUG/qTzyva+786rSer4lbcXLx6c2fnZFduSMeE=; b=CjARSti7sU4cIdzJ4gvljA1hwaCkjFsxcXTtPEqtYJBPq6hVg36+znn/OAoj3DPHwe wHWBSfyjPFp79ZDZMEInqnk7Sc+0z2O7tWetRn73UQyQBVvegq+s8/504hVzK7Rjm9z/ QBJ4C1qtbgR576hSVAiLR+cUf+hKjG8ZvJmt66eKJh7iRGgTHNs22D9vP3KMjc3jLdYe DSuc7N99geO3Nc/K2SUup26doCeaHd2FS/IdwvMhktoqjjKqeReW79O+s5nfMfIn/ZgM zRlAt6cPxV5QS1e0UAJBqM7UhPOQ6ntuCTDiz9FW1mFgHvo1gY/ep0Sj/GuSFcQxG4yf EhLg== X-Gm-Message-State: ACgBeo2uGZiO+D99vHyuYqirwWauO3TCa/gzvw82xrefc7TlvtVSVT9M w6CvnCVDG87IR3s5R7hDtm3IWgyls+GU X-Google-Smtp-Source: AA6agR5ArNCC0pdLFJhOUHoz7DemaPrAZYB/cQ9BC5Pk+bNHcL2HXo20P9iy91mRbvsJYkFtLpZSGh7nby8s X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:ab82:a348:500d:1fc4]) (user=irogers job=sendgmr) by 2002:a25:5242:0:b0:68f:4012:f131 with SMTP id g63-20020a255242000000b0068f4012f131mr28277518ybb.222.1661355608506; Wed, 24 Aug 2022 08:40:08 -0700 (PDT) Date: Wed, 24 Aug 2022 08:38:50 -0700 In-Reply-To: <20220824153901.488576-1-irogers@google.com> Message-Id: <20220824153901.488576-8-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 07/18] perf record: 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_Almeida?= " , 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_Li=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: bpf@vger.kernel.org Switch to the use of mutex wrappers that provide better error checking for synth_lock. Signed-off-by: Ian Rogers --- tools/perf/builtin-record.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 4713f0f3a6cf..a7b7a317d81b 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -21,6 +21,7 @@ #include "util/evsel.h" #include "util/debug.h" #include "util/mmap.h" +#include "util/mutex.h" #include "util/target.h" #include "util/session.h" #include "util/tool.h" @@ -608,17 +609,18 @@ static int process_synthesized_event(struct perf_tool *tool, return record__write(rec, NULL, event, event->header.size); } +static struct mutex synth_lock; + static int process_locked_synthesized_event(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample __maybe_unused, struct machine *machine __maybe_unused) { - static pthread_mutex_t synth_lock = PTHREAD_MUTEX_INITIALIZER; int ret; - pthread_mutex_lock(&synth_lock); + mutex_lock(&synth_lock); ret = process_synthesized_event(tool, event, sample, machine); - pthread_mutex_unlock(&synth_lock); + mutex_unlock(&synth_lock); return ret; } @@ -1917,6 +1919,7 @@ static int record__synthesize(struct record *rec, bool tail) } if (rec->opts.nr_threads_synthesize > 1) { + mutex_init(&synth_lock); perf_set_multithreaded(); f = process_locked_synthesized_event; } @@ -1930,8 +1933,10 @@ static int record__synthesize(struct record *rec, bool tail) rec->opts.nr_threads_synthesize); } - if (rec->opts.nr_threads_synthesize > 1) + if (rec->opts.nr_threads_synthesize > 1) { perf_set_singlethreaded(); + mutex_destroy(&synth_lock); + } out: return err;