Skip to content

Commit

Permalink
treewide: replace stb_ds with gr_vec
Browse files Browse the repository at this point in the history
Replace all calls to stb data structures macros with the newly added
gr_vec API.

Signed-off-by: Robin Jarry <[email protected]>
Acked-by: Christophe Fontaine <[email protected]>
  • Loading branch information
rjarry committed Nov 1, 2024
1 parent 443690c commit fb6a8cc
Show file tree
Hide file tree
Showing 23 changed files with 161 additions and 233 deletions.
4 changes: 1 addition & 3 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ ForEachMacros:
- rte_graph_foreach_node
- gr_vec_foreach
- gr_vec_foreach_ref
- stbds_arrforeach
- arrforeach
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Regroup
Expand All @@ -94,7 +92,7 @@ IncludeCategories:
Priority: -1
- Regex: '^<(gr_|gr\.)'
Priority: 100
- Regex: '^<(rte_|event|ecoli|stb_|numa.h|libsmartcols.h)'
- Regex: '^<(rte_|event|ecoli|numa.h|libsmartcols.h)'
Priority: 500
- Regex: '^<cmocka'
Priority: 100000
Expand Down
1 change: 0 additions & 1 deletion .containerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@
/redhat-linux-build
/subprojects/dpdk
/subprojects/ecoli
/subprojects/stb
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@
/redhat-linux-build
/subprojects/dpdk
/subprojects/ecoli
/subprojects/stb
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ smoke-tests: all
coverage: test
$Q mkdir -p $(BUILDDIR)/coverage
$Q gcovr --html-details $(BUILDDIR)/coverage/index.html --txt \
-e '.*stb_ds.*' -e '.*_test.c' -ur . $(BUILDDIR)
-e '.*_test.c' -ur . $(BUILDDIR)
@echo Coverage data is present in $(BUILDDIR)/coverage/index.html

.PHONY: all
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ Anyone can contribute to `grout`. See
| DPDK | Build & Runtime | BSD-3-Clause | https://git.dpdk.org/dpdk/ |
| libnuma | Build & Runtime | LGPL-2.1 | https://github.com/numactl/numactl |
| libevent | Build & Runtime | BSD-3-Clause | https://github.com/libevent/libevent |
| libstb | Build & Runtime | Public Domain | https://github.com/nothings/stb |
| libecoli | Build & Runtime | BSD-3-Clause | https://git.sr.ht/~rjarry/libecoli |
| libsmartcols | Build & Runtime | LGPL-2.1 | https://github.com/util-linux/util-linux/tree/master/libsmartcols |
| cmocka | Build | Apache-2.0 | https://github.com/clibs/cmocka |
Expand Down
28 changes: 14 additions & 14 deletions main/dpdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include <gr_api.h>
#include <gr_errno.h>
#include <gr_log.h>
#include <gr_stb_ds.h>
#include <gr_string.h>
#include <gr_vec.h>

#include <rte_eal.h>
#include <rte_errno.h>
Expand Down Expand Up @@ -154,28 +154,28 @@ int dpdk_init(const struct gr_args *args) {
goto end;
}

arrpush(eal_args, "");
arrpush(eal_args, "-l");
arrpush(eal_args, main_lcore);
arrpush(eal_args, "-a");
arrpush(eal_args, "0000:00:00.0");
gr_vec_add(eal_args, "");
gr_vec_add(eal_args, "-l");
gr_vec_add(eal_args, main_lcore);
gr_vec_add(eal_args, "-a");
gr_vec_add(eal_args, "0000:00:00.0");

if (args->test_mode) {
arrpush(eal_args, "--no-shconf");
arrpush(eal_args, "--no-huge");
arrpush(eal_args, "-m");
arrpush(eal_args, "2048");
gr_vec_add(eal_args, "--no-shconf");
gr_vec_add(eal_args, "--no-huge");
gr_vec_add(eal_args, "-m");
gr_vec_add(eal_args, "2048");
} else {
arrpush(eal_args, "--in-memory");
gr_vec_add(eal_args, "--in-memory");
}

LOG(INFO, "%s", rte_version());

char *buf = strjoin(eal_args, arrlen(eal_args), " ");
char *buf = strjoin(eal_args, gr_vec_len(eal_args), " ");
LOG(INFO, "EAL arguments:%s", buf);
free(buf);

if ((ret = rte_eal_init(arrlen(eal_args), eal_args)) < 0) {
if ((ret = rte_eal_init(gr_vec_len(eal_args), eal_args)) < 0) {
ret = -ret;
goto end;
}
Expand All @@ -191,7 +191,7 @@ int dpdk_init(const struct gr_args *args) {

ret = 0;
end:
arrfree(eal_args);
gr_vec_free(eal_args);
return errno_set(ret);
}

Expand Down
17 changes: 0 additions & 17 deletions main/gr_stb_ds.h

This file was deleted.

1 change: 0 additions & 1 deletion main/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ src += files(
'module.c',
'sd_notify.c',
'signals.c',
'stb_ds_impl.c',
'string.c',
)

Expand Down
20 changes: 9 additions & 11 deletions main/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <gr_api.h>
#include <gr_log.h>
#include <gr_module.h>
#include <gr_stb_ds.h>
#include <gr_vec.h>

#include <assert.h>
#include <stdio.h>
Expand Down Expand Up @@ -59,22 +59,21 @@ void modules_init(struct event_base *ev_base) {
struct gr_module *mod, **mods = NULL;

STAILQ_FOREACH (mod, &modules, entries)
arrpush(mods, mod); // NOLINT
gr_vec_add(mods, mod);

if (mods == NULL)
ABORT("failed to alloc module array");

qsort(mods, arrlen(mods), sizeof(struct gr_module *), module_init_prio_order);
qsort(mods, gr_vec_len(mods), sizeof(struct gr_module *), module_init_prio_order);

for (int i = 0; i < arrlen(mods); i++) {
mod = mods[i];
gr_vec_foreach (mod, mods) {
if (mod->init != NULL) {
LOG(DEBUG, "%s prio %i", mod->name, mod->init_prio);
mod->init(ev_base);
}
}

arrfree(mods);
gr_vec_free(mods);
}

static int module_fini_prio_order(const void *a, const void *b) {
Expand All @@ -87,22 +86,21 @@ void modules_fini(struct event_base *ev_base) {
struct gr_module *mod, **mods = NULL;

STAILQ_FOREACH (mod, &modules, entries)
arrpush(mods, mod); // NOLINT
gr_vec_add(mods, mod);

if (mods == NULL)
ABORT("failed to alloc module array");

qsort(mods, arrlen(mods), sizeof(struct gr_module *), module_fini_prio_order);
qsort(mods, gr_vec_len(mods), sizeof(struct gr_module *), module_fini_prio_order);

for (int i = 0; i < arrlen(mods); i++) {
mod = mods[i];
gr_vec_foreach (mod, mods) {
if (mod->fini != NULL) {
LOG(DEBUG, "%s prio %i", mod->name, mod->fini_prio);
mod->fini(ev_base);
}
}

arrfree(mods);
gr_vec_free(mods);
}

void gr_modules_dp_init(void) {
Expand Down
24 changes: 0 additions & 24 deletions main/stb_ds_impl.c

This file was deleted.

7 changes: 3 additions & 4 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ dpdk_dep = dependency(
ev_core_dep = dependency('libevent_core')
ev_thread_dep = dependency('libevent_pthreads')
numa_dep = dependency('numa')
stb_dep = dependency('stb', fallback: ['stb', 'stb_dep'])
ecoli_dep = dependency('libecoli', fallback: ['ecoli', 'libecoli_dep'])
smartcols_dep = dependency('smartcols')

Expand All @@ -85,7 +84,7 @@ subdir('cli')
grout_exe = executable(
'grout', src,
include_directories: inc + api_inc,
dependencies: [dpdk_dep, ev_core_dep, ev_thread_dep, numa_dep, stb_dep],
dependencies: [dpdk_dep, ev_core_dep, ev_thread_dep, numa_dep],
c_args: ['-D__GROUT_MAIN__'],
install: true,
install_dir: 'sbin',
Expand All @@ -106,11 +105,11 @@ cmocka_dep = dependency('cmocka')
foreach t : tests
name = fs.replace_suffix(t['sources'].get(0), '').underscorify()
t += {
'sources': t['sources'] + files('main/stb_ds_impl.c', 'main/string.c'),
'sources': t['sources'] + files('main/string.c'),
'include_directories': inc + api_inc,
'c_args': ['-coverage', '-D__GROUT_MAIN__'],
'link_args': t['link_args'] + ['-lgcov'],
'dependencies': [dpdk_dep, ev_core_dep, ev_thread_dep, numa_dep, ecoli_dep, cmocka_dep, stb_dep],
'dependencies': [dpdk_dep, ev_core_dep, ev_thread_dep, numa_dep, ecoli_dep, cmocka_dep],
}
test(name, executable(name, kwargs: t), suite: 'unit')
endforeach
6 changes: 3 additions & 3 deletions modules/infra/api/rxq.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <gr_infra.h>
#include <gr_module.h>
#include <gr_port.h>
#include <gr_stb_ds.h>
#include <gr_vec.h>
#include <gr_worker.h>

#include <errno.h>
Expand All @@ -20,7 +20,7 @@ static struct api_out rxq_list(const void * /*request*/, void **response) {
size_t len;

STAILQ_FOREACH (worker, &workers, next)
n_rxqs += arrlen(worker->rxqs);
n_rxqs += gr_vec_len(worker->rxqs);

len = sizeof(*resp) + n_rxqs * sizeof(struct gr_port_rxq_map);
if ((resp = malloc(len)) == NULL)
Expand All @@ -30,7 +30,7 @@ static struct api_out rxq_list(const void * /*request*/, void **response) {

n_rxqs = 0;
STAILQ_FOREACH (worker, &workers, next) {
arrforeach (qmap, worker->rxqs) {
gr_vec_foreach_ref (qmap, worker->rxqs) {
struct gr_port_rxq_map *q = &resp->rxqs[n_rxqs];
q->iface_id = port_get_iface(qmap->port_id)->id;
q->rxq_id = qmap->queue_id;
Expand Down
Loading

0 comments on commit fb6a8cc

Please sign in to comment.