From f8d50682cd1245f6f5ce4c846ca6f1bdc11255a6 Mon Sep 17 00:00:00 2001 From: Dave Barach Date: Tue, 14 May 2019 18:01:44 -0400 Subject: init / exit function ordering The vlib init function subsystem now supports a mix of procedural and formally-specified ordering constraints. We should eliminate procedural knowledge wherever possible. The following schemes are *roughly* equivalent: static clib_error_t *init_runs_first (vlib_main_t *vm) { clib_error_t *error; ... do some stuff... if ((error = vlib_call_init_function (init_runs_next))) return error; ... } VLIB_INIT_FUNCTION (init_runs_first); and static clib_error_t *init_runs_first (vlib_main_t *vm) { ... do some stuff... } VLIB_INIT_FUNCTION (init_runs_first) = { .runs_before = VLIB_INITS("init_runs_next"), }; The first form will [most likely] call "init_runs_next" on the spot. The second form means that "init_runs_first" runs before "init_runs_next," possibly much earlier in the sequence. Please DO NOT construct sets of init functions where A before B actually means A *right before* B. It's not necessary - simply combine A and B - and it leads to hugely annoying debugging exercises when trying to switch from ad-hoc procedural ordering constraints to formal ordering constraints. Change-Id: I5e4353503bf43b4acb11a45fb33c79a5ade8426c Signed-off-by: Dave Barach --- src/vlib/linux/pci.c | 13 +++++++------ src/vlib/linux/vmbus.c | 9 +++++++-- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'src/vlib/linux') diff --git a/src/vlib/linux/pci.c b/src/vlib/linux/pci.c index 8b614c751a1..20d44cd6d6e 100644 --- a/src/vlib/linux/pci.c +++ b/src/vlib/linux/pci.c @@ -1449,13 +1449,9 @@ linux_pci_init (vlib_main_t * vm) { vlib_pci_main_t *pm = &pci_main; vlib_pci_addr_t *addr = 0, *addrs; - clib_error_t *error; pm->vlib_main = vm; - if ((error = vlib_call_init_function (vm, unix_input_init))) - return error; - ASSERT (sizeof (vlib_pci_addr_t) == sizeof (u32)); addrs = vlib_pci_get_all_dev_addrs (); @@ -1471,10 +1467,15 @@ linux_pci_init (vlib_main_t * vm) } /* *INDENT-ON* */ - return error; + return 0; } -VLIB_INIT_FUNCTION (linux_pci_init); +/* *INDENT-OFF* */ +VLIB_INIT_FUNCTION (linux_pci_init) = +{ + .runs_after = VLIB_INITS("unix_input_init"), +}; +/* *INDENT-ON* */ /* * fd.io coding-style-patch-verification: ON diff --git a/src/vlib/linux/vmbus.c b/src/vlib/linux/vmbus.c index d0efbd748ef..2fc438b4778 100644 --- a/src/vlib/linux/vmbus.c +++ b/src/vlib/linux/vmbus.c @@ -407,10 +407,15 @@ linux_vmbus_init (vlib_main_t * vm) pm->vlib_main = vm; - return vlib_call_init_function (vm, unix_input_init); + return 0; } -VLIB_INIT_FUNCTION (linux_vmbus_init); +/* *INDENT-OFF* */ +VLIB_INIT_FUNCTION (linux_vmbus_init) = +{ + .runs_before = VLIB_INITS("unix_input_init"), +}; +/* *INDENT-ON* */ /* * fd.io coding-style-patch-verification: ON -- cgit 1.2.3-korg