Multiarch handling in different constructor macros

This significantly reduces need for

...

in multiarch code. Simply constructor macros will jost create static unused
entry if CLIB_MARCH_VARIANT is defined and that will be optimized out by
compiler.

Change-Id: I17d1c4ac0c903adcfadaa4a07de1b854c7ab14ac
Signed-off-by: Damjan Marion <damarion@cisco.com>
This commit is contained in:
Damjan Marion
2018-08-10 22:39:11 +02:00
committed by Damjan Marion
parent 3bf6c2bfe5
commit 6e36351faf
18 changed files with 92 additions and 62 deletions
+3 -4
View File
@@ -415,7 +415,6 @@ VLIB_NODE_FN (acl_out_fa_ip4_node) (vlib_main_t * vm,
return acl_fa_node_fn (vm, node, frame, 0, 0, 0, 0, &acl_out_fa_ip4_node);
}
#ifndef CLIB_MARCH_VARIANT
static u8 *
format_fa_5tuple (u8 * s, va_list * args)
{
@@ -447,14 +446,16 @@ format_fa_5tuple (u8 * s, va_list * args)
p5t->pkt.tcp_flags, p5t->pkt.flags_reserved);
}
#ifndef CLIB_MARCH_VARIANT
u8 *
format_acl_plugin_5tuple (u8 * s, va_list * args)
{
return format_fa_5tuple (s, args);
}
#endif
/* packet trace format function */
u8 *
static u8 *
format_acl_plugin_trace (u8 * s, va_list * args)
{
CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
@@ -475,7 +476,6 @@ format_acl_plugin_trace (u8 * s, va_list * args)
return s;
}
/* *INDENT-OFF* */
static char *acl_fa_error_strings[] = {
@@ -634,7 +634,6 @@ VNET_FEATURE_INIT (acl_out_ip4_fa_feature, static) =
.node_name = "acl-plugin-out-ip4-fa",
.runs_before = VNET_FEATURES ("interface-output"),
};
#endif
/* *INDENT-ON* */
-2
View File
@@ -530,7 +530,6 @@ VLIB_NODE_FN (avf_input_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
return n_rx;
}
#ifndef CLIB_MARCH_VARIANT
/* *INDENT-OFF* */
VLIB_REGISTER_NODE (avf_input_node) = {
.name = "avf-input",
@@ -541,7 +540,6 @@ VLIB_REGISTER_NODE (avf_input_node) = {
.n_errors = AVF_INPUT_N_ERROR,
.error_strings = avf_input_error_strings,
};
#endif
/* *INDENT-ON* */
+2 -9
View File
@@ -37,7 +37,6 @@ typedef enum
DPDK_TX_FUNC_N_ERROR,
} dpdk_tx_func_error_t;
#ifndef CLIB_MARCH_VARIANT
static char *dpdk_tx_func_error_strings[] = {
#define _(n,s) s,
foreach_dpdk_tx_func_error
@@ -65,7 +64,6 @@ dpdk_set_mac_address (vnet_hw_interface_t * hi, char *address)
return NULL;
}
}
#endif
static struct rte_mbuf *
dpdk_replicate_packet_mb (vlib_buffer_t * b)
@@ -516,7 +514,6 @@ VNET_DEVICE_CLASS_TX_FN (dpdk_device_class) (vlib_main_t * vm,
return tx_pkts;
}
#ifndef CLIB_MARCH_VARIANT
static void
dpdk_clear_hw_interface_counters (u32 instance)
{
@@ -677,12 +674,9 @@ VNET_DEVICE_CLASS (dpdk_device_class) = {
};
/* *INDENT-ON* */
#endif
#define UP_DOWN_FLAG_EVENT 1
#ifndef CLIB_MARCH_VARIANT
uword
static uword
admin_up_down_process (vlib_main_t * vm,
vlib_node_runtime_t * rt, vlib_frame_t * f)
{
@@ -726,14 +720,13 @@ admin_up_down_process (vlib_main_t * vm,
}
/* *INDENT-OFF* */
VLIB_REGISTER_NODE (admin_up_down_process_node,static) = {
VLIB_REGISTER_NODE (admin_up_down_process_node) = {
.function = admin_up_down_process,
.type = VLIB_NODE_TYPE_PROCESS,
.name = "admin-up-down-process",
.process_log2_n_stack_bytes = 17, // 256KB
};
/* *INDENT-ON* */
#endif
/*
* fd.io coding-style-patch-verification: ON
+1 -4
View File
@@ -60,6 +60,7 @@
extern vnet_device_class_t dpdk_device_class;
extern vlib_node_registration_t dpdk_input_node;
extern vlib_node_registration_t admin_up_down_process_node;
#define foreach_dpdk_pmd \
_ ("net_thunderx", THUNDERX) \
@@ -521,10 +522,6 @@ clib_error_t *unformat_rss_fn (unformat_input_t * input, uword * rss_fn);
clib_error_t *unformat_hqos (unformat_input_t * input,
dpdk_device_config_hqos_t * hqos);
uword
admin_up_down_process (vlib_main_t * vm,
vlib_node_runtime_t * rt, vlib_frame_t * f);
clib_error_t *dpdk_pool_create (vlib_main_t * vm, u8 * pool_name,
u32 elt_size, u32 num_elts,
u32 pool_priv_size, u16 cache_size, u8 numa,
-4
View File
@@ -28,13 +28,11 @@
#include <dpdk/device/dpdk_priv.h>
#ifndef CLIB_MARCH_VARIANT
static char *dpdk_error_strings[] = {
#define _(n,s) s,
foreach_dpdk_error
#undef _
};
#endif
STATIC_ASSERT (VNET_DEVICE_INPUT_NEXT_IP4_INPUT - 1 ==
VNET_DEVICE_INPUT_NEXT_IP4_NCS_INPUT,
@@ -644,7 +642,6 @@ VLIB_NODE_FN (dpdk_input_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
return n_rx_packets;
}
#ifndef CLIB_MARCH_VARIANT
/* *INDENT-OFF* */
VLIB_REGISTER_NODE (dpdk_input_node) = {
.type = VLIB_NODE_TYPE_INPUT,
@@ -661,7 +658,6 @@ VLIB_REGISTER_NODE (dpdk_input_node) = {
.error_strings = dpdk_error_strings,
};
/* *INDENT-ON* */
#endif
/*
* fd.io coding-style-patch-verification: ON
+2 -1
View File
@@ -58,7 +58,8 @@ rte_delay_us_override (unsigned us)
/* Only suspend for the admin_down_process */
vlib_process_t *proc = vlib_get_current_process (vm);
if (!(proc->flags & VLIB_PROCESS_IS_RUNNING) ||
(proc->node_runtime.function != admin_up_down_process))
(proc->node_runtime.node_index !=
admin_up_down_process_node.index))
return 0;
f64 delay = 1e-6 * us;
+8 -11
View File
@@ -40,7 +40,7 @@ typedef enum
MEMIF_TX_N_ERROR,
} memif_tx_func_error_t;
static __clib_unused char *memif_tx_func_error_strings[] = {
static char *memif_tx_func_error_strings[] = {
#define _(n,s) s,
foreach_memif_tx_func_error
#undef _
@@ -61,7 +61,7 @@ format_memif_device_name (u8 * s, va_list * args)
}
#endif
static __clib_unused u8 *
static u8 *
format_memif_device (u8 * s, va_list * args)
{
u32 dev_instance = va_arg (*args, u32);
@@ -77,7 +77,7 @@ format_memif_device (u8 * s, va_list * args)
return s;
}
static __clib_unused u8 *
static u8 *
format_memif_tx_trace (u8 * s, va_list * args)
{
s = format (s, "Unimplemented...");
@@ -432,7 +432,7 @@ VNET_DEVICE_CLASS_TX_FN (memif_device_class) (vlib_main_t * vm,
mq, ptd);
}
static __clib_unused void
static void
memif_set_interface_next_node (vnet_main_t * vnm, u32 hw_if_index,
u32 node_index)
{
@@ -451,13 +451,13 @@ memif_set_interface_next_node (vnet_main_t * vnm, u32 hw_if_index,
vlib_node_add_next (vlib_get_main (), memif_input_node.index, node_index);
}
static __clib_unused void
static void
memif_clear_hw_interface_counters (u32 instance)
{
/* Nothing for now */
}
static __clib_unused clib_error_t *
static clib_error_t *
memif_interface_rx_mode_change (vnet_main_t * vnm, u32 hw_if_index, u32 qid,
vnet_hw_interface_rx_mode mode)
{
@@ -474,7 +474,7 @@ memif_interface_rx_mode_change (vnet_main_t * vnm, u32 hw_if_index, u32 qid,
return 0;
}
static __clib_unused clib_error_t *
static clib_error_t *
memif_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
{
memif_main_t *mm = &memif_main;
@@ -490,7 +490,7 @@ memif_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
return error;
}
static __clib_unused clib_error_t *
static clib_error_t *
memif_subif_add_del_function (vnet_main_t * vnm,
u32 hw_if_index,
struct vnet_sw_interface_t *st, int is_add)
@@ -499,7 +499,6 @@ memif_subif_add_del_function (vnet_main_t * vnm,
return 0;
}
#ifndef CLIB_MARCH_VARIANT
/* *INDENT-OFF* */
VNET_DEVICE_CLASS (memif_device_class) = {
.name = "memif",
@@ -515,8 +514,6 @@ VNET_DEVICE_CLASS (memif_device_class) = {
.rx_mode_change_function = memif_interface_rx_mode_change,
};
#endif
/* *INDENT-ON* */
/*
-2
View File
@@ -885,7 +885,6 @@ VLIB_NODE_FN (memif_input_node) (vlib_main_t * vm,
return n_rx;
}
#ifndef CLIB_MARCH_VARIANT
/* *INDENT-OFF* */
VLIB_REGISTER_NODE (memif_input_node) = {
.name = "memif-input",
@@ -896,7 +895,6 @@ VLIB_REGISTER_NODE (memif_input_node) = {
.n_errors = MEMIF_INPUT_N_ERROR,
.error_strings = memif_input_error_strings,
};
#endif
/* *INDENT-ON* */
+8
View File
@@ -151,6 +151,7 @@ typedef struct
vlib_cli_command_t *cli_command_registrations;
} vlib_cli_main_t;
#ifndef CLIB_MARCH_VARIANT
#define VLIB_CLI_COMMAND(x,...) \
__VA_ARGS__ vlib_cli_command_t x; \
static void __vlib_cli_command_registration_##x (void) \
@@ -172,6 +173,13 @@ static void __vlib_cli_command_unregistration_##x (void) \
next_cli_command); \
} \
__VA_ARGS__ vlib_cli_command_t x
#else
/* create unused pointer to silence compiler warnings and get whole
function optimized out */
#define VLIB_CLI_COMMAND(x,...) \
static __clib_unused vlib_cli_command_t __clib_unused_##x
#endif
#define VLIB_CLI_PARSE_RULE(x) \
vlib_cli_parse_rule_t x
/* Output to current CLI connection. */
+33
View File
@@ -115,6 +115,7 @@ typedef struct vlib_config_function_runtime_t
/* Declaration is global (e.g. not static) so that init functions can
be called from other modules to resolve init function depend. */
#ifndef CLIB_MARCH_VARIANT
#define VLIB_DECLARE_INIT_FUNCTION(x, tag) \
vlib_init_function_t * _VLIB_INIT_FUNCTION_SYMBOL (x, tag) = x; \
static void __vlib_add_##tag##_function_##x (void) \
@@ -152,6 +153,12 @@ static void __vlib_rm_##tag##_function_##x (void) \
next = next->next_init_function; \
} \
}
#else
/* create unused pointer to silence compiler warnings and get whole
function optimized out */
#define VLIB_DECLARE_INIT_FUNCTION(x, tag) \
static __clib_unused void * __clib_unused_##tag##_##x = x;
#endif
#define VLIB_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,init)
#define VLIB_WORKER_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,worker_init)
@@ -161,6 +168,7 @@ static void __vlib_rm_##tag##_function_##x (void) \
#define VLIB_MAIN_LOOP_EXIT_FUNCTION(x) \
VLIB_DECLARE_INIT_FUNCTION(x,main_loop_exit)
#ifndef CLIB_MARCH_VARIANT
#define VLIB_CONFIG_FUNCTION(x,n,...) \
__VA_ARGS__ vlib_config_function_runtime_t \
VLIB_CONFIG_FUNCTION_SYMBOL(x); \
@@ -191,7 +199,20 @@ static void __vlib_rm_config_function_##x (void) \
.function = x, \
.is_early = 0, \
}
#else
/* create unused pointer to silence compiler warnings and get whole
function optimized out */
#define VLIB_CONFIG_FUNCTION(x,n,...) \
static __clib_unused vlib_config_function_runtime_t \
VLIB_CONFIG_FUNCTION_SYMBOL (__clib_unused_##x) \
= { \
.name = n, \
.function = x, \
.is_early = 0, \
}
#endif
#ifndef CLIB_MARCH_VARIANT
#define VLIB_EARLY_CONFIG_FUNCTION(x,n,...) \
__VA_ARGS__ vlib_config_function_runtime_t \
VLIB_CONFIG_FUNCTION_SYMBOL(x); \
@@ -222,6 +243,18 @@ static void __vlib_rm_config_function_##x (void) \
.function = x, \
.is_early = 1, \
}
#else
/* create unused pointer to silence compiler warnings and get whole
function optimized out */
#define VLIB_EARLY_CONFIG_FUNCTION(x,n,...) \
static __clib_unused vlib_config_function_runtime_t \
VLIB_CONFIG_FUNCTION_SYMBOL (__clib_unused_##x) \
= { \
.name = n, \
.function = x, \
.is_early = 1, \
}
#endif
/* Call given init function: used for init function dependencies. */
#define vlib_call_init_function(vm, x) \
+5
View File
@@ -150,6 +150,7 @@ typedef struct _vlib_node_registration
} vlib_node_registration_t;
#ifndef CLIB_MARCH_VARIANT
#define VLIB_REGISTER_NODE(x,...) \
__VA_ARGS__ vlib_node_registration_t x; \
static void __vlib_add_node_registration_##x (void) \
@@ -169,6 +170,10 @@ static void __vlib_rm_node_registration_##x (void) \
&x, next_registration); \
} \
__VA_ARGS__ vlib_node_registration_t x
#else
#define VLIB_REGISTER_NODE(x,...) \
static __clib_unused vlib_node_registration_t __clib_unused_##x
#endif
#define VLIB_NODE_FN(node) \
uword CLIB_MARCH_SFX (node##_fn)(); \
-5
View File
@@ -36,7 +36,6 @@ typedef enum
BOND_INPUT_N_ERROR,
} bond_input_error_t;
#ifndef CLIB_MARCH_VARIANT
static char *bond_input_error_strings[] = {
#define _(n,s) s,
foreach_bond_input_error
@@ -60,8 +59,6 @@ format_bond_input_trace (u8 * s, va_list * args)
return s;
}
#endif
typedef enum
{
@@ -360,7 +357,6 @@ VLIB_NODE_FN (bond_input_node) (vlib_main_t * vm,
return frame->n_vectors;
}
#ifndef CLIB_MARCH_VARIANT
static clib_error_t *
bond_input_init (vlib_main_t * vm)
{
@@ -457,7 +453,6 @@ bond_hw_interface_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
}
VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (bond_hw_interface_up_down);
#endif
/*
* fd.io coding-style-patch-verification: ON
@@ -650,7 +650,6 @@ VLIB_NODE_FN (vhost_user_input_node) (vlib_main_t * vm,
return n_rx_packets;
}
#ifndef CLIB_MARCH_VARIANT
/* *INDENT-OFF* */
VLIB_REGISTER_NODE (vhost_user_input_node) = {
.type = VLIB_NODE_TYPE_INPUT,
@@ -667,7 +666,6 @@ VLIB_REGISTER_NODE (vhost_user_input_node) = {
.error_strings = vhost_user_input_func_error_strings,
};
/* *INDENT-ON* */
#endif
/*
* fd.io coding-style-patch-verification: ON
@@ -630,7 +630,6 @@ vhost_user_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index,
return /* no error */ 0;
}
#ifndef CLIB_MARCH_VARIANT
/* *INDENT-OFF* */
VNET_DEVICE_CLASS (vhost_user_device_class) = {
.name = "vhost-user",
@@ -643,8 +642,6 @@ VNET_DEVICE_CLASS (vhost_user_device_class) = {
.format_tx_trace = format_vhost_trace,
};
#endif
/* *INDENT-ON* */
/*
+9
View File
@@ -99,6 +99,7 @@ typedef struct
extern vnet_feature_main_t feature_main;
#ifndef CLIB_MARCH_VARIANT
#define VNET_FEATURE_ARC_INIT(x,...) \
__VA_ARGS__ vnet_feature_arc_registration_t vnet_feat_arc_##x;\
static void __vnet_add_feature_arc_registration_##x (void) \
@@ -138,6 +139,14 @@ static void __vnet_rm_feature_registration_##x (void) \
VLIB_REMOVE_FROM_LINKED_LIST (fm->next_feature, r, next); \
} \
__VA_ARGS__ vnet_feature_registration_t vnet_feat_##x
#else
#define VNET_FEATURE_ARC_INIT(x,...) \
extern vnet_feature_arc_registration_t __clib_unused vnet_feat_arc_##x; \
static vnet_feature_arc_registration_t __clib_unused __clib_unused_vnet_feat_arc_##x
#define VNET_FEATURE_INIT(x,...) \
extern vnet_feature_registration_t __clib_unused vnet_feat_##x; \
static vnet_feature_registration_t __clib_unused __clib_unused_vnet_feat_##x
#endif
void
vnet_config_update_feature_count (vnet_feature_main_t * fm, u8 arc,
+14
View File
@@ -108,6 +108,7 @@ typedef struct _vnet_interface_function_list_elt
clib_error_t *(*fp) (struct vnet_main_t * vnm, u32 if_index, u32 flags);
} _vnet_interface_function_list_elt_t;
#ifndef CLIB_MARCH_VARIANT
#define _VNET_INTERFACE_FUNCTION_DECL_PRIO(f,tag,p) \
\
static void __vnet_interface_function_init_##tag##_##f (void) \
@@ -146,6 +147,12 @@ static void __vnet_interface_function_deinit_##tag##_##f (void) \
next = next->next_interface_function; \
} \
}
#else
/* create unused pointer to silence compiler warnings and get whole
function optimized out */
#define _VNET_INTERFACE_FUNCTION_DECL_PRIO(f,tag,p) \
static __clib_unused void * __clib_unused_##f = f;
#endif
#define _VNET_INTERFACE_FUNCTION_DECL(f,tag) \
_VNET_INTERFACE_FUNCTION_DECL_PRIO(f,tag,VNET_ITF_FUNC_PRIORITY_LOW)
@@ -248,6 +255,7 @@ typedef struct _vnet_device_class
vnet_interface_set_mac_address_function_t *mac_addr_change_function;
} vnet_device_class_t;
#ifndef CLIB_MARCH_VARIANT
#define VNET_DEVICE_CLASS(x,...) \
__VA_ARGS__ vnet_device_class_t x; \
static void __vnet_add_device_class_registration_##x (void) \
@@ -267,6 +275,12 @@ static void __vnet_rm_device_class_registration_##x (void) \
&x, next_class_registration); \
} \
__VA_ARGS__ vnet_device_class_t x
#else
/* create unused pointer to silence compiler warnings and get whole
function optimized out */
#define VNET_DEVICE_CLASS(x,...) \
static __clib_unused vnet_device_class_t __clib_unused_##x
#endif
#define VNET_DEVICE_CLASS_TX_FN(devclass) \
uword CLIB_MARCH_SFX (devclass##_tx_fn)(); \
+2 -4
View File
@@ -47,7 +47,6 @@ typedef struct
u8 packet_data[64];
} ip4_input_trace_t;
#ifndef CLIB_MARCH_VARIANT
static u8 *
format_ip4_input_trace (u8 * s, va_list * va)
{
@@ -60,7 +59,6 @@ format_ip4_input_trace (u8 * s, va_list * va)
return s;
}
#endif
static_always_inline u32
ip4_input_set_next (u32 sw_if_index, vlib_buffer_t * b, int arc_enabled)
@@ -312,6 +310,7 @@ char *ip4_error_strings[] = {
foreach_ip4_error
#undef _
};
#endif
/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ip4_input_node) = {
@@ -356,6 +355,7 @@ ip4_init (vlib_main_t * vm)
hdlc_register_input_protocol (vm, HDLC_PROTOCOL_ip4, ip4_input_node.index);
{
extern vlib_node_registration_t ip4_input_no_checksum_node;
pg_node_t *pn;
pn = pg_get_node (ip4_input_node.index);
pn->unformat_edit = unformat_pg_ip4_header;
@@ -405,8 +405,6 @@ ip4_main_loop_enter (vlib_main_t * vm)
VLIB_MAIN_LOOP_ENTER_FUNCTION (ip4_main_loop_enter);
#endif
/*
* fd.io coding-style-patch-verification: ON
*
+5 -11
View File
@@ -76,7 +76,6 @@ typedef struct
u8 raw[12]; /* raw data */
} l2output_trace_t;
#ifndef CLIB_MARCH_VARIANT
/* packet trace format function */
static u8 *
format_l2output_trace (u8 * s, va_list * args)
@@ -103,7 +102,6 @@ static char *l2output_error_strings[] = {
foreach_l2output_error
#undef _
};
#endif
/**
* Check for split horizon violations.
@@ -430,7 +428,6 @@ VLIB_NODE_FN (l2output_node) (vlib_main_t * vm,
return frame->n_vectors;
}
#ifndef CLIB_MARCH_VARIANT
/* *INDENT-OFF* */
VLIB_REGISTER_NODE (l2output_node) = {
.name = "l2-output",
@@ -481,11 +478,10 @@ typedef enum
* sending packets to the error-drop node to drop the packet. Then, stale L2FIB
* entries for delted tunnels won't cause possible packet or memory corrpution.
*/
static vlib_node_registration_t l2output_bad_intf_node;
static uword
l2output_bad_intf_node_fn (vlib_main_t * vm,
vlib_node_runtime_t * node, vlib_frame_t * frame)
VLIB_NODE_FN (l2output_bad_intf_node) (vlib_main_t * vm,
vlib_node_runtime_t * node,
vlib_frame_t * frame)
{
u32 n_left_from, *from, *to_next;
l2output_next_t next_index = 0;
@@ -539,8 +535,7 @@ l2output_bad_intf_node_fn (vlib_main_t * vm,
}
/* *INDENT-OFF* */
VLIB_REGISTER_NODE (l2output_bad_intf_node,static) = {
.function = l2output_bad_intf_node_fn,
VLIB_REGISTER_NODE (l2output_bad_intf_node) = {
.name = "l2-output-bad-intf",
.vector_size = sizeof (u32),
.type = VLIB_NODE_TYPE_INTERNAL,
@@ -555,8 +550,6 @@ VLIB_REGISTER_NODE (l2output_bad_intf_node,static) = {
[0] = "error-drop",
},
};
VLIB_NODE_FUNCTION_MULTIARCH (l2output_bad_intf_node, l2output_bad_intf_node_fn);
/* *INDENT-ON* */
static clib_error_t *
@@ -588,6 +581,7 @@ l2output_init (vlib_main_t * vm)
VLIB_INIT_FUNCTION (l2output_init);
#ifndef CLIB_MARCH_VARIANT
/** Create a mapping in the next node mapping table for the given sw_if_index. */
void
l2output_create_output_node_mapping (vlib_main_t * vlib_main,