summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src
diff options
context:
space:
mode:
authorDmitry Antipov <dmantipov@yandex.ru>2020-07-28 16:38:29 +0300
committerAmar Tumballi <amar@kadalu.io>2020-08-11 04:39:46 +0000
commit634ce64d0f03ddf3c2a3c05ce21cf9cdcbb763c5 (patch)
tree2b88b83b0dca81dcd6aa5bf27451fa65b8ea820a /libglusterfs/src
parent163aa7d2bcbba71107602ab6672da1af53b31726 (diff)
libglusterfs: annotate synctasks with ThreadSanitizer API
If --enable-tsan is specified and API headers are detected, annotate synctask context initialization and context switch with ThreadSanitizer API. Change-Id: I7ac4085d7ed055448f1fc80df7d59905d129f186 Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru> Fixes: #1400
Diffstat (limited to 'libglusterfs/src')
-rw-r--r--libglusterfs/src/glusterfs/syncop.h20
-rw-r--r--libglusterfs/src/syncop.c35
2 files changed, 55 insertions, 0 deletions
diff --git a/libglusterfs/src/glusterfs/syncop.h b/libglusterfs/src/glusterfs/syncop.h
index 1a801a91444..4e9241a32fc 100644
--- a/libglusterfs/src/glusterfs/syncop.h
+++ b/libglusterfs/src/glusterfs/syncop.h
@@ -31,6 +31,11 @@
#define SYNCOPCTX_PID 0x00000008
#define SYNCOPCTX_LKOWNER 0x00000010
+#ifdef HAVE_TSAN_API
+/* Currently hardcoded within thread context maintained by the sanitizer. */
+#define TSAN_THREAD_NAMELEN 64
+#endif
+
struct synctask;
struct syncproc;
struct syncenv;
@@ -71,6 +76,13 @@ struct synctask {
uid_t uid;
gid_t gid;
+#ifdef HAVE_TSAN_API
+ struct {
+ void *fiber;
+ char name[TSAN_THREAD_NAMELEN];
+ } tsan;
+#endif
+
ucontext_t ctx;
struct syncproc *proc;
@@ -83,6 +95,14 @@ struct synctask {
struct syncproc {
pthread_t processor;
+
+#ifdef HAVE_TSAN_API
+ struct {
+ void *fiber;
+ char name[TSAN_THREAD_NAMELEN];
+ } tsan;
+#endif
+
ucontext_t sched;
struct syncenv *env;
struct synctask *current;
diff --git a/libglusterfs/src/syncop.c b/libglusterfs/src/syncop.c
index 71d37b76f25..95bea675379 100644
--- a/libglusterfs/src/syncop.c
+++ b/libglusterfs/src/syncop.c
@@ -11,6 +11,10 @@
#include "glusterfs/syncop.h"
#include "glusterfs/libglusterfs-messages.h"
+#ifdef HAVE_TSAN_API
+#include <sanitizer/tsan_interface.h>
+#endif
+
int
syncopctx_setfsuid(void *uid)
{
@@ -262,6 +266,11 @@ synctask_yield(struct synctask *task, struct timespec *delta)
if (task->state != SYNCTASK_DONE) {
task->state = SYNCTASK_SUSPEND;
}
+
+#ifdef HAVE_TSAN_API
+ __tsan_switch_to_fiber(task->proc->tsan.fiber, 0);
+#endif
+
if (swapcontext(&task->ctx, &task->proc->sched) < 0) {
gf_msg("syncop", GF_LOG_ERROR, errno, LG_MSG_SWAPCONTEXT_FAILED,
"swapcontext failed");
@@ -357,6 +366,10 @@ synctask_destroy(struct synctask *task)
pthread_cond_destroy(&task->cond);
}
+#ifdef HAVE_TSAN_API
+ __tsan_destroy_fiber(task->tsan.fiber);
+#endif
+
GF_FREE(task);
}
@@ -467,6 +480,13 @@ synctask_create(struct syncenv *env, size_t stacksize, synctask_fn_t fn,
makecontext(&newtask->ctx, (void (*)(void))synctask_wrap, 0);
+#ifdef HAVE_TSAN_API
+ newtask->tsan.fiber = __tsan_create_fiber(0);
+ snprintf(newtask->tsan.name, TSAN_THREAD_NAMELEN, "<synctask of %s>",
+ this->name);
+ __tsan_set_fiber_name(newtask->tsan.fiber, newtask->tsan.name);
+#endif
+
newtask->state = SYNCTASK_INIT;
newtask->slept = 1;
@@ -638,6 +658,10 @@ synctask_switchto(struct synctask *task)
task->ctx.uc_flags &= ~_UC_TLSBASE;
#endif
+#ifdef HAVE_TSAN_API
+ __tsan_switch_to_fiber(task->tsan.fiber, 0);
+#endif
+
if (swapcontext(&task->proc->sched, &task->ctx) < 0) {
gf_msg("syncop", GF_LOG_ERROR, errno, LG_MSG_SWAPCONTEXT_FAILED,
"swapcontext failed");
@@ -675,10 +699,21 @@ syncenv_processor(void *thdata)
proc = thdata;
+#ifdef HAVE_TSAN_API
+ proc->tsan.fiber = __tsan_create_fiber(0);
+ snprintf(proc->tsan.name, TSAN_THREAD_NAMELEN, "<sched of syncenv@%p>",
+ proc);
+ __tsan_set_fiber_name(proc->tsan.fiber, proc->tsan.name);
+#endif
+
while ((task = syncenv_task(proc)) != NULL) {
synctask_switchto(task);
}
+#ifdef HAVE_TSAN_API
+ __tsan_destroy_fiber(proc->tsan.fiber);
+#endif
+
return NULL;
}