summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2020-03-19 11:26:12 +0100
committerSimon Rettberg2020-03-19 11:26:12 +0100
commitba617b55eb606ab487f154b124750e121518d5e5 (patch)
tree0615ed15ac989f1f21c791d3c111e264932f22ed
parentcmake: Fix version.c building on fresh checkouts (diff)
downloaddnbd3-ba617b55eb606ab487f154b124750e121518d5e5.tar.gz
dnbd3-ba617b55eb606ab487f154b124750e121518d5e5.tar.xz
dnbd3-ba617b55eb606ab487f154b124750e121518d5e5.zip
[SERVER] Add name param to threadpool_run
-rw-r--r--src/server/altservers.c2
-rw-r--r--src/server/image.c2
-rw-r--r--src/server/server.c6
-rw-r--r--src/server/threadpool.c8
-rw-r--r--src/server/threadpool.h3
-rw-r--r--src/server/uplink.c2
6 files changed, 16 insertions, 7 deletions
diff --git a/src/server/altservers.c b/src/server/altservers.c
index 1ba75f4..5076a05 100644
--- a/src/server/altservers.c
+++ b/src/server/altservers.c
@@ -172,7 +172,7 @@ void altservers_findUplinkAsync(dnbd3_uplink_t *uplink)
if ( uplink->rttTestResult != RTT_INPROGRESS ) {
dnbd3_uplink_t *current = ref_get_uplink( &uplink->image->uplinkref );
if ( current == uplink ) {
- threadpool_run( &altservers_runCheck, uplink );
+ threadpool_run( &altservers_runCheck, uplink, "UPLINK" );
} else if ( current != NULL ) {
ref_put( &current->reference );
}
diff --git a/src/server/image.c b/src/server/image.c
index 81ec479..0ec1d58 100644
--- a/src/server/image.c
+++ b/src/server/image.c
@@ -1817,6 +1817,7 @@ static void* closeUnusedFds(void* nix UNUSED)
timing_gets( &deadline, -UNUSED_FD_TIMEOUT );
int fds[FDCOUNT];
int fdindex = 0;
+ setThreadName( "unused-fd-close" );
mutex_lock( &imageListLock );
for ( int i = 0; i < _num_images; ++i ) {
dnbd3_image_t * const image = _images[i];
@@ -1857,6 +1858,7 @@ static void* saveLoadAllCacheMaps(void* nix UNUSED)
static ticks nextSave;
declare_now;
bool full = timing_reached( &nextSave, &now );
+ setThreadName( "cache-mapper" );
mutex_lock( &imageListLock );
for ( int i = 0; i < _num_images; ++i ) {
dnbd3_image_t * const image = _images[i];
diff --git a/src/server/server.c b/src/server/server.c
index 71a49b9..fa7bcda 100644
--- a/src/server/server.c
+++ b/src/server/server.c
@@ -404,7 +404,7 @@ int main(int argc, char *argv[])
if ( sigReload ) {
sigReload = false;
logadd( LOG_INFO, "SIGHUP received, re-scanning image directory" );
- threadpool_run( &server_asyncImageListLoad, NULL );
+ threadpool_run( &server_asyncImageListLoad, NULL, "IMAGE_RELOAD" );
}
if ( sigLogCycle ) {
sigLogCycle = false;
@@ -431,7 +431,7 @@ int main(int argc, char *argv[])
continue;
}
- if ( !threadpool_run( &net_handleNewConnection, (void *)dnbd3_client ) ) {
+ if ( !threadpool_run( &net_handleNewConnection, (void *)dnbd3_client, "CLIENT" ) ) {
logadd( LOG_ERROR, "Could not start thread for new connection." );
free( dnbd3_client );
continue;
@@ -574,7 +574,7 @@ static int handlePendingJobs(void)
jobHead = *temp; // Make it list head
*temp = NULL; // Split off part before that
while ( todo != NULL ) {
- threadpool_run( todo->startRoutine, todo->arg );
+ threadpool_run( todo->startRoutine, todo->arg, "TIMER_TASK" );
old = todo;
todo = todo->next;
if ( old->intervalSecs == 0 ) {
diff --git a/src/server/threadpool.c b/src/server/threadpool.c
index 96162a6..63ae19f 100644
--- a/src/server/threadpool.c
+++ b/src/server/threadpool.c
@@ -8,6 +8,7 @@ typedef struct _entry_t {
dnbd3_signal_t* signal;
void *(*startRoutine)(void *);
void * arg;
+ const char *name;
} entry_t;
static void *threadpool_worker(void *entryPtr);
@@ -56,7 +57,7 @@ void threadpool_waitEmpty()
} while ( activeThreads != 0 );
}
-bool threadpool_run(void *(*startRoutine)(void *), void *arg)
+bool threadpool_run(void *(*startRoutine)(void *), void *arg, const char *name)
{
if ( unlikely( _shutdown ) ) {
logadd( LOG_MINOR, "Cannot submit work to threadpool while shutting down!" );
@@ -97,6 +98,7 @@ bool threadpool_run(void *(*startRoutine)(void *), void *arg)
}
entry->startRoutine = startRoutine;
entry->arg = arg;
+ entry->name = name;
atomic_thread_fence( memory_order_release );
signal_call( entry->signal );
return true;
@@ -126,6 +128,9 @@ keep_going:;
logadd( LOG_ERROR, "Worker woke up but has no work to do!" );
exit( 1 );
}
+ if ( entry->name != NULL ) {
+ setThreadName( entry->name );
+ }
#endif
// Start assigned work
(*entry->startRoutine)( entry->arg );
@@ -146,6 +151,7 @@ keep_going:;
// Reaching here means pool is full; just let the thread exit
break;
}
+ setThreadName( "[dead]" );
signal_close( entry->signal );
free( entry );
activeThreads--;
diff --git a/src/server/threadpool.h b/src/server/threadpool.h
index ee0b3aa..d8a526e 100644
--- a/src/server/threadpool.h
+++ b/src/server/threadpool.h
@@ -26,9 +26,10 @@ void threadpool_waitEmpty();
* Run a thread using the thread pool.
* @param startRoutine function to run in new thread
* @param arg argument to pass to thead
+ * @param name STRING CONSTANT (literal) for debugging purposes
* @return true if thread was started
*/
-bool threadpool_run(void *(*startRoutine)(void *), void *arg);
+bool threadpool_run(void *(*startRoutine)(void *), void *arg, const char *name);
#endif
diff --git a/src/server/uplink.c b/src/server/uplink.c
index af854d6..a7f140f 100644
--- a/src/server/uplink.c
+++ b/src/server/uplink.c
@@ -435,7 +435,7 @@ success_ref:
job->length = len;
job->uplink = uplink;
ref_inc( &uplink->reference ); // Hold one for the thread, thread will return it
- threadpool_run( &prefetchForClient, (void*)job );
+ threadpool_run( &prefetchForClient, (void*)job, "PREFETCH" );
}
}
if ( getUplink ) {