Skip to content

Commit 6fe0644

Browse files
captain5050acmel
authored andcommitted
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: Ian Rogers <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Athira Rajeev <[email protected]> Cc: Bill Wendling <[email protected]> Cc: Chaitanya S Prakash <[email protected]> Cc: Fei Lang <[email protected]> Cc: Howard Chu <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James Clark <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Justin Stitt <[email protected]> Cc: Kan Liang <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Nathan Chancellor <[email protected]> Cc: Nick Desaulniers <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephen Brennan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent ab2c742 commit 6fe0644

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

tools/perf/util/dsos.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ static struct dso *__dsos__find_by_longname_id(struct dsos *dsos,
157157
const char *name,
158158
const struct dso_id *id,
159159
bool write_locked)
160+
SHARED_LOCKS_REQUIRED(dsos->lock)
160161
{
161162
struct dsos__key key = {
162163
.long_name = name,
@@ -262,6 +263,7 @@ static int dsos__find_id_cb(struct dso *dso, void *data)
262263

263264
static struct dso *__dsos__find_id(struct dsos *dsos, const char *name, const struct dso_id *id,
264265
bool cmp_short, bool write_locked)
266+
SHARED_LOCKS_REQUIRED(dsos->lock)
265267
{
266268
struct dso *res;
267269

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

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

tools/perf/util/mutex.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
/* Documents functions that acquire a lock in the body of a function, and do not release it. */
4343
#define EXCLUSIVE_LOCK_FUNCTION(...) __attribute__((exclusive_lock_function(__VA_ARGS__)))
4444

45+
/*
46+
* Documents functions that acquire a shared (reader) lock in the body of a
47+
* function, and do not release it.
48+
*/
49+
#define SHARED_LOCK_FUNCTION(...) __attribute__((shared_lock_function(__VA_ARGS__)))
50+
4551
/*
4652
* Documents functions that expect a lock to be held on entry to the function,
4753
* and release it in the body of the function.
@@ -55,6 +61,9 @@
5561
/* Documents a function that expects a mutex to be held prior to entry. */
5662
#define EXCLUSIVE_LOCKS_REQUIRED(...) __attribute__((exclusive_locks_required(__VA_ARGS__)))
5763

64+
/* Documents a function that expects a shared (reader) lock to be held prior to entry. */
65+
#define SHARED_LOCKS_REQUIRED(...) __attribute__((shared_locks_required(__VA_ARGS__)))
66+
5867
/* Turns off thread safety checking within the body of a particular function. */
5968
#define NO_THREAD_SAFETY_ANALYSIS __attribute__((no_thread_safety_analysis))
6069

@@ -66,9 +75,11 @@
6675
#define LOCKS_EXCLUDED(...)
6776
#define LOCK_RETURNED(x)
6877
#define EXCLUSIVE_LOCK_FUNCTION(...)
78+
#define SHARED_LOCK_FUNCTION(...)
6979
#define UNLOCK_FUNCTION(...)
7080
#define EXCLUSIVE_TRYLOCK_FUNCTION(...)
7181
#define EXCLUSIVE_LOCKS_REQUIRED(...)
82+
#define SHARED_LOCKS_REQUIRED(...)
7283
#define NO_THREAD_SAFETY_ANALYSIS
7384

7485
#endif

tools/perf/util/rwsem.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ int exit_rwsem(struct rw_semaphore *sem)
2727
}
2828

2929
int down_read(struct rw_semaphore *sem)
30+
NO_THREAD_SAFETY_ANALYSIS
3031
{
3132
#if RWS_ERRORCHECK
3233
mutex_lock(&sem->mtx);
@@ -37,6 +38,7 @@ int down_read(struct rw_semaphore *sem)
3738
}
3839

3940
int up_read(struct rw_semaphore *sem)
41+
NO_THREAD_SAFETY_ANALYSIS
4042
{
4143
#if RWS_ERRORCHECK
4244
mutex_unlock(&sem->mtx);
@@ -47,6 +49,7 @@ int up_read(struct rw_semaphore *sem)
4749
}
4850

4951
int down_write(struct rw_semaphore *sem)
52+
NO_THREAD_SAFETY_ANALYSIS
5053
{
5154
#if RWS_ERRORCHECK
5255
mutex_lock(&sem->mtx);
@@ -57,6 +60,7 @@ int down_write(struct rw_semaphore *sem)
5760
}
5861

5962
int up_write(struct rw_semaphore *sem)
63+
NO_THREAD_SAFETY_ANALYSIS
6064
{
6165
#if RWS_ERRORCHECK
6266
mutex_unlock(&sem->mtx);

tools/perf/util/rwsem.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
#define RWS_ERRORCHECK 0
1212

13-
struct rw_semaphore {
13+
struct LOCKABLE rw_semaphore {
1414
#if RWS_ERRORCHECK
1515
struct mutex mtx;
1616
#else
@@ -21,10 +21,10 @@ struct rw_semaphore {
2121
int init_rwsem(struct rw_semaphore *sem);
2222
int exit_rwsem(struct rw_semaphore *sem);
2323

24-
int down_read(struct rw_semaphore *sem);
25-
int up_read(struct rw_semaphore *sem);
24+
int down_read(struct rw_semaphore *sem) SHARED_LOCK_FUNCTION(sem);
25+
int up_read(struct rw_semaphore *sem) UNLOCK_FUNCTION(sem);
2626

27-
int down_write(struct rw_semaphore *sem);
28-
int up_write(struct rw_semaphore *sem);
27+
int down_write(struct rw_semaphore *sem) EXCLUSIVE_LOCK_FUNCTION(sem);
28+
int up_write(struct rw_semaphore *sem) UNLOCK_FUNCTION(sem);
2929

3030
#endif /* _PERF_RWSEM_H */

0 commit comments

Comments
 (0)