summaryrefslogtreecommitdiff
path: root/lib/thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/thread.c')
-rw-r--r--lib/thread.c129
1 files changed, 66 insertions, 63 deletions
diff --git a/lib/thread.c b/lib/thread.c
index 285b9b501a..c140c7600c 100644
--- a/lib/thread.c
+++ b/lib/thread.c
@@ -342,7 +342,7 @@ static void show_thread_poll_helper(struct vty *vty, struct thread_master *m)
if (!thread)
vty_out(vty, "ERROR ");
else
- vty_out(vty, "%s ", thread->funcname);
+ vty_out(vty, "%s ", thread->xref->funcname);
} else
vty_out(vty, " ");
@@ -352,7 +352,7 @@ static void show_thread_poll_helper(struct vty *vty, struct thread_master *m)
if (!thread)
vty_out(vty, "ERROR\n");
else
- vty_out(vty, "%s\n", thread->funcname);
+ vty_out(vty, "%s\n", thread->xref->funcname);
} else
vty_out(vty, "\n");
}
@@ -633,9 +633,6 @@ unsigned long thread_timer_remain_second(struct thread *thread)
return thread_timer_remain_msec(thread) / 1000LL;
}
-#define debugargdef const char *funcname, const char *schedfrom, int fromln
-#define debugargpass funcname, schedfrom, fromln
-
struct timeval thread_timer_remain(struct thread *thread)
{
struct timeval remain;
@@ -678,7 +675,7 @@ char *thread_timer_to_hhmmss(char *buf, int buf_size,
/* Get new thread. */
static struct thread *thread_get(struct thread_master *m, uint8_t type,
int (*func)(struct thread *), void *arg,
- debugargdef)
+ const struct xref_threadsched *xref)
{
struct thread *thread = thread_list_pop(&m->unuse);
struct cpu_thread_history tmp;
@@ -707,18 +704,17 @@ static struct thread *thread_get(struct thread_master *m, uint8_t type,
* This hopefully saves us some serious
* hash_get lookups.
*/
- if (thread->funcname != funcname || thread->func != func) {
+ if ((thread->xref && thread->xref->funcname != xref->funcname)
+ || thread->func != func) {
tmp.func = func;
- tmp.funcname = funcname;
+ tmp.funcname = xref->funcname;
thread->hist =
hash_get(m->cpu_record, &tmp,
(void *(*)(void *))cpu_record_hash_alloc);
}
thread->hist->total_active++;
thread->func = func;
- thread->funcname = funcname;
- thread->schedfrom = schedfrom;
- thread->schedfrom_line = fromln;
+ thread->xref = xref;
return thread;
}
@@ -832,21 +828,23 @@ done:
}
/* Add new read thread. */
-struct thread *funcname_thread_add_read_write(int dir, struct thread_master *m,
- int (*func)(struct thread *),
- void *arg, int fd,
- struct thread **t_ptr,
- debugargdef)
+struct thread *_thread_add_read_write(const struct xref_threadsched *xref,
+ struct thread_master *m,
+ int (*func)(struct thread *),
+ void *arg, int fd, struct thread **t_ptr)
{
+ int dir = xref->thread_type;
struct thread *thread = NULL;
struct thread **thread_array;
if (dir == THREAD_READ)
- frrtrace(9, frr_libfrr, schedule_read, m, funcname, schedfrom,
- fromln, t_ptr, fd, 0, arg, 0);
+ frrtrace(9, frr_libfrr, schedule_read, m,
+ xref->funcname, xref->xref.file, xref->xref.line,
+ t_ptr, fd, 0, arg, 0);
else
- frrtrace(9, frr_libfrr, schedule_write, m, funcname, schedfrom,
- fromln, t_ptr, fd, 0, arg, 0);
+ frrtrace(9, frr_libfrr, schedule_write, m,
+ xref->funcname, xref->xref.file, xref->xref.line,
+ t_ptr, fd, 0, arg, 0);
assert(fd >= 0 && fd < m->fd_limit);
frr_with_mutex(&m->mtx) {
@@ -882,7 +880,7 @@ struct thread *funcname_thread_add_read_write(int dir, struct thread_master *m,
/* make sure we have room for this fd + pipe poker fd */
assert(queuepos + 1 < m->handler.pfdsize);
- thread = thread_get(m, dir, func, arg, debugargpass);
+ thread = thread_get(m, dir, func, arg, xref);
m->handler.pfds[queuepos].fd = fd;
m->handler.pfds[queuepos].events |=
@@ -910,10 +908,10 @@ struct thread *funcname_thread_add_read_write(int dir, struct thread_master *m,
}
static struct thread *
-funcname_thread_add_timer_timeval(struct thread_master *m,
- int (*func)(struct thread *), int type,
- void *arg, struct timeval *time_relative,
- struct thread **t_ptr, debugargdef)
+_thread_add_timer_timeval(const struct xref_threadsched *xref,
+ struct thread_master *m, int (*func)(struct thread *),
+ int type, void *arg, struct timeval *time_relative,
+ struct thread **t_ptr)
{
struct thread *thread;
@@ -922,7 +920,8 @@ funcname_thread_add_timer_timeval(struct thread_master *m,
assert(type == THREAD_TIMER);
assert(time_relative);
- frrtrace(9, frr_libfrr, schedule_timer, m, funcname, schedfrom, fromln,
+ frrtrace(9, frr_libfrr, schedule_timer, m,
+ xref->funcname, xref->xref.file, xref->xref.line,
t_ptr, 0, 0, arg, (long)time_relative->tv_sec);
frr_with_mutex(&m->mtx) {
@@ -930,7 +929,7 @@ funcname_thread_add_timer_timeval(struct thread_master *m,
/* thread is already scheduled; don't reschedule */
return NULL;
- thread = thread_get(m, type, func, arg, debugargpass);
+ thread = thread_get(m, type, func, arg, xref);
frr_with_mutex(&thread->mtx) {
monotime(&thread->u.sands);
@@ -951,10 +950,10 @@ funcname_thread_add_timer_timeval(struct thread_master *m,
/* Add timer event thread. */
-struct thread *funcname_thread_add_timer(struct thread_master *m,
- int (*func)(struct thread *),
- void *arg, long timer,
- struct thread **t_ptr, debugargdef)
+struct thread *_thread_add_timer(const struct xref_threadsched *xref,
+ struct thread_master *m,
+ int (*func)(struct thread *),
+ void *arg, long timer, struct thread **t_ptr)
{
struct timeval trel;
@@ -963,16 +962,16 @@ struct thread *funcname_thread_add_timer(struct thread_master *m,
trel.tv_sec = timer;
trel.tv_usec = 0;
- return funcname_thread_add_timer_timeval(m, func, THREAD_TIMER, arg,
- &trel, t_ptr, debugargpass);
+ return _thread_add_timer_timeval(xref, m, func, THREAD_TIMER, arg,
+ &trel, t_ptr);
}
/* Add timer event thread with "millisecond" resolution */
-struct thread *funcname_thread_add_timer_msec(struct thread_master *m,
- int (*func)(struct thread *),
- void *arg, long timer,
- struct thread **t_ptr,
- debugargdef)
+struct thread *_thread_add_timer_msec(const struct xref_threadsched *xref,
+ struct thread_master *m,
+ int (*func)(struct thread *),
+ void *arg, long timer,
+ struct thread **t_ptr)
{
struct timeval trel;
@@ -981,29 +980,31 @@ struct thread *funcname_thread_add_timer_msec(struct thread_master *m,
trel.tv_sec = timer / 1000;
trel.tv_usec = 1000 * (timer % 1000);
- return funcname_thread_add_timer_timeval(m, func, THREAD_TIMER, arg,
- &trel, t_ptr, debugargpass);
+ return _thread_add_timer_timeval(xref, m, func, THREAD_TIMER, arg,
+ &trel, t_ptr);
}
/* Add timer event thread with "millisecond" resolution */
-struct thread *funcname_thread_add_timer_tv(struct thread_master *m,
- int (*func)(struct thread *),
- void *arg, struct timeval *tv,
- struct thread **t_ptr, debugargdef)
+struct thread *_thread_add_timer_tv(const struct xref_threadsched *xref,
+ struct thread_master *m,
+ int (*func)(struct thread *),
+ void *arg, struct timeval *tv,
+ struct thread **t_ptr)
{
- return funcname_thread_add_timer_timeval(m, func, THREAD_TIMER, arg, tv,
- t_ptr, debugargpass);
+ return _thread_add_timer_timeval(xref, m, func, THREAD_TIMER, arg, tv,
+ t_ptr);
}
/* Add simple event thread. */
-struct thread *funcname_thread_add_event(struct thread_master *m,
- int (*func)(struct thread *),
- void *arg, int val,
- struct thread **t_ptr, debugargdef)
+struct thread *_thread_add_event(const struct xref_threadsched *xref,
+ struct thread_master *m,
+ int (*func)(struct thread *),
+ void *arg, int val, struct thread **t_ptr)
{
struct thread *thread = NULL;
- frrtrace(9, frr_libfrr, schedule_event, m, funcname, schedfrom, fromln,
+ frrtrace(9, frr_libfrr, schedule_event, m,
+ xref->funcname, xref->xref.file, xref->xref.line,
t_ptr, 0, val, arg, 0);
assert(m != NULL);
@@ -1013,7 +1014,7 @@ struct thread *funcname_thread_add_event(struct thread_master *m,
/* thread is already scheduled; don't reschedule */
break;
- thread = thread_get(m, THREAD_EVENT, func, arg, debugargpass);
+ thread = thread_get(m, THREAD_EVENT, func, arg, xref);
frr_with_mutex(&thread->mtx) {
thread->u.val = val;
thread_list_add_tail(&m->event, thread);
@@ -1239,8 +1240,9 @@ void thread_cancel(struct thread **thread)
master = (*thread)->master;
- frrtrace(9, frr_libfrr, thread_cancel, master, (*thread)->funcname,
- (*thread)->schedfrom, (*thread)->schedfrom_line, NULL, (*thread)->u.fd,
+ frrtrace(9, frr_libfrr, thread_cancel, master,
+ (*thread)->xref->funcname, (*thread)->xref->xref.file,
+ (*thread)->xref->xref.line, NULL, (*thread)->u.fd,
(*thread)->u.val, (*thread)->arg, (*thread)->u.sands.tv_sec);
assert(master->owner == pthread_self());
@@ -1287,8 +1289,8 @@ void thread_cancel_async(struct thread_master *master, struct thread **thread,
if (thread && *thread)
frrtrace(9, frr_libfrr, thread_cancel_async, master,
- (*thread)->funcname, (*thread)->schedfrom,
- (*thread)->schedfrom_line, NULL, (*thread)->u.fd,
+ (*thread)->xref->funcname, (*thread)->xref->xref.file,
+ (*thread)->xref->xref.line, NULL, (*thread)->u.fd,
(*thread)->u.val, (*thread)->arg,
(*thread)->u.sands.tv_sec);
else
@@ -1673,8 +1675,9 @@ void thread_call(struct thread *thread)
GETRUSAGE(&before);
thread->real = before.real;
- frrtrace(9, frr_libfrr, thread_call, thread->master, thread->funcname,
- thread->schedfrom, thread->schedfrom_line, NULL, thread->u.fd,
+ frrtrace(9, frr_libfrr, thread_call, thread->master,
+ thread->xref->funcname, thread->xref->xref.file,
+ thread->xref->xref.line, NULL, thread->u.fd,
thread->u.val, thread->arg, thread->u.sands.tv_sec);
pthread_setspecific(thread_current, thread);
@@ -1724,7 +1727,7 @@ void thread_call(struct thread *thread)
flog_warn(
EC_LIB_SLOW_THREAD,
"SLOW THREAD: task %s (%lx) ran for %lums (cpu time %lums)",
- thread->funcname, (unsigned long)thread->func,
+ thread->xref->funcname, (unsigned long)thread->func,
realtime / 1000, cputime / 1000);
}
#endif /* CONSUMED_TIME_CHECK */
@@ -1732,15 +1735,15 @@ void thread_call(struct thread *thread)
}
/* Execute thread */
-void funcname_thread_execute(struct thread_master *m,
- int (*func)(struct thread *), void *arg, int val,
- debugargdef)
+void _thread_execute(const struct xref_threadsched *xref,
+ struct thread_master *m, int (*func)(struct thread *),
+ void *arg, int val)
{
struct thread *thread;
/* Get or allocate new thread to execute. */
frr_with_mutex(&m->mtx) {
- thread = thread_get(m, THREAD_EVENT, func, arg, debugargpass);
+ thread = thread_get(m, THREAD_EVENT, func, arg, xref);
/* Set its event value. */
frr_with_mutex(&thread->mtx) {