perf mutex: Wrapped usage of pthread_mutex_t
PATCH 1/4 perf mutex: Wrapped usage of pthread_mutex_t
From: pavithra <[email protected]>
Added a new header file mutex.h that wraps the usage of pthread_mutex_t and updated lock in dso.h.
--- tools/perf/util/Build | 1 + tools/perf/util/dso.c | 33 ++++++++++++++++----------------- tools/perf/util/dso.h | 3 ++- tools/perf/util/mutex.c | 32 ++++++++++++++++++++++++++++++++ tools/perf/util/mutex.h | 15 +++++++++++++++ tools/perf/util/symbol.c | 4 ++-- 6 files changed, 68 insertions(+), 20 deletions(-) create mode 100644 tools/perf/util/mutex.c create mode 100644 tools/perf/util/mutex.h
tools/perf/util/Build +1 -0
@@ -120,6 +120,7 @@ perf-y += time-utils.o perf-y += expr-bison.o perf-y += branch.o perf-y += mem2node.o +perf-y += mutex.o perf-$(CONFIG_LIBBPF) += bpf-loader.o perf-$(CONFIG_LIBBPF) += bpf_map.o
tools/perf/util/dso.c +16 -17
@@ -426,7 +426,7 @@ void dso__set_module_info(struct dso *dso, struct kmod_path *m,*/ static LIST_HEAD (dso__data_open);static long dso__data_open_cnt; -static pthread_mutex_t dso__data_open_lock =PTHREAD_MUTEX_INITIALIZER ; +static struct mutex dso__data_open_lock =PTHREAD_MUTEX_INITIALIZER ;static void dso__list_add (struct dso *dso) {
@@ -633,9 +633,9 @@ static void check_data_close(void)*/ void dso__data_close (struct dso *dso) { -pthread_mutex_lock (&dso__data_open_lock); +mutex_lock (&dso__data_open_lock);close_dso (dso); -pthread_mutex_unlock (&dso__data_open_lock); +mutex_unlock (&dso__data_open_lock); }static void try_to_open_dso (struct dso *dso,struct machine *machine)
@@ -684,20 +684,19 @@ int dso__data_get_fd(struct dso *dso, struct machine *machine)if (dso->data.status ==DSO_DATA_STATUS_ERROR )return -1 ; -if (pthread_mutex_lock (&dso__data_open_lock) <0 ) -return -1 ; +mutex_lock (&dso__data_open_lock);try_to_open_dso (dso, machine);if (dso->data.fd <0 ) -pthread_mutex_unlock (&dso__data_open_lock); +mutex_unlock (&dso__data_open_lock);return dso->data.fd; }void dso__data_put_fd (struct dso *dso__maybe_unused ) { -pthread_mutex_unlock (&dso__data_open_lock); +mutex_unlock (&dso__data_open_lock); }bool dso__data_status_seen (struct dso *dso,enum dso_data_status_seen by)
@@ -756,7 +755,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;
@@ -765,7 +764,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)
@@ -802,7 +801,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;
@@ -823,7 +822,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; }
@@ -843,7 +842,7 @@ static ssize_t file_read(struct dso *dso, struct machine *machine, {ssize_t ret; -pthread_mutex_lock (&dso__data_open_lock); +mutex_lock (&dso__data_open_lock);/* * dso->data.fd might be closed if other thread opened another
@@ -859,7 +858,7 @@ static ssize_t file_read(struct dso *dso, struct machine *machine, ret =pread (dso->data.fd, data,DSO__DATA_CACHE_SIZE , offset); out: -pthread_mutex_unlock (&dso__data_open_lock); +mutex_unlock (&dso__data_open_lock);return ret; }
@@ -953,7 +952,7 @@ static int file_size(struct dso *dso, struct machine *machine)struct stat st;char sbuf[STRERR_BUFSIZE ]; -pthread_mutex_lock (&dso__data_open_lock); +mutex_lock (&dso__data_open_lock);/* * dso->data.fd might be closed if other thread opened another
@@ -977,7 +976,7 @@ static int file_size(struct dso *dso, struct machine *machine) dso->data.file_size = st.st_size; out: -pthread_mutex_unlock (&dso__data_open_lock); +mutex_unlock (&dso__data_open_lock);return ret; }
@@ -1192,7 +1191,7 @@ struct dso *dso__new(const char *name) 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 ); }
@@ -1226,7 +1225,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); }
tools/perf/util/dso.h +2 -1
@@ -11,6 +11,7 @@#include <stdio.h> #include <linux/bitops.h> #include "build-id.h" +#include "mutex.h" struct machine ;struct map ;
@@ -132,7 +133,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 */
tools/perf/util/mutex.c new file +32 -0
@@ -0,0 +1,32 @@ +#include <mutex.h> +#include <pthread.h> + +//to avoid the warning : implicit declaration of BUG_ON, +//we add the following 2 headers. +#include <linux/compiler.h> +#include <linux/kernel.h> + +void mutex_init (struct mutex *mtx) +{ +pthread_mutexattr_t lock_attr; +pthread_mutexattr_init (&lock_attr); +pthread_mutexattr_settype (&lock_attr,PTHREAD_MUTEX_ERRORCHECK ); +BUG_ON (pthread_mutex_init (&mtx->lock, &lock_attr)); +//on success, returns 0. +pthread_mutexattr_destroy (&lock_attr); +} + +void mutex_destroy (struct mutex *mtx) +{ +BUG_ON (pthread_mutex_destroy (&mtx->lock));//on success, returns 0. +} + +void mutex_lock (struct mutex *mtx) +{ +BUG_ON (pthread_mutex_lock (&mtx->lock) !=0 ); +} + +void mutex_unlock (struct mutex *mtx) +{ +BUG_ON (pthread_mutex_unlock (&mtx->lock) !=0 ); +}
tools/perf/util/mutex.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef __PERF_MUTEX_H +#define _PERF_MUTEX_H + +#include <pthread.h> + +struct mutex { +pthread_mutex_t lock; +}; + +void mutex_lock (struct mutex *mtx); +void mutex_unlock (struct mutex *mtx); +void mutex_init (struct mutex *mtx); +void mutex_destroy (struct mutex *mtx); + +#endif /* _PERF_MUTEX_H */
tools/perf/util/symbol.c +2 -2
@@ -1629,7 +1629,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)) {
@@ -1778,7 +1778,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;
Signature · 1 line
2.25.1
PATCH 2/4 perf mutex with nsinfo: Updated pthread_mutex_t usage
From: pavithra <[email protected]>
Updated usage of pthread_mutex_t with nsinfo
with the new wrapped lock(struct) in mutex.h
(remove data races).
--- tools/perf/builtin-inject.c | 6 +++--- tools/perf/util/map.c | 2 ++ tools/perf/util/probe-event.c | 6 +++++- tools/perf/util/symbol.c | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-)
tools/perf/builtin-inject.c +3 -3
@@ -388,10 +388,10 @@ static int perf_event__repipe_id_index(struct perf_session *session,static int dso__read_build_id (struct dso *dso) {if (dso->has_build_id) -return 0 ; - +return 0 ; +if (filename__read_build_id (dso->long_name, dso->build_id, -sizeof (dso->build_id)) >0 ) { +sizeof (dso->build_id)) >0 ) { dso->has_build_id = true;return 0 ; }
tools/perf/util/map.c +2 -0
@@ -214,8 +214,10 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,if (!(prot &PROT_EXEC ))dso__set_loaded (dso); } +mutex_lock (&dso->lock); dso->nsinfo = nsi;dso__put (dso); +mutex_unlock (&dso->lock); }return map; out_delete:
tools/perf/util/probe-event.c +5 -1
@@ -38,6 +38,7 @@#include "session.h" #include "string2.h" #include "strbuf.h" +#include "mutex.h" #include <subcmd/pager.h> #include <linux/ctype.h>
@@ -171,8 +172,11 @@ struct map *get_target_map(const char *target, struct nsinfo *nsi, bool user)struct map *map; map =dso__new_map (target); -if (map && map->dso) +if (map && map->dso) { +mutex_lock (&map->dso->lock); map->dso->nsinfo =nsinfo__get (nsi); +mutex_unlock (&map->dso->lock); + }return map; }else {return kernel_get_module_map (target);
tools/perf/util/symbol.c +1 -1
@@ -1619,7 +1619,7 @@ int dso__load(struct dso *dso, struct map *map)struct nscookie nsc;char newmapname[PATH_MAX ];const char *map_path = dso->long_name; - +mutex_lock (&dso->lock); perfmap =strncmp (dso->name,"/tmp/perf-" ,10 ) ==0 ;if (perfmap) { if (dso->nsinfo && (dso__find_perf_map(newmapname,
Signature · 1 line
2.25.1
Namhyung Kim
maintainerRe: [PATCH v1 2/4] perf mutex with nsinfo: Updated pthread_mutex_t usage
Quoted 6 lines · On Wed, Jul 27, 2022 at 4:20 AM <[email protected]> wrote:
From: pavithra <[email protected]>
Updated usage of
pthread_mutex_twith nsinfo
with the new wrapped lock(struct) inmutex.h
(remove data races).
It doesn't look like you updated the usage with new wrapping. Instead you introduced new usage. Then I think you need to describe why it's needed and what problems it solves.
Quoted 14 lines
Signed-off-by pavithra <[email protected]>--- tools/perf/builtin-inject.c | 6 +++--- tools/perf/util/map.c | 2 ++ tools/perf/util/probe-event.c | 6 +++++- tools/perf/util/symbol.c | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-)tools/perf/builtin-inject.c +0
-0
tools/perf/builtin-inject.c static int perf_event__repipe_id_index(struct perf_session *session, · line 394
Quoted 10 lines
tools/perf/builtin-inject.c +3
-3@@ -388,10 +388,10 @@ static int perf_event__repipe_id_index(struct perf_session *session,static int dso__read_build_id (struct dso *dso) {if (dso->has_build_id) -return 0 ; - +return 0 ; +if (filename__read_build_id (dso->long_name, dso->build_id, -sizeof (dso->build_id)) >0 ) { +sizeof (dso->build_id)) >0 ) {
Unrelated whitespace changes.. is it really needed?
Also I'm not sure you are working on acme/perf/core branch.
Quoted 48 lines
tools/perf/builtin-inject.c +0
-0dso->has_build_id = true;return 0 ; }tools/perf/util/map.c +2
-0@@ -214,8 +214,10 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,if (!(prot &PROT_EXEC ))dso__set_loaded (dso); } +mutex_lock (&dso->lock); dso->nsinfo = nsi;dso__put (dso); +mutex_unlock (&dso->lock); }return map; out_delete:tools/perf/util/probe-event.c +5
-1@@ -38,6 +38,7 @@#include "session.h" #include "string2.h" #include "strbuf.h" +#include "mutex.h" #include <subcmd/pager.h> #include <linux/ctype.h> @@ -171,8 +172,11 @@ struct map *get_target_map(const char *target, struct nsinfo *nsi, bool user)struct map *map; map =dso__new_map (target); -if (map && map->dso) +if (map && map->dso) { +mutex_lock (&map->dso->lock); map->dso->nsinfo =nsinfo__get (nsi); +mutex_unlock (&map->dso->lock); + }return map; }else {return kernel_get_module_map (target);tools/perf/util/symbol.c +0
-0
tools/perf/util/symbol.c int dso__load(struct dso *dso, struct map *map) · line 1622
Quoted 5 lines
tools/perf/util/symbol.c +1
-1@@ -1619,7 +1619,7 @@ int dso__load(struct dso *dso, struct map *map)struct nscookie nsc;char newmapname[PATH_MAX ];const char *map_path = dso->long_name; - +mutex_lock (&dso->lock);
No matching unlock?
Thanks,
Namhyung
Quoted 6 lines
tools/perf/util/symbol.c +0
-1perfmap =strncmp (dso->name,"/tmp/perf-" ,10 ) ==0 ;if (perfmap) { if (dso->nsinfo && (dso__find_perf_map(newmapname, --2.25.1
PATCH 3/4 perf mutex and cond: Updated files mutex.h & mutex.c
In reply to [email protected]From: pavithra <[email protected]>
Added new struct and corresponding
functions to wrap usage of pthread_cond_t.
Added a new function for mutex_trylock-similar tomutex_lock.
--- tools/perf/util/mutex.c | 37 ++++++++++++++++++++++++++++++++----- tools/perf/util/mutex.h | 13 +++++++++++-- 2 files changed, 43 insertions(+), 7 deletions(-)
tools/perf/util/mutex.c +32 -5
@@ -1,8 +1,8 @@#include <mutex.h> #include <pthread.h> -//to avoid the warning : implicit declaration of BUG_ON, -//we add the following 2 headers. +/*to avoid the warning : implicit declaration of BUG_ON*/ +/*we add the following 2 headers*/ #include <linux/compiler.h> #include <linux/kernel.h>
@@ -11,14 +11,15 @@ void mutex_init(struct mutex *mtx)pthread_mutexattr_t lock_attr;pthread_mutexattr_init (&lock_attr);pthread_mutexattr_settype (&lock_attr,PTHREAD_MUTEX_ERRORCHECK ); -BUG_ON (pthread_mutex_init (&mtx->lock, &lock_attr)); -//on success, returns 0. +/*pthread_mutex_init:on success, returns 0*/ +BUG_ON (pthread_mutex_init (&mtx->lock, &lock_attr));pthread_mutexattr_destroy (&lock_attr); }void mutex_destroy (struct mutex *mtx) { -BUG_ON (pthread_mutex_destroy (&mtx->lock));//on success, returns 0. +/*pthread_mutex_destroy:on success, returns 0*/ +BUG_ON (pthread_mutex_destroy (&mtx->lock)); }void mutex_lock (struct mutex *mtx)
@@ -30,3 +31,29 @@ void mutex_unlock(struct mutex *mtx) {BUG_ON (pthread_mutex_unlock (&mtx->lock) !=0 ); } + +bool mutex_trylock (struct mutex *mtx) +{ +return pthread_mutex_trylock (&mtx->lock)!=0 ; +} + +void cond_wait (struct cond *cnd,struct mutex *mtx) +{ +BUG_ON (pthread_cond_wait (&cnd->cond, &mtx->lock) !=0 ); +} + +void cond_signal (struct cond *cnd) +{ +BUG_ON (pthread_cond_signal (&cnd->cond) !=0 ); +} + +void cond_init (struct cond *cnd) +{ +pthread_condattr_t attr; + +pthread_condattr_init (&attr); + +/*pthread_cond_init:on success, returns 0*/ +BUG_ON (pthread_cond_init (&cnd->cond, &attr)); +pthread_condattr_destroy (&attr); +}
tools/perf/util/mutex.h +11 -2
@@ -1,15 +1,24 @@#ifndef __PERF_MUTEX_H -#define _PERF_MUTEX_H +#define __PERF_MUTEX_H#include <pthread.h> +#include <stdbool.h> struct mutex {pthread_mutex_t lock; }; +struct cond { +pthread_cond_t cond; +}; +void mutex_lock (struct mutex *mtx);void mutex_unlock (struct mutex *mtx); +bool mutex_trylock (struct mutex *mtx);void mutex_init (struct mutex *mtx);void mutex_destroy (struct mutex *mtx); -#endif /* _PERF_MUTEX_H */ +void cond_wait (struct cond *cnd,struct mutex *mtx); +void cond_signal (struct cond *cnd); +void cond_init (struct cond *cnd); +#endif /* __PERF_MUTEX_H */
Signature · 1 line
2.25.1
Namhyung Kim
maintainerRe: [PATCH v1 3/4] perf mutex and cond: Updated files mutex.h & mutex.c
Quoted 35 lines · On Wed, Jul 27, 2022 at 4:20 AM <[email protected]> wrote:
From: pavithra <[email protected]>
Added new struct and corresponding
functions to wrap usage ofpthread_cond_t.
Added a new function for mutex_trylock-similar tomutex_lock.Signed-off-by pavithra <[email protected]>--- tools/perf/util/mutex.c | 37 ++++++++++++++++++++++++++++++++----- tools/perf/util/mutex.h | 13 +++++++++++-- 2 files changed, 43 insertions(+), 7 deletions(-)tools/perf/util/mutex.c +2
-4@@ -1,8 +1,8 @@#include <mutex.h> #include <pthread.h> -//to avoid the warning : implicit declaration of BUG_ON, -//we add the following 2 headers. +/*to avoid the warning : implicit declaration of BUG_ON*/ +/*we add the following 2 headers*/ #include <linux/compiler.h> #include <linux/kernel.h> @@ -11,14 +11,15 @@ void mutex_init(struct mutex *mtx)pthread_mutexattr_t lock_attr;pthread_mutexattr_init (&lock_attr);pthread_mutexattr_settype (&lock_attr,PTHREAD_MUTEX_ERRORCHECK ); -BUG_ON (pthread_mutex_init (&mtx->lock, &lock_attr)); -//on success, returns 0.
tools/perf/util/mutex.c void mutex_init(struct mutex *mtx) · line 22
Quoted 10 lines
tools/perf/util/mutex.c +4
-1+/*pthread_mutex_init:on success, returns 0*/ +BUG_ON (pthread_mutex_init (&mtx->lock, &lock_attr));pthread_mutexattr_destroy (&lock_attr); }void mutex_destroy (struct mutex *mtx) { -BUG_ON (pthread_mutex_destroy (&mtx->lock));//on success, returns 0. +/*pthread_mutex_destroy:on success, returns 0*/ +BUG_ON (pthread_mutex_destroy (&mtx->lock));
Above changes should belong to the patch 1.
Quoted 21 lines
tools/perf/util/mutex.c +14
-0}void mutex_lock (struct mutex *mtx)@@ -30,3 +31,29 @@ void mutex_unlock(struct mutex *mtx) {BUG_ON (pthread_mutex_unlock (&mtx->lock) !=0 ); } + +bool mutex_trylock (struct mutex *mtx) +{ +return pthread_mutex_trylock (&mtx->lock)!=0 ; +} + +void cond_wait (struct cond *cnd,struct mutex *mtx) +{ +BUG_ON (pthread_cond_wait (&cnd->cond, &mtx->lock) !=0 ); +} + +void cond_signal (struct cond *cnd) +{ +BUG_ON (pthread_cond_signal (&cnd->cond) !=0 );
tools/perf/util/mutex.c void mutex_unlock(struct mutex *mtx) · line 57
Quoted 10 lines
tools/perf/util/mutex.c +10
-0+} + +void cond_init (struct cond *cnd) +{ +pthread_condattr_t attr; + +pthread_condattr_init (&attr); + +/*pthread_cond_init:on success, returns 0*/ +BUG_ON (pthread_cond_init (&cnd->cond, &attr));
Please be consistent with != 0.
Thanks,
Namhyung
Quoted 36 lines
tools/perf/util/mutex.c +2
-0+pthread_condattr_destroy (&attr); +}tools/perf/util/mutex.h +11
-3@@ -1,15 +1,24 @@#ifndef __PERF_MUTEX_H -#define _PERF_MUTEX_H +#define __PERF_MUTEX_H#include <pthread.h> +#include <stdbool.h> struct mutex {pthread_mutex_t lock; }; +struct cond { +pthread_cond_t cond; +}; +void mutex_lock (struct mutex *mtx);void mutex_unlock (struct mutex *mtx); +bool mutex_trylock (struct mutex *mtx);void mutex_init (struct mutex *mtx);void mutex_destroy (struct mutex *mtx); -#endif /* _PERF_MUTEX_H */ +void cond_wait (struct cond *cnd,struct mutex *mtx); +void cond_signal (struct cond *cnd); +void cond_init (struct cond *cnd); +#endif /* __PERF_MUTEX_H */ --2.25.1
PATCH 4/4 perf mutex and cond: Updated every occurrence of pthread_mutex and pthread_cond
In reply to [email protected]From: pavithra <[email protected]>
Structs using pthread_mutex_t and pthread_cond_t were updated and all the usage of them were replaced with the new wrapped functions as per the declaration & definition in mutex.h and mutex.c files. Header files included in each file were modified so as to avoid redefinition errors.
--- tools/perf/builtin-inject.c | 1 - tools/perf/builtin-top.c | 42 +++++++++++++++---------------- tools/perf/ui/browsers/annotate.c | 4 +-- tools/perf/util/annotate.c | 8 +++--- tools/perf/util/annotate.h | 3 ++- tools/perf/util/hist.c | 6 ++--- tools/perf/util/hist.h | 3 ++- tools/perf/util/symbol.c | 2 +- tools/perf/util/top.h | 5 ++-- 9 files changed, 38 insertions(+), 36 deletions(-)
tools/perf/builtin-inject.c +0 -1
@@ -395,7 +395,6 @@ static int dso__read_build_id(struct dso *dso) dso->has_build_id = true;return 0 ; } -return -1 ; }
tools/perf/builtin-top.c +21 -21
126 lines not on this page · raw message
tools/perf/ui/browsers/annotate.c +2 -2
@@ -309,7 +309,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);
@@ -421,7 +421,7 @@ 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);
tools/perf/util/annotate.c +4 -4
@@ -803,7 +803,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);
@@ -811,7 +811,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,
@@ -1063,7 +1063,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;
@@ -1082,7 +1082,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,
tools/perf/util/annotate.h +2 -1
@@ -11,6 +11,7 @@#include <pthread.h> #include <asm/bug.h> #include "symbol_conf.h" +#include "mutex.h" struct hist_browser_timer ;struct hist_entry ;
@@ -268,7 +269,7 @@ struct annotated_source { };struct annotation { -pthread_mutex_t lock; +struct mutex lock;u64 max_coverage;u64 start;u64 hit_cycles;
tools/perf/util/hist.c +3 -3
@@ -1565,13 +1565,13 @@ struct rb_root_cached *hists__get_rotate_entries_in(struct hists *hists) {struct rb_root_cached *root; -pthread_mutex_lock (&hists->lock); +mutex_lock (&hists->lock); root = hists->entries_in;if (++hists->entries_in > &hists->entries_in_array[1 ]) hists->entries_in = &hists->entries_in_array[0 ]; -pthread_mutex_unlock (&hists->lock); +mutex_unlock (&hists->lock);return root; }
@@ -2731,7 +2731,7 @@ int __hists__init(struct hists *hists, struct perf_hpp_list *hpp_list) hists->entries_in = &hists->entries_in_array[0 ]; hists->entries_collapsed =RB_ROOT_CACHED ; hists->entries =RB_ROOT_CACHED ; -pthread_mutex_init (&hists->lock,NULL ); +mutex_init (&hists->lock); hists->socket_filter =-1 ; hists->hpp_list = hpp_list;INIT_LIST_HEAD (&hists->hpp_formats);
tools/perf/util/hist.h +2 -1
@@ -8,6 +8,7 @@#include "evsel.h" #include "color.h" #include "events_stats.h" +#include "util/mutex.h" struct hist_entry ;struct hist_entry_ops ;
@@ -88,7 +89,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 events_stats stats;u64 event_stream;u16 col_len[HISTC_NR_COLS ];
tools/perf/util/symbol.c +1 -1
@@ -278,7 +278,7 @@ struct symbol *symbol__new(u64 start, u64 len, u8 binding, u8 type, const char *if (symbol_conf.priv_size) {if (symbol_conf.init_annotation) {struct annotation *notes = (void *)sym; -pthread_mutex_init (¬es->lock,NULL ); +mutex_init (¬es->lock); } sym = ((void *)sym) + symbol_conf.priv_size; }
tools/perf/util/top.h +3 -2
@@ -5,6 +5,7 @@#include "tool.h" #include "evswitch.h" #include "annotate.h" +#include "mutex.h" #include "ordered-events.h" #include "record.h" #include <linux/types.h>
@@ -49,8 +50,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; };
Signature · 1 line
2.25.1
Namhyung Kim
maintainerRe: [PATCH v1 4/4] perf mutex and cond: Updated every occurrence of pthread_mutex and pthread_cond
Quoted 10 lines · On Wed, Jul 27, 2022 at 4:20 AM <[email protected]> wrote:
From: pavithra <[email protected]>
Structs using
pthread_mutex_tandpthread_cond_twere updated and all the usage of them were replaced with the new wrapped functions as per the declaration & definition inmutex.handmutex.cfiles. Header files included in each file were modified so as to avoid redefinition errors.
You seem to use a very narrow line width setting. I think the recommended setup for git commit message is around 72.
Anyway, to minimize potential bad impact I'd suggest to break the conversion into separate commits. One for perf top, another for annotate, and for hist.
Quoted 19 lines
Signed-off-by pavithra <[email protected]>--- tools/perf/builtin-inject.c | 1 - tools/perf/builtin-top.c | 42 +++++++++++++++---------------- tools/perf/ui/browsers/annotate.c | 4 +-- tools/perf/util/annotate.c | 8 +++--- tools/perf/util/annotate.h | 3 ++- tools/perf/util/hist.c | 6 ++--- tools/perf/util/hist.h | 3 ++- tools/perf/util/symbol.c | 2 +- tools/perf/util/top.h | 5 ++-- 9 files changed, 38 insertions(+), 36 deletions(-)tools/perf/builtin-inject.c +0
-0
tools/perf/builtin-inject.c static int dso__read_build_id(struct dso *dso) · line 398
Quoted 4 lines
tools/perf/builtin-inject.c +0
-1@@ -395,7 +395,6 @@ static int dso__read_build_id(struct dso *dso) dso->has_build_id = true;return 0 ; } -
Please try not to touch other code unnecessarily.
Quoted 269 lines
tools/perf/builtin-inject.c +0
-0return -1 ; }tools/perf/builtin-top.c +21
-21@@ -132,10 +132,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 );@@ -151,7 +151,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; }@@ -204,19 +204,19 @@ static void perf_top__record_precise_ip(struct perf_top *top, notes =symbol__annotation (sym); -if (pthread_mutex_trylock (¬es->lock)) -return ; +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)) {/* * 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);if (err == -ERANGE && !he->ms.map->erange_warned)ui__warn_map_erange (he->ms.map, sym, ip);@@ -226,7 +226,7 @@ static void perf_top__record_precise_ip(struct perf_top *top,sleep (1 ); } -pthread_mutex_lock (&he->hists->lock); +mutex_lock (&he->hists->lock); } }@@ -246,7 +246,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);@@ -267,7 +267,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)@@ -824,13 +824,13 @@ static void perf_event__process_sample(struct perf_tool *tool,else iter.ops = &hist_iter_normal; -pthread_mutex_lock (&hists->lock); +mutex_lock (&hists->lock); err =hist_entry_iter__add (&iter, &al, top->max_stack, top);if (err <0 )pr_err ("Problem incrementing symbol period, skipping event\n" ); -pthread_mutex_unlock (&hists->lock); +mutex_unlock (&hists->lock); }addr_location__put (&al);@@ -886,10 +886,10 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)perf_mmap__consume (md);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); } }@@ -1094,10 +1094,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" );@@ -1211,8 +1211,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); +cond_init (&top->qe.cond); }static int __cmd_top (struct perf_top *top)@@ -1330,7 +1330,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; }tools/perf/ui/browsers/annotate.c +2
-2@@ -309,7 +309,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);@@ -421,7 +421,7 @@ 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);tools/perf/util/annotate.c +4
-4@@ -803,7 +803,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);@@ -811,7 +811,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,@@ -1063,7 +1063,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;@@ -1082,7 +1082,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,tools/perf/util/annotate.h +2
-1@@ -11,6 +11,7 @@#include <pthread.h> #include <asm/bug.h> #include "symbol_conf.h" +#include "mutex.h" struct hist_browser_timer ;struct hist_entry ;@@ -268,7 +269,7 @@ struct annotated_source { };struct annotation { -pthread_mutex_t lock; +struct mutex lock;u64 max_coverage;u64 start;u64 hit_cycles;tools/perf/util/hist.c +3
-3@@ -1565,13 +1565,13 @@ struct rb_root_cached *hists__get_rotate_entries_in(struct hists *hists) {struct rb_root_cached *root; -pthread_mutex_lock (&hists->lock); +mutex_lock (&hists->lock); root = hists->entries_in;if (++hists->entries_in > &hists->entries_in_array[1 ]) hists->entries_in = &hists->entries_in_array[0 ]; -pthread_mutex_unlock (&hists->lock); +mutex_unlock (&hists->lock);return root; }@@ -2731,7 +2731,7 @@ int __hists__init(struct hists *hists, struct perf_hpp_list *hpp_list) hists->entries_in = &hists->entries_in_array[0 ]; hists->entries_collapsed =RB_ROOT_CACHED ; hists->entries =RB_ROOT_CACHED ; -pthread_mutex_init (&hists->lock,NULL ); +mutex_init (&hists->lock); hists->socket_filter =-1 ; hists->hpp_list = hpp_list;INIT_LIST_HEAD (&hists->hpp_formats);tools/perf/util/hist.h +1
-0@@ -8,6 +8,7 @@#include "evsel.h" #include "color.h" #include "events_stats.h" +#include "util/mutex.h" struct hist_entry ;struct hist_entry_ops ;
tools/perf/util/hist.h struct hists { · line 92
Quoted 5 lines
tools/perf/util/hist.h +1
-1@@ -88,7 +89,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;
As Arnaldo mentioned, please keep the existing indentation.
Quoted 29 lines
tools/perf/util/hist.h +0
-0struct events_stats stats;u64 event_stream;u16 col_len[HISTC_NR_COLS ];tools/perf/util/symbol.c +1
-1@@ -278,7 +278,7 @@ struct symbol *symbol__new(u64 start, u64 len, u8 binding, u8 type, const char *if (symbol_conf.priv_size) {if (symbol_conf.init_annotation) {struct annotation *notes = (void *)sym; -pthread_mutex_init (¬es->lock,NULL ); +mutex_init (¬es->lock); } sym = ((void *)sym) + symbol_conf.priv_size; }tools/perf/util/top.h +1
-0@@ -5,6 +5,7 @@#include "tool.h" #include "evswitch.h" #include "annotate.h" +#include "mutex.h" #include "ordered-events.h" #include "record.h" #include <linux/types.h>
tools/perf/util/top.h struct perf_top { · line 54
Quoted 7 lines
tools/perf/util/top.h +2
-2@@ -49,8 +50,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;
Ditto.
Thanks,
Namhyung
Quoted 6 lines
tools/perf/util/top.h +0
-1} qe; }; --2.25.1
Arnaldo Carvalho de Melo
maintainerEm Wed, Jul 27, 2022 at 04:49:51PM +0530, [email protected] escreveu:
Quoted 4 lines
From: pavithra <[email protected]>
Added a new header file
mutex.hthat wraps the usage ofpthread_mutex_tand updated lock indso.h.
Hi,
You should create a first patch with just the new mutex.c andmutex.h files, then you go on to change the users of pthread_mutex_lock/unlock to the wrappers.
Also please add the license on the first line of the new
mutex.[ch] files, see Documentation/process/license-rules.rst.
tldr; probably what you want is to have this single line in
those the two new files (mutex.[ch]):
// SPDX-License-Identifier: GPL-2.0
Quoted 29 lines
Signed-off-by pavithra <[email protected]>--- tools/perf/util/Build | 1 + tools/perf/util/dso.c | 33 ++++++++++++++++----------------- tools/perf/util/dso.h | 3 ++- tools/perf/util/mutex.c | 32 ++++++++++++++++++++++++++++++++ tools/perf/util/mutex.h | 15 +++++++++++++++ tools/perf/util/symbol.c | 4 ++-- 6 files changed, 68 insertions(+), 20 deletions(-) create mode 100644 tools/perf/util/mutex.c create mode 100644 tools/perf/util/mutex.htools/perf/util/Build +1
-0@@ -120,6 +120,7 @@ perf-y += time-utils.o perf-y += expr-bison.o perf-y += branch.o perf-y += mem2node.o +perf-y += mutex.o perf-$(CONFIG_LIBBPF) += bpf-loader.o perf-$(CONFIG_LIBBPF) += bpf_map.otools/perf/util/dso.c +0
-0
tools/perf/util/dso.c void dso__set_module_info(struct dso *dso, struct kmod_path *m, · line 429
Quoted 5 lines
tools/perf/util/dso.c +1
-1@@ -426,7 +426,7 @@ void dso__set_module_info(struct dso *dso, struct kmod_path *m,*/ static LIST_HEAD (dso__data_open);static long dso__data_open_cnt; -static pthread_mutex_t dso__data_open_lock =PTHREAD_MUTEX_INITIALIZER ; +static struct mutex dso__data_open_lock =PTHREAD_MUTEX_INITIALIZER ;
Please find in include/linux/mutex.h the replacement for PTHREAD_MUTEX_INITIALIZER, since we're trying to mimic the kernel mutex api.
Quoted 142 lines
tools/perf/util/dso.c +15
-16static void dso__list_add (struct dso *dso) {@@ -633,9 +633,9 @@ static void check_data_close(void)*/ void dso__data_close (struct dso *dso) { -pthread_mutex_lock (&dso__data_open_lock); +mutex_lock (&dso__data_open_lock);close_dso (dso); -pthread_mutex_unlock (&dso__data_open_lock); +mutex_unlock (&dso__data_open_lock); }static void try_to_open_dso (struct dso *dso,struct machine *machine)@@ -684,20 +684,19 @@ int dso__data_get_fd(struct dso *dso, struct machine *machine)if (dso->data.status ==DSO_DATA_STATUS_ERROR )return -1 ; -if (pthread_mutex_lock (&dso__data_open_lock) <0 ) -return -1 ; +mutex_lock (&dso__data_open_lock);try_to_open_dso (dso, machine);if (dso->data.fd <0 ) -pthread_mutex_unlock (&dso__data_open_lock); +mutex_unlock (&dso__data_open_lock);return dso->data.fd; }void dso__data_put_fd (struct dso *dso__maybe_unused ) { -pthread_mutex_unlock (&dso__data_open_lock); +mutex_unlock (&dso__data_open_lock); }bool dso__data_status_seen (struct dso *dso,enum dso_data_status_seen by)@@ -756,7 +755,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;@@ -765,7 +764,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)@@ -802,7 +801,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;@@ -823,7 +822,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; }@@ -843,7 +842,7 @@ static ssize_t file_read(struct dso *dso, struct machine *machine, {ssize_t ret; -pthread_mutex_lock (&dso__data_open_lock); +mutex_lock (&dso__data_open_lock);/* * dso->data.fd might be closed if other thread opened another @@ -859,7 +858,7 @@ static ssize_t file_read(struct dso *dso, struct machine *machine, ret =pread (dso->data.fd, data,DSO__DATA_CACHE_SIZE , offset); out: -pthread_mutex_unlock (&dso__data_open_lock); +mutex_unlock (&dso__data_open_lock);return ret; }@@ -953,7 +952,7 @@ static int file_size(struct dso *dso, struct machine *machine)struct stat st;char sbuf[STRERR_BUFSIZE ]; -pthread_mutex_lock (&dso__data_open_lock); +mutex_lock (&dso__data_open_lock);/* * dso->data.fd might be closed if other thread opened another @@ -977,7 +976,7 @@ static int file_size(struct dso *dso, struct machine *machine) dso->data.file_size = st.st_size; out: -pthread_mutex_unlock (&dso__data_open_lock); +mutex_unlock (&dso__data_open_lock);return ret; }@@ -1192,7 +1191,7 @@ struct dso *dso__new(const char *name) 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 ); }@@ -1226,7 +1225,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); }tools/perf/util/dso.h +1
-0@@ -11,6 +11,7 @@#include <stdio.h> #include <linux/bitops.h> #include "build-id.h" +#include "mutex.h" struct machine ;struct map ;
tools/perf/util/dso.h struct dso_cache { · line 136
Quoted 5 lines
tools/perf/util/dso.h +1
-1@@ -132,7 +133,7 @@ struct dso_cache {struct auxtrace_cache ;struct dso { -pthread_mutex_t lock; +struct mutex lock;
There was a previous alignment of the member names, when you see something like this in code you're changing, please keep the style.
Quoted 87 lines
tools/perf/util/dso.h +0
-0struct 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 */ tools/perf/util/mutex.c new file +32
-0@@ -0,0 +1,32 @@ +#include <mutex.h> +#include <pthread.h> + +//to avoid the warning : implicit declaration of BUG_ON, +//we add the following 2 headers. +#include <linux/compiler.h> +#include <linux/kernel.h> + +void mutex_init (struct mutex *mtx) +{ +pthread_mutexattr_t lock_attr; +pthread_mutexattr_init (&lock_attr); +pthread_mutexattr_settype (&lock_attr,PTHREAD_MUTEX_ERRORCHECK ); +BUG_ON (pthread_mutex_init (&mtx->lock, &lock_attr)); +//on success, returns 0. +pthread_mutexattr_destroy (&lock_attr); +} + +void mutex_destroy (struct mutex *mtx) +{ +BUG_ON (pthread_mutex_destroy (&mtx->lock));//on success, returns 0. +} + +void mutex_lock (struct mutex *mtx) +{ +BUG_ON (pthread_mutex_lock (&mtx->lock) !=0 ); +} + +void mutex_unlock (struct mutex *mtx) +{ +BUG_ON (pthread_mutex_unlock (&mtx->lock) !=0 ); +}tools/perf/util/mutex.h new file +15
-0@@ -0,0 +1,15 @@ +#ifndef __PERF_MUTEX_H +#define _PERF_MUTEX_H + +#include <pthread.h> + +struct mutex { +pthread_mutex_t lock; +}; + +void mutex_lock (struct mutex *mtx); +void mutex_unlock (struct mutex *mtx); +void mutex_init (struct mutex *mtx); +void mutex_destroy (struct mutex *mtx); + +#endif /* _PERF_MUTEX_H */ tools/perf/util/symbol.c +2
-2@@ -1629,7 +1629,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)) {@@ -1778,7 +1778,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;Signature · 1 line
2.25.1
Signature · 1 line
- Arnaldo
Namhyung Kim
maintainerHi,
Quoted 3 lines · Arnaldo Carvalho de Melo
Em Wed, Jul 27, 2022 at 04:49:51PM +0530, [email protected] escreveu:
Quoted 1 line
From: pavithra <[email protected]>
Please set the author name to be a full name.
Quoted 3 lines
Quoted 3 lines
Added a new header file
mutex.hthat wraps the usage ofpthread_mutex_tand updated lock indso.h.
What is the point of the wrapping? I think it's to add error checks. Then you need to describe it here and/or in the file comment.
Quoted 19 lines
Hi,
You should create a first patch with just the new
mutex.candmutex.hfiles, then you go on to change the users of pthread_mutex_lock/unlock to the wrappers.Also please add the license on the first line of the new
mutex.[ch] files, seeDocumentation/process/license-rules.rst.tldr; probably what you want is to have this single line in
those the two new files (mutex.[ch]):// SPDX-License-Identifier: GPL-2.0
Quoted 2 lines
Signed-off-by pavithra <[email protected]>---
[SNIP]
Quoted 11 lines
tools/perf/util/mutex.c line 5
Quoted 11 lines
tools/perf/util/mutex.c new file +5
-0@@ -0,0 +1,32 @@ +#include <mutex.h> +#include <pthread.h> + +//to avoid the warning : implicit declaration of BUG_ON, +//we add the following 2 headers.
We usually omit this kind of information. But if you really think it's necessary, you can add a single line comment like:
#include <linux/kernel.h> /* BUG_ON */
Quoted 6 lines
tools/perf/util/mutex.c line 11
Quoted 6 lines
tools/perf/util/mutex.c new file +6
-0+#include <linux/compiler.h> +#include <linux/kernel.h> + +void mutex_init (struct mutex *mtx) +{ +pthread_mutexattr_t lock_attr;
No indentation?
Quoted 4 lines
tools/perf/util/mutex.c line 15
Quoted 4 lines
tools/perf/util/mutex.c new file +4
-0+pthread_mutexattr_init (&lock_attr); +pthread_mutexattr_settype (&lock_attr,PTHREAD_MUTEX_ERRORCHECK ); +BUG_ON (pthread_mutex_init (&mtx->lock, &lock_attr)); +//on success, returns 0.
I believe this belongs to the above line, but it can just be omitted.
Quoted 11 lines
tools/perf/util/mutex.c line 26
Quoted 11 lines
tools/perf/util/mutex.c new file +11
-0+pthread_mutexattr_destroy (&lock_attr); +} + +void mutex_destroy (struct mutex *mtx) +{ +BUG_ON (pthread_mutex_destroy (&mtx->lock));//on success, returns 0. +} + +void mutex_lock (struct mutex *mtx) +{ +BUG_ON (pthread_mutex_lock (&mtx->lock) !=0 );
Maybe this form is better to indicate it returns 0 on success.
Thanks,
Namhyung
Quoted 56 lines
Quoted 50 lines
tools/perf/util/mutex.c new file +6
-0+} + +void mutex_unlock (struct mutex *mtx) +{ +BUG_ON (pthread_mutex_unlock (&mtx->lock) !=0 ); +}tools/perf/util/mutex.h new file +15
-0@@ -0,0 +1,15 @@ +#ifndef __PERF_MUTEX_H +#define _PERF_MUTEX_H + +#include <pthread.h> + +struct mutex { +pthread_mutex_t lock; +}; + +void mutex_lock (struct mutex *mtx); +void mutex_unlock (struct mutex *mtx); +void mutex_init (struct mutex *mtx); +void mutex_destroy (struct mutex *mtx); + +#endif /* _PERF_MUTEX_H */ tools/perf/util/symbol.c +2
-3@@ -1629,7 +1629,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)) {@@ -1778,7 +1778,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; --Quoted 2 lines
2.25.1
--
- Arnaldo