lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAM9d7chRyvYQMYaPSiem8_9wwh6+p0mgF3qMD++17QNpbWGGeg@mail.gmail.com>
Date:   Wed, 27 Jul 2022 15:43:00 -0700
From:   Namhyung Kim <namhyung@...nel.org>
To:     gpavithrasha@...il.com
Cc:     Arnaldo Carvalho de Melo <acme@...nel.org>,
        Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...hat.com>,
        Mark Rutland <mark.rutland@....com>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Jiri Olsa <jolsa@...hat.com>,
        linux-kernel <linux-kernel@...r.kernel.org>,
        linux-perf-users <linux-perf-users@...r.kernel.org>,
        Ian Rogers <irogers@...gle.com>
Subject: Re: [PATCH v1 3/4] perf mutex and cond: Updated files mutex.h & mutex.c

On Wed, Jul 27, 2022 at 4:20 AM <gpavithrasha@...il.com> wrote:
>
> From: pavithra <gpavithrasha@...il.com>
>
> Added new struct and corresponding
> functions to wrap usage of pthread_cond_t.
> Added a new function for mutex_trylock-similar to
> mutex_lock.
>
> Signed-off-by: pavithra <gpavithrasha@...il.com>
> ---
>  tools/perf/util/mutex.c | 37 ++++++++++++++++++++++++++++++++-----
>  tools/perf/util/mutex.h | 13 +++++++++++--
>  2 files changed, 43 insertions(+), 7 deletions(-)
>
> diff --git a/tools/perf/util/mutex.c b/tools/perf/util/mutex.c
> index b7264a1438c4..9dc37a3f374f 100644
> --- a/tools/perf/util/mutex.c
> +++ b/tools/perf/util/mutex.c
> @@ -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));

Above changes should belong to the patch 1.

>  }
>
>  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));

Please be consistent with != 0.

Thanks,
Namhyung


> +pthread_condattr_destroy(&attr);
> +}
> diff --git a/tools/perf/util/mutex.h b/tools/perf/util/mutex.h
> index ab2ebb98b24a..f1b4aaa151be 100644
> --- a/tools/perf/util/mutex.h
> +++ b/tools/perf/util/mutex.h
> @@ -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
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ