mirror of
https://github.com/haproxy/haproxy.git
synced 2026-07-15 20:03:33 -04:00
MINOR: task: move the profiling checks to the called functions not callers
The checks on TH_FL_TASK_PROFILING that are used to decide whether or not to set t->wake_date from now_mono_time() used to be made in callers of __tasklet_wakeup_on() and __tasklet_wakeup_after(), but not only this needlessly inflates code by placing this in every caller (~4kB), it also renders the design fragile since each caller needs to blindly copy-paste that statement. Let's move the operation in the callees instead. As a bonus, it allows to check the flag on the target thread and not on the calling thread (which was arguably a bug though without a noticeable effect since for now profiling is for all threads or none).
This commit is contained in:
parent
9ec82560f2
commit
5fd3c8bf70
2 changed files with 10 additions and 7 deletions
|
|
@ -27,7 +27,6 @@
|
|||
|
||||
#include <import/eb32tree.h>
|
||||
|
||||
#include <haproxy/activity.h>
|
||||
#include <haproxy/api.h>
|
||||
#include <haproxy/clock.h>
|
||||
#include <haproxy/fd.h>
|
||||
|
|
@ -472,8 +471,6 @@ static inline void _tasklet_wakeup_on(struct tasklet *tl, int thr, uint f, const
|
|||
#endif
|
||||
}
|
||||
|
||||
if (_HA_ATOMIC_LOAD(&th_ctx->flags) & TH_FL_TASK_PROFILING)
|
||||
tl->wake_date = now_mono_time();
|
||||
__tasklet_wakeup_on(tl, thr);
|
||||
}
|
||||
|
||||
|
|
@ -540,8 +537,6 @@ static inline void _task_instant_wakeup(struct task *t, unsigned int f, const st
|
|||
#endif
|
||||
}
|
||||
|
||||
if (_HA_ATOMIC_LOAD(&th_ctx->flags) & TH_FL_TASK_PROFILING)
|
||||
t->wake_date = now_mono_time();
|
||||
__tasklet_wakeup_on((struct tasklet *)t, thr);
|
||||
}
|
||||
|
||||
|
|
@ -585,8 +580,6 @@ static inline struct list *_tasklet_wakeup_after(struct list *head, struct taskl
|
|||
#endif
|
||||
}
|
||||
|
||||
if (th_ctx->flags & TH_FL_TASK_PROFILING)
|
||||
tl->wake_date = now_mono_time();
|
||||
return __tasklet_wakeup_after(head, tl);
|
||||
}
|
||||
|
||||
|
|
|
|||
10
src/task.c
10
src/task.c
|
|
@ -138,6 +138,9 @@ void __tasklet_wakeup_on(struct tasklet *tl, int thr)
|
|||
{
|
||||
if (likely(thr < 0)) {
|
||||
/* this tasklet runs on the caller thread */
|
||||
if (_HA_ATOMIC_LOAD(&th_ctx->flags) & TH_FL_TASK_PROFILING)
|
||||
tl->wake_date = now_mono_time();
|
||||
|
||||
if (tl->state & TASK_HEAVY) {
|
||||
LIST_APPEND(&th_ctx->tasklets[TL_HEAVY], &tl->list);
|
||||
th_ctx->tl_class_mask |= 1 << TL_HEAVY;
|
||||
|
|
@ -161,6 +164,9 @@ void __tasklet_wakeup_on(struct tasklet *tl, int thr)
|
|||
_HA_ATOMIC_INC(&th_ctx->rq_total);
|
||||
} else {
|
||||
/* this tasklet runs on a specific thread. */
|
||||
if (_HA_ATOMIC_LOAD(&ha_thread_ctx[thr].flags) & TH_FL_TASK_PROFILING)
|
||||
tl->wake_date = now_mono_time();
|
||||
|
||||
MT_LIST_APPEND(&ha_thread_ctx[thr].shared_tasklet_list, list_to_mt_list(&tl->list));
|
||||
_HA_ATOMIC_INC(&ha_thread_ctx[thr].rq_total);
|
||||
wake_thread(thr);
|
||||
|
|
@ -174,6 +180,10 @@ void __tasklet_wakeup_on(struct tasklet *tl, int thr)
|
|||
struct list *__tasklet_wakeup_after(struct list *head, struct tasklet *tl)
|
||||
{
|
||||
BUG_ON(tl->tid >= 0 && tid != tl->tid);
|
||||
|
||||
if (_HA_ATOMIC_LOAD(&th_ctx->flags) & TH_FL_TASK_PROFILING)
|
||||
tl->wake_date = now_mono_time();
|
||||
|
||||
/* this tasklet runs on the caller thread */
|
||||
if (!head) {
|
||||
if (tl->state & TASK_HEAVY) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue