Commit 6fe06449 authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo
Browse files

perf rwsem: Add clang's -Wthread-safety annotations



Add annotations used by clang's -Wthread-safety.

Fix dsos compilation errors caused by a lock of annotations.

Signed-off-by: default avatarIan Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Bill Wendling <morbo@google.com>
Cc: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
Cc: Fei Lang <langfei@huawei.com>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Justin Stitt <justinstitt@google.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <nick.desaulniers+lkml@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephen Brennan <stephen.s.brennan@oracle.com>
Link: https://lore.kernel.org/r/20250519224645.1810891-2-irogers@google.com


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent ab2c742d
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -157,6 +157,7 @@ static struct dso *__dsos__find_by_longname_id(struct dsos *dsos,
					       const char *name,
					       const struct dso_id *id,
					       bool write_locked)
	SHARED_LOCKS_REQUIRED(dsos->lock)
{
	struct dsos__key key = {
		.long_name = name,
@@ -262,6 +263,7 @@ static int dsos__find_id_cb(struct dso *dso, void *data)

static struct dso *__dsos__find_id(struct dsos *dsos, const char *name, const struct dso_id *id,
				   bool cmp_short, bool write_locked)
	SHARED_LOCKS_REQUIRED(dsos->lock)
{
	struct dso *res;

@@ -338,6 +340,7 @@ static struct dso *__dsos__addnew_id(struct dsos *dsos, const char *name, const
}

static struct dso *__dsos__findnew_id(struct dsos *dsos, const char *name, const struct dso_id *id)
	SHARED_LOCKS_REQUIRED(dsos->lock)
{
	struct dso *dso = __dsos__find_id(dsos, name, id, false, /*write_locked=*/true);

+11 −0
Original line number Diff line number Diff line
@@ -42,6 +42,12 @@
/* Documents functions that acquire a lock in the body of a function, and do not release it. */
#define EXCLUSIVE_LOCK_FUNCTION(...)  __attribute__((exclusive_lock_function(__VA_ARGS__)))

/*
 * Documents functions that acquire a shared (reader) lock in the body of a
 * function, and do not release it.
 */
#define SHARED_LOCK_FUNCTION(...)  __attribute__((shared_lock_function(__VA_ARGS__)))

/*
 * Documents functions that expect a lock to be held on entry to the function,
 * and release it in the body of the function.
@@ -55,6 +61,9 @@
/* Documents a function that expects a mutex to be held prior to entry. */
#define EXCLUSIVE_LOCKS_REQUIRED(...) __attribute__((exclusive_locks_required(__VA_ARGS__)))

/* Documents a function that expects a shared (reader) lock to be held prior to entry. */
#define SHARED_LOCKS_REQUIRED(...) __attribute__((shared_locks_required(__VA_ARGS__)))

/* Turns off thread safety checking within the body of a particular function. */
#define NO_THREAD_SAFETY_ANALYSIS __attribute__((no_thread_safety_analysis))

@@ -66,9 +75,11 @@
#define LOCKS_EXCLUDED(...)
#define LOCK_RETURNED(x)
#define EXCLUSIVE_LOCK_FUNCTION(...)
#define SHARED_LOCK_FUNCTION(...)
#define UNLOCK_FUNCTION(...)
#define EXCLUSIVE_TRYLOCK_FUNCTION(...)
#define EXCLUSIVE_LOCKS_REQUIRED(...)
#define SHARED_LOCKS_REQUIRED(...)
#define NO_THREAD_SAFETY_ANALYSIS

#endif
+4 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ int exit_rwsem(struct rw_semaphore *sem)
}

int down_read(struct rw_semaphore *sem)
	NO_THREAD_SAFETY_ANALYSIS
{
#if RWS_ERRORCHECK
	mutex_lock(&sem->mtx);
@@ -37,6 +38,7 @@ int down_read(struct rw_semaphore *sem)
}

int up_read(struct rw_semaphore *sem)
	NO_THREAD_SAFETY_ANALYSIS
{
#if RWS_ERRORCHECK
	mutex_unlock(&sem->mtx);
@@ -47,6 +49,7 @@ int up_read(struct rw_semaphore *sem)
}

int down_write(struct rw_semaphore *sem)
	NO_THREAD_SAFETY_ANALYSIS
{
#if RWS_ERRORCHECK
	mutex_lock(&sem->mtx);
@@ -57,6 +60,7 @@ int down_write(struct rw_semaphore *sem)
}

int up_write(struct rw_semaphore *sem)
	NO_THREAD_SAFETY_ANALYSIS
{
#if RWS_ERRORCHECK
	mutex_unlock(&sem->mtx);
+5 −5
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@
 */
#define RWS_ERRORCHECK 0

struct rw_semaphore {
struct LOCKABLE rw_semaphore {
#if RWS_ERRORCHECK
	struct mutex mtx;
#else
@@ -21,10 +21,10 @@ struct rw_semaphore {
int init_rwsem(struct rw_semaphore *sem);
int exit_rwsem(struct rw_semaphore *sem);

int down_read(struct rw_semaphore *sem);
int up_read(struct rw_semaphore *sem);
int down_read(struct rw_semaphore *sem) SHARED_LOCK_FUNCTION(sem);
int up_read(struct rw_semaphore *sem) UNLOCK_FUNCTION(sem);

int down_write(struct rw_semaphore *sem);
int up_write(struct rw_semaphore *sem);
int down_write(struct rw_semaphore *sem) EXCLUSIVE_LOCK_FUNCTION(sem);
int up_write(struct rw_semaphore *sem) UNLOCK_FUNCTION(sem);

#endif /* _PERF_RWSEM_H */