Skip to contentSkip to conversation

liblockdep: remove the need for liblockdep_init

PATCH In review Sasha Levin 2 participants 26 messages Feb 10, 2013 – Feb 20, 2013 perf events

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/11 liblockdep: remove the need for liblockdep_init

Use a constructor in the library instead of making the user manually call liblockdep_init().

---
 tools/lib/lockdep/common.c                    | 2 +-
 tools/lib/lockdep/include/liblockdep/common.h | 1 -
 tools/lib/lockdep/tests/AA.c                  | 1 -
 tools/lib/lockdep/tests/ABBA.c                | 1 -
 tools/lib/lockdep/tests/ABBCCA.c              | 1 -
 tools/lib/lockdep/tests/ABBCCDDA.c            | 1 -
 tools/lib/lockdep/tests/ABCABC.c              | 1 -
 tools/lib/lockdep/tests/ABCDBCDA.c            | 1 -
 tools/lib/lockdep/tests/ABCDBDDA.c            | 1 -
 tools/lib/lockdep/tests/WW.c                  | 1 -
 tools/lib/lockdep/tests/unlock_balance.c      | 1 -
 tools/lib/lockdep/uinclude/linux/lockdep.h    | 1 -
 12 files changed, 1 insertion(+), 12 deletions(-)
tools/lib/lockdep/common.c +1 -1
index 99d3b4b..d2946e0 100644
@@ -10,7 +10,7 @@ __thread struct task_struct current_obj;
 bool debug_locks = true;
 bool debug_locks_silent;
 
-void liblockdep_init(void)
+__attribute__((constructor)) static void liblockdep_init(void)
 {
 	lockdep_init();
 }
tools/lib/lockdep/include/liblockdep/common.h +0 -1
index b72f9c1..f6f7fec8 100644
@@ -26,7 +26,6 @@ struct lockdep_map {
 #endif
 };
 
-void liblockdep_init(void);
 void liblockdep_set_thread(void);
 void lockdep_init_map(struct lockdep_map *lock, const char *name,
 			struct lock_class_key *key, int subclass);
tools/lib/lockdep/tests/AA.c +0 -1
index 933d32f..3f71333 100644
@@ -4,7 +4,6 @@ void main(void)
 {
 	pthread_mutex_t a, b;
 
-	liblockdep_init();
 	liblockdep_set_thread();
 
 	pthread_mutex_init(&a, NULL);
tools/lib/lockdep/tests/ABBA.c +0 -1
index 9f5146b..08d87a7 100644
@@ -5,7 +5,6 @@ void main(void)
 {
 	pthread_mutex_t a, b;
 
-	liblockdep_init();
 	liblockdep_set_thread();
 
 	pthread_mutex_init(&a, NULL);
tools/lib/lockdep/tests/ABBCCA.c +0 -1
index b7435d7..c5d0e5c 100644
@@ -5,7 +5,6 @@ void main(void)
 {
 	pthread_mutex_t a, b, c;
 
-	liblockdep_init();
 	liblockdep_set_thread();
 
 	pthread_mutex_init(&a, NULL);
tools/lib/lockdep/tests/ABBCCDDA.c +0 -1
index 2425330..e12dc98 100644
@@ -5,7 +5,6 @@ void main(void)
 {
 	pthread_mutex_t a, b, c, d;
 
-	liblockdep_init();
 	liblockdep_set_thread();
 
 	pthread_mutex_init(&a, NULL);
tools/lib/lockdep/tests/ABCABC.c +0 -1
index 2ee30fe..70879c95 100644
@@ -5,7 +5,6 @@ void main(void)
 {
 	pthread_mutex_t a, b, c;
 
-	liblockdep_init();
 	liblockdep_set_thread();
 
 	pthread_mutex_init(&a, NULL);
tools/lib/lockdep/tests/ABCDBCDA.c +0 -1
index 32d19d6..00cd676 100644
@@ -5,7 +5,6 @@ void main(void)
 {
 	liblockdep_pthread_mutex_t a, b, c, d;
 
-	liblockdep_init();
 	liblockdep_set_thread();
 
 	liblockdep_pthread_mutex_init(&a, NULL);
tools/lib/lockdep/tests/ABCDBDDA.c +0 -1
index 850eaca..19b3ed1 100644
@@ -5,7 +5,6 @@ void main(void)
 {
 	pthread_mutex_t a, b, c, d;
 
-	liblockdep_init();
 	liblockdep_set_thread();
 
 	pthread_mutex_init(&a, NULL);
tools/lib/lockdep/tests/WW.c +0 -1
index 4b1be0f..2467b13 100644
@@ -4,7 +4,6 @@ void main(void)
 {
 	pthread_rwlock_t a, b;
 
-	liblockdep_init();
 	liblockdep_set_thread();
 
 	pthread_rwlock_init(&a, NULL);
tools/lib/lockdep/tests/unlock_balance.c +0 -1
index 9dfaf97..07a4c21 100644
@@ -4,7 +4,6 @@ void main(void)
 {
 	pthread_mutex_t a;
 
-	liblockdep_init();
 	liblockdep_set_thread();
 
 	pthread_mutex_init(&a, NULL);
tools/lib/lockdep/uinclude/linux/lockdep.h +0 -1
index 1ed83a5..611cb28 100644
@@ -25,7 +25,6 @@ struct task_struct {
 extern __thread struct task_struct current_obj;
 #define current (&current_obj)
 
-void liblockdep_init(void);
 void liblockdep_set_thread(void);
 
 #define debug_locks_off() 1
Signature · 1 line
1.8.1.2
#1 lore raw

PATCH v2 2/11 liblockdep: remove the need for liblockdep_set_thread

Generate the task_struct data on the fly when needed, instead on on thread creation.

---
 tools/lib/lockdep/common.c                    | 8 +++++---
 tools/lib/lockdep/include/liblockdep/common.h | 1 -
 tools/lib/lockdep/tests/AA.c                  | 2 --
 tools/lib/lockdep/tests/ABBA.c                | 2 --
 tools/lib/lockdep/tests/ABBCCA.c              | 2 --
 tools/lib/lockdep/tests/ABBCCDDA.c            | 2 --
 tools/lib/lockdep/tests/ABCABC.c              | 2 --
 tools/lib/lockdep/tests/ABCDBCDA.c            | 2 --
 tools/lib/lockdep/tests/ABCDBDDA.c            | 2 --
 tools/lib/lockdep/tests/WW.c                  | 2 --
 tools/lib/lockdep/tests/unlock_balance.c      | 2 --
 tools/lib/lockdep/uinclude/linux/lockdep.h    | 4 ++--
 12 files changed, 7 insertions(+), 24 deletions(-)
tools/lib/lockdep/common.c +5 -3
index d2946e0..c0f1166 100644
@@ -15,8 +15,10 @@ __attribute__((constructor)) static void liblockdep_init(void)
 	lockdep_init();
 }
 
-void liblockdep_set_thread(void)
+struct task_struct *__curr(void)
 {
-	prctl(PR_GET_NAME, current->comm);
-	current->pid = syscall(__NR_gettid);
+	prctl(PR_GET_NAME, current_obj.comm);
+	current_obj.pid = syscall(__NR_gettid);
+
+	return &current_obj;
 }
tools/lib/lockdep/include/liblockdep/common.h +0 -1
index f6f7fec8..a675ef0 100644
@@ -26,7 +26,6 @@ struct lockdep_map {
 #endif
 };
 
-void liblockdep_set_thread(void);
 void lockdep_init_map(struct lockdep_map *lock, const char *name,
 			struct lock_class_key *key, int subclass);
 void lock_acquire(struct lockdep_map *lock, unsigned int subclass,
tools/lib/lockdep/tests/AA.c +0 -2
index 3f71333..a443e65 100644
@@ -4,8 +4,6 @@ void main(void)
 {
 	pthread_mutex_t a, b;
 
-	liblockdep_set_thread();
-
 	pthread_mutex_init(&a, NULL);
 	pthread_mutex_init(&b, NULL);
 
tools/lib/lockdep/tests/ABBA.c +0 -2
index 08d87a7..07f0e29 100644
@@ -5,8 +5,6 @@ void main(void)
 {
 	pthread_mutex_t a, b;
 
-	liblockdep_set_thread();
-
 	pthread_mutex_init(&a, NULL);
 	pthread_mutex_init(&b, NULL);
 
tools/lib/lockdep/tests/ABBCCA.c +0 -2
index c5d0e5c..843db09 100644
@@ -5,8 +5,6 @@ void main(void)
 {
 	pthread_mutex_t a, b, c;
 
-	liblockdep_set_thread();
-
 	pthread_mutex_init(&a, NULL);
 	pthread_mutex_init(&b, NULL);
 	pthread_mutex_init(&c, NULL);
tools/lib/lockdep/tests/ABBCCDDA.c +0 -2
index e12dc98..33620e2 100644
@@ -5,8 +5,6 @@ void main(void)
 {
 	pthread_mutex_t a, b, c, d;
 
-	liblockdep_set_thread();
-
 	pthread_mutex_init(&a, NULL);
 	pthread_mutex_init(&b, NULL);
 	pthread_mutex_init(&c, NULL);
tools/lib/lockdep/tests/ABCABC.c +0 -2
index 70879c95..3fee51e 100644
@@ -5,8 +5,6 @@ void main(void)
 {
 	pthread_mutex_t a, b, c;
 
-	liblockdep_set_thread();
-
 	pthread_mutex_init(&a, NULL);
 	pthread_mutex_init(&b, NULL);
 	pthread_mutex_init(&c, NULL);
tools/lib/lockdep/tests/ABCDBCDA.c +0 -2
index 00cd676..aadf11e 100644
@@ -5,8 +5,6 @@ void main(void)
 {
 	liblockdep_pthread_mutex_t a, b, c, d;
 
-	liblockdep_set_thread();
-
 	liblockdep_pthread_mutex_init(&a, NULL);
 	liblockdep_pthread_mutex_init(&b, NULL);
 	liblockdep_pthread_mutex_init(&c, NULL);
tools/lib/lockdep/tests/ABCDBDDA.c +0 -2
index 19b3ed1..680c6cf 100644
@@ -5,8 +5,6 @@ void main(void)
 {
 	pthread_mutex_t a, b, c, d;
 
-	liblockdep_set_thread();
-
 	pthread_mutex_init(&a, NULL);
 	pthread_mutex_init(&b, NULL);
 	pthread_mutex_init(&c, NULL);
tools/lib/lockdep/tests/WW.c +0 -2
index 2467b13..d44f77d 100644
@@ -4,8 +4,6 @@ void main(void)
 {
 	pthread_rwlock_t a, b;
 
-	liblockdep_set_thread();
-
 	pthread_rwlock_init(&a, NULL);
 	pthread_rwlock_init(&b, NULL);
 
tools/lib/lockdep/tests/unlock_balance.c +0 -2
index 07a4c21..0bc62de 100644
@@ -4,8 +4,6 @@ void main(void)
 {
 	pthread_mutex_t a;
 
-	liblockdep_set_thread();
-
 	pthread_mutex_init(&a, NULL);
 
 	pthread_mutex_lock(&a);
tools/lib/lockdep/uinclude/linux/lockdep.h +2 -2
index 611cb28..52609c5 100644
@@ -23,9 +23,9 @@ struct task_struct {
 };
 
 extern __thread struct task_struct current_obj;
-#define current (&current_obj)
+extern struct task_struct *__curr(void);
 
-void liblockdep_set_thread(void);
+#define current (__curr())
 
 #define debug_locks_off() 1
 #define task_pid_nr(tsk) ((tsk)->pid)
Signature · 1 line
1.8.1.2
#2 lore raw

[tip:core/locking] liblockdep: Remove the need for liblockdep_set_thread()

Commit-ID:  4d81b02bbc6aa485e9cf0bdb6951b7b1b4952bb8
Gitweb:     http://git.kernel.org/tip/4d81b02bbc6aa485e9cf0bdb6951b7b1b4952bb8
Author:     Sasha Levin <[email protected]>
AuthorDate: Sat, 9 Feb 2013 19:39:32 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 11 Feb 2013 10:12:36 +0100

liblockdep: Remove the need for liblockdep_set_thread()

Generate the task_struct data on the fly when needed, instead on on thread creation.

---
 tools/lib/lockdep/common.c                    | 8 +++++---
 tools/lib/lockdep/include/liblockdep/common.h | 1 -
 tools/lib/lockdep/tests/AA.c                  | 2 --
 tools/lib/lockdep/tests/ABBA.c                | 2 --
 tools/lib/lockdep/tests/ABBCCA.c              | 2 --
 tools/lib/lockdep/tests/ABBCCDDA.c            | 2 --
 tools/lib/lockdep/tests/ABCABC.c              | 2 --
 tools/lib/lockdep/tests/ABCDBCDA.c            | 2 --
 tools/lib/lockdep/tests/ABCDBDDA.c            | 2 --
 tools/lib/lockdep/tests/WW.c                  | 2 --
 tools/lib/lockdep/tests/unlock_balance.c      | 2 --
 tools/lib/lockdep/uinclude/linux/lockdep.h    | 4 ++--
 12 files changed, 7 insertions(+), 24 deletions(-)
tools/lib/lockdep/common.c +5 -3
index d2946e0..c0f1166 100644
@@ -15,8 +15,10 @@ __attribute__((constructor)) static void liblockdep_init(void)
 	lockdep_init();
 }
 
-void liblockdep_set_thread(void)
+struct task_struct *__curr(void)
 {
-	prctl(PR_GET_NAME, current->comm);
-	current->pid = syscall(__NR_gettid);
+	prctl(PR_GET_NAME, current_obj.comm);
+	current_obj.pid = syscall(__NR_gettid);
+
+	return &current_obj;
 }
tools/lib/lockdep/include/liblockdep/common.h +0 -1
index f6f7fec8..a675ef0 100644
@@ -26,7 +26,6 @@ struct lockdep_map {
 #endif
 };
 
-void liblockdep_set_thread(void);
 void lockdep_init_map(struct lockdep_map *lock, const char *name,
 			struct lock_class_key *key, int subclass);
 void lock_acquire(struct lockdep_map *lock, unsigned int subclass,
tools/lib/lockdep/tests/AA.c +0 -2
index 3f71333..a443e65 100644
@@ -4,8 +4,6 @@ void main(void)
 {
 	pthread_mutex_t a, b;
 
-	liblockdep_set_thread();
-
 	pthread_mutex_init(&a, NULL);
 	pthread_mutex_init(&b, NULL);
 
tools/lib/lockdep/tests/ABBA.c +0 -2
index 08d87a7..07f0e29 100644
@@ -5,8 +5,6 @@ void main(void)
 {
 	pthread_mutex_t a, b;
 
-	liblockdep_set_thread();
-
 	pthread_mutex_init(&a, NULL);
 	pthread_mutex_init(&b, NULL);
 
tools/lib/lockdep/tests/ABBCCA.c +0 -2
index c5d0e5c..843db09 100644
@@ -5,8 +5,6 @@ void main(void)
 {
 	pthread_mutex_t a, b, c;
 
-	liblockdep_set_thread();
-
 	pthread_mutex_init(&a, NULL);
 	pthread_mutex_init(&b, NULL);
 	pthread_mutex_init(&c, NULL);
tools/lib/lockdep/tests/ABBCCDDA.c +0 -2
index e12dc98..33620e2 100644
@@ -5,8 +5,6 @@ void main(void)
 {
 	pthread_mutex_t a, b, c, d;
 
-	liblockdep_set_thread();
-
 	pthread_mutex_init(&a, NULL);
 	pthread_mutex_init(&b, NULL);
 	pthread_mutex_init(&c, NULL);
tools/lib/lockdep/tests/ABCABC.c +0 -2
index 70879c95..3fee51e 100644
@@ -5,8 +5,6 @@ void main(void)
 {
 	pthread_mutex_t a, b, c;
 
-	liblockdep_set_thread();
-
 	pthread_mutex_init(&a, NULL);
 	pthread_mutex_init(&b, NULL);
 	pthread_mutex_init(&c, NULL);
tools/lib/lockdep/tests/ABCDBCDA.c +0 -2
index 00cd676..aadf11e 100644
@@ -5,8 +5,6 @@ void main(void)
 {
 	liblockdep_pthread_mutex_t a, b, c, d;
 
-	liblockdep_set_thread();
-
 	liblockdep_pthread_mutex_init(&a, NULL);
 	liblockdep_pthread_mutex_init(&b, NULL);
 	liblockdep_pthread_mutex_init(&c, NULL);
tools/lib/lockdep/tests/ABCDBDDA.c +0 -2
index 19b3ed1..680c6cf 100644
@@ -5,8 +5,6 @@ void main(void)
 {
 	pthread_mutex_t a, b, c, d;
 
-	liblockdep_set_thread();
-
 	pthread_mutex_init(&a, NULL);
 	pthread_mutex_init(&b, NULL);
 	pthread_mutex_init(&c, NULL);
tools/lib/lockdep/tests/WW.c +0 -2
index 2467b13..d44f77d 100644
@@ -4,8 +4,6 @@ void main(void)
 {
 	pthread_rwlock_t a, b;
 
-	liblockdep_set_thread();
-
 	pthread_rwlock_init(&a, NULL);
 	pthread_rwlock_init(&b, NULL);
 
tools/lib/lockdep/tests/unlock_balance.c +0 -2
index 07a4c21..0bc62de 100644
@@ -4,8 +4,6 @@ void main(void)
 {
 	pthread_mutex_t a;
 
-	liblockdep_set_thread();
-
 	pthread_mutex_init(&a, NULL);
 
 	pthread_mutex_lock(&a);
tools/lib/lockdep/uinclude/linux/lockdep.h +2 -2
index 611cb28..52609c5 100644
@@ -23,9 +23,9 @@ struct task_struct {
 };
 
 extern __thread struct task_struct current_obj;
-#define current (&current_obj)
+extern struct task_struct *__curr(void);
 
-void liblockdep_set_thread(void);
+#define current (__curr())
 
 #define debug_locks_off() 1
 #define task_pid_nr(tsk) ((tsk)->pid)
#3 lore raw

PATCH v2 3/11 perf: stop using liblockdep_init and liblockdep_set_thread

In reply to Sasha Levin

These functions are no longer needed by liblockdep, drop them.

---
 tools/perf/builtin-sched.c          | 2 --
 tools/perf/builtin-top.c            | 4 ----
 tools/perf/config/feature-tests.mak | 1 -
 tools/perf/perf.c                   | 3 ---
 tools/perf/util/liblockdep.h        | 2 --
 5 files changed, 12 deletions(-)
tools/perf/builtin-sched.c +0 -2
index 53d9225..e1f0c44 100644
@@ -468,8 +468,6 @@ static void *thread_func(void *ctx)
 	char comm2[22];
 	int fd;
 
-	liblockdep_set_thread();
-
 	free(parms);
 
 	sprintf(comm2, ":%s", this_task->comm);
tools/perf/builtin-top.c +0 -4
index c9b99ef..c9ff395 100644
@@ -588,8 +588,6 @@ static void *display_thread_tui(void *arg)
 		.refresh	= top->delay_secs,
 	};
 
-	liblockdep_set_thread();
-
 	perf_top__sort_new_samples(top);
 
 	/*
@@ -615,8 +613,6 @@ static void *display_thread(void *arg)
 	struct perf_top *top = arg;
 	int delay_msecs, c;
 
-	liblockdep_set_thread();
-
 	tcgetattr(0, &save);
 	tc = save;
 	tc.c_lflag &= ~(ICANON | ECHO);
tools/perf/config/feature-tests.mak +0 -1
index 1f5a37e..20f8f7b 100644
@@ -223,7 +223,6 @@ define SOURCE_LIBLOCKDEP
 
 int main(void)
 {
-	liblockdep_init();
 	return 0;
 }
 endef
tools/perf/perf.c +0 -3
index ddbd315..0f661fb 100644
@@ -446,9 +446,6 @@ int main(int argc, const char **argv)
 {
 	const char *cmd;
 
-	liblockdep_init();
-	liblockdep_set_thread();
-
 	page_size = sysconf(_SC_PAGE_SIZE);
 
 	cmd = perf_extract_argv0_path(argv[0]);
tools/perf/util/liblockdep.h +0 -2
index 628a2f5..798263f 100644
@@ -5,7 +5,5 @@
 #else
 
 #define LIBLOCKDEP_PTHREAD_MUTEX_INITIALIZER(mtx) PTHREAD_MUTEX_INITIALIZER
-#define liblockdep_init()
-#define liblockdep_set_thread()
 
 #endif
Signature · 1 line
1.8.1.2
#4 lore raw

[tip:core/locking] perf: Stop using liblockdep_init() and liblockdep_set_thread()

Commit-ID:  bf48cfee5efb3f86c0620acd76b873a6f50bb11a
Gitweb:     http://git.kernel.org/tip/bf48cfee5efb3f86c0620acd76b873a6f50bb11a
Author:     Sasha Levin <[email protected]>
AuthorDate: Sat, 9 Feb 2013 19:39:33 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 11 Feb 2013 10:12:37 +0100

perf: Stop using liblockdep_init() and liblockdep_set_thread()

These functions are no longer needed by liblockdep, drop them.

---
 tools/perf/builtin-sched.c          | 2 --
 tools/perf/builtin-top.c            | 4 ----
 tools/perf/config/feature-tests.mak | 1 -
 tools/perf/perf.c                   | 3 ---
 tools/perf/util/liblockdep.h        | 2 --
 5 files changed, 12 deletions(-)
tools/perf/builtin-sched.c +0 -2
index 53d9225..e1f0c44 100644
@@ -468,8 +468,6 @@ static void *thread_func(void *ctx)
 	char comm2[22];
 	int fd;
 
-	liblockdep_set_thread();
-
 	free(parms);
 
 	sprintf(comm2, ":%s", this_task->comm);
tools/perf/builtin-top.c +0 -4
index c9b99ef..c9ff395 100644
@@ -588,8 +588,6 @@ static void *display_thread_tui(void *arg)
 		.refresh	= top->delay_secs,
 	};
 
-	liblockdep_set_thread();
-
 	perf_top__sort_new_samples(top);
 
 	/*
@@ -615,8 +613,6 @@ static void *display_thread(void *arg)
 	struct perf_top *top = arg;
 	int delay_msecs, c;
 
-	liblockdep_set_thread();
-
 	tcgetattr(0, &save);
 	tc = save;
 	tc.c_lflag &= ~(ICANON | ECHO);
tools/perf/config/feature-tests.mak +0 -1
index 1f5a37e..20f8f7b 100644
@@ -223,7 +223,6 @@ define SOURCE_LIBLOCKDEP
 
 int main(void)
 {
-	liblockdep_init();
 	return 0;
 }
 endef
tools/perf/perf.c +0 -3
index ddbd315..0f661fb 100644
@@ -446,9 +446,6 @@ int main(int argc, const char **argv)
 {
 	const char *cmd;
 
-	liblockdep_init();
-	liblockdep_set_thread();
-
 	page_size = sysconf(_SC_PAGE_SIZE);
 
 	cmd = perf_extract_argv0_path(argv[0]);
tools/perf/util/liblockdep.h +0 -2
index 628a2f5..798263f 100644
@@ -5,7 +5,5 @@
 #else
 
 #define LIBLOCKDEP_PTHREAD_MUTEX_INITIALIZER(mtx) PTHREAD_MUTEX_INITIALIZER
-#define liblockdep_init()
-#define liblockdep_set_thread()
 
 #endif
#5 lore raw

PATCH v2 4/11 liblockdep: fix AA test

In reply to Sasha Levin

We were accidently unlocking the dummy mutex in the test, which meant that we were testing unlock balance instead of AA deadlock.

---
 tools/lib/lockdep/tests/AA.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/lockdep/tests/AA.c +1 -1
index a443e65..0f782ff 100644
@@ -8,6 +8,6 @@ void main(void)
 	pthread_mutex_init(&b, NULL);
 
 	pthread_mutex_lock(&a);
-	pthread_mutex_unlock(&b);
+	pthread_mutex_lock(&b);
 	pthread_mutex_lock(&a);
 }
Signature · 1 line
1.8.1.2
#6 lore raw

[tip:core/locking] liblockdep: Fix the AA locking test

Commit-ID:  47283ee709d09e43cff7feaf8bb9ff24fb9e7fd5
Gitweb:     http://git.kernel.org/tip/47283ee709d09e43cff7feaf8bb9ff24fb9e7fd5
Author:     Sasha Levin <[email protected]>
AuthorDate: Sat, 9 Feb 2013 19:39:34 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 11 Feb 2013 10:12:37 +0100

liblockdep: Fix the AA locking test

We were accidently unlocking the dummy mutex in the test, which meant that we were testing unlock balance instead of AA deadlock.

---
 tools/lib/lockdep/tests/AA.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/lockdep/tests/AA.c +1 -1
index a443e65..0f782ff 100644
@@ -8,6 +8,6 @@ void main(void)
 	pthread_mutex_init(&b, NULL);
 
 	pthread_mutex_lock(&a);
-	pthread_mutex_unlock(&b);
+	pthread_mutex_lock(&b);
 	pthread_mutex_lock(&a);
 }
#7 lore raw

PATCH v2 5/11 liblockdep: correct the ABCDBCDA test

In reply to Sasha Levin

There's no need to use liblockdep specific calls, they are wrapped for us.

---
 tools/lib/lockdep/tests/ABCDBCDA.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tools/lib/lockdep/tests/ABCDBCDA.c +5 -5
index aadf11e..427ba56 100644
@@ -3,12 +3,12 @@
 
 void main(void)
 {
-	liblockdep_pthread_mutex_t a, b, c, d;
+	pthread_mutex_t a, b, c, d;
 
-	liblockdep_pthread_mutex_init(&a, NULL);
-	liblockdep_pthread_mutex_init(&b, NULL);
-	liblockdep_pthread_mutex_init(&c, NULL);
-	liblockdep_pthread_mutex_init(&d, NULL);
+	pthread_mutex_init(&a, NULL);
+	pthread_mutex_init(&b, NULL);
+	pthread_mutex_init(&c, NULL);
+	pthread_mutex_init(&d, NULL);
 
 	LOCK_UNLOCK_2(a, b);
 	LOCK_UNLOCK_2(c, d);
Signature · 1 line
1.8.1.2
#8 lore raw

[tip:core/locking] liblockdep: Correct the ABCDBCDA test

Commit-ID:  23e9e95acb727267e171a34e2bb65dbe0b188ee1
Gitweb:     http://git.kernel.org/tip/23e9e95acb727267e171a34e2bb65dbe0b188ee1
Author:     Sasha Levin <[email protected]>
AuthorDate: Sat, 9 Feb 2013 19:39:35 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 11 Feb 2013 10:12:38 +0100

liblockdep: Correct the ABCDBCDA test

There's no need to use liblockdep specific calls, they are wrapped for us.

---
 tools/lib/lockdep/tests/ABCDBCDA.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tools/lib/lockdep/tests/ABCDBCDA.c +5 -5
index aadf11e..427ba56 100644
@@ -3,12 +3,12 @@
 
 void main(void)
 {
-	liblockdep_pthread_mutex_t a, b, c, d;
+	pthread_mutex_t a, b, c, d;
 
-	liblockdep_pthread_mutex_init(&a, NULL);
-	liblockdep_pthread_mutex_init(&b, NULL);
-	liblockdep_pthread_mutex_init(&c, NULL);
-	liblockdep_pthread_mutex_init(&d, NULL);
+	pthread_mutex_init(&a, NULL);
+	pthread_mutex_init(&b, NULL);
+	pthread_mutex_init(&c, NULL);
+	pthread_mutex_init(&d, NULL);
 
 	LOCK_UNLOCK_2(a, b);
 	LOCK_UNLOCK_2(c, d);
#9 lore raw

PATCH v2 6/11 liblockdep: rbtree support

In reply to Sasha Levin

We re-use kernel's rbtree structure for the preload improvement in the following patches.

---
 tools/lib/lockdep/rbtree.c                          | 1 +
 tools/lib/lockdep/uinclude/linux/rbtree.h           | 1 +
 tools/lib/lockdep/uinclude/linux/rbtree_augmented.h | 2 ++
 3 files changed, 4 insertions(+)
 create mode 100644 tools/lib/lockdep/rbtree.c
 create mode 100644 tools/lib/lockdep/uinclude/linux/rbtree.h
 create mode 100644 tools/lib/lockdep/uinclude/linux/rbtree_augmented.h
tools/lib/lockdep/rbtree.c new file +1 -0
new file mode 100644
index 0000000..f7f4303
@@ -0,0 +1 @@
+#include "../../../lib/rbtree.c"
tools/lib/lockdep/uinclude/linux/rbtree.h new file +1 -0
new file mode 100644
index 0000000..965901d
@@ -0,0 +1 @@
+#include "../../../include/linux/rbtree.h"
tools/lib/lockdep/uinclude/linux/rbtree_augmented.h new file +2 -0
new file mode 100644
index 0000000..c375947
@@ -0,0 +1,2 @@
+#define __always_inline
+#include "../../../include/linux/rbtree_augmented.h"
Signature · 1 line
1.8.1.2
#10 lore raw

[tip:core/locking] liblockdep: Add rbtree support

Commit-ID:  b91dbe96f6e72471bd00e74791507357e09cfbb5
Gitweb:     http://git.kernel.org/tip/b91dbe96f6e72471bd00e74791507357e09cfbb5
Author:     Sasha Levin <[email protected]>
AuthorDate: Sat, 9 Feb 2013 19:39:36 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 11 Feb 2013 10:12:39 +0100

liblockdep: Add rbtree support

We re-use kernel's rbtree structure for the preload improvement in the following patches.

---
 tools/lib/lockdep/rbtree.c                          | 1 +
 tools/lib/lockdep/uinclude/linux/rbtree.h           | 1 +
 tools/lib/lockdep/uinclude/linux/rbtree_augmented.h | 2 ++
 3 files changed, 4 insertions(+)
tools/lib/lockdep/rbtree.c new file +1 -0
new file mode 100644
index 0000000..f7f4303
@@ -0,0 +1 @@
+#include "../../../lib/rbtree.c"
tools/lib/lockdep/uinclude/linux/rbtree.h new file +1 -0
new file mode 100644
index 0000000..965901d
@@ -0,0 +1 @@
+#include "../../../include/linux/rbtree.h"
tools/lib/lockdep/uinclude/linux/rbtree_augmented.h new file +2 -0
new file mode 100644
index 0000000..c375947
@@ -0,0 +1,2 @@
+#define __always_inline
+#include "../../../include/linux/rbtree_augmented.h"
#11 lore raw

PATCH v2 7/11 liblockdep: prevent multiple declarations of CALLER_ADDR0

In reply to Sasha Levin

They are declared once in the public and once in the private headers, prevent declaring them twice if both headers are used.

---
 tools/lib/lockdep/include/liblockdep/common.h | 3 +++
 tools/lib/lockdep/uinclude/linux/kernel.h     | 2 ++
 2 files changed, 5 insertions(+)
tools/lib/lockdep/include/liblockdep/common.h +3 -0
index a675ef0..1bad66c 100644
@@ -3,8 +3,11 @@
 
 #include <pthread.h>
 
+#ifndef CALLER_ADDR0
 #define CALLER_ADDR0 (__builtin_return_address(0))
 #define _THIS_IP_ CALLER_ADDR0
+#endif
+
 #define NR_LOCKDEP_CACHING_CLASSES 2
 #define MAX_LOCKDEP_SUBCLASSES 8UL
 
tools/lib/lockdep/uinclude/linux/kernel.h +2 -0
index da97ce8..af02ac1 100644
@@ -28,7 +28,9 @@
 #define noinline
 #define list_add_tail_rcu list_add_tail
 
+#ifndef CALLER_ADDR0
 #define _THIS_IP_ CALLER_ADDR0
 #define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
+#endif
 
 #endif
Signature · 1 line
1.8.1.2
#12 lore raw

[tip:core/locking] liblockdep: Prevent multiple declarations of CALLER_ADDR0

Commit-ID:  8299c063bfa238da87fbdd15b1c3a31ca6e8ff74
Gitweb:     http://git.kernel.org/tip/8299c063bfa238da87fbdd15b1c3a31ca6e8ff74
Author:     Sasha Levin <[email protected]>
AuthorDate: Sat, 9 Feb 2013 19:39:37 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 11 Feb 2013 10:12:39 +0100

liblockdep: Prevent multiple declarations of CALLER_ADDR0

They are declared once in the public and once in the private headers, prevent declaring them twice if both headers are used.

---
 tools/lib/lockdep/include/liblockdep/common.h | 3 +++
 tools/lib/lockdep/uinclude/linux/kernel.h     | 2 ++
 2 files changed, 5 insertions(+)
tools/lib/lockdep/include/liblockdep/common.h +3 -0
index a675ef0..1bad66c 100644
@@ -3,8 +3,11 @@
 
 #include <pthread.h>
 
+#ifndef CALLER_ADDR0
 #define CALLER_ADDR0 (__builtin_return_address(0))
 #define _THIS_IP_ CALLER_ADDR0
+#endif
+
 #define NR_LOCKDEP_CACHING_CLASSES 2
 #define MAX_LOCKDEP_SUBCLASSES 8UL
 
tools/lib/lockdep/uinclude/linux/kernel.h +2 -0
index da97ce8..af02ac1 100644
@@ -28,7 +28,9 @@
 #define noinline
 #define list_add_tail_rcu list_add_tail
 
+#ifndef CALLER_ADDR0
 #define _THIS_IP_ CALLER_ADDR0
 #define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
+#endif
 
 #endif
#13 lore raw

PATCH v2 8/11 liblockdep: keep headers declarations even if lib is disabled

In reply to Sasha Levin

We need the public headers in the core module code for the preload thing.

---
 tools/lib/lockdep/include/liblockdep/mutex.h  | 4 ++--
 tools/lib/lockdep/include/liblockdep/rwlock.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
tools/lib/lockdep/include/liblockdep/mutex.h +2 -2
index 5154a9d..6ebe733 100644
@@ -1,8 +1,6 @@
 #ifndef _LIBLOCKDEP_MUTEX_H
 #define _LIBLOCKDEP_MUTEX_H
 
-#ifdef __USE_LIBLOCKDEP
-
 #include <pthread.h>
 #include "common.h"
 
@@ -61,6 +59,8 @@ static inline int liblockdep_pthread_mutex_destroy(liblockdep_pthread_mutex_t *l
 	return pthread_mutex_destroy(&lock->mutex);
 }
 
+#ifdef __USE_LIBLOCKDEP
+
 #define pthread_mutex_t         liblockdep_pthread_mutex_t
 #define pthread_mutex_init      liblockdep_pthread_mutex_init
 #define pthread_mutex_lock      liblockdep_pthread_mutex_lock
tools/lib/lockdep/include/liblockdep/rwlock.h +2 -2
index 26f9a68..a1d820b 100644
@@ -1,8 +1,6 @@
 #ifndef _LIBLOCKDEP_RWLOCK_H
 #define _LIBLOCKDEP_RWLOCK_H
 
-#ifdef __USE_LIBLOCKDEP
-
 #include <pthread.h>
 #include "common.h"
 
@@ -77,6 +75,8 @@ static inline int liblockdep_rwlock_destroy(liblockdep_pthread_rwlock_t *lock)
 	return pthread_rwlock_destroy(&lock->rwlock);
 }
 
+#ifdef __USE_LIBLOCKDEP
+
 #define pthread_rwlock_t		liblockdep_pthread_rwlock_t
 #define pthread_rwlock_init		liblockdep_pthread_rwlock_init
 #define pthread_rwlock_rdlock		liblockdep_pthread_rwlock_rdlock
Signature · 1 line
1.8.1.2
#14 lore raw

[tip:core/locking] liblockdep: Keep header declarations even if the library is disabled

Commit-ID:  fab0398231a1fff5a3d0ded5f7416c9d2e3d48d1
Gitweb:     http://git.kernel.org/tip/fab0398231a1fff5a3d0ded5f7416c9d2e3d48d1
Author:     Sasha Levin <[email protected]>
AuthorDate: Sat, 9 Feb 2013 19:39:38 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 11 Feb 2013 10:12:40 +0100

liblockdep: Keep header declarations even if the library is disabled

We need the public headers in the core module code for the preload thing.

---
 tools/lib/lockdep/include/liblockdep/mutex.h  | 4 ++--
 tools/lib/lockdep/include/liblockdep/rwlock.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
tools/lib/lockdep/include/liblockdep/mutex.h +2 -2
index 5154a9d..6ebe733 100644
@@ -1,8 +1,6 @@
 #ifndef _LIBLOCKDEP_MUTEX_H
 #define _LIBLOCKDEP_MUTEX_H
 
-#ifdef __USE_LIBLOCKDEP
-
 #include <pthread.h>
 #include "common.h"
 
@@ -61,6 +59,8 @@ static inline int liblockdep_pthread_mutex_destroy(liblockdep_pthread_mutex_t *l
 	return pthread_mutex_destroy(&lock->mutex);
 }
 
+#ifdef __USE_LIBLOCKDEP
+
 #define pthread_mutex_t         liblockdep_pthread_mutex_t
 #define pthread_mutex_init      liblockdep_pthread_mutex_init
 #define pthread_mutex_lock      liblockdep_pthread_mutex_lock
tools/lib/lockdep/include/liblockdep/rwlock.h +2 -2
index 26f9a68..a1d820b 100644
@@ -1,8 +1,6 @@
 #ifndef _LIBLOCKDEP_RWLOCK_H
 #define _LIBLOCKDEP_RWLOCK_H
 
-#ifdef __USE_LIBLOCKDEP
-
 #include <pthread.h>
 #include "common.h"
 
@@ -77,6 +75,8 @@ static inline int liblockdep_rwlock_destroy(liblockdep_pthread_rwlock_t *lock)
 	return pthread_rwlock_destroy(&lock->rwlock);
 }
 
+#ifdef __USE_LIBLOCKDEP
+
 #define pthread_rwlock_t		liblockdep_pthread_rwlock_t
 #define pthread_rwlock_init		liblockdep_pthread_rwlock_init
 #define pthread_rwlock_rdlock		liblockdep_pthread_rwlock_rdlock
#15 lore raw

PATCH v2 9/11 liblockdep: support using LD_PRELOAD

In reply to Sasha Levin

This allows lockdep to be used without being compiled in the original program.

Usage is quite simple:

LD_PRELOAD=/path/to/liblockdep.so /path/to/my/program

And magically, you'll have lockdep in your program!

---
 tools/lib/lockdep/Makefile  |   4 +-
 tools/lib/lockdep/preload.c | 209 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 211 insertions(+), 2 deletions(-)
 create mode 100644 tools/lib/lockdep/preload.c
tools/lib/lockdep/Makefile +2 -2
index e82ffe9..245f8ba 100644
@@ -143,7 +143,7 @@ do_app_build =						\
 
 do_compile_shared_library =			\
 	($(print_shared_lib_compile)		\
-	$(CC) --shared $^ -o $@)
+	$(CC) --shared -ldl $^ -o $@)
 
 do_build_static_lib =				\
 	($(print_static_lib_build)		\
@@ -161,7 +161,7 @@ $(obj)/%.o: $(src)/%.c
 %.o: $(src)/%.c
 	$(Q)$(call do_compile)
 
-PEVENT_LIB_OBJS = common.o lockdep.o
+PEVENT_LIB_OBJS = common.o lockdep.o preload.o rbtree.o
 
 ALL_OBJS = $(PEVENT_LIB_OBJS)
 
tools/lib/lockdep/preload.c new file +209 -0

209 lines not on this page · raw message

Signature · 1 line
1.8.1.2
#16 lore raw

[tip:core/locking] liblockdep: Support using LD_PRELOAD

Commit-ID:  eb1aa2ea7da68149bd9ec4491379a81277127ac0
Gitweb:     http://git.kernel.org/tip/eb1aa2ea7da68149bd9ec4491379a81277127ac0
Author:     Sasha Levin <[email protected]>
AuthorDate: Sat, 9 Feb 2013 19:39:39 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 11 Feb 2013 10:12:40 +0100

liblockdep: Support using LD_PRELOAD

This allows lockdep to be used without being compiled in the original program.

Usage is quite simple:

LD_PRELOAD=/path/to/liblockdep.so /path/to/my/program

And magically, you'll have lockdep checking in your program!

---
 tools/lib/lockdep/Makefile  |   4 +-
 tools/lib/lockdep/preload.c | 209 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 211 insertions(+), 2 deletions(-)
tools/lib/lockdep/Makefile +2 -2
index e82ffe9..245f8ba 100644
@@ -143,7 +143,7 @@ do_app_build =						\
 
 do_compile_shared_library =			\
 	($(print_shared_lib_compile)		\
-	$(CC) --shared $^ -o $@)
+	$(CC) --shared -ldl $^ -o $@)
 
 do_build_static_lib =				\
 	($(print_static_lib_build)		\
@@ -161,7 +161,7 @@ $(obj)/%.o: $(src)/%.c
 %.o: $(src)/%.c
 	$(Q)$(call do_compile)
 
-PEVENT_LIB_OBJS = common.o lockdep.o
+PEVENT_LIB_OBJS = common.o lockdep.o preload.o rbtree.o
 
 ALL_OBJS = $(PEVENT_LIB_OBJS)
 
tools/lib/lockdep/preload.c new file +209 -0

209 lines not on this page · raw message

#17 lore raw

PATCH v2 10/11 liblockdep: add tests for the LD_PRELOAD feature

In reply to Sasha Levin

Use same tests, but without compiling with liblockdep in the first place.

---
 tools/lib/lockdep/run_tests.sh | 12 ++++++++++++
 1 file changed, 12 insertions(+)
tools/lib/lockdep/run_tests.sh +12 -0
index 4dd32d1..211e91d 100755
@@ -13,3 +13,15 @@ for i in `ls tests/*.c`; do
 	fi
 	rm tests/$testname
 done
+
+for i in `ls tests/*.c`; do
+	testname=$(basename -s .c "$i")
+	gcc -o tests/$testname -lpthread -Iinclude $i &> /dev/null
+	echo -ne "(PRELOAD) $testname... "
+	if [ $(LD_PRELOAD=./liblockdep.so timeout 1 ./tests/$testname | wc -l) -gt 0 ]; then
+		echo "PASSED!"
+	else
+		echo "FAILED!"
+	fi
+	rm tests/$testname
+done
Signature · 1 line
1.8.1.2
#18 lore raw

[tip:core/locking] liblockdep: Add tests for the LD_PRELOAD feature

Commit-ID:  36c2dd52a2740ea6b87fc51713531e560d135c5c
Gitweb:     http://git.kernel.org/tip/36c2dd52a2740ea6b87fc51713531e560d135c5c
Author:     Sasha Levin <[email protected]>
AuthorDate: Sat, 9 Feb 2013 19:39:40 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 11 Feb 2013 10:12:41 +0100

liblockdep: Add tests for the LD_PRELOAD feature

Use same tests, but without compiling with liblockdep in the first place.

---
 tools/lib/lockdep/run_tests.sh | 12 ++++++++++++
 1 file changed, 12 insertions(+)
tools/lib/lockdep/run_tests.sh +12 -0
index 4dd32d1..211e91d 100755
@@ -13,3 +13,15 @@ for i in `ls tests/*.c`; do
 	fi
 	rm tests/$testname
 done
+
+for i in `ls tests/*.c`; do
+	testname=$(basename -s .c "$i")
+	gcc -o tests/$testname -lpthread -Iinclude $i &> /dev/null
+	echo -ne "(PRELOAD) $testname... "
+	if [ $(LD_PRELOAD=./liblockdep.so timeout 1 ./tests/$testname | wc -l) -gt 0 ]; then
+		echo "PASSED!"
+	else
+		echo "FAILED!"
+	fi
+	rm tests/$testname
+done
#19 lore raw

PATCH v2 11/11 liblockdep: preload helper

In reply to Sasha Levin

This is a simple wrapper to make using liblockdep on existing applications much easier.

After running 'make && make install', it becomes quite simple to test things with liblockdep. For example, to try it on perf:

lockdep perf

No other integration required.

---
 tools/lib/lockdep/Makefile | 12 ++++++++----
 tools/lib/lockdep/lockdep  |  3 +++
 2 files changed, 11 insertions(+), 4 deletions(-)
 create mode 100755 tools/lib/lockdep/lockdep
tools/lib/lockdep/Makefile +8 -4
index 245f8ba..b22122f 100644
@@ -34,7 +34,9 @@ DESTDIR ?=
 DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
 
 prefix ?= /usr/local
-bindir_relative = lib
+libdir_relative = lib
+libdir = $(prefix)/$(libdir_relative)
+bindir_relative = bin
 bindir = $(prefix)/$(bindir_relative)
 
 export DESTDIR DESTDIR_SQ INSTALL
@@ -90,13 +92,14 @@ objtree		:= $(CURDIR)
 src		:= $(srctree)
 obj		:= $(objtree)
 
-export prefix bindir src obj
+export prefix libdir bindir src obj
 
 # Shell quotes
+libdir_SQ = $(subst ','\'',$(libdir))
 bindir_SQ = $(subst ','\'',$(bindir))
-bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
 
 LIB_FILE = liblockdep.a liblockdep.so
+BIN_FILE = lockdep
 
 CONFIG_INCLUDES =
 CONFIG_LIBS	=
@@ -229,7 +232,8 @@ define do_install
 endef
 
 install_lib: all_cmd
-	$(Q)$(call do_install,$(LIB_FILE),$(bindir_SQ))
+	$(Q)$(call do_install,$(LIB_FILE),$(libdir_SQ))
+	$(Q)$(call do_install,$(BIN_FILE),$(bindir_SQ))
 
 install: install_lib
 
tools/lib/lockdep/lockdep new file +3 -0
new file mode 100755
index 0000000..a805c81
@@ -0,0 +1,3 @@
+#! /bin/bash
+
+LD_PRELOAD="liblockdep.so $LD_PRELOAD" "$@"
Signature · 1 line
1.8.1.2
#20 lore raw

[tip:core/locking] liblockdep: Add the 'lockdep' user-space utility

Commit-ID:  c2823ae46fb1641cc691c3dcc0eeb4356fce267a
Gitweb:     http://git.kernel.org/tip/c2823ae46fb1641cc691c3dcc0eeb4356fce267a
Author:     Sasha Levin <[email protected]>
AuthorDate: Sat, 9 Feb 2013 19:39:41 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 11 Feb 2013 10:12:41 +0100

liblockdep: Add the 'lockdep' user-space utility

This is a simple wrapper to make using liblockdep on existing applications much easier.

After running 'make && make install', it becomes quite simple to test things with liblockdep. For example, to try it on perf:

lockdep perf

No other integration required.

---
 tools/lib/lockdep/Makefile | 12 ++++++++----
 tools/lib/lockdep/lockdep  |  3 +++
 2 files changed, 11 insertions(+), 4 deletions(-)
tools/lib/lockdep/Makefile +8 -4
index 245f8ba..b22122f 100644
@@ -34,7 +34,9 @@ DESTDIR ?=
 DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
 
 prefix ?= /usr/local
-bindir_relative = lib
+libdir_relative = lib
+libdir = $(prefix)/$(libdir_relative)
+bindir_relative = bin
 bindir = $(prefix)/$(bindir_relative)
 
 export DESTDIR DESTDIR_SQ INSTALL
@@ -90,13 +92,14 @@ objtree		:= $(CURDIR)
 src		:= $(srctree)
 obj		:= $(objtree)
 
-export prefix bindir src obj
+export prefix libdir bindir src obj
 
 # Shell quotes
+libdir_SQ = $(subst ','\'',$(libdir))
 bindir_SQ = $(subst ','\'',$(bindir))
-bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
 
 LIB_FILE = liblockdep.a liblockdep.so
+BIN_FILE = lockdep
 
 CONFIG_INCLUDES =
 CONFIG_LIBS	=
@@ -229,7 +232,8 @@ define do_install
 endef
 
 install_lib: all_cmd
-	$(Q)$(call do_install,$(LIB_FILE),$(bindir_SQ))
+	$(Q)$(call do_install,$(LIB_FILE),$(libdir_SQ))
+	$(Q)$(call do_install,$(BIN_FILE),$(bindir_SQ))
 
 install: install_lib
 
tools/lib/lockdep/lockdep new file +3 -0
new file mode 100755
index 0000000..a805c81
@@ -0,0 +1,3 @@
+#! /bin/bash
+
+LD_PRELOAD="liblockdep.so $LD_PRELOAD" "$@"
#21 lore raw

[tip:core/locking] liblockdep: Remove the need for liblockdep_init()

In reply to Sasha Levin
Commit-ID:  62347c63f0646e76a36dc7039d395e0faa880c79
Gitweb:     http://git.kernel.org/tip/62347c63f0646e76a36dc7039d395e0faa880c79
Author:     Sasha Levin <[email protected]>
AuthorDate: Sat, 9 Feb 2013 19:39:31 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 11 Feb 2013 10:12:36 +0100

liblockdep: Remove the need for liblockdep_init()

Use a constructor in the library instead of making the user manually call liblockdep_init().

---
 tools/lib/lockdep/common.c                    | 2 +-
 tools/lib/lockdep/include/liblockdep/common.h | 1 -
 tools/lib/lockdep/tests/AA.c                  | 1 -
 tools/lib/lockdep/tests/ABBA.c                | 1 -
 tools/lib/lockdep/tests/ABBCCA.c              | 1 -
 tools/lib/lockdep/tests/ABBCCDDA.c            | 1 -
 tools/lib/lockdep/tests/ABCABC.c              | 1 -
 tools/lib/lockdep/tests/ABCDBCDA.c            | 1 -
 tools/lib/lockdep/tests/ABCDBDDA.c            | 1 -
 tools/lib/lockdep/tests/WW.c                  | 1 -
 tools/lib/lockdep/tests/unlock_balance.c      | 1 -
 tools/lib/lockdep/uinclude/linux/lockdep.h    | 1 -
 12 files changed, 1 insertion(+), 12 deletions(-)
tools/lib/lockdep/common.c +1 -1
index 99d3b4b..d2946e0 100644
@@ -10,7 +10,7 @@ __thread struct task_struct current_obj;
 bool debug_locks = true;
 bool debug_locks_silent;
 
-void liblockdep_init(void)
+__attribute__((constructor)) static void liblockdep_init(void)
 {
 	lockdep_init();
 }
tools/lib/lockdep/include/liblockdep/common.h +0 -1
index b72f9c1..f6f7fec8 100644
@@ -26,7 +26,6 @@ struct lockdep_map {
 #endif
 };
 
-void liblockdep_init(void);
 void liblockdep_set_thread(void);
 void lockdep_init_map(struct lockdep_map *lock, const char *name,
 			struct lock_class_key *key, int subclass);
tools/lib/lockdep/tests/AA.c +0 -1
index 933d32f..3f71333 100644
@@ -4,7 +4,6 @@ void main(void)
 {
 	pthread_mutex_t a, b;
 
-	liblockdep_init();
 	liblockdep_set_thread();
 
 	pthread_mutex_init(&a, NULL);
tools/lib/lockdep/tests/ABBA.c +0 -1
index 9f5146b..08d87a7 100644
@@ -5,7 +5,6 @@ void main(void)
 {
 	pthread_mutex_t a, b;
 
-	liblockdep_init();
 	liblockdep_set_thread();
 
 	pthread_mutex_init(&a, NULL);
tools/lib/lockdep/tests/ABBCCA.c +0 -1
index b7435d7..c5d0e5c 100644
@@ -5,7 +5,6 @@ void main(void)
 {
 	pthread_mutex_t a, b, c;
 
-	liblockdep_init();
 	liblockdep_set_thread();
 
 	pthread_mutex_init(&a, NULL);
tools/lib/lockdep/tests/ABBCCDDA.c +0 -1
index 2425330..e12dc98 100644
@@ -5,7 +5,6 @@ void main(void)
 {
 	pthread_mutex_t a, b, c, d;
 
-	liblockdep_init();
 	liblockdep_set_thread();
 
 	pthread_mutex_init(&a, NULL);
tools/lib/lockdep/tests/ABCABC.c +0 -1
index 2ee30fe..70879c95 100644
@@ -5,7 +5,6 @@ void main(void)
 {
 	pthread_mutex_t a, b, c;
 
-	liblockdep_init();
 	liblockdep_set_thread();
 
 	pthread_mutex_init(&a, NULL);
tools/lib/lockdep/tests/ABCDBCDA.c +0 -1
index 32d19d6..00cd676 100644
@@ -5,7 +5,6 @@ void main(void)
 {
 	liblockdep_pthread_mutex_t a, b, c, d;
 
-	liblockdep_init();
 	liblockdep_set_thread();
 
 	liblockdep_pthread_mutex_init(&a, NULL);
tools/lib/lockdep/tests/ABCDBDDA.c +0 -1
index 850eaca..19b3ed1 100644
@@ -5,7 +5,6 @@ void main(void)
 {
 	pthread_mutex_t a, b, c, d;
 
-	liblockdep_init();
 	liblockdep_set_thread();
 
 	pthread_mutex_init(&a, NULL);
tools/lib/lockdep/tests/WW.c +0 -1
index 4b1be0f..2467b13 100644
@@ -4,7 +4,6 @@ void main(void)
 {
 	pthread_rwlock_t a, b;
 
-	liblockdep_init();
 	liblockdep_set_thread();
 
 	pthread_rwlock_init(&a, NULL);
tools/lib/lockdep/tests/unlock_balance.c +0 -1
index 9dfaf97..07a4c21 100644
@@ -4,7 +4,6 @@ void main(void)
 {
 	pthread_mutex_t a;
 
-	liblockdep_init();
 	liblockdep_set_thread();
 
 	pthread_mutex_init(&a, NULL);
tools/lib/lockdep/uinclude/linux/lockdep.h +0 -1
index 1ed83a5..611cb28 100644
@@ -25,7 +25,6 @@ struct task_struct {
 extern __thread struct task_struct current_obj;
 #define current (&current_obj)
 
-void liblockdep_init(void);
 void liblockdep_set_thread(void);
 
 #define debug_locks_off() 1
#22 lore raw
In reply to Sasha Levin
Quoted 4 lines · Sasha Levin

Use a constructor in the library instead of making the user manually call liblockdep_init().

Quoted 14 lines
---
 tools/lib/lockdep/common.c                    | 2 +-
 tools/lib/lockdep/include/liblockdep/common.h | 1 -
 tools/lib/lockdep/tests/AA.c                  | 1 -
 tools/lib/lockdep/tests/ABBA.c                | 1 -
 tools/lib/lockdep/tests/ABBCCA.c              | 1 -
 tools/lib/lockdep/tests/ABBCCDDA.c            | 1 -
 tools/lib/lockdep/tests/ABCABC.c              | 1 -
 tools/lib/lockdep/tests/ABCDBCDA.c            | 1 -
 tools/lib/lockdep/tests/ABCDBDDA.c            | 1 -
 tools/lib/lockdep/tests/WW.c                  | 1 -
 tools/lib/lockdep/tests/unlock_balance.c      | 1 -
 tools/lib/lockdep/uinclude/linux/lockdep.h    | 1 -
 12 files changed, 1 insertion(+), 12 deletions(-)

Note that due to the heavy objections in the kvmtool thread I have removed the tools/lib/lockdep library and tooling commits from the locking tree - to be able to merge the other locking commits upstream.

I'm pretty sad about this outcome as your code really brought new development life into lockdep - if you still want to pursue this approach then you might want to try it via the tools/kvm tree, or via a separate project.

Thanks,

Ingo

#23 lore raw
Quoted 22 lines · Ingo Molnar
Quoted 4 lines · Sasha Levin

Use a constructor in the library instead of making the user manually call liblockdep_init().

Quoted 14 lines
---
 tools/lib/lockdep/common.c                    | 2 +-
 tools/lib/lockdep/include/liblockdep/common.h | 1 -
 tools/lib/lockdep/tests/AA.c                  | 1 -
 tools/lib/lockdep/tests/ABBA.c                | 1 -
 tools/lib/lockdep/tests/ABBCCA.c              | 1 -
 tools/lib/lockdep/tests/ABBCCDDA.c            | 1 -
 tools/lib/lockdep/tests/ABCABC.c              | 1 -
 tools/lib/lockdep/tests/ABCDBCDA.c            | 1 -
 tools/lib/lockdep/tests/ABCDBDDA.c            | 1 -
 tools/lib/lockdep/tests/WW.c                  | 1 -
 tools/lib/lockdep/tests/unlock_balance.c      | 1 -
 tools/lib/lockdep/uinclude/linux/lockdep.h    | 1 -
 12 files changed, 1 insertion(+), 12 deletions(-)
Quoted 4 lines

Note that due to the heavy objections in the kvmtool thread I have removed the tools/lib/lockdep library and tooling commits from the locking tree - to be able to merge the other locking commits upstream.

Understood.

Quoted 4 lines

I'm pretty sad about this outcome as your code really brought new development life into lockdep - if you still want to pursue this approach then you might want to try it via the tools/kvm tree, or via a separate project.

I'm most likely to just fold it into a standalone project since I'm not quite certain the purpose of tools/ at this point.

Thanks,
Sasha

#24 lore raw
Quoted 30 lines · Sasha Levin
Quoted 22 lines · Ingo Molnar
Quoted 4 lines · Sasha Levin

Use a constructor in the library instead of making the user manually call liblockdep_init().

Quoted 14 lines
---
 tools/lib/lockdep/common.c                    | 2 +-
 tools/lib/lockdep/include/liblockdep/common.h | 1 -
 tools/lib/lockdep/tests/AA.c                  | 1 -
 tools/lib/lockdep/tests/ABBA.c                | 1 -
 tools/lib/lockdep/tests/ABBCCA.c              | 1 -
 tools/lib/lockdep/tests/ABBCCDDA.c            | 1 -
 tools/lib/lockdep/tests/ABCABC.c              | 1 -
 tools/lib/lockdep/tests/ABCDBCDA.c            | 1 -
 tools/lib/lockdep/tests/ABCDBDDA.c            | 1 -
 tools/lib/lockdep/tests/WW.c                  | 1 -
 tools/lib/lockdep/tests/unlock_balance.c      | 1 -
 tools/lib/lockdep/uinclude/linux/lockdep.h    | 1 -
 12 files changed, 1 insertion(+), 12 deletions(-)
Quoted 4 lines

Note that due to the heavy objections in the kvmtool thread I have removed the tools/lib/lockdep library and tooling commits from the locking tree - to be able to merge the other locking commits upstream.

Understood.

Quoted 8 lines
Quoted 4 lines

I'm pretty sad about this outcome as your code really brought new development life into lockdep - if you still want to pursue this approach then you might want to try it via the tools/kvm tree, or via a separate project.

I'm most likely to just fold it into a standalone project since I'm not quite certain the purpose of tools/ at this point.

You could also tempt Linus with a standalone pull request - altough at this point I'm not sure he'd take it.

Sharing the source code between user-space and kernel space makes quite a bit of sense, and copying files, while it works, just encourages needless forking. The impact of your changes on kernel/lockdep.c was minimal:

47dd80e801c3 lockdep: Be nice about building from userspace

  kernel/lockdep.c | 4 ++++
  1 file changed, 4 insertions(+)

So I don't see any substantial 'drag' or downside on the kernel lockdep subsystem - and I see a lot of upsides from exposing user-space to the lockdep code.

Have you tried to check the locking of something more complex, such as Firefox? (assuming it uses pthread mutexes and rwlocks - I'm not sure about that.)

Thanks,

Ingo

#25 lore raw
Quoted 38 lines · Ingo Molnar
Quoted 35 lines · Sasha Levin
Quoted 22 lines · Ingo Molnar
Quoted 4 lines · Sasha Levin

Use a constructor in the library instead of making the user manually call liblockdep_init().

Quoted 14 lines
---
 tools/lib/lockdep/common.c                    | 2 +-
 tools/lib/lockdep/include/liblockdep/common.h | 1 -
 tools/lib/lockdep/tests/AA.c                  | 1 -
 tools/lib/lockdep/tests/ABBA.c                | 1 -
 tools/lib/lockdep/tests/ABBCCA.c              | 1 -
 tools/lib/lockdep/tests/ABBCCDDA.c            | 1 -
 tools/lib/lockdep/tests/ABCABC.c              | 1 -
 tools/lib/lockdep/tests/ABCDBCDA.c            | 1 -
 tools/lib/lockdep/tests/ABCDBDDA.c            | 1 -
 tools/lib/lockdep/tests/WW.c                  | 1 -
 tools/lib/lockdep/tests/unlock_balance.c      | 1 -
 tools/lib/lockdep/uinclude/linux/lockdep.h    | 1 -
 12 files changed, 1 insertion(+), 12 deletions(-)
Quoted 4 lines

Note that due to the heavy objections in the kvmtool thread I have removed the tools/lib/lockdep library and tooling commits from the locking tree - to be able to merge the other locking commits upstream.

Understood.

Quoted 4 lines

I'm pretty sad about this outcome as your code really brought new development life into lockdep - if you still want to pursue this approach then you might want to try it via the tools/kvm tree, or via a separate project.

Quoted 6 lines
Quoted 3 lines

I'm most likely to just fold it into a standalone project since I'm not quite certain the purpose of tools/ at this point.

You could also tempt Linus with a standalone pull request - altough at this point I'm not sure he'd take it.

So I've gone though the kvmtool thread and while liblockdep was referenced several times Linus didn't share his opinion on it.

Linus, would you be interested in adding liblockdep to your tree? I'm not looking to start another threadnaught about pros and cons of userspace code in the kernel, I just want to know how to proceed with liblockdep. Thanks!

Quoted 9 lines

Sharing the source code between user-space and kernel space makes quite a bit of sense, and copying files, while it works, just encourages needless forking. The impact of your changes on kernel/lockdep.c was minimal:

47dd80e801c3 lockdep: Be nice about building from userspace

  kernel/lockdep.c | 4 ++++
  1 file changed, 4 insertions(+)
Quoted 7 lines

So I don't see any substantial 'drag' or downside on the kernel lockdep subsystem - and I see a lot of upsides from exposing user-space to the lockdep code.

Have you tried to check the locking of something more complex, such as Firefox? (assuming it uses pthread mutexes and rwlocks - I'm not sure about that.)

Yup! I was actually working on that the day before you've sent this mail :)

firefox does use pthread locks.

firefox/thunderbird use their own wrappers for malloc, which take locks on the allocation path - this is quite problematic for the current liblockdep code since it tries to allocate lock objects to store the extra lockdep data - which results in a deadlock. The fix is quite trivial, the discovery of this deadlock was quite interesting though :)

Once I got firefox to work properly with liblockdep there was one spew showing up after browsing for a bit but I haven't dug into it yet - waiting for a quiet weekend to do that.

Thanks,
Sasha