Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perf timer #5

Merged
merged 2 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/bfdev
Submodule bfdev updated 92 files
+0 −1 .github/workflows/ubuntu-clang.yml
+5 −6 .github/workflows/ubuntu-gcc.yml
+11 −6 .github/workflows/windows.yml
+8 −2 CMakeLists.txt
+11 −9 README.md
+2 −38 build.cmake
+67 −64 docs/components.md
+0 −1 examples/list/.gitignore
+0 −6 examples/list/CMakeLists.txt
+0 −220 examples/list/selftest.c
+29 −28 examples/mpi/bbp.c
+13 −15 examples/mpi/fibonacci.c
+10 −10 examples/mpi/helper.h
+21 −22 examples/mpi/machin.c
+0 −1 examples/slist/.gitignore
+0 −6 examples/slist/CMakeLists.txt
+0 −129 examples/slist/selftest.c
+3 −3 examples/time.h
+37 −21 include/bfdev/bitmap.h
+2 −0 include/bfdev/bitops-endian.h
+4 −0 include/bfdev/bits.h
+4 −12 include/bfdev/bitwalk-comp.h
+150 −58 include/bfdev/bitwalk.h
+6 −0 include/bfdev/compiler/types.h
+1 −1 include/bfdev/container.h
+25 −4 include/bfdev/fsm.h
+1 −1 include/bfdev/hash.h
+11 −0 include/bfdev/macro.h
+2 −2 include/bfdev/math.h
+19 −6 include/bfdev/mpi.h
+19 −20 include/bfdev/notifier.h
+32 −0 include/bfdev/port/stdio.h
+45 −0 include/bfdev/port/stdlib.h
+81 −0 include/bfdev/port/string.h
+66 −0 include/port/allocator.h
+4 −4 include/port/log.h
+43 −0 scripts/sanitize.cmake
+3 −36 src/allocator.c
+8 −7 src/argv.c
+4 −2 src/array.c
+18 −14 src/bitmap.c
+34 −65 src/bitwalk.c
+11 −5 src/bloom.c
+1 −0 src/btree-utils.c
+5 −5 src/btree.c
+2 −2 src/cache/cache.c
+2 −2 src/crypto/ascii85.c
+21 −13 src/fifo.c
+1 −7 src/fsm.c
+5 −2 src/hashmap.c
+5 −5 src/hlist-debug.c
+5 −2 src/ilist.c
+2 −2 src/levenshtein.c
+4 −4 src/libc/strdup.c
+11 −4 src/list-sort.c
+8 −6 src/log.c
+2 −2 src/matrix.c
+3 −2 src/minpool.c
+272 −216 src/mpi.c
+11 −13 src/notifier.c
+12 −4 src/prandom.c
+8 −4 src/radix.c
+31 −19 src/ringbuf.c
+1 −1 src/scnprintf.c
+5 −3 src/skiplist.c
+12 −3 src/slist-debug.c
+3 −3 src/sort.c
+2 −1 src/stringhash.c
+1 −1 src/textsearch/bm.c
+1 −1 src/textsearch/kmp.c
+1 −1 src/textsearch/sunday.c
+13 −0 testsuite/CMakeLists.txt
+2 −0 testsuite/array/.gitignore
+19 −0 testsuite/array/CMakeLists.txt
+49 −0 testsuite/array/fuzzy.c
+2 −0 testsuite/bitwalk/.gitignore
+16 −0 testsuite/bitwalk/CMakeLists.txt
+334 −0 testsuite/bitwalk/fuzzy.c
+12 −0 testsuite/build.cmake
+2 −0 testsuite/list/.gitignore
+16 −0 testsuite/list/CMakeLists.txt
+359 −0 testsuite/list/iterator.c
+3 −0 testsuite/mpi/.gitignore
+21 −0 testsuite/mpi/CMakeLists.txt
+241 −0 testsuite/mpi/empty.c
+209 −0 testsuite/mpi/fuzzy.c
+2 −0 testsuite/slist/.gitignore
+16 −0 testsuite/slist/CMakeLists.txt
+206 −0 testsuite/slist/iterator.c
+236 −0 testsuite/testsuite.c
+18 −0 testsuite/testsuite.cmake
+76 −0 testsuite/testsuite.h
22 changes: 14 additions & 8 deletions src/event/xdbd_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,40 @@

#include <xdbd_timer.h>

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);
}
5 changes: 3 additions & 2 deletions src/event/xdbd_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
#include <bfdev.h>

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);
Expand Down
Loading