From 6e36351faf5b69a0bfb8235b3b06f8b2c24e5547 Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Fri, 10 Aug 2018 22:39:11 +0200 Subject: 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 --- src/vnet/bonding/node.c | 5 ----- src/vnet/devices/virtio/vhost_user_input.c | 2 -- src/vnet/devices/virtio/vhost_user_output.c | 3 --- src/vnet/feature/feature.h | 9 +++++++++ src/vnet/interface.h | 14 ++++++++++++++ src/vnet/ip/ip4_input.c | 6 ++---- src/vnet/l2/l2_output.c | 16 +++++----------- 7 files changed, 30 insertions(+), 25 deletions(-) (limited to 'src/vnet') diff --git a/src/vnet/bonding/node.c b/src/vnet/bonding/node.c index ba3e8e32a36..361509c549d 100644 --- a/src/vnet/bonding/node.c +++ b/src/vnet/bonding/node.c @@ -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 diff --git a/src/vnet/devices/virtio/vhost_user_input.c b/src/vnet/devices/virtio/vhost_user_input.c index 3f2b4022dee..1a7a0c47150 100644 --- a/src/vnet/devices/virtio/vhost_user_input.c +++ b/src/vnet/devices/virtio/vhost_user_input.c @@ -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 diff --git a/src/vnet/devices/virtio/vhost_user_output.c b/src/vnet/devices/virtio/vhost_user_output.c index 9c65f249b4b..029c0c04cc5 100644 --- a/src/vnet/devices/virtio/vhost_user_output.c +++ b/src/vnet/devices/virtio/vhost_user_output.c @@ -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* */ /* diff --git a/src/vnet/feature/feature.h b/src/vnet/feature/feature.h index 88a919f083a..eb9b7b06243 100644 --- a/src/vnet/feature/feature.h +++ b/src/vnet/feature/feature.h @@ -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, diff --git a/src/vnet/interface.h b/src/vnet/interface.h index e9adfe84cbf..b34d19c55ef 100644 --- a/src/vnet/interface.h +++ b/src/vnet/interface.h @@ -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)(); \ diff --git a/src/vnet/ip/ip4_input.c b/src/vnet/ip/ip4_input.c index d11d558eb93..1425786a4b1 100644 --- a/src/vnet/ip/ip4_input.c +++ b/src/vnet/ip/ip4_input.c @@ -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 * diff --git a/src/vnet/l2/l2_output.c b/src/vnet/l2/l2_output.c index 1fa042ffd54..2811215307f 100644 --- a/src/vnet/l2/l2_output.c +++ b/src/vnet/l2/l2_output.c @@ -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, -- cgit 1.2.3-korg