From 1520ecd126a2d774f81a053c985c652ed7d54ec1 Mon Sep 17 00:00:00 2001 From: John Sanpe Date: Thu, 11 Apr 2024 13:47:57 +0800 Subject: [PATCH 1/2] perf timer: update bfdev version Signed-off-by: John Sanpe --- lib/bfdev | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bfdev b/lib/bfdev index ed6879b..1e69be7 160000 --- a/lib/bfdev +++ b/lib/bfdev @@ -1 +1 @@ -Subproject commit ed6879b25705e98b091ca8d35ca4b6e921f0087e +Subproject commit 1e69be70b431ebe6032e2173a82a3f2012e46c26 From 5a94aaca984800d227306c3a929ba9c7c7817546 Mon Sep 17 00:00:00 2001 From: John Sanpe Date: Fri, 12 Apr 2024 13:48:54 +0800 Subject: [PATCH 2/2] perf timer: using more higher performing heap Signed-off-by: John Sanpe --- src/event/xdbd_timer.c | 22 ++++++++++++++-------- src/event/xdbd_timer.h | 5 +++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/event/xdbd_timer.c b/src/event/xdbd_timer.c index 8ff5294..70aa8c1 100644 --- a/src/event/xdbd_timer.c +++ b/src/event/xdbd_timer.c @@ -5,34 +5,40 @@ #include -BFDEV_RB_ROOT_CACHED(xdbd_timers); +BFDEV_HEAP_ROOT(xdbd_timers); static inline long -timer_cmp(const bfdev_rb_node_t *key1, const bfdev_rb_node_t *key2, void *pdata) +timer_cmp(const bfdev_heap_node_t *key1, const bfdev_heap_node_t *key2, void *pdata) { xdbd_timer_t *node1, *node2; - node1 = bfdev_container_of(key1, xdbd_timer_t, rb); - node2 = bfdev_container_of(key2, xdbd_timer_t, rb); + node1 = bfdev_heap_entry(key1, xdbd_timer_t, node); + node2 = bfdev_heap_entry(key2, xdbd_timer_t, node); /* Ignoring conflicts */ - return node1->time < node2->time ? BFDEV_LT : BFDEV_BT; + return bfdev_cmp(node1->time > node2->time); } xdbd_timer_t * xdbd_first_timer(void) { - return bfdev_rb_cached_first_entry(&xdbd_timers, xdbd_timer_t, rb); + bfdev_heap_node_t *node; + xdbd_timer_t *timer; + + node = BFDEV_HEAP_ROOT_NODE(&xdbd_timers); + timer = bfdev_heap_entry(node, xdbd_timer_t, node); + + return timer; } void xdbd_add_timer(xdbd_timer_t *timer) { - bfdev_rb_cached_insert(&xdbd_timers, &timer->rb, timer_cmp, NULL); + bfdev_heap_insert(&xdbd_timers, &timer->node, timer_cmp, NULL); } void xdbd_remove_timer(xdbd_timer_t *timer) { - bfdev_rb_cached_remove(&xdbd_timers, &timer->rb); + bfdev_heap_remove(&xdbd_timers, &timer->node); } diff --git a/src/event/xdbd_timer.h b/src/event/xdbd_timer.h index 5c718b6..49e1f9a 100644 --- a/src/event/xdbd_timer.h +++ b/src/event/xdbd_timer.h @@ -10,11 +10,12 @@ #include struct xdbd_timer_s { - bfdev_rb_node_t rb; + bfdev_heap_node_t node; xdbd_msec_t time; }; -extern bfdev_rb_root_cached_t xdbd_timers; +extern bfdev_heap_root_t +xdbd_timers; extern xdbd_timer_t * xdbd_first_timer(void);