summaryrefslogtreecommitdiffstats
path: root/src/vlib
diff options
context:
space:
mode:
Diffstat (limited to 'src/vlib')
-rw-r--r--src/vlib/cli.c19
-rw-r--r--src/vlib/error.c79
-rw-r--r--src/vlib/threads.h33
-rw-r--r--src/vlib/trace.c162
4 files changed, 133 insertions, 160 deletions
diff --git a/src/vlib/cli.c b/src/vlib/cli.c
index 5cad95ee004..cad105f17c6 100644
--- a/src/vlib/cli.c
+++ b/src/vlib/cli.c
@@ -849,17 +849,14 @@ show_memory_usage (vlib_main_t * vm,
*/
was_enabled = clib_mem_trace_enable_disable (0);
- /* *INDENT-OFF* */
- foreach_vlib_main (
- ({
- vlib_cli_output (vm, "%sThread %d %s\n", index ? "\n":"", index,
- vlib_worker_threads[index].name);
- vlib_cli_output (vm, " %U\n", format_clib_mem_heap,
- mm->per_cpu_mheaps[index],
- verbose);
- index++;
- }));
- /* *INDENT-ON* */
+ foreach_vlib_main ()
+ {
+ vlib_cli_output (vm, "%sThread %d %s\n", index ? "\n" : "", index,
+ vlib_worker_threads[index].name);
+ vlib_cli_output (vm, " %U\n", format_clib_mem_heap,
+ mm->per_cpu_mheaps[index], verbose);
+ index++;
+ }
/* Restore the trace flag */
clib_mem_trace_enable_disable (was_enabled);
diff --git a/src/vlib/error.c b/src/vlib/error.c
index 7d502d777a3..99664c618a9 100644
--- a/src/vlib/error.c
+++ b/src/vlib/error.c
@@ -252,42 +252,40 @@ show_errors (vlib_main_t * vm,
vlib_cli_output (vm, "%=10s%=35s%=35s%=10s", "Count", "Node", "Reason",
"Severity");
+ foreach_vlib_main ()
+ {
+ em = &this_vlib_main->error_main;
+
+ if (verbose)
+ vlib_cli_output (vm, "Thread %u (%v):", index,
+ vlib_worker_threads[index].name);
- /* *INDENT-OFF* */
- foreach_vlib_main(({
- em = &this_vlib_main->error_main;
+ for (ni = 0; ni < vec_len (this_vlib_main->node_main.nodes); ni++)
+ {
+ n = vlib_get_node (this_vlib_main, ni);
+ for (code = 0; code < n->n_errors; code++)
+ {
+ i = n->error_heap_index + code;
+ c = em->counters[i];
+ if (i < vec_len (em->counters_last_clear))
+ c -= em->counters_last_clear[i];
+ sums[i] += c;
- if (verbose)
- vlib_cli_output(vm, "Thread %u (%v):", index,
- vlib_worker_threads[index].name);
+ if (c == 0 && verbose < 2)
+ continue;
- for (ni = 0; ni < vec_len (this_vlib_main->node_main.nodes); ni++)
- {
- n = vlib_get_node (this_vlib_main, ni);
- for (code = 0; code < n->n_errors; code++)
- {
- i = n->error_heap_index + code;
- c = em->counters[i];
- if (i < vec_len (em->counters_last_clear))
- c -= em->counters_last_clear[i];
- sums[i] += c;
-
- if (c == 0 && verbose < 2)
- continue;
-
- if (verbose)
- vlib_cli_output (vm, "%10lu%=35v%=35s%=10s%=6d", c, n->name,
- em->counters_heap[i].name,
- sev2str(em->counters_heap[i].severity), i);
- else
- vlib_cli_output (vm, "%10lu%=35v%=35s%=10s", c, n->name,
- em->counters_heap[i].name,
- sev2str(em->counters_heap[i].severity));
- }
- }
- index++;
- }));
- /* *INDENT-ON* */
+ if (verbose)
+ vlib_cli_output (vm, "%10lu%=35v%=35s%=10s%=6d", c, n->name,
+ em->counters_heap[i].name,
+ sev2str (em->counters_heap[i].severity), i);
+ else
+ vlib_cli_output (vm, "%10lu%=35v%=35s%=10s", c, n->name,
+ em->counters_heap[i].name,
+ sev2str (em->counters_heap[i].severity));
+ }
+ }
+ index++;
+ }
if (verbose)
vlib_cli_output (vm, "Total:");
@@ -335,14 +333,13 @@ clear_error_counters (vlib_main_t * vm,
vlib_error_main_t *em;
u32 i;
- /* *INDENT-OFF* */
- foreach_vlib_main(({
- em = &this_vlib_main->error_main;
- vec_validate (em->counters_last_clear, vec_len (em->counters) - 1);
- for (i = 0; i < vec_len (em->counters); i++)
- em->counters_last_clear[i] = em->counters[i];
- }));
- /* *INDENT-ON* */
+ foreach_vlib_main ()
+ {
+ em = &this_vlib_main->error_main;
+ vec_validate (em->counters_last_clear, vec_len (em->counters) - 1);
+ for (i = 0; i < vec_len (em->counters); i++)
+ em->counters_last_clear[i] = em->counters[i];
+ }
return 0;
}
diff --git a/src/vlib/threads.h b/src/vlib/threads.h
index d715ebfff58..28a81f78712 100644
--- a/src/vlib/threads.h
+++ b/src/vlib/threads.h
@@ -237,29 +237,16 @@ typedef enum
void vlib_worker_thread_fork_fixup (vlib_fork_fixup_t which);
-#define foreach_vlib_main(body) \
- do \
- { \
- vlib_main_t **__vlib_mains = 0, *this_vlib_main; \
- int ii; \
- \
- for (ii = 0; ii < vec_len (vlib_global_main.vlib_mains); ii++) \
- { \
- this_vlib_main = vlib_global_main.vlib_mains[ii]; \
- ASSERT (ii == 0 || this_vlib_main->parked_at_barrier == 1); \
- if (this_vlib_main) \
- vec_add1 (__vlib_mains, this_vlib_main); \
- } \
- \
- for (ii = 0; ii < vec_len (__vlib_mains); ii++) \
- { \
- this_vlib_main = __vlib_mains[ii]; \
- /* body uses this_vlib_main... */ \
- (body); \
- } \
- vec_free (__vlib_mains); \
- } \
- while (0);
+#define foreach_vlib_main() \
+ for (vlib_main_t *ii = 0, *this_vlib_main = vlib_global_main.vlib_mains[0]; \
+ (ii - (vlib_main_t *) 0) < vec_len (vlib_global_main.vlib_mains); \
+ ii++, this_vlib_main = \
+ vlib_global_main.vlib_mains[ii - (vlib_main_t *) 0]) \
+ if (CLIB_ASSERT_ENABLE && \
+ !(ii == 0 || \
+ (this_vlib_main && this_vlib_main->parked_at_barrier == 1))) \
+ ASSERT (0); \
+ else if (this_vlib_main)
#define foreach_sched_policy \
_(SCHED_OTHER, OTHER, "other") \
diff --git a/src/vlib/trace.c b/src/vlib/trace.c
index 836e8b473a6..4bbd9505b71 100644
--- a/src/vlib/trace.c
+++ b/src/vlib/trace.c
@@ -117,25 +117,23 @@ clear_trace_buffer (void)
int i;
vlib_trace_main_t *tm;
- /* *INDENT-OFF* */
- foreach_vlib_main (
- ({
- tm = &this_vlib_main->trace_main;
-
- tm->trace_enable = 0;
- vec_free (tm->nodes);
- }));
-
- foreach_vlib_main (
- ({
- tm = &this_vlib_main->trace_main;
-
- for (i = 0; i < vec_len (tm->trace_buffer_pool); i++)
- if (! pool_is_free_index (tm->trace_buffer_pool, i))
- vec_free (tm->trace_buffer_pool[i]);
- pool_free (tm->trace_buffer_pool);
- }));
- /* *INDENT-ON* */
+ foreach_vlib_main ()
+ {
+ tm = &this_vlib_main->trace_main;
+
+ tm->trace_enable = 0;
+ vec_free (tm->nodes);
+ }
+
+ foreach_vlib_main ()
+ {
+ tm = &this_vlib_main->trace_main;
+
+ for (i = 0; i < vec_len (tm->trace_buffer_pool); i++)
+ if (!pool_is_free_index (tm->trace_buffer_pool, i))
+ vec_free (tm->trace_buffer_pool[i]);
+ pool_free (tm->trace_buffer_pool);
+ }
}
u8 *
@@ -309,52 +307,50 @@ cli_show_trace_buffer (vlib_main_t * vm,
/* Get active traces from pool. */
- /* *INDENT-OFF* */
- foreach_vlib_main (
- ({
- fmt = "------------------- Start of thread %d %s -------------------\n";
- s = format (s, fmt, index, vlib_worker_threads[index].name);
+ foreach_vlib_main ()
+ {
+ fmt = "------------------- Start of thread %d %s -------------------\n";
+ s = format (s, fmt, index, vlib_worker_threads[index].name);
- tm = &this_vlib_main->trace_main;
+ tm = &this_vlib_main->trace_main;
- trace_apply_filter(this_vlib_main);
+ trace_apply_filter (this_vlib_main);
- traces = 0;
- pool_foreach (h, tm->trace_buffer_pool)
- {
- vec_add1 (traces, h[0]);
- }
+ traces = 0;
+ pool_foreach (h, tm->trace_buffer_pool)
+ {
+ vec_add1 (traces, h[0]);
+ }
- if (vec_len (traces) == 0)
- {
- s = format (s, "No packets in trace buffer\n");
- goto done;
- }
-
- /* Sort them by increasing time. */
- vec_sort_with_function (traces, trace_time_cmp);
-
- for (i = 0; i < vec_len (traces); i++)
- {
- if (i == max)
- {
- char *warn = "Limiting display to %d packets."
- " To display more specify max.";
- vlib_cli_output (vm, warn, max);
- s = format (s, warn, max);
- goto done;
- }
-
- s = format (s, "Packet %d\n%U\n\n", i + 1,
- format_vlib_trace, vm, traces[i]);
- }
-
- done:
- vec_free (traces);
-
- index++;
- }));
- /* *INDENT-ON* */
+ if (vec_len (traces) == 0)
+ {
+ s = format (s, "No packets in trace buffer\n");
+ goto done;
+ }
+
+ /* Sort them by increasing time. */
+ vec_sort_with_function (traces, trace_time_cmp);
+
+ for (i = 0; i < vec_len (traces); i++)
+ {
+ if (i == max)
+ {
+ char *warn = "Limiting display to %d packets."
+ " To display more specify max.";
+ vlib_cli_output (vm, warn, max);
+ s = format (s, warn, max);
+ goto done;
+ }
+
+ s = format (s, "Packet %d\n%U\n\n", i + 1, format_vlib_trace, vm,
+ traces[i]);
+ }
+
+ done:
+ vec_free (traces);
+
+ index++;
+ }
vlib_cli_output (vm, "%v", s);
vec_free (s);
@@ -394,8 +390,7 @@ trace_update_capture_options (u32 add, u32 node_index, u32 filter, u8 verbose)
if (add == ~0)
add = 50;
- /* *INDENT-OFF* */
- foreach_vlib_main ((
+ foreach_vlib_main ()
{
tm = &this_vlib_main->trace_main;
tm->verbose = verbose;
@@ -411,14 +406,13 @@ trace_update_capture_options (u32 add, u32 node_index, u32 filter, u8 verbose)
tn->limit = tn->count = 0;
else
tn->limit += add;
- }));
+ }
- foreach_vlib_main ((
+ foreach_vlib_main ()
{
tm = &this_vlib_main->trace_main;
tm->trace_enable = 1;
- }));
- /* *INDENT-ON* */
+ }
vlib_enable_disable_pkt_trace_filter (! !filter);
}
@@ -533,24 +527,22 @@ VLIB_CLI_COMMAND (add_trace_cli,static) = {
void
trace_filter_set (u32 node_index, u32 flag, u32 count)
{
- /* *INDENT-OFF* */
- foreach_vlib_main (
- ({
- vlib_trace_main_t *tm;
-
- tm = &this_vlib_main->trace_main;
- tm->filter_node_index = node_index;
- tm->filter_flag = flag;
- tm->filter_count = count;
-
- /*
- * Clear the trace limits to stop any in-progress tracing
- * Prevents runaway trace allocations when the filter changes
- * (or is removed)
- */
- vec_free (tm->nodes);
- }));
- /* *INDENT-ON* */
+ foreach_vlib_main ()
+ {
+ vlib_trace_main_t *tm;
+
+ tm = &this_vlib_main->trace_main;
+ tm->filter_node_index = node_index;
+ tm->filter_flag = flag;
+ tm->filter_count = count;
+
+ /*
+ * Clear the trace limits to stop any in-progress tracing
+ * Prevents runaway trace allocations when the filter changes
+ * (or is removed)
+ */
+ vec_free (tm->nodes);
+ }
}