From c2cfa843b42d30b8d589d507e5b41f6fac704384 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 29 Nov 2017 19:36:26 -0500 Subject: [PATCH] lib, pimd: Convert timer_wheel to use thread_execute_name Allow at timer wheel creation time the ability to specify a name for what we want the 'show thread cpu' to show up as. Modify pim to note this. Signed-off-by: Donald Sharp --- lib/wheel.c | 21 +++++++++++++++++++-- lib/wheel.h | 4 +++- pimd/pim_upstream.c | 11 +++++++---- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/lib/wheel.c b/lib/wheel.c index b1a3e89fc7..722b02424a 100644 --- a/lib/wheel.c +++ b/lib/wheel.c @@ -29,7 +29,9 @@ DEFINE_MTYPE_STATIC(LIB, TIMER_WHEEL_LIST, "Timer Wheel Slot List") static int debug_timer_wheel = 0; -static int wheel_timer_thread(struct thread *t) +static int wheel_timer_thread(struct thread *t); + +static int wheel_timer_thread_helper(struct thread *t) { struct listnode *node, *nextnode; unsigned long long curr_slot; @@ -65,15 +67,29 @@ static int wheel_timer_thread(struct thread *t) return 0; } +static int wheel_timer_thread(struct thread *t) +{ + struct timer_wheel *wheel; + + wheel = THREAD_ARG(t); + + thread_execute_name(wheel->master, wheel_timer_thread_helper, + wheel, 0, wheel->name); + + return 0; +} + struct timer_wheel *wheel_init(struct thread_master *master, int period, size_t slots, unsigned int (*slot_key)(void *), - void (*slot_run)(void *)) + void (*slot_run)(void *), + const char *run_name) { struct timer_wheel *wheel; size_t i; wheel = XCALLOC(MTYPE_TIMER_WHEEL, sizeof(struct timer_wheel)); + wheel->name = XSTRDUP(MTYPE_TIMER_WHEEL, run_name); wheel->slot_key = slot_key; wheel->slot_run = slot_run; @@ -104,6 +120,7 @@ void wheel_delete(struct timer_wheel *wheel) THREAD_OFF(wheel->timer); XFREE(MTYPE_TIMER_WHEEL_LIST, wheel->wheel_slot_lists); + XFREE(MTYPE_TIMER_WHEEL, wheel->name); XFREE(MTYPE_TIMER_WHEEL, wheel); } diff --git a/lib/wheel.h b/lib/wheel.h index 1f9f95ed31..c8e83fafcb 100644 --- a/lib/wheel.h +++ b/lib/wheel.h @@ -21,6 +21,7 @@ #define __WHEEL_H__ struct timer_wheel { + char *name; struct thread_master *master; int slots; long long curr_slot; @@ -76,7 +77,8 @@ struct timer_wheel { */ struct timer_wheel *wheel_init(struct thread_master *master, int period, size_t slots, unsigned int (*slot_key)(void *), - void (*slot_run)(void *)); + void (*slot_run)(void *), + const char *run_name); /* * Delete the specified timer wheel created diff --git a/pimd/pim_upstream.c b/pimd/pim_upstream.c index 15cbf6fbc3..cc255a51e2 100644 --- a/pimd/pim_upstream.c +++ b/pimd/pim_upstream.c @@ -1764,15 +1764,18 @@ void pim_upstream_remove_lhr_star_pimreg(struct pim_instance *pim, void pim_upstream_init(struct pim_instance *pim) { - char hash_name[64]; + char name[64]; + snprintf(name, 64, "PIM %s Timer Wheel", + pim->vrf->name); pim->upstream_sg_wheel = wheel_init(master, 31000, 100, pim_upstream_hash_key, - pim_upstream_sg_running); + pim_upstream_sg_running, name); - snprintf(hash_name, 64, "PIM %s Upstream Hash", pim->vrf->name); + snprintf(name, 64, "PIM %s Upstream Hash", + pim->vrf->name); pim->upstream_hash = hash_create_size(8192, pim_upstream_hash_key, - pim_upstream_equal, hash_name); + pim_upstream_equal, name); pim->upstream_list = list_new(); pim->upstream_list->cmp = pim_upstream_compare; -- 2.39.5