diff options
Diffstat (limited to 'src/vlib')
-rw-r--r-- | src/vlib/drop.c | 12 | ||||
-rw-r--r-- | src/vlib/error.c | 9 | ||||
-rw-r--r-- | src/vlib/error.h | 30 | ||||
-rw-r--r-- | src/vlib/node.c | 2 | ||||
-rw-r--r-- | src/vlib/node.h | 19 | ||||
-rw-r--r-- | src/vlib/threads.c | 2 |
6 files changed, 36 insertions, 38 deletions
diff --git a/src/vlib/drop.c b/src/vlib/drop.c index 2b245b561e3..034a23fb759 100644 --- a/src/vlib/drop.c +++ b/src/vlib/drop.c @@ -27,8 +27,8 @@ typedef enum static u8 * validate_error (vlib_main_t * vm, vlib_error_t * e, u32 index) { - uword node_index = vlib_error_get_node (e[0]); - uword code = vlib_error_get_code (e[0]); + uword node_index = vlib_error_get_node (&vm->node_main, e[0]); + uword code = vlib_error_get_code (&vm->node_main, e[0]); vlib_node_t *n; if (node_index >= vec_len (vm->node_main.nodes)) @@ -69,10 +69,10 @@ counter_index (vlib_main_t * vm, vlib_error_t e) vlib_node_t *n; u32 ci, ni; - ni = vlib_error_get_node (e); + ni = vlib_error_get_node (&vm->node_main, e); n = vlib_get_node (vm, ni); - ci = vlib_error_get_code (e); + ci = vlib_error_get_code (&vm->node_main, e); ASSERT (ci < n->n_errors); ci += n->error_heap_index; @@ -90,8 +90,8 @@ format_error_trace (u8 * s, va_list * va) vlib_error_main_t *em = &vm->error_main; u32 i; - error_node = vlib_get_node (vm, vlib_error_get_node (e[0])); - i = counter_index (vm, e[0]); + error_node = vlib_get_node (vm, vlib_error_get_node (&vm->node_main, e[0])); + i = counter_index (vm, vlib_error_get_code (&vm->node_main, e[0])); s = format (s, "%v: %s", error_node->name, em->error_strings_heap[i]); return s; diff --git a/src/vlib/error.c b/src/vlib/error.c index 58e13431d9f..0918f624a66 100644 --- a/src/vlib/error.c +++ b/src/vlib/error.c @@ -52,8 +52,10 @@ vlib_error_drop_buffers (vlib_main_t * vm, { u32 n_left_this_frame, n_buffers_left, *args, n_args_left; vlib_error_t drop_error; + vlib_node_t *n; - drop_error = vlib_error_set (drop_error_node, drop_error_code); + n = vlib_get_node (vm, drop_error_node); + drop_error = n->error_heap_index + drop_error_code; n_buffers_left = n_buffers; while (n_buffers_left > 0) @@ -116,6 +118,8 @@ vlib_register_errors (vlib_main_t * vm, u32 node_index, u32 n_errors, char *error_strings[]) { vlib_error_main_t *em = &vm->error_main; + vlib_node_main_t *nm = &vm->node_main; + vlib_node_t *n = vlib_get_node (vm, node_index); uword l; void *oldheap; @@ -182,11 +186,14 @@ vlib_register_errors (vlib_main_t * vm, uword i; clib_memset (&t, 0, sizeof (t)); + if (n_errors > 0) + vec_validate (nm->node_by_error, n->error_heap_index + n_errors - 1); for (i = 0; i < n_errors; i++) { t.format = (char *) format (0, "%v %s: %%d", n->name, error_strings[i]); vm->error_elog_event_types[n->error_heap_index + i] = t; + nm->node_by_error[n->error_heap_index + i] = n->index; } } } diff --git a/src/vlib/error.h b/src/vlib/error.h index 58352519be2..0da3a18d85d 100644 --- a/src/vlib/error.h +++ b/src/vlib/error.h @@ -40,38 +40,8 @@ #ifndef included_vlib_error_h #define included_vlib_error_h -/* Combined 16 bit node & 16 bit code as 32 bit number. */ typedef u16 vlib_error_t; -always_inline u32 -vlib_error_get_node (vlib_error_t e) -{ - return e >> 6; -} - -always_inline u32 -vlib_error_get_code (vlib_error_t e) -{ - return e & 0x3f; -} - -always_inline vlib_error_t -vlib_error_set (u32 node_index, u32 code) -{ - ASSERT (node_index < (1 << 10)); - ASSERT (code < (1 << 6)); - return (node_index << 6) | code; -} - -always_inline vlib_error_t -vlib_error_set_code (vlib_error_t e, u32 code) -{ - ASSERT (vlib_error_get_code (e) == 0); - ASSERT (code < (1 << 6)); - e |= code; - return e; -} - typedef struct { /* Error counters. */ diff --git a/src/vlib/node.c b/src/vlib/node.c index 44a3a3ee25d..0e6038d01fa 100644 --- a/src/vlib/node.c +++ b/src/vlib/node.c @@ -502,7 +502,7 @@ register_node (vlib_main_t * vm, vlib_node_registration_t * r) vec_resize (rt->errors, r->n_errors); for (i = 0; i < vec_len (rt->errors); i++) - rt->errors[i] = vlib_error_set (n->index, i); + rt->errors[i] = n->error_heap_index + i; STATIC_ASSERT_SIZEOF (vlib_node_runtime_t, 128); ASSERT (vec_len (n->runtime_data) <= VLIB_NODE_RUNTIME_DATA_SIZE); diff --git a/src/vlib/node.h b/src/vlib/node.h index bec0ed2d2c0..40d0165f402 100644 --- a/src/vlib/node.h +++ b/src/vlib/node.h @@ -760,8 +760,27 @@ typedef struct /* Node registrations added by constructors */ vlib_node_registration_t *node_registrations; + + /* Node index from error code */ + u32 *node_by_error; } vlib_node_main_t; +typedef u16 vlib_error_t; + +always_inline u32 +vlib_error_get_node (vlib_node_main_t * nm, vlib_error_t e) +{ + return nm->node_by_error[e]; +} + +always_inline u32 +vlib_error_get_code (vlib_node_main_t * nm, vlib_error_t e) +{ + u32 node_index = nm->node_by_error[e]; + vlib_node_t *n = nm->nodes[node_index]; + u32 error_code = e - n->error_heap_index; + return error_code; +} #define FRAME_QUEUE_MAX_NELTS 64 typedef struct diff --git a/src/vlib/threads.c b/src/vlib/threads.c index e59919e7a26..49b6e811240 100644 --- a/src/vlib/threads.c +++ b/src/vlib/threads.c @@ -845,6 +845,7 @@ start_workers (vlib_main_t * vm) #ifdef VLIB_SUPPORTS_ARBITRARY_SCALAR_SIZES nm_clone->frame_size_hash = hash_create (0, sizeof (uword)); #endif + nm_clone->node_by_error = nm->node_by_error; /* Packet trace buffers are guaranteed to be empty, nothing to do here */ @@ -1182,6 +1183,7 @@ vlib_worker_thread_node_refork (void) nm_clone->processes = vec_dup_aligned (nm->processes, CLIB_CACHE_LINE_BYTES); + nm_clone->node_by_error = nm->node_by_error; } void |