fd-io-styleify pass

Change-Id: If2d57a213fc2fec996db26df332910c3d2105f97
Signed-off-by: Dave Barach <dave@barachs.net>
This commit is contained in:
Dave Barach
2016-07-08 08:13:45 -04:00
committed by Damjan Marion
parent 0557a91ca7
commit 9b8ffd99fb
65 changed files with 9372 additions and 7765 deletions

View File

@ -0,0 +1,45 @@
#!/usr/bin/emacs --script
(fset 'fix-foreach
[?\C-u ?\C-s ?_ ?f ?o ?r ?e ?a ?c ?h ? ?* ?\( ?\C-a ?\C-o tab ?/ ?* ? ?* ?I ?N ?D ?E ?N ?T ?- ?O ?F ?F ?* ? ?* ?/ ?\C-u ?\C-s ?\C-s ?\C-b escape ?\C-f ?\C-e ?\C-j ?/ ?* ? ?* ?I ?N ?D ?E ?N ?T ?- ?O ?N ?* ? ?* ?/])
(fset 'fix-cli-command
[?\C-s ?C ?L ?I ?_ ?C ?O ?M ?M ?A ?N ?D ?\C-a ?\C-o ?/ ?* ? ?* ?I ?N ?D ?E ?N ?T ?- ?O ?F ?F ?* ? ?* ?/ ?\C-s ?\} ?\C-e ?\C-j ?/ ?* ? ?I ?N ?D ?E ?N backspace backspace backspace backspace backspace ?* ?I ?N ?D ?E ?N ?T ?- ?O ?N ?* ? ?* ?/])
(fset 'fix-node
[?\C-s ?R ?E ?G ?I ?S ?T ?E ?R ?_ ?N ?O ?D ?E ?\C-a ?\C-o ?/ ?* ? ?* ?I ?N ?D ?E ?N ?T ?- ?O ?F ?F ?* ? ?* ?/ ?\C-a ?\C-n ?\C-s ?\{ ?\C-b escape ?\C-f ?\C-e ?\C-j ?/ ?* ?\S- ?* ?I ?N ?D ?E ?N ?T ?- ?O ?N ?* ? ?* ?/])
(fset 'fix-elog-type
[?\C-s ?E ?L ?O ?G ?_ ?T ?Y ?P ?E ?_ ?D ?E ?C ?L ?A ?R ?E ?\C-a ?\C-o tab ?/ ?* ? ?* ?I ?N ?D ?E ?N ?T ?- ?O ?F ?F ?* ? ?* ?/ ?\C-a ?\C-n ?\C-n tab escape ?\C-f ?\C-e ?\C-j tab ?/ ?* ? ?* ?I ?N ?D ?E ?N ?T ?- ?O ?N ?* ? ?* ?/ ?\C-a ?\C-n])
;; insert style boilerplate
(defun insert-style-boilerplate () (interactive)
(save-excursion (goto-char (point-max))
(insert "
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style \"gnu\")
* End:
*/")))
;; Driver routine which runs the set of keyboard macros
;; defined above, as well as the bottom boilerplate lisp fn.
(defun fd-io-styleify () (interactive)
(save-excursion (goto-char (point-min))
(ignore-errors (execute-kbd-macro 'fix-foreach 0)))
(save-excursion (goto-char (point-min))
(ignore-errors (execute-kbd-macro 'fix-cli-command 0)))
(save-excursion (goto-char (point-min))
(ignore-errors (execute-kbd-macro 'fix-node 0)))
(save-excursion (goto-char (point-min))
(ignore-errors (execute-kbd-macro 'fix-elog-type 0)))
(insert-style-boilerplate))
;;(setq index 0)
;;(while (elt argv index)
;; (message "Processing argv %d is %s" index (elt argv index))
;; (find-file (elt argv index))
;; (fd-io-styleify)
;; (setq index (1+ index)))
;; (save-buffers-kill-emacs)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -40,13 +40,13 @@
#ifndef included_vlib_buffer_node_h
#define included_vlib_buffer_node_h
/** \file
/** \file
vlib buffer/node functions
*/
/** \brief Finish enqueueing two buffers forward in the graph.
Standard dual loop boilerplate element. This is a MACRO,
with MULTIPLE SIDE EFFECTS. In the ideal case,
with MULTIPLE SIDE EFFECTS. In the ideal case,
<code>next_index == next0 == next1</code>,
which means that the speculative enqueue at the top of the dual loop
has correctly dealt with both packets. In that case, the macro does
@ -146,20 +146,20 @@ generic_buffer_node_inline (vlib_main_t * vm,
vlib_node_runtime_t * node,
vlib_frame_t * frame,
uword sizeof_trace,
void * opaque1,
void *opaque1,
uword opaque2,
void (* two_buffers) (vlib_main_t * vm,
void * opaque1,
uword opaque2,
vlib_buffer_t * b0, vlib_buffer_t * b1,
u32 * next0, u32 * next1),
void (* one_buffer) (vlib_main_t * vm,
void * opaque1,
void (*two_buffers) (vlib_main_t * vm,
void *opaque1,
uword opaque2,
vlib_buffer_t * b0,
u32 * next0))
vlib_buffer_t * b1,
u32 * next0, u32 * next1),
void (*one_buffer) (vlib_main_t * vm,
void *opaque1, uword opaque2,
vlib_buffer_t * b0,
u32 * next0))
{
u32 n_left_from, * from, * to_next;
u32 n_left_from, *from, *to_next;
u32 next_index;
from = vlib_frame_vector_args (frame);
@ -174,18 +174,17 @@ generic_buffer_node_inline (vlib_main_t * vm,
{
u32 n_left_to_next;
vlib_get_next_frame (vm, node, next_index,
to_next, n_left_to_next);
vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
while (n_left_from >= 4 && n_left_to_next >= 2)
{
vlib_buffer_t * p0, * p1;
vlib_buffer_t *p0, *p1;
u32 pi0, next0;
u32 pi1, next1;
/* Prefetch next iteration. */
{
vlib_buffer_t * p2, * p3;
vlib_buffer_t *p2, *p3;
p2 = vlib_get_buffer (vm, from[2]);
p3 = vlib_get_buffer (vm, from[3]);
@ -213,10 +212,10 @@ generic_buffer_node_inline (vlib_main_t * vm,
to_next, n_left_to_next,
pi0, pi1, next0, next1);
}
while (n_left_from > 0 && n_left_to_next > 0)
{
vlib_buffer_t * p0;
vlib_buffer_t *p0;
u32 pi0, next0;
pi0 = from[0];
@ -242,3 +241,11 @@ generic_buffer_node_inline (vlib_main_t * vm,
}
#endif /* included_vlib_buffer_node_h */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

File diff suppressed because it is too large Load Diff

View File

@ -44,58 +44,62 @@
struct vlib_cli_command_t;
typedef struct {
typedef struct
{
u32 min_char;
/* Indexed by name[position] - min_char. */
uword ** bitmaps;
uword **bitmaps;
} vlib_cli_parse_position_t;
typedef struct {
u8 * name;
typedef struct
{
u8 *name;
u32 index;
} vlib_cli_sub_command_t;
typedef struct {
u8 * name;
typedef struct
{
u8 *name;
u32 rule_index;
u32 command_index;
} vlib_cli_sub_rule_t;
typedef struct {
char * name;
char * short_help;
char * long_help;
typedef struct
{
char *name;
char *short_help;
char *long_help;
/* Number of bytes in parsed data. Zero for vector. */
uword data_size;
unformat_function_t * unformat_function;
unformat_function_t *unformat_function;
/* Opaque for unformat function. */
uword unformat_function_arg[2];
} vlib_cli_parse_rule_t;
/* CLI command callback function. */
typedef clib_error_t * (vlib_cli_command_function_t)
typedef clib_error_t *(vlib_cli_command_function_t)
(struct vlib_main_t * vm,
unformat_input_t * input,
struct vlib_cli_command_t * cmd);
unformat_input_t * input, struct vlib_cli_command_t * cmd);
typedef struct vlib_cli_command_t {
typedef struct vlib_cli_command_t
{
/* Command path (e.g. "show something").
Spaces delimit elements of path. */
char * path;
char *path;
/* Short/long help strings. */
char * short_help;
char * long_help;
char *short_help;
char *long_help;
/* Callback function. */
vlib_cli_command_function_t * function;
vlib_cli_command_function_t *function;
/* Opaque. */
uword function_arg;
@ -104,44 +108,44 @@ typedef struct vlib_cli_command_t {
uword is_mp_safe;
/* Sub commands for this command. */
vlib_cli_sub_command_t * sub_commands;
vlib_cli_sub_command_t *sub_commands;
/* Hash table mapping name (e.g. last path element) to sub command index. */
uword * sub_command_index_by_name;
uword *sub_command_index_by_name;
/* bitmap[p][c][i] says whether sub-command i has character
c in position p. */
vlib_cli_parse_position_t * sub_command_positions;
vlib_cli_parse_position_t *sub_command_positions;
/* Hash table mapping name (e.g. last path element) to sub rule index. */
uword * sub_rule_index_by_name;
uword *sub_rule_index_by_name;
/* Vector of possible parse rules for this path. */
vlib_cli_sub_rule_t * sub_rules;
vlib_cli_sub_rule_t *sub_rules;
/* List of CLI commands, built by constructors */
struct vlib_cli_command_t * next_cli_command;
struct vlib_cli_command_t *next_cli_command;
} vlib_cli_command_t;
typedef void (vlib_cli_output_function_t) (uword arg,
u8 * buffer,
uword buffer_bytes);
typedef struct {
u8 * buffer, uword buffer_bytes);
typedef struct
{
/* Vector of all known commands. */
vlib_cli_command_t * commands;
vlib_cli_command_t *commands;
/* Hash table mapping normalized path to index into all_commands. */
uword * command_index_by_path;
uword *command_index_by_path;
/* Vector of all known parse rules. */
vlib_cli_parse_rule_t * parse_rules;
vlib_cli_parse_rule_t *parse_rules;
/* Hash table mapping parse rule name to index into parse_rule vector. */
uword * parse_rule_index_by_name;
uword *parse_rule_index_by_name;
/* Data parsed for rules. */
void ** parse_rule_data;
void **parse_rule_data;
/* registration list added by constructors */
vlib_cli_command_t *cli_command_registrations;
@ -158,26 +162,31 @@ static void __vlib_cli_command_registration_##x (void) \
x.next_cli_command = cm->cli_command_registrations; \
cm->cli_command_registrations = &x; \
} \
__VA_ARGS__ vlib_cli_command_t x
__VA_ARGS__ vlib_cli_command_t x
#define VLIB_CLI_PARSE_RULE(x) \
vlib_cli_parse_rule_t x
vlib_cli_parse_rule_t x
/* Output to current CLI connection. */
void vlib_cli_output (struct vlib_main_t * vm, char * fmt, ...);
void vlib_cli_output (struct vlib_main_t *vm, char *fmt, ...);
/* Process CLI input. */
void vlib_cli_input (struct vlib_main_t * vm,
void vlib_cli_input (struct vlib_main_t *vm,
unformat_input_t * input,
vlib_cli_output_function_t * function,
uword function_arg);
clib_error_t * vlib_cli_register (struct vlib_main_t * vm,
vlib_cli_command_t * c);
clib_error_t * vlib_cli_register_parse_rule (struct vlib_main_t * vm,
vlib_cli_parse_rule_t * c);
clib_error_t *vlib_cli_register (struct vlib_main_t *vm,
vlib_cli_command_t * c);
clib_error_t *vlib_cli_register_parse_rule (struct vlib_main_t *vm,
vlib_cli_parse_rule_t * c);
uword unformat_vlib_cli_sub_input (unformat_input_t * i, va_list * args);
#endif /* included_vlib_cli_h */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -43,8 +43,16 @@
always_inline void *
vlib_cli_get_parse_rule_result (vlib_main_t * vm, uword index)
{
vlib_cli_main_t * cm = &vm->cli_main;
vlib_cli_main_t *cm = &vm->cli_main;
return vec_elt (cm->parse_rule_data, index);
}
#endif /* included_vlib_cli_funcs_h */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -39,20 +39,21 @@
#include <vlib/vlib.h>
void vlib_clear_simple_counters (vlib_simple_counter_main_t * cm)
void
vlib_clear_simple_counters (vlib_simple_counter_main_t * cm)
{
uword i, j;
u16 * my_minis;
u16 *my_minis;
for (i = 0; i < vec_len(cm->minis); i++)
for (i = 0; i < vec_len (cm->minis); i++)
{
my_minis = cm->minis[i];
for (j = 0; j < vec_len (my_minis); j++)
{
cm->maxi[j] += my_minis[j];
my_minis[j] = 0;
}
{
cm->maxi[j] += my_minis[j];
my_minis[j] = 0;
}
}
j = vec_len (cm->maxi);
@ -62,22 +63,23 @@ void vlib_clear_simple_counters (vlib_simple_counter_main_t * cm)
cm->value_at_last_clear[i] = cm->maxi[i];
}
void vlib_clear_combined_counters (vlib_combined_counter_main_t * cm)
void
vlib_clear_combined_counters (vlib_combined_counter_main_t * cm)
{
uword i, j;
vlib_mini_counter_t * my_minis;
vlib_mini_counter_t *my_minis;
for (i = 0; i < vec_len(cm->minis); i++)
for (i = 0; i < vec_len (cm->minis); i++)
{
my_minis = cm->minis[i];
for (j = 0; j < vec_len (my_minis); j++)
{
cm->maxi[j].packets += my_minis[j].packets;
cm->maxi[j].bytes += my_minis[j].bytes;
my_minis[j].packets = 0;
my_minis[j].bytes = 0;
}
{
cm->maxi[j].packets += my_minis[j].packets;
cm->maxi[j].bytes += my_minis[j].bytes;
my_minis[j].packets = 0;
my_minis[j].bytes = 0;
}
}
j = vec_len (cm->maxi);
@ -86,15 +88,16 @@ void vlib_clear_combined_counters (vlib_combined_counter_main_t * cm)
for (i = 0; i < j; i++)
{
vlib_counter_t * c = vec_elt_at_index (cm->value_at_last_clear, i);
vlib_counter_t *c = vec_elt_at_index (cm->value_at_last_clear, i);
c[0] = cm->maxi[i];
}
}
void vlib_validate_simple_counter (vlib_simple_counter_main_t *cm, u32 index)
void
vlib_validate_simple_counter (vlib_simple_counter_main_t * cm, u32 index)
{
vlib_thread_main_t * tm = vlib_get_thread_main();
vlib_thread_main_t *tm = vlib_get_thread_main ();
int i;
vec_validate (cm->minis, tm->n_vlib_mains - 1);
@ -103,33 +106,46 @@ void vlib_validate_simple_counter (vlib_simple_counter_main_t *cm, u32 index)
vec_validate_aligned (cm->maxi, index, CLIB_CACHE_LINE_BYTES);
}
void vlib_validate_combined_counter (vlib_combined_counter_main_t *cm, u32 index)
void
vlib_validate_combined_counter (vlib_combined_counter_main_t * cm, u32 index)
{
vlib_thread_main_t * tm = vlib_get_thread_main();
vlib_thread_main_t *tm = vlib_get_thread_main ();
int i;
vec_validate (cm->minis, tm->n_vlib_mains - 1);
for (i = 0; i < tm->n_vlib_mains ; i++)
for (i = 0; i < tm->n_vlib_mains; i++)
vec_validate_aligned (cm->minis[i], index, CLIB_CACHE_LINE_BYTES);
vec_validate_aligned (cm->maxi, index, CLIB_CACHE_LINE_BYTES);
}
void serialize_vlib_simple_counter_main (serialize_main_t * m, va_list * va)
void
serialize_vlib_simple_counter_main (serialize_main_t * m, va_list * va)
{
clib_warning ("unimplemented");
}
void unserialize_vlib_simple_counter_main (serialize_main_t * m, va_list * va)
void
unserialize_vlib_simple_counter_main (serialize_main_t * m, va_list * va)
{
clib_warning ("unimplemented");
}
void serialize_vlib_combined_counter_main (serialize_main_t * m, va_list * va)
void
serialize_vlib_combined_counter_main (serialize_main_t * m, va_list * va)
{
clib_warning ("unimplemented");
}
void unserialize_vlib_combined_counter_main (serialize_main_t * m, va_list * va)
void
unserialize_vlib_combined_counter_main (serialize_main_t * m, va_list * va)
{
clib_warning ("unimplemented");
}
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -40,40 +40,39 @@
#ifndef included_vlib_counter_h
#define included_vlib_counter_h
/*
/*
* Annoyingly enough, counters are created long before
* the CPU configuration is available, so we have to
* preallocate the mini-counter per-cpu vectors
*/
typedef struct {
typedef struct
{
/* Compact counters that (rarely) can overflow. */
u16 ** minis;
u16 **minis;
/* Counters to hold overflow. */
u64 * maxi;
u64 *maxi;
/* Counter values as of last clear. */
u64 * value_at_last_clear;
u64 *value_at_last_clear;
/* Values as of last serialize. */
u64 * value_at_last_serialize;
u64 *value_at_last_serialize;
/* Last counter index serialized incrementally. */
u32 last_incremental_serialize_index;
/* Counter name. */
char * name;
char *name;
} vlib_simple_counter_main_t;
always_inline void
vlib_increment_simple_counter (vlib_simple_counter_main_t * cm,
u32 cpu_index,
u32 index,
u32 increment)
u32 cpu_index, u32 index, u32 increment)
{
u16 * my_minis;
u16 * mini;
u16 *my_minis;
u16 *mini;
u32 old, new;
my_minis = cm->minis[cpu_index];
@ -100,7 +99,7 @@ vlib_get_simple_counter (vlib_simple_counter_main_t * cm, u32 index)
v = 0;
for (i = 0; i < vec_len(cm->minis); i++)
for (i = 0; i < vec_len (cm->minis); i++)
{
my_minis = cm->minis[i];
mini = vec_elt_at_index (my_minis, index);
@ -121,12 +120,12 @@ vlib_get_simple_counter (vlib_simple_counter_main_t * cm, u32 index)
always_inline void
vlib_zero_simple_counter (vlib_simple_counter_main_t * cm, u32 index)
{
u16 * my_minis;
u16 *my_minis;
int i;
ASSERT (index < vec_len (cm->maxi));
for (i = 0; i < vec_len(cm->minis); i++)
for (i = 0; i < vec_len (cm->minis); i++)
{
my_minis = cm->minis[i];
my_minis[index] = 0;
@ -140,7 +139,8 @@ vlib_zero_simple_counter (vlib_simple_counter_main_t * cm, u32 index)
/* Combined counters hold both packets and byte differences. */
/* Maxi-packet/byte counter. */
typedef struct {
typedef struct
{
u64 packets, bytes;
} vlib_counter_t;
@ -162,10 +162,13 @@ vlib_counter_sub (vlib_counter_t * a, vlib_counter_t * b)
always_inline void
vlib_counter_zero (vlib_counter_t * a)
{ a->packets = a->bytes = 0; }
{
a->packets = a->bytes = 0;
}
/* Micro-counter: 16 bits of packets and 16 bits of byte difference. */
typedef struct {
typedef struct
{
/* Packet count. */
u16 packets;
@ -173,21 +176,22 @@ typedef struct {
i16 bytes;
} vlib_mini_counter_t;
typedef struct {
typedef struct
{
/* Compact counters that (rarely) can overflow. */
vlib_mini_counter_t ** minis;
vlib_mini_counter_t **minis;
/* Counters to hold overflow. */
vlib_counter_t * maxi;
vlib_counter_t *maxi;
/* Debug counters for testing. */
vlib_counter_t * debug;
vlib_counter_t *debug;
/* Counter values as of last clear. */
vlib_counter_t * value_at_last_clear;
vlib_counter_t *value_at_last_clear;
/* Counter values as of last serialize. */
vlib_counter_t * value_at_last_serialize;
vlib_counter_t *value_at_last_serialize;
/* Last counter index serialized incrementally. */
u32 last_incremental_serialize_index;
@ -199,7 +203,7 @@ typedef struct {
u32 ave_packets, ave_bytes;
/* Counter name. */
char * name;
char *name;
} vlib_combined_counter_main_t;
@ -208,12 +212,11 @@ void vlib_clear_combined_counters (vlib_combined_counter_main_t * cm);
always_inline void
vlib_increment_combined_counter (vlib_combined_counter_main_t * cm,
u32 cpu_index,
u32 cpu_index,
u32 index,
u32 packet_increment,
u32 byte_increment)
u32 packet_increment, u32 byte_increment)
{
vlib_mini_counter_t * my_minis, * mini;
vlib_mini_counter_t *my_minis, *mini;
u32 old_packets, new_packets;
i32 old_bytes, new_bytes;
@ -233,7 +236,7 @@ vlib_increment_combined_counter (vlib_combined_counter_main_t * cm,
/* Bytes always overflow before packets.. */
if (PREDICT_FALSE (mini->bytes != new_bytes))
{
vlib_counter_t * maxi = vec_elt_at_index (cm->maxi, index);
vlib_counter_t *maxi = vec_elt_at_index (cm->maxi, index);
__sync_fetch_and_add (&maxi->packets, new_packets);
__sync_fetch_and_add (&maxi->bytes, new_bytes);
@ -246,17 +249,16 @@ vlib_increment_combined_counter (vlib_combined_counter_main_t * cm,
/* This is never done in the speed path */
static inline void
vlib_get_combined_counter (vlib_combined_counter_main_t * cm,
u32 index,
vlib_counter_t * result)
u32 index, vlib_counter_t * result)
{
vlib_mini_counter_t * my_minis, * mini;
vlib_counter_t * maxi;
vlib_mini_counter_t *my_minis, *mini;
vlib_counter_t *maxi;
int i;
result->packets = 0;
result->bytes = 0;
for (i = 0; i < vec_len(cm->minis); i++)
for (i = 0; i < vec_len (cm->minis); i++)
{
my_minis = cm->minis[i];
@ -274,13 +276,12 @@ vlib_get_combined_counter (vlib_combined_counter_main_t * cm,
}
always_inline void
vlib_zero_combined_counter (vlib_combined_counter_main_t * cm,
u32 index)
vlib_zero_combined_counter (vlib_combined_counter_main_t * cm, u32 index)
{
vlib_mini_counter_t * mini, * my_minis;
vlib_mini_counter_t *mini, *my_minis;
int i;
for (i = 0; i < vec_len(cm->minis); i++)
for (i = 0; i < vec_len (cm->minis); i++)
{
my_minis = cm->minis[i];
@ -294,13 +295,25 @@ vlib_zero_combined_counter (vlib_combined_counter_main_t * cm,
vlib_counter_zero (&cm->value_at_last_clear[index]);
}
void vlib_validate_simple_counter (vlib_simple_counter_main_t *cm, u32 index);
void vlib_validate_combined_counter (vlib_combined_counter_main_t *cm, u32 index);
void vlib_validate_simple_counter (vlib_simple_counter_main_t * cm,
u32 index);
void vlib_validate_combined_counter (vlib_combined_counter_main_t * cm,
u32 index);
/* Number of simple/combined counters allocated. */
#define vlib_counter_len(cm) vec_len((cm)->maxi)
serialize_function_t serialize_vlib_simple_counter_main, unserialize_vlib_simple_counter_main;
serialize_function_t serialize_vlib_combined_counter_main, unserialize_vlib_combined_counter_main;
serialize_function_t serialize_vlib_simple_counter_main,
unserialize_vlib_simple_counter_main;
serialize_function_t serialize_vlib_combined_counter_main,
unserialize_vlib_combined_counter_main;
#endif /* included_vlib_counter_h */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -41,7 +41,8 @@
#define included_vlib_defs_h
/* Receive or transmit. */
typedef enum {
typedef enum
{
VLIB_RX,
VLIB_TX,
VLIB_N_RX_TX = 2, /* Used to size arrays. */
@ -50,21 +51,32 @@ typedef enum {
#define vlib_foreach_rx_tx(v) for (v = 0; v < VLIB_N_RX_TX; v++)
/* Read/write. */
typedef enum {
typedef enum
{
VLIB_READ,
VLIB_WRITE,
} vlib_read_or_write_t;
/* Up/down. */
typedef enum {
typedef enum
{
VLIB_DOWN = 0,
VLIB_UP = 1,
} vlib_up_or_down_t;
/* Enable/disable. */
typedef enum {
typedef enum
{
VLIB_DISABLE = 0,
VLIB_ENABLE = 1,
} vlib_enable_or_disable_t;
#endif /* included_vlib_defs_h */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

File diff suppressed because it is too large Load Diff

View File

@ -16,14 +16,17 @@
#include <vlib/vlib.h>
#include <vppinfra/elog.h>
static inline void elog_four_int_sample (u32 *data)
static inline void
elog_four_int_sample (u32 * data)
{
ELOG_TYPE_DECLARE(e) =
{
.format = "four int: first %d second %d third %d fourth %d",
.format_args = "i4i4i4i4",
};
struct { u32 data[4];} * ed;
ELOG_TYPE_DECLARE (e) =
{
.format = "four int: first %d second %d third %d fourth %d",.format_args =
"i4i4i4i4",};
struct
{
u32 data[4];
} *ed;
ed = ELOG_DATA (&vlib_global_main.elog_main, e);
ed->data[0] = data[0];
ed->data[1] = data[1];
@ -31,15 +34,19 @@ static inline void elog_four_int_sample (u32 *data)
ed->data[3] = data[3];
}
static inline void elog_four_int_track_sample (u32 *data)
static inline void
elog_four_int_track_sample (u32 * data)
{
ELOG_TYPE_DECLARE(e) =
{
.format = "four_int_track: first %d second %d third %d fourth %d",
.format_args = "i4i4i4i4",
};
struct { u32 data[4];} * ed;
ELOG_TRACK(sample_track);
ELOG_TYPE_DECLARE (e) =
{
.format =
"four_int_track: first %d second %d third %d fourth %d",.format_args =
"i4i4i4i4",};
struct
{
u32 data[4];
} *ed;
ELOG_TRACK (sample_track);
ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, e, sample_track);
ed->data[0] = data[0];
ed->data[1] = data[1];
@ -47,39 +54,36 @@ static inline void elog_four_int_track_sample (u32 *data)
ed->data[3] = data[3];
}
static inline void elog_enum_sample (u8 which)
static inline void
elog_enum_sample (u8 which)
{
ELOG_TYPE_DECLARE (e) =
ELOG_TYPE_DECLARE (e) =
{
.format = "my enum: %s",.format_args = "t1",.n_enum_strings =
2,.enum_strings =
{
.format = "my enum: %s",
.format_args = "t1",
.n_enum_strings = 2,
.enum_strings =
{
"string 1",
"string 2",
},
};
struct { u8 which;} * ed;
"string 1", "string 2",},};
struct
{
u8 which;
} *ed;
ed = ELOG_DATA (&vlib_global_main.elog_main, e);
ed->which = which;
}
static inline void elog_one_datum_sample (u32 data)
static inline void
elog_one_datum_sample (u32 data)
{
ELOG_TYPE_DECLARE (e) =
{
.format = "one datum: %d",
.format_args = "i4",
};
ELOG_TYPE_DECLARE (e) =
{
.format = "one datum: %d",.format_args = "i4",};
elog (&vlib_global_main.elog_main, &e, data);
}
static clib_error_t *
test_elog_command_fn (vlib_main_t * vm,
unformat_input_t * input,
vlib_cli_command_t * cmd)
unformat_input_t * input, vlib_cli_command_t * cmd)
{
int i;
u32 samples[4];
@ -87,9 +91,9 @@ test_elog_command_fn (vlib_main_t * vm,
for (i = 0; i < 10; i++)
{
samples[0] = i;
samples[1] = i+1;
samples[2] = i+2;
samples[3] = i+3;
samples[1] = i + 1;
samples[2] = i + 2;
samples[3] = i + 3;
elog_four_int_sample (samples);
elog_four_int_track_sample (samples);
@ -101,8 +105,18 @@ test_elog_command_fn (vlib_main_t * vm,
return 0;
}
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (test_elog_command, static) = {
.path = "test elog sample",
.short_help = "test elog sample",
.function = test_elog_command_fn,
};
/* *INDENT-ON* */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -47,10 +47,9 @@ vlib_error_drop_buffers (vlib_main_t * vm,
u32 next_buffer_stride,
u32 n_buffers,
u32 next_index,
u32 drop_error_node,
u32 drop_error_code)
u32 drop_error_node, u32 drop_error_code)
{
u32 n_left_this_frame, n_buffers_left, * args, n_args_left;
u32 n_left_this_frame, n_buffers_left, *args, n_args_left;
vlib_error_t drop_error;
drop_error = vlib_error_set (drop_error_node, drop_error_code);
@ -67,7 +66,7 @@ vlib_error_drop_buffers (vlib_main_t * vm,
while (n_left_this_frame >= 4)
{
u32 bi0, bi1, bi2, bi3;
vlib_buffer_t * b0, * b1, * b2, * b3;
vlib_buffer_t *b0, *b1, *b2, *b3;
args[0] = bi0 = buffers[0];
args[1] = bi1 = buffers[1];
@ -92,7 +91,7 @@ vlib_error_drop_buffers (vlib_main_t * vm,
while (n_left_this_frame >= 1)
{
u32 bi0;
vlib_buffer_t * b0;
vlib_buffer_t *b0;
args[0] = bi0 = buffers[0];
@ -113,22 +112,21 @@ vlib_error_drop_buffers (vlib_main_t * vm,
/* Convenience node to drop a vector of buffers with a "misc error". */
static uword
misc_drop_buffers (vlib_main_t * vm,
vlib_node_runtime_t * node,
vlib_frame_t * frame)
vlib_node_runtime_t * node, vlib_frame_t * frame)
{
return vlib_error_drop_buffers (vm, node,
vlib_frame_args (frame),
/* buffer stride */ 1,
frame->n_vectors,
/* next */ 0,
node->node_index,
/* error */ 0);
return vlib_error_drop_buffers (vm, node, vlib_frame_args (frame),
/* buffer stride */ 1,
frame->n_vectors,
/* next */ 0,
node->node_index,
/* error */ 0);
}
static char * misc_drop_buffers_error_strings[] = {
[0] = "misc. errors",
static char *misc_drop_buffers_error_strings[] = {
[0] = "misc. errors",
};
/* *INDENT-OFF* */
VLIB_REGISTER_NODE (misc_drop_buffers_node,static) = {
.function = misc_drop_buffers,
.name = "misc-drop-buffers",
@ -140,18 +138,18 @@ VLIB_REGISTER_NODE (misc_drop_buffers_node,static) = {
},
.error_strings = misc_drop_buffers_error_strings,
};
/* *INDENT-ON* */
/* Reserves given number of error codes for given node. */
void vlib_register_errors (vlib_main_t * vm,
u32 node_index,
u32 n_errors,
char * error_strings[])
void
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_t * n = vlib_get_node (vm, node_index);
vlib_error_main_t *em = &vm->error_main;
vlib_node_t *n = vlib_get_node (vm, node_index);
uword l;
ASSERT(os_get_cpu_number() == 0);
ASSERT (os_get_cpu_number () == 0);
/* Free up any previous error strings. */
if (n->n_errors > 0)
@ -164,14 +162,12 @@ void vlib_register_errors (vlib_main_t * vm,
return;
n->error_heap_index =
heap_alloc (em->error_strings_heap, n_errors,
n->error_heap_handle);
heap_alloc (em->error_strings_heap, n_errors, n->error_heap_handle);
l = vec_len (em->error_strings_heap);
clib_memcpy (vec_elt_at_index (em->error_strings_heap, n->error_heap_index),
error_strings,
n_errors * sizeof (error_strings[0]));
error_strings, n_errors * sizeof (error_strings[0]));
/* Allocate a counter/elog type for each error. */
vec_validate (em->counters, l - 1);
@ -180,12 +176,11 @@ void vlib_register_errors (vlib_main_t * vm,
/* Zero counters for re-registrations of errors. */
if (n->error_heap_index + n_errors <= vec_len (em->counters_last_clear))
clib_memcpy (em->counters + n->error_heap_index,
em->counters_last_clear + n->error_heap_index,
n_errors * sizeof (em->counters[0]));
em->counters_last_clear + n->error_heap_index,
n_errors * sizeof (em->counters[0]));
else
memset (em->counters + n->error_heap_index,
0,
n_errors * sizeof (em->counters[0]));
0, n_errors * sizeof (em->counters[0]));
{
elog_event_type_t t;
@ -195,8 +190,7 @@ void vlib_register_errors (vlib_main_t * vm,
for (i = 0; i < n_errors; i++)
{
t.format = (char *) format (0, "%v %s: %%d",
n->name,
error_strings[i]);
n->name, error_strings[i]);
vm->error_elog_event_types[n->error_heap_index + i] = t;
}
}
@ -204,35 +198,37 @@ void vlib_register_errors (vlib_main_t * vm,
static clib_error_t *
show_errors (vlib_main_t * vm,
unformat_input_t * input,
vlib_cli_command_t * cmd)
unformat_input_t * input, vlib_cli_command_t * cmd)
{
vlib_error_main_t * em = &vm->error_main;
vlib_node_t * n;
vlib_error_main_t *em = &vm->error_main;
vlib_node_t *n;
u32 code, i, ni;
u64 c;
int index = 0;
int verbose = 0;
u64 * sums = 0;
u64 *sums = 0;
if (unformat (input, "verbose %d", &verbose))
;
else if (unformat (input, "verbose"))
verbose = 1;
vec_validate(sums, vec_len(em->counters));
vec_validate (sums, vec_len (em->counters));
if (verbose)
vlib_cli_output (vm, "%=10s%=40s%=20s%=6s", "Count", "Node", "Reason",
"Index");
vlib_cli_output (vm, "%=10s%=40s%=20s%=6s", "Count", "Node", "Reason",
"Index");
else
vlib_cli_output (vm, "%=10s%=40s%=6s", "Count", "Node", "Reason");
/* *INDENT-OFF* */
foreach_vlib_main(({
em = &this_vlib_main->error_main;
if (verbose)
vlib_cli_output(vm, "Thread %u (%v):", index, vlib_worker_threads[index].name);
vlib_cli_output(vm, "Thread %u (%v):", index,
vlib_worker_threads[index].name);
for (ni = 0; ni < vec_len (this_vlib_main->node_main.nodes); ni++)
{
@ -249,18 +245,19 @@ show_errors (vlib_main_t * vm,
continue;
if (verbose)
vlib_cli_output (vm, "%10Ld%=40v%=20s%=6d", c, n->name,
vlib_cli_output (vm, "%10Ld%=40v%=20s%=6d", c, n->name,
em->error_strings_heap[i], i);
else
vlib_cli_output (vm, "%10d%=40v%s", c, n->name,
vlib_cli_output (vm, "%10d%=40v%s", c, n->name,
em->error_strings_heap[i]);
}
}
index++;
}));
/* *INDENT-ON* */
if (verbose)
vlib_cli_output(vm, "Total:");
vlib_cli_output (vm, "Total:");
for (ni = 0; ni < vec_len (vm->node_main.nodes); ni++)
{
@ -269,56 +266,73 @@ show_errors (vlib_main_t * vm,
{
i = n->error_heap_index + code;
if (sums[i])
{
if (verbose)
vlib_cli_output (vm, "%10Ld%=40v%=20s%=10d", sums[i], n->name,
em->error_strings_heap[i], i);
}
{
if (verbose)
vlib_cli_output (vm, "%10Ld%=40v%=20s%=10d", sums[i], n->name,
em->error_strings_heap[i], i);
}
}
}
vec_free(sums);
vec_free (sums);
return 0;
}
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (cli_show_errors, static) = {
.path = "show errors",
.short_help = "Show error counts",
.function = show_errors,
};
/* *INDENT-ON* */
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (cli_show_node_counters, static) = {
.path = "show node counters",
.short_help = "Show node counters",
.function = show_errors,
};
/* *INDENT-ON* */
static clib_error_t *
clear_error_counters (vlib_main_t * vm,
unformat_input_t * input,
vlib_cli_command_t * cmd)
unformat_input_t * input, vlib_cli_command_t * cmd)
{
vlib_error_main_t * em;
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* */
return 0;
}
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (cli_clear_error_counters, static) = {
.path = "clear errors",
.short_help = "Clear error counters",
.function = clear_error_counters,
};
/* *INDENT-ON* */
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (cli_clear_node_counters, static) = {
.path = "clear node counters",
.short_help = "Clear node counters",
.function = clear_error_counters,
};
/* *INDENT-ON* */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -45,11 +45,15 @@ typedef u32 vlib_error_t;
always_inline u32
vlib_error_get_node (vlib_error_t e)
{ return e >> 12; }
{
return e >> 12;
}
always_inline u32
vlib_error_get_code (vlib_error_t e)
{ return e & 0xfff; }
{
return e & 0xfff;
}
always_inline vlib_error_t
vlib_error_set (u32 node_index, u32 code)
@ -68,22 +72,30 @@ vlib_error_set_code (vlib_error_t e, u32 code)
return e;
}
typedef struct {
typedef struct
{
/* Error counters. */
u64 * counters;
u64 *counters;
/* Counter values as of last counter clear. */
u64 * counters_last_clear;
u64 *counters_last_clear;
/* Error name strings in heap. Heap index
indexes counter vector. */
char ** error_strings_heap;
char **error_strings_heap;
} vlib_error_main_t;
/* Per node error registration. */
void vlib_register_errors (struct vlib_main_t * vm,
void vlib_register_errors (struct vlib_main_t *vm,
u32 node_index,
u32 n_errors,
char * error_strings[]);
u32 n_errors, char *error_strings[]);
#endif /* included_vlib_error_h */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -45,17 +45,18 @@
always_inline void
vlib_error_elog_count (vlib_main_t * vm, uword counter, uword increment)
{
elog_main_t * em = &vm->elog_main;
elog_main_t *em = &vm->elog_main;
if (VLIB_ELOG_MAIN_LOOP > 0 && increment > 0)
elog (em, vec_elt_at_index (vm->error_elog_event_types, counter), increment);
elog (em, vec_elt_at_index (vm->error_elog_event_types, counter),
increment);
}
always_inline void
vlib_error_count (vlib_main_t * vm, uword node_index,
uword counter, uword increment)
{
vlib_node_t * n = vlib_get_node (vm, node_index);
vlib_error_main_t * em = &vm->error_main;
vlib_node_t *n = vlib_get_node (vm, node_index);
vlib_error_main_t *em = &vm->error_main;
ASSERT (counter < n->n_errors);
counter += n->error_heap_index;
@ -74,7 +75,14 @@ vlib_error_drop_buffers (vlib_main_t * vm,
u32 next_buffer_stride,
u32 n_buffers,
u32 error_next_index,
u32 error_node,
u32 error_code);
u32 error_node, u32 error_code);
#endif /* included_vlib_error_funcs_h */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -39,32 +39,46 @@
#include <vlib/vlib.h>
u8 * format_vlib_rx_tx (u8 * s, va_list * args)
u8 *
format_vlib_rx_tx (u8 * s, va_list * args)
{
vlib_rx_or_tx_t r = va_arg (*args, vlib_rx_or_tx_t);
char * t;
char *t;
switch (r)
{
case VLIB_RX: t = "rx"; break;
case VLIB_TX: t = "tx"; break;
default: t = "INVALID"; break;
case VLIB_RX:
t = "rx";
break;
case VLIB_TX:
t = "tx";
break;
default:
t = "INVALID";
break;
}
vec_add (s, t, strlen (t));
return s;
}
u8 * format_vlib_read_write (u8 * s, va_list * args)
u8 *
format_vlib_read_write (u8 * s, va_list * args)
{
vlib_rx_or_tx_t r = va_arg (*args, vlib_rx_or_tx_t);
char * t;
char *t;
switch (r)
{
case VLIB_READ: t = "read"; break;
case VLIB_WRITE: t = "write"; break;
default: t = "INVALID"; break;
case VLIB_READ:
t = "read";
break;
case VLIB_WRITE:
t = "write";
break;
default:
t = "INVALID";
break;
}
vec_add (s, t, strlen (t));
@ -72,9 +86,10 @@ u8 * format_vlib_read_write (u8 * s, va_list * args)
}
/* Formats buffer data as printable ascii or as hex. */
u8 * format_vlib_buffer_data (u8 * s, va_list * args)
u8 *
format_vlib_buffer_data (u8 * s, va_list * args)
{
u8 * data = va_arg (*args, u8 *);
u8 *data = va_arg (*args, u8 *);
u32 n_data_bytes = va_arg (*args, u32);
u32 i, is_printable;
@ -87,7 +102,7 @@ u8 * format_vlib_buffer_data (u8 * s, va_list * args)
else if (c >= 0x7f)
is_printable = 0;
}
if (is_printable)
vec_add (s, data, n_data_bytes);
else
@ -97,9 +112,10 @@ u8 * format_vlib_buffer_data (u8 * s, va_list * args)
}
/* Enable/on => 1; disable/off => 0. */
uword unformat_vlib_enable_disable (unformat_input_t * input, va_list * args)
uword
unformat_vlib_enable_disable (unformat_input_t * input, va_list * args)
{
int * result = va_arg (*args, int *);
int *result = va_arg (*args, int *);
int enable;
if (unformat (input, "enable") || unformat (input, "on"))
@ -114,9 +130,10 @@ uword unformat_vlib_enable_disable (unformat_input_t * input, va_list * args)
}
/* rx/tx => VLIB_RX/VLIB_TX. */
uword unformat_vlib_rx_tx (unformat_input_t * input, va_list * args)
uword
unformat_vlib_rx_tx (unformat_input_t * input, va_list * args)
{
int * result = va_arg (*args, int *);
int *result = va_arg (*args, int *);
if (unformat (input, "rx"))
*result = VLIB_RX;
else if (unformat (input, "tx"))
@ -127,29 +144,29 @@ uword unformat_vlib_rx_tx (unformat_input_t * input, va_list * args)
}
/* Parse an int either %d or 0x%x. */
uword unformat_vlib_number (unformat_input_t * input, va_list * args)
uword
unformat_vlib_number (unformat_input_t * input, va_list * args)
{
int * result = va_arg (*args, int *);
int *result = va_arg (*args, int *);
return (unformat (input, "0x%x", result)
|| unformat (input, "%d", result));
return (unformat (input, "0x%x", result) || unformat (input, "%d", result));
}
/* Parse a-zA-Z0-9_ token and hash to value. */
uword unformat_vlib_number_by_name (unformat_input_t * input, va_list * args)
uword
unformat_vlib_number_by_name (unformat_input_t * input, va_list * args)
{
uword * hash = va_arg (*args, uword *);
int * result = va_arg (*args, int *);
uword * p;
u8 * token;
uword *hash = va_arg (*args, uword *);
int *result = va_arg (*args, int *);
uword *p;
u8 *token;
int i;
if (! unformat_user (input, unformat_token, "a-zA-Z0-9_", &token))
if (!unformat_user (input, unformat_token, "a-zA-Z0-9_", &token))
return 0;
/* Null terminate. */
if (vec_len (token) > 0 &&
token[vec_len (token) - 1] != 0)
if (vec_len (token) > 0 && token[vec_len (token) - 1] != 0)
vec_add1 (token, 0);
/* Check for exact match. */
@ -163,9 +180,17 @@ uword unformat_vlib_number_by_name (unformat_input_t * input, va_list * args)
token[i] = 'A' + token[i] - 'a';
p = hash_get_mem (hash, token);
done:
done:
vec_free (token);
if (p)
*result = p[0];
return p != 0;
}
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -41,11 +41,11 @@
#define included_vlib_format_h
/* Format vlib_rx_or_tx_t/vlib_read_or_write_t enum as string. */
u8 * format_vlib_rx_tx (u8 * s, va_list * args);
u8 * format_vlib_read_write (u8 * s, va_list * args);
u8 *format_vlib_rx_tx (u8 * s, va_list * args);
u8 *format_vlib_read_write (u8 * s, va_list * args);
/* Formats buffer data as printable ascii or as hex. */
u8 * format_vlib_buffer_data (u8 * s, va_list * args);
u8 *format_vlib_buffer_data (u8 * s, va_list * args);
/* Enable/on => 1; disable/off => 0. */
uword unformat_vlib_enable_disable (unformat_input_t * input, va_list * args);
@ -65,3 +65,11 @@ uword unformat_vlib_number (unformat_input_t * input, va_list * args);
#define FORMAT_VLIB_HEADER_NO_RECURSION (~0)
#endif /* included_vlib_format_h */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -22,16 +22,24 @@
always_inline vlib_main_t *
vlib_get_main (void)
{
vlib_main_t * vm;
vm = vlib_mains ? vlib_mains[os_get_cpu_number()] : &vlib_global_main;
ASSERT(vm);
vlib_main_t *vm;
vm = vlib_mains ? vlib_mains[os_get_cpu_number ()] : &vlib_global_main;
ASSERT (vm);
return vm;
}
always_inline vlib_thread_main_t *
vlib_get_thread_main()
vlib_get_thread_main ()
{
return &vlib_thread_main;
}
#endif /* included_vlib_global_funcs_h_ */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -19,7 +19,7 @@
static inline void
i2c_delay (i2c_bus_t * b, f64 timeout)
{
vlib_main_t * vm = vlib_get_main();
vlib_main_t *vm = vlib_get_main ();
vlib_time_wait (vm, timeout);
}
@ -31,7 +31,7 @@ i2c_wait_for_scl (i2c_bus_t * b)
while (t < b->hold_time)
{
int sda, scl;
i2c_delay(b, b->rise_fall_time);
i2c_delay (b, b->rise_fall_time);
b->get_bits (b, &scl, &sda);
if (scl)
@ -87,7 +87,7 @@ i2c_write_bit (i2c_bus_t * b, int sda)
}
static void
i2c_read_bit (i2c_bus_t * b, int * sda)
i2c_read_bit (i2c_bus_t * b, int *sda)
{
int scl;
@ -116,7 +116,7 @@ i2c_write_byte (i2c_bus_t * b, u8 data)
b->put_bits (b, 0, 1);
i2c_delay (b, b->rise_fall_time);
i2c_read_bit(b, &sda);
i2c_read_bit (b, &sda);
if (sda)
b->timeout = 1;
@ -171,35 +171,37 @@ vlib_i2c_xfer (i2c_bus_t * bus, i2c_msg_t * msgs)
int i;
vec_foreach (msg, msgs)
{
i2c_start (bus);
i2c_write_byte (bus, (msg->addr << 1) + (msg->flags == I2C_MSG_FLAG_READ));
{
i2c_start (bus);
i2c_write_byte (bus,
(msg->addr << 1) + (msg->flags == I2C_MSG_FLAG_READ));
if (msg->flags & I2C_MSG_FLAG_READ)
for (i=0; i< msg->len; i++)
{
i2c_read_byte (bus, &msg->buffer[i], /* ack */ i + 1 != msg->len);
if (bus->timeout)
goto done;
}
if (msg->flags & I2C_MSG_FLAG_READ)
for (i = 0; i < msg->len; i++)
{
i2c_read_byte (bus, &msg->buffer[i], /* ack */ i + 1 != msg->len);
if (bus->timeout)
goto done;
}
else
for (i=0; i< msg->len; i++)
{
i2c_write_byte (bus, msg->buffer[i]);
if (bus->timeout)
goto done;
}
}
else
for (i = 0; i < msg->len; i++)
{
i2c_write_byte (bus, msg->buffer[i]);
if (bus->timeout)
goto done;
}
}
done:
i2c_stop(bus);
i2c_stop (bus);
}
void
vlib_i2c_read_eeprom (i2c_bus_t * bus, u8 i2c_addr, u16 start_addr, u16 length, u8 * data)
vlib_i2c_read_eeprom (i2c_bus_t * bus, u8 i2c_addr, u16 start_addr,
u16 length, u8 * data)
{
i2c_msg_t * msg = 0;
i2c_msg_t *msg = 0;
u8 start_address[1];
vec_validate (msg, 1);
@ -207,7 +209,7 @@ vlib_i2c_read_eeprom (i2c_bus_t * bus, u8 i2c_addr, u16 start_addr, u16 length,
start_address[0] = start_addr;
msg[0].addr = i2c_addr;
msg[0].flags = I2C_MSG_FLAG_WRITE;
msg[0].buffer = (u8 *) &start_address;
msg[0].buffer = (u8 *) & start_address;
msg[0].len = 1;
msg[1].addr = i2c_addr;
@ -215,8 +217,15 @@ vlib_i2c_read_eeprom (i2c_bus_t * bus, u8 i2c_addr, u16 start_addr, u16 length,
msg[1].buffer = data;
msg[1].len = length;
vlib_i2c_xfer(bus, msg);
vlib_i2c_xfer (bus, msg);
vec_free (msg);
}
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -22,16 +22,18 @@
#define I2C_MSG_FLAG_WRITE 0
#define I2C_MSG_FLAG_READ 1
typedef struct {
u8 addr;
u8 flags;
u16 len;
u8 * buffer;
typedef struct
{
u8 addr;
u8 flags;
u16 len;
u8 *buffer;
} i2c_msg_t;
typedef struct i2c_bus_t {
void (* put_bits) (struct i2c_bus_t * b, int scl, int sda);
void (* get_bits) (struct i2c_bus_t * b, int *scl, int *sda);
typedef struct i2c_bus_t
{
void (*put_bits) (struct i2c_bus_t * b, int scl, int sda);
void (*get_bits) (struct i2c_bus_t * b, int *scl, int *sda);
int timeout;
u32 clock;
@ -45,13 +47,21 @@ typedef struct i2c_bus_t {
void vlib_i2c_init (i2c_bus_t * bus);
void vlib_i2c_xfer (i2c_bus_t * bus, i2c_msg_t * msgs);
void vlib_i2c_read_eeprom (i2c_bus_t * bus, u8 i2c_addr, u16 start_addr, u16 length, u8 * data);
void vlib_i2c_read_eeprom (i2c_bus_t * bus, u8 i2c_addr, u16 start_addr,
u16 length, u8 * data);
static inline int
vlib_i2c_bus_timed_out(i2c_bus_t * bus)
vlib_i2c_bus_timed_out (i2c_bus_t * bus)
{
return bus->timeout;
}
#endif /* included_vlib_i2c_h */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -40,30 +40,31 @@
#include <vlib/vlib.h>
clib_error_t *
vlib_call_init_exit_functions (vlib_main_t * vm,
_vlib_init_function_list_elt_t *head,
int call_once)
vlib_call_init_exit_functions (vlib_main_t * vm,
_vlib_init_function_list_elt_t * head,
int call_once)
{
clib_error_t * error = 0;
_vlib_init_function_list_elt_t * i;
clib_error_t *error = 0;
_vlib_init_function_list_elt_t *i;
i = head;
while (i)
{
if (call_once && !hash_get (vm->init_functions_called, i->f))
{
if (call_once)
hash_set1 (vm->init_functions_called, i->f);
error = i->f (vm);
if (error)
return error;
}
{
if (call_once)
hash_set1 (vm->init_functions_called, i->f);
error = i->f (vm);
if (error)
return error;
}
i = i->next_init_function;
}
return error;
}
clib_error_t * vlib_call_all_init_functions (vlib_main_t * vm)
clib_error_t *
vlib_call_all_init_functions (vlib_main_t * vm)
{
/* Call dummy functions to make sure purely static modules are
linked in. */
@ -71,29 +72,31 @@ clib_error_t * vlib_call_all_init_functions (vlib_main_t * vm)
foreach_vlib_module_reference;
#undef _
return vlib_call_init_exit_functions
(vm, vm->init_function_registrations, 1 /* call_once */);
return vlib_call_init_exit_functions
(vm, vm->init_function_registrations, 1 /* call_once */ );
}
clib_error_t * vlib_call_all_main_loop_enter_functions (vlib_main_t * vm)
{
return vlib_call_init_exit_functions
(vm, vm->main_loop_enter_function_registrations, 1 /* call_once */);
}
clib_error_t * vlib_call_all_main_loop_exit_functions (vlib_main_t * vm)
{
return vlib_call_init_exit_functions
(vm, vm->main_loop_exit_function_registrations, 1 /* call_once */);
}
clib_error_t * vlib_call_all_config_functions (vlib_main_t * vm,
unformat_input_t * input,
int is_early)
clib_error_t *
vlib_call_all_main_loop_enter_functions (vlib_main_t * vm)
{
clib_error_t * error = 0;
vlib_config_function_runtime_t * c, ** all;
uword * hash = 0, * p;
return vlib_call_init_exit_functions
(vm, vm->main_loop_enter_function_registrations, 1 /* call_once */ );
}
clib_error_t *
vlib_call_all_main_loop_exit_functions (vlib_main_t * vm)
{
return vlib_call_init_exit_functions
(vm, vm->main_loop_exit_function_registrations, 1 /* call_once */ );
}
clib_error_t *
vlib_call_all_config_functions (vlib_main_t * vm,
unformat_input_t * input, int is_early)
{
clib_error_t *error = 0;
vlib_config_function_runtime_t *c, **all;
uword *hash = 0, *p;
uword i;
hash = hash_create_string (0, sizeof (uword));
@ -111,10 +114,9 @@ clib_error_t * vlib_call_all_config_functions (vlib_main_t * vm,
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
u8 * s, * v;
u8 *s, *v;
if (! unformat (input, "%s %v", &s, &v)
|| ! (p = hash_get_mem (hash, s)))
if (!unformat (input, "%s %v", &s, &v) || !(p = hash_get_mem (hash, s)))
{
error = clib_error_create ("unknown input `%s %v'", s, v);
goto done;
@ -134,7 +136,7 @@ clib_error_t * vlib_call_all_config_functions (vlib_main_t * vm,
/* Is this an early config? Are we doing early configs? */
if (is_early ^ c->is_early)
continue;
continue;
/* Already called? */
if (hash_get (vm->init_functions_called, c->function))
@ -146,7 +148,7 @@ clib_error_t * vlib_call_all_config_functions (vlib_main_t * vm,
goto done;
}
done:
done:
for (i = 0; i < vec_len (all); i++)
{
c = all[i];
@ -156,3 +158,11 @@ clib_error_t * vlib_call_all_config_functions (vlib_main_t * vm,
hash_free (hash);
return error;
}
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -48,27 +48,29 @@
functions are typically used to register and setup packet
processing nodes. */
typedef clib_error_t * (vlib_init_function_t) (struct vlib_main_t * vm);
typedef clib_error_t *(vlib_init_function_t) (struct vlib_main_t * vm);
typedef struct _vlib_init_function_list_elt {
struct _vlib_init_function_list_elt * next_init_function;
vlib_init_function_t * f;
typedef struct _vlib_init_function_list_elt
{
struct _vlib_init_function_list_elt *next_init_function;
vlib_init_function_t *f;
} _vlib_init_function_list_elt_t;
/* Configuration functions: called with configuration input just before
main polling loop starts. */
typedef clib_error_t * (vlib_config_function_t) (struct vlib_main_t * vm,
unformat_input_t * input);
typedef clib_error_t *(vlib_config_function_t) (struct vlib_main_t * vm,
unformat_input_t * input);
typedef struct vlib_config_function_runtime_t {
typedef struct vlib_config_function_runtime_t
{
/* Function to call. Set to null once function has already been called. */
vlib_config_function_t * function;
vlib_config_function_t *function;
/* Input for function. */
unformat_input_t input;
/* next config function registration */
struct vlib_config_function_runtime_t * next_registration;
struct vlib_config_function_runtime_t *next_registration;
/* To be invoked as soon as the clib heap is available */
u8 is_early;
@ -104,7 +106,7 @@ static void __vlib_add_##tag##_function_##x (void) \
= vm->tag##_function_registrations; \
vm->tag##_function_registrations = &_vlib_init_function; \
_vlib_init_function.f = &x; \
}
}
#define VLIB_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,init)
@ -207,16 +209,16 @@ static void __vlib_add_config_function_##x (void) \
})
/* External functions. */
clib_error_t * vlib_call_all_init_functions (struct vlib_main_t * vm);
clib_error_t * vlib_call_all_config_functions (struct vlib_main_t * vm,
unformat_input_t * input,
int is_early);
clib_error_t * vlib_call_all_main_loop_enter_functions (struct vlib_main_t * vm);
clib_error_t * vlib_call_all_main_loop_exit_functions (struct vlib_main_t * vm);
clib_error_t *
vlib_call_init_exit_functions (struct vlib_main_t * vm,
_vlib_init_function_list_elt_t *head,
int call_once);
clib_error_t *vlib_call_all_init_functions (struct vlib_main_t *vm);
clib_error_t *vlib_call_all_config_functions (struct vlib_main_t *vm,
unformat_input_t * input,
int is_early);
clib_error_t *vlib_call_all_main_loop_enter_functions (struct vlib_main_t
*vm);
clib_error_t *vlib_call_all_main_loop_exit_functions (struct vlib_main_t *vm);
clib_error_t *vlib_call_init_exit_functions (struct vlib_main_t *vm,
_vlib_init_function_list_elt_t *
head, int call_once);
#define foreach_vlib_module_reference \
_ (node_cli) \
@ -226,5 +228,11 @@ vlib_call_init_exit_functions (struct vlib_main_t * vm,
#define _(x) void vlib_##x##_reference (void);
foreach_vlib_module_reference
#undef _
#endif /* included_vlib_init_h */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -19,10 +19,11 @@ vlib_lex_main_t vlib_lex_main;
#define LEX_DEBUG 0
u8 * format_vlib_lex_token (u8 * s, va_list * args)
u8 *
format_vlib_lex_token (u8 * s, va_list * args)
{
vlib_lex_main_t *lm = va_arg (*args, vlib_lex_main_t *);
vlib_lex_token_t *t = va_arg (*args, vlib_lex_token_t *);
vlib_lex_token_t *t = va_arg (*args, vlib_lex_token_t *);
if (t->token == VLIB_LEX_word)
s = format (s, "%s", t->value.as_pointer);
@ -31,7 +32,8 @@ u8 * format_vlib_lex_token (u8 * s, va_list * args)
return s;
}
void vlib_lex_get_token (vlib_lex_main_t * lm, vlib_lex_token_t * rv)
void
vlib_lex_get_token (vlib_lex_main_t * lm, vlib_lex_token_t * rv)
{
u8 c;
vlib_lex_table_t *t;
@ -40,7 +42,7 @@ void vlib_lex_get_token (vlib_lex_main_t * lm, vlib_lex_token_t * rv)
if (PREDICT_FALSE (lm->pushback_sp >= 0))
{
rv[0] = lm->pushback_vector [lm->pushback_sp--];
rv[0] = lm->pushback_vector[lm->pushback_sp--];
return;
}
@ -48,15 +50,15 @@ void vlib_lex_get_token (vlib_lex_main_t * lm, vlib_lex_token_t * rv)
while (1)
{
if (PREDICT_FALSE(lm->current_index >= vec_len (lm->input_vector)))
if (PREDICT_FALSE (lm->current_index >= vec_len (lm->input_vector)))
{
rv->token = VLIB_LEX_eof;
return;
}
t = vec_elt_at_index (lm->lex_tables, lm->current_table_index);
c = (lm->input_vector [lm->current_index++]) & 0x7f;
e = &t->entries [c];
c = (lm->input_vector[lm->current_index++]) & 0x7f;
e = &t->entries[c];
lm->current_table_index = e->next_table_index;
switch (e->action)
@ -82,43 +84,44 @@ void vlib_lex_get_token (vlib_lex_main_t * lm, vlib_lex_token_t * rv)
continue;
case VLIB_LEX_ADD_TO_TOKEN:
vec_add1(lm->token_buffer, c);
vec_add1 (lm->token_buffer, c);
continue;
case VLIB_LEX_KEYWORD_CHECK: {
uword * p;
case VLIB_LEX_KEYWORD_CHECK:
{
uword *p;
vec_add1 (lm->token_buffer, 0);
vec_add1 (lm->token_buffer, 0);
/* It's either a keyword or just a word. */
p = hash_get_mem (lm->lex_keywords, lm->token_buffer);
if (p)
{
rv->token = p[0];
if (LEX_DEBUG > 0)
clib_warning ("keyword '%s' token %s",
lm->token_buffer,
lm->lex_token_names[rv->token]);
}
else
{
/* it's a WORD */
rv->token = VLIB_LEX_word;
rv->value.as_pointer = vec_dup (lm->token_buffer);
if (LEX_DEBUG > 0)
clib_warning ("%s, value '%s'",
lm->lex_token_names[VLIB_LEX_word],
rv->value.as_pointer);
}
_vec_len (lm->token_buffer) = 0;
/* It's either a keyword or just a word. */
p = hash_get_mem (lm->lex_keywords, lm->token_buffer);
if (p)
{
rv->token = p[0];
if (LEX_DEBUG > 0)
clib_warning ("keyword '%s' token %s",
lm->token_buffer,
lm->lex_token_names[rv->token]);
}
else
{
/* it's a WORD */
rv->token = VLIB_LEX_word;
rv->value.as_pointer = vec_dup (lm->token_buffer);
if (LEX_DEBUG > 0)
clib_warning ("%s, value '%s'",
lm->lex_token_names[VLIB_LEX_word],
rv->value.as_pointer);
}
_vec_len (lm->token_buffer) = 0;
/* Rescan the character which terminated the keyword/word. */
lm->current_index--;
return;
}
/* Rescan the character which terminated the keyword/word. */
lm->current_index--;
return;
}
case VLIB_LEX_RETURN_AND_RESCAN:
ASSERT(lm->current_index);
ASSERT (lm->current_index);
lm->current_index--;
/* note flow-through */
@ -128,11 +131,12 @@ void vlib_lex_get_token (vlib_lex_main_t * lm, vlib_lex_token_t * rv)
lm->current_token_value = ~0;
if (LEX_DEBUG > 0)
{
clib_warning ("table %s char '%c'(0x%02x) next table %s return %s",
t->name, c, c, lm->lex_tables[e->next_table_index].name,
lm->lex_token_names[e->token]);
if (rv->token == VLIB_LEX_number)
clib_warning (" numeric value 0x%x (%d)", rv->value,
clib_warning
("table %s char '%c'(0x%02x) next table %s return %s",
t->name, c, c, lm->lex_tables[e->next_table_index].name,
lm->lex_token_names[e->token]);
if (rv->token == VLIB_LEX_number)
clib_warning (" numeric value 0x%x (%d)", rv->value,
rv->value);
}
return;
@ -140,7 +144,8 @@ void vlib_lex_get_token (vlib_lex_main_t * lm, vlib_lex_token_t * rv)
}
}
u16 vlib_lex_add_token (vlib_lex_main_t *lm, char *token_name)
u16
vlib_lex_add_token (vlib_lex_main_t * lm, char *token_name)
{
uword *p;
u16 rv;
@ -157,7 +162,8 @@ u16 vlib_lex_add_token (vlib_lex_main_t *lm, char *token_name)
return rv;
}
static u16 add_keyword (vlib_lex_main_t *lm, char *keyword, char *token_name)
static u16
add_keyword (vlib_lex_main_t * lm, char *keyword, char *token_name)
{
uword *p;
u16 token;
@ -172,14 +178,17 @@ static u16 add_keyword (vlib_lex_main_t *lm, char *keyword, char *token_name)
return token;
}
u16 vlib_lex_find_or_add_keyword (vlib_lex_main_t *lm, char *keyword, char *token_name)
u16
vlib_lex_find_or_add_keyword (vlib_lex_main_t * lm, char *keyword,
char *token_name)
{
uword * p = hash_get_mem (lm->lex_keywords, keyword);
uword *p = hash_get_mem (lm->lex_keywords, keyword);
return p ? p[0] : add_keyword (lm, keyword, token_name);
}
void vlib_lex_set_action_range (u32 table_index, u8 lo, u8 hi, u16 action,
u16 token, u32 next_table_index)
void
vlib_lex_set_action_range (u32 table_index, u8 lo, u8 hi, u16 action,
u16 token, u32 next_table_index)
{
int i;
vlib_lex_main_t *lm = &vlib_lex_main;
@ -194,7 +203,8 @@ void vlib_lex_set_action_range (u32 table_index, u8 lo, u8 hi, u16 action,
}
}
u16 vlib_lex_add_table (char *name)
u16
vlib_lex_add_table (char *name)
{
vlib_lex_main_t *lm = &vlib_lex_main;
vlib_lex_table_t *t;
@ -202,7 +212,7 @@ u16 vlib_lex_add_table (char *name)
p = hash_get_mem (lm->lex_tables_by_name, name);
ASSERT(p == 0);
ASSERT (p == 0);
pool_get_aligned (lm->lex_tables, t, CLIB_CACHE_LINE_BYTES);
@ -213,13 +223,14 @@ u16 vlib_lex_add_table (char *name)
vlib_lex_set_action_range (t - lm->lex_tables, 1, 0x7F, VLIB_LEX_IGNORE, ~0,
t - lm->lex_tables);
vlib_lex_set_action_range (t - lm->lex_tables, 0, 0, VLIB_LEX_RETURN, VLIB_LEX_eof,
t - lm->lex_tables);
vlib_lex_set_action_range (t - lm->lex_tables, 0, 0, VLIB_LEX_RETURN,
VLIB_LEX_eof, t - lm->lex_tables);
return t - lm->lex_tables;
}
void vlib_lex_reset (vlib_lex_main_t *lm, u8 *input_vector)
void
vlib_lex_reset (vlib_lex_main_t * lm, u8 * input_vector)
{
if (lm->pushback_vector)
_vec_len (lm->pushback_vector) = 0;
@ -229,7 +240,8 @@ void vlib_lex_reset (vlib_lex_main_t *lm, u8 *input_vector)
lm->current_index = 0;
}
static clib_error_t * lex_onetime_init (vlib_main_t * vm)
static clib_error_t *
lex_onetime_init (vlib_main_t * vm)
{
vlib_lex_main_t *lm = &vlib_lex_main;
@ -249,3 +261,11 @@ static clib_error_t * lex_onetime_init (vlib_main_t * vm)
}
VLIB_INIT_FUNCTION (lex_onetime_init);
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -37,57 +37,64 @@
_ (lpar) \
_ (rpar)
typedef enum {
typedef enum
{
#define _(f) VLIB_LEX_##f,
foreach_vlib_lex_global_token
#undef _
} vlib_lex_global_token_t;
typedef enum {
typedef enum
{
VLIB_LEX_IGNORE,
VLIB_LEX_ADD_TO_TOKEN,
VLIB_LEX_RETURN,
VLIB_LEX_RETURN_AND_RESCAN,
VLIB_LEX_KEYWORD_CHECK,
VLIB_LEX_START_NUMBER,
VLIB_LEX_START_NUMBER,
VLIB_LEX_ADD_TO_NUMBER,
} vlib_lex_action_t;
typedef struct {
typedef struct
{
u16 action;
u16 next_table_index;
u16 token;
} vlib_lex_table_entry_t;
typedef struct {
typedef struct
{
char *name;
vlib_lex_table_entry_t entries [128];
vlib_lex_table_entry_t entries[128];
} vlib_lex_table_t;
typedef struct {
typedef struct
{
u32 token;
union {
union
{
uword as_uword;
void * as_pointer;
char * as_string;
void *as_pointer;
char *as_string;
} value;
} vlib_lex_token_t;
typedef struct {
vlib_lex_table_t * lex_tables;
uword * lex_tables_by_name;
typedef struct
{
vlib_lex_table_t *lex_tables;
uword *lex_tables_by_name;
/* Vector of token strings. */
char ** lex_token_names;
char **lex_token_names;
/* Hash mapping c string name to token index. */
uword * lex_tokens_by_name;
uword *lex_tokens_by_name;
/* Hash mapping c string keyword name to token index. */
uword * lex_keywords;
uword *lex_keywords;
vlib_lex_token_t * pushback_vector;
vlib_lex_token_t *pushback_vector;
i32 pushback_sp;
@ -104,7 +111,7 @@ typedef struct {
u32 current_index;
/* Re-used vector for forming token strings and hashing them. */
u8 * token_buffer;
u8 *token_buffer;
} vlib_lex_main_t;
vlib_lex_main_t vlib_lex_main;
@ -114,17 +121,25 @@ vlib_lex_cleanup_token (vlib_lex_token_t * t)
{
if (t->token == VLIB_LEX_word)
{
u8 * tv = t->value.as_pointer;
u8 *tv = t->value.as_pointer;
vec_free (tv);
}
}
u16 vlib_lex_add_table (char *name);
void vlib_lex_get_token (vlib_lex_main_t *lm, vlib_lex_token_t * result);
u16 vlib_lex_add_token (vlib_lex_main_t *lm, char *token_name);
void vlib_lex_set_action_range (u32 table_index, u8 lo, u8 hi, u16 action,
void vlib_lex_get_token (vlib_lex_main_t * lm, vlib_lex_token_t * result);
u16 vlib_lex_add_token (vlib_lex_main_t * lm, char *token_name);
void vlib_lex_set_action_range (u32 table_index, u8 lo, u8 hi, u16 action,
u16 token, u32 next_table_index);
void vlib_lex_reset (vlib_lex_main_t *lm, u8 *input_vector);
void vlib_lex_reset (vlib_lex_main_t * lm, u8 * input_vector);
format_function_t format_vlib_lex_token;
#endif /* included_vlib_lex_h */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

File diff suppressed because it is too large Load Diff

View File

@ -56,7 +56,8 @@
#define VLIB_ELOG_MAIN_LOOP 0
#endif
typedef struct vlib_main_t {
typedef struct vlib_main_t
{
/* Instruction level timing state. */
clib_time_t clib_time;
@ -91,25 +92,24 @@ typedef struct vlib_main_t {
#define VLIB_MAIN_LOOP_EXIT_CLI 2
/* Error marker to use when exiting main loop. */
clib_error_t * main_loop_error;
clib_error_t *main_loop_error;
/* Name for e.g. syslog. */
char * name;
char *name;
/* Start and size of CLIB heap. */
void * heap_base;
void *heap_base;
uword heap_size;
vlib_buffer_main_t * buffer_main;
vlib_buffer_main_t *buffer_main;
vlib_physmem_main_t physmem_main;
/* Allocate/free buffer memory for DMA transfers, descriptor rings, etc.
buffer memory is guaranteed to be cache-aligned. */
void * (* os_physmem_alloc_aligned) (vlib_physmem_main_t * pm,
uword n_bytes,
uword alignment);
void (* os_physmem_free) (void * x);
void *(*os_physmem_alloc_aligned) (vlib_physmem_main_t * pm,
uword n_bytes, uword alignment);
void (*os_physmem_free) (void *x);
/* Node graph main structure. */
vlib_node_main_t node_main;
@ -125,26 +125,26 @@ typedef struct vlib_main_t {
/* Punt packets to underlying operating system for when fast switching
code does not know what to do. */
void (* os_punt_frame) (struct vlib_main_t * vm,
struct vlib_node_runtime_t * node,
vlib_frame_t * frame);
void (*os_punt_frame) (struct vlib_main_t * vm,
struct vlib_node_runtime_t * node,
vlib_frame_t * frame);
/* Multicast distribution. Set to zero for MC disabled. */
mc_main_t * mc_main;
mc_main_t *mc_main;
/* Stream index to use for distribution when MC is enabled. */
u32 mc_stream_index;
vlib_one_time_waiting_process_t * procs_waiting_for_mc_stream_join;
vlib_one_time_waiting_process_t *procs_waiting_for_mc_stream_join;
/* Event logger. */
elog_main_t elog_main;
/* Node call and return event types. */
elog_event_type_t * node_call_elog_event_types;
elog_event_type_t * node_return_elog_event_types;
elog_event_type_t *node_call_elog_event_types;
elog_event_type_t *node_return_elog_event_types;
elog_event_type_t * error_elog_event_types;
elog_event_type_t *error_elog_event_types;
/* Seed for random number generator. */
uword random_seed;
@ -153,7 +153,7 @@ typedef struct vlib_main_t {
clib_random_buffer_t random_buffer;
/* Hash table to record which init functions have been called. */
uword * init_functions_called;
uword *init_functions_called;
/* to compare with node runtime */
u32 cpu_index;
@ -166,12 +166,12 @@ typedef struct vlib_main_t {
_vlib_init_function_list_elt_t *main_loop_exit_function_registrations;
_vlib_init_function_list_elt_t *api_init_function_registrations;
vlib_config_function_runtime_t *config_function_registrations;
mc_serialize_msg_t *mc_msg_registrations; /* mc_main is a pointer... */
mc_serialize_msg_t *mc_msg_registrations; /* mc_main is a pointer... */
/* control-plane API queue signal pending, length indication */
volatile u32 queue_signal_pending;
volatile u32 api_queue_nonempty;
void (*queue_signal_callback)(struct vlib_main_t *);
void (*queue_signal_callback) (struct vlib_main_t *);
u8 **argv;
} vlib_main_t;
@ -180,11 +180,15 @@ vlib_main_t vlib_global_main;
always_inline f64
vlib_time_now (vlib_main_t * vm)
{ return clib_time_now (&vm->clib_time); }
{
return clib_time_now (&vm->clib_time);
}
always_inline f64
vlib_time_now_ticks (vlib_main_t * vm, u64 n)
{ return clib_time_now_internal (&vm->clib_time, n); }
{
return clib_time_now_internal (&vm->clib_time, n);
}
/* Busy wait for specified time. */
always_inline void
@ -231,7 +235,9 @@ vlib_panic_with_error (vlib_main_t * vm, clib_error_t * error)
always_inline void
vlib_panic (vlib_main_t * vm)
{ vlib_panic_with_error (vm, 0); }
{
vlib_panic_with_error (vm, 0);
}
always_inline u32
vlib_vector_input_stats_index (vlib_main_t * vm, word delta)
@ -284,7 +290,7 @@ vlib_increment_main_loop_counter (vlib_main_t * vm)
is_wrap = (c & pow2_mask (VLIB_LOG2_MAIN_LOOPS_PER_STATS_UPDATE)) == 0;
if (is_wrap)
wraps++;
wraps++;
i = vlib_vector_input_stats_index (vm, /* delta */ is_wrap);
@ -299,8 +305,8 @@ vlib_increment_main_loop_counter (vlib_main_t * vm)
vm->node_counts_per_main_loop[i] = n;
}
always_inline void vlib_set_queue_signal_callback
(vlib_main_t *vm, void (*fp)(vlib_main_t *))
always_inline void vlib_set_queue_signal_callback
(vlib_main_t * vm, void (*fp) (vlib_main_t *))
{
vm->queue_signal_callback = fp;
}
@ -317,3 +323,11 @@ u32 vlib_app_num_thread_stacks_needed (void) __attribute__ ((weak));
extern void vlib_node_sync_stats (vlib_main_t * vm, vlib_node_t * n);
#endif /* included_vlib_main_h */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

Some files were not shown because too many files have changed in this diff Show More