Re: [PATCH v3 11/18] perf dso: Update use of pthread mutex

Adrian Hunter
2022-08-26T10:37:45Z

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 <irogers@google.com>
> ---
> 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 <pthread.h>
> #include <linux/refcount.h>
> #include <linux/types.h>
> #include <linux/rbtree.h>
> @@ -11,6 +10,7 @@
> #include <stdio.h>
> #include <linux/bitops.h>
> #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;