MEDIUM: task: add and preset a thread ID in the task struct
The tasks currently rely on a mask but do not have an assigned thread ID,
contrary to tasklets. However, in practice they're either running on a
single thread or on any thread, so that it will be worth simplifying all
this in order to ease the transition to the thread groups.
This patch introduces a "tid" field in the task struct, that's either
the number of the thread the task is attached to, or a negative value
if the task is not bound to a thread, (i.e. its mask is all_threads_mask).
The new ID is only set and updated but not used yet.
diff --git a/src/stream.c b/src/stream.c
index 7df2cc6..867cba8 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -3284,7 +3284,7 @@
}
chunk_appendf(&trash,
- " task=%p (state=0x%02x nice=%d calls=%u rate=%u exp=%s tmask=0x%lx%s",
+ " task=%p (state=0x%02x nice=%d calls=%u rate=%u exp=%s tid=%d tmask=0x%lx%s",
strm->task,
strm->task->state,
strm->task->nice, strm->task->calls, read_freq_ctr(&strm->call_rate),
@@ -3292,6 +3292,7 @@
tick_is_expired(strm->task->expire, now_ms) ? "<PAST>" :
human_time(TICKS_TO_MS(strm->task->expire - now_ms),
TICKS_TO_MS(1000)) : "<NEVER>",
+ strm->task->tid,
strm->task->thread_mask,
task_in_rq(strm->task) ? ", running" : "");
@@ -3334,12 +3335,13 @@
}
else if ((tmpctx = sc_appctx(scf)) != NULL) {
chunk_appendf(&trash,
- " app0=%p st0=%d st1=%d st2=%d applet=%s tmask=0x%lx nice=%d calls=%u rate=%u cpu=%llu lat=%llu\n",
+ " app0=%p st0=%d st1=%d st2=%d applet=%s tid=%d tmask=0x%lx nice=%d calls=%u rate=%u cpu=%llu lat=%llu\n",
tmpctx,
tmpctx->st0,
tmpctx->st1,
tmpctx->_st2,
tmpctx->applet->name,
+ tmpctx->t->tid,
tmpctx->t->thread_mask,
tmpctx->t->nice, tmpctx->t->calls, read_freq_ctr(&tmpctx->call_rate),
(unsigned long long)tmpctx->t->cpu_time, (unsigned long long)tmpctx->t->lat_time);
@@ -3373,12 +3375,13 @@
}
else if ((tmpctx = sc_appctx(scb)) != NULL) {
chunk_appendf(&trash,
- " app1=%p st0=%d st1=%d st2=%d applet=%s tmask=0x%lx nice=%d calls=%u rate=%u cpu=%llu lat=%llu\n",
+ " app1=%p st0=%d st1=%d st2=%d applet=%s tid=%d tmask=0x%lx nice=%d calls=%u rate=%u cpu=%llu lat=%llu\n",
tmpctx,
tmpctx->st0,
tmpctx->st1,
tmpctx->_st2,
tmpctx->applet->name,
+ tmpctx->t->tid,
tmpctx->t->thread_mask,
tmpctx->t->nice, tmpctx->t->calls, read_freq_ctr(&tmpctx->call_rate),
(unsigned long long)tmpctx->t->cpu_time, (unsigned long long)tmpctx->t->lat_time);