From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0BDB1C17 for ; Fri, 26 Aug 2022 10:37:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661510259; x=1693046259; h=message-id:date:mime-version:subject:to:references:from: in-reply-to:content-transfer-encoding; bh=9hnCuIQP0Do9Va8hiUiS3qPMSpvIWNQCjLORaXq96rM=; b=SkN7+8A8mFTAywJwapYZC4VN9VBqMP4vOj9mMlam4gdn8rex+34AVvYA jkCrdxf0cXhuzs0exIQ9fsVGQYS1CfbEh27VgMcmeSL3C2Rf2Meubusmq 1oer5ZqlWeavcdZyEyOZltAWsoyw5t+eJGDIayszalqzYlqL4edfK6AVr fhHY+h50PEMqZBcvaAHI7qZcaVyHkL1RpmBez/0Rl0cMu49HTAMK+Don0 /FEMlYNvh6xs8Ll/r9hACXjuHis34AXg6mV8u0MpCdROhHiOrR1kYnkFI xp9eVdmiJTv7SkHsXVlo8rbu6Iyir0OQtp/x2XfRw+ecUE6gMfsGONl16 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="356194475" X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="356194475" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 03:37:39 -0700 X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="606726872" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO [10.0.2.15]) ([10.252.50.209]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 03:37:26 -0700 Message-ID: <12acbe02-bd73-07bb-d0e1-cb13dcd790c0@intel.com> Date: Fri, 26 Aug 2022 13:37:21 +0300 Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0 Thunderbird/91.11.0 Subject: Re: [PATCH v3 11/18] perf dso: Update use of pthread mutex Content-Language: en-US To: Ian Rogers , 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 , =?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 References: <20220824153901.488576-1-irogers@google.com> <20220824153901.488576-12-irogers@google.com> From: Adrian Hunter Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki In-Reply-To: <20220824153901.488576-12-irogers@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 24/08/22 18:38, Ian Rogers wrote: > Switch to the use of mutex wrappers that provide better error checking. > > Signed-off-by: Ian Rogers > --- > tools/perf/util/dso.c | 12 ++++++------ Some not done yet $ grep -i pthread_mut tools/perf/util/dso.c static pthread_mutex_t dso__data_open_lock = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_lock(&dso__data_open_lock); pthread_mutex_unlock(&dso__data_open_lock); if (pthread_mutex_lock(&dso__data_open_lock) < 0) pthread_mutex_unlock(&dso__data_open_lock); pthread_mutex_unlock(&dso__data_open_lock); pthread_mutex_lock(&dso__data_open_lock); pthread_mutex_unlock(&dso__data_open_lock); pthread_mutex_lock(&dso__data_open_lock); pthread_mutex_unlock(&dso__data_open_lock); > tools/perf/util/dso.h | 4 ++-- > tools/perf/util/symbol.c | 4 ++-- > 3 files changed, 10 insertions(+), 10 deletions(-) > > diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c > index 5ac13958d1bd..a9789a955403 100644 > --- a/tools/perf/util/dso.c > +++ b/tools/perf/util/dso.c > @@ -795,7 +795,7 @@ dso_cache__free(struct dso *dso) > struct rb_root *root = &dso->data.cache; > struct rb_node *next = rb_first(root); > > - pthread_mutex_lock(&dso->lock); > + mutex_lock(&dso->lock); > while (next) { > struct dso_cache *cache; > > @@ -804,7 +804,7 @@ dso_cache__free(struct dso *dso) > rb_erase(&cache->rb_node, root); > free(cache); > } > - pthread_mutex_unlock(&dso->lock); > + mutex_unlock(&dso->lock); > } > > static struct dso_cache *__dso_cache__find(struct dso *dso, u64 offset) > @@ -841,7 +841,7 @@ dso_cache__insert(struct dso *dso, struct dso_cache *new) > struct dso_cache *cache; > u64 offset = new->offset; > > - pthread_mutex_lock(&dso->lock); > + mutex_lock(&dso->lock); > while (*p != NULL) { > u64 end; > > @@ -862,7 +862,7 @@ dso_cache__insert(struct dso *dso, struct dso_cache *new) > > cache = NULL; > out: > - pthread_mutex_unlock(&dso->lock); > + mutex_unlock(&dso->lock); > return cache; > } > > @@ -1297,7 +1297,7 @@ struct dso *dso__new_id(const char *name, struct dso_id *id) > dso->root = NULL; > INIT_LIST_HEAD(&dso->node); > INIT_LIST_HEAD(&dso->data.open_entry); > - pthread_mutex_init(&dso->lock, NULL); > + mutex_init(&dso->lock); > refcount_set(&dso->refcnt, 1); > } > > @@ -1336,7 +1336,7 @@ void dso__delete(struct dso *dso) > dso__free_a2l(dso); > zfree(&dso->symsrc_filename); > nsinfo__zput(dso->nsinfo); > - pthread_mutex_destroy(&dso->lock); > + mutex_destroy(&dso->lock); > free(dso); > } > > diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h > index 66981c7a9a18..58d94175e714 100644 > --- a/tools/perf/util/dso.h > +++ b/tools/perf/util/dso.h > @@ -2,7 +2,6 @@ > #ifndef __PERF_DSO > #define __PERF_DSO > > -#include > #include > #include > #include > @@ -11,6 +10,7 @@ > #include > #include > #include "build-id.h" > +#include "mutex.h" > > struct machine; > struct map; > @@ -145,7 +145,7 @@ struct dso_cache { > struct auxtrace_cache; > > struct dso { > - pthread_mutex_t lock; > + struct mutex lock; > struct list_head node; > struct rb_node rb_node; /* rbtree node sorted by long name */ > struct rb_root *root; /* root of rbtree that rb_node is in */ > diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c > index a4b22caa7c24..656d9b4dd456 100644 > --- a/tools/perf/util/symbol.c > +++ b/tools/perf/util/symbol.c > @@ -1800,7 +1800,7 @@ int dso__load(struct dso *dso, struct map *map) > } > > nsinfo__mountns_enter(dso->nsinfo, &nsc); > - pthread_mutex_lock(&dso->lock); > + mutex_lock(&dso->lock); > > /* check again under the dso->lock */ > if (dso__loaded(dso)) { > @@ -1964,7 +1964,7 @@ int dso__load(struct dso *dso, struct map *map) > ret = 0; > out: > dso__set_loaded(dso); > - pthread_mutex_unlock(&dso->lock); > + mutex_unlock(&dso->lock); > nsinfo__mountns_exit(&nsc); > > return ret;