Index: subr_taskqueue.c =================================================================== RCS file: /usr/ncvs/src/sys/kern/subr_taskqueue.c,v retrieving revision 1.26 diff -u -r1.26 subr_taskqueue.c --- subr_taskqueue.c 24 Apr 2005 16:52:45 -0000 1.26 +++ subr_taskqueue.c 25 Apr 2005 15:58:28 -0000 @@ -25,7 +25,7 @@ */ #include -__FBSDID("$FreeBSD: src/sys/kern/subr_taskqueue.c,v 1.26 2005/04/24 16:52:45 sam Exp $"); +__FBSDID("$FreeBSD: src/sys/kern/subr_taskqueue.c,v 1.25 2004/10/05 04:16:00 imp Exp $"); #include #include @@ -56,6 +56,9 @@ }; static void init_taskqueue_list(void *data); +#ifdef DIAGNOSTIC +struct mtx dont_sleep_in_taskqueue; +#endif static void init_taskqueue_list(void *data __unused) @@ -63,6 +66,10 @@ mtx_init(&taskqueue_queues_mutex, "taskqueue list", NULL, MTX_DEF); STAILQ_INIT(&taskqueue_queues); +#ifdef DIAGNOSTIC + mtx_init(&dont_sleep_in_taskqueue, "dont_sleep_in_taskqueue", + NULL, MTX_DEF); +#endif } SYSINIT(taskqueue_list, SI_SUB_INTRINSIC, SI_ORDER_ANY, init_taskqueue_list, NULL); @@ -174,6 +181,14 @@ { struct task *task; int owned, pending; +#ifdef DIAGNOSTIC + struct bintime bt1, bt2; + struct timespec ts2; + static uint64_t maxdt = 36893488147419102LL; /* 2 msec */ + static task_fn_t *lastfunc; + task_fn_t *t_func; + void *t_arg; +#endif owned = mtx_owned(&queue->tq_mutex); if (!owned) @@ -189,9 +204,34 @@ task->ta_pending = 0; queue->tq_running = task; mtx_unlock(&queue->tq_mutex); +#ifdef DIAGNOSTIC + binuptime(&bt1); + mtx_lock(&dont_sleep_in_taskqueue); + t_func = task->ta_func; + t_arg = task->ta_context; +#endif task->ta_func(task->ta_context, pending); +#ifdef DIAGNOSTIC + mtx_unlock(&dont_sleep_in_taskqueue); + binuptime(&bt2); + bintime_sub(&bt2, &bt1); + if (bt2.frac > maxdt) { + if (lastfunc != t_func || + bt2.frac > maxdt * 2) { + bintime2timespec(&bt2, &ts2); + printf("Expensive taskqueue(9) function: " + "%p(%p) %jd.%09ld s\n", + t_func, t_arg, + (intmax_t)ts2.tv_sec, + ts2.tv_nsec); + } + maxdt = bt2.frac; + lastfunc = t_func; + } +#endif + mtx_lock(&queue->tq_mutex); queue->tq_running = NULL; wakeup(task);