From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by dpdk.org (Postfix) with ESMTP id BA9FD1B658 for ; Thu, 2 Nov 2017 23:10:49 +0100 (CET) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id EC88820C11; Thu, 2 Nov 2017 18:10:46 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute1.internal (MEProxy); Thu, 02 Nov 2017 18:10:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= date:from:message-id:subject:to:x-me-sender:x-me-sender :x-sasl-enc; s=mesmtp; bh=5hWmZD0hMErn7feNrFEi2yoxtIIlbXk1BDoVaN styRQ=; b=Fka6jli5PNzl0W2hb7FxsRIGBuB2FhQOd0wpXMjbZcMX/UNGjPwv9t TNpP8CUpCkD8ZBhhiAfdxCeGnMncdRIMXvrA/uSPp+GPx66O8UGS91oTNCFQLWeh Fb1XB250ZWpORrPRYvY1y3F3Dcpgqx5MvxoINm5LBu+5S3GPOH4Bk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=date:from:message-id:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=5hWmZD0hMErn7feNr FEi2yoxtIIlbXk1BDoVaNstyRQ=; b=jFyZS29tSGXWuXYljaE/az1blAnZcRkZR 3Wr5hpHXbkCJmebtb0GffisF42iNXNsM6Kyq7rrufvTZOk6IzClqeLdpVt+Tx1nP iGpP/rStt0LCceUvm4usQYvV8hI9XBevif6SOPIJl7G+8Bm8JErFngPBMWvQpkte NSpwix2tyiYfeuW1z/sbgYDQbQnHRkv58JdlFW/W0SeKdTJhYc5yLvtbY0E0CdgE Aki/2XBI2G80ZAuWTavbbnxKRt9aFQxPYHTYqWKR7qZ0Lj1M/Mj8hixSKTcSTdEp asZzh47z2BjKbezIDhAyQ3uwisPE+QxK5b0Q0cKtpzM1VFBLjXmHA== X-ME-Sender: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 73B5B7FAED for ; Thu, 2 Nov 2017 18:10:46 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Date: Thu, 2 Nov 2017 23:10:34 +0100 Message-Id: <20171102221034.6919-1-thomas@monjalon.net> X-Mailer: git-send-email 2.14.2 Subject: [dpdk-dev] [PATCH] use macro to declare constructor functions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Nov 2017 22:10:50 -0000 It is easier to find all constructor functions when they use the same macros RTE_INIT or RTE_INIT_PRIO. The macro definitions are moved from rte_eal.h to rte_common.h. Signed-off-by: Thomas Monjalon --- examples/performance-thread/common/lthread_diag.c | 3 +-- examples/performance-thread/common/lthread_sched.c | 3 +-- examples/performance-thread/common/lthread_tls.c | 4 +--- .../performance-thread/pthread_shim/pthread_shim.c | 5 +---- lib/librte_acl/rte_acl.c | 3 +-- lib/librte_eal/common/arch/x86/rte_memcpy.c | 3 +-- lib/librte_eal/common/arch/x86/rte_spinlock.c | 3 +-- lib/librte_eal/common/eal_common_timer.c | 3 +-- lib/librte_eal/common/include/rte_common.h | 23 ++++++++++++++++++++++ lib/librte_eal/common/include/rte_eal.h | 23 ---------------------- lib/librte_hash/rte_crc_arm64.h | 3 +-- lib/librte_hash/rte_hash_crc.h | 3 +-- lib/librte_net/rte_net_crc.c | 3 +-- 13 files changed, 34 insertions(+), 48 deletions(-) diff --git a/examples/performance-thread/common/lthread_diag.c b/examples/performance-thread/common/lthread_diag.c index bce1a0c38..b5007d77e 100644 --- a/examples/performance-thread/common/lthread_diag.c +++ b/examples/performance-thread/common/lthread_diag.c @@ -296,8 +296,7 @@ _lthread_diag_default_cb(uint64_t time, struct lthread *lt, int diag_event, /* * plug in default diag callback with mask off */ -void _lthread_diag_ctor(void)__attribute__((constructor)); -void _lthread_diag_ctor(void) +RTE_INIT(_lthread_diag_ctor) { diag_cb = _lthread_diag_default_cb; diag_mask = 0; diff --git a/examples/performance-thread/common/lthread_sched.c b/examples/performance-thread/common/lthread_sched.c index e100c4144..779aeb17f 100644 --- a/examples/performance-thread/common/lthread_sched.c +++ b/examples/performance-thread/common/lthread_sched.c @@ -117,8 +117,7 @@ uint64_t diag_mask; /* constructor */ -void lthread_sched_ctor(void) __attribute__ ((constructor)); -void lthread_sched_ctor(void) +RTE_INIT(lthread_sched_ctor) { memset(schedcore, 0, sizeof(schedcore)); rte_atomic16_init(&num_schedulers); diff --git a/examples/performance-thread/common/lthread_tls.c b/examples/performance-thread/common/lthread_tls.c index 56f0c2f1b..2259fad44 100644 --- a/examples/performance-thread/common/lthread_tls.c +++ b/examples/performance-thread/common/lthread_tls.c @@ -62,9 +62,7 @@ RTE_DEFINE_PER_LTHREAD(void *, dummy); static struct lthread_key key_table[LTHREAD_MAX_KEYS]; -void lthread_tls_ctor(void) __attribute__((constructor)); - -void lthread_tls_ctor(void) +RTE_INIT(thread_tls_ctor) { key_pool = NULL; key_pool_init = 0; diff --git a/examples/performance-thread/pthread_shim/pthread_shim.c b/examples/performance-thread/pthread_shim/pthread_shim.c index 113bafa00..bc7cf2b0f 100644 --- a/examples/performance-thread/pthread_shim/pthread_shim.c +++ b/examples/performance-thread/pthread_shim/pthread_shim.c @@ -202,10 +202,7 @@ static void *__libc_dl_handle = RTLD_NEXT; * The constructor function initialises the * function pointers for pthread library functions */ -void -pthread_intercept_ctor(void)__attribute__((constructor)); -void -pthread_intercept_ctor(void) +RTE_INIT(pthread_intercept_ctor) { override = 0; /* diff --git a/lib/librte_acl/rte_acl.c b/lib/librte_acl/rte_acl.c index d1f40bef0..67f41f3d3 100644 --- a/lib/librte_acl/rte_acl.c +++ b/lib/librte_acl/rte_acl.c @@ -120,8 +120,7 @@ rte_acl_set_ctx_classify(struct rte_acl_ctx *ctx, enum rte_acl_classify_alg alg) * if both conditions are met: * at build time compiler supports AVX2 and target cpu supports AVX2. */ -static void __attribute__((constructor)) -rte_acl_init(void) +RTE_INIT(rte_acl_init) { enum rte_acl_classify_alg alg = RTE_ACL_CLASSIFY_DEFAULT; diff --git a/lib/librte_eal/common/arch/x86/rte_memcpy.c b/lib/librte_eal/common/arch/x86/rte_memcpy.c index 74ae702de..174bef155 100644 --- a/lib/librte_eal/common/arch/x86/rte_memcpy.c +++ b/lib/librte_eal/common/arch/x86/rte_memcpy.c @@ -37,8 +37,7 @@ void *(*rte_memcpy_ptr)(void *dst, const void *src, size_t n) = NULL; -static void __attribute__((constructor)) -rte_memcpy_init(void) +RTE_INIT(rte_memcpy_init) { #ifdef CC_SUPPORT_AVX512F if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F)) { diff --git a/lib/librte_eal/common/arch/x86/rte_spinlock.c b/lib/librte_eal/common/arch/x86/rte_spinlock.c index c383e9f0d..1244a90b5 100644 --- a/lib/librte_eal/common/arch/x86/rte_spinlock.c +++ b/lib/librte_eal/common/arch/x86/rte_spinlock.c @@ -38,8 +38,7 @@ uint8_t rte_rtm_supported; /* cache the flag to avoid the overhead of the rte_cpu_get_flag_enabled function */ -static void __attribute__((constructor)) -rte_rtm_init(void) +RTE_INIT(rte_rtm_init) { rte_rtm_supported = rte_cpu_get_flag_enabled(RTE_CPUFLAG_RTM); } diff --git a/lib/librte_eal/common/eal_common_timer.c b/lib/librte_eal/common/eal_common_timer.c index 5980b294e..568ae2fdb 100644 --- a/lib/librte_eal/common/eal_common_timer.c +++ b/lib/librte_eal/common/eal_common_timer.c @@ -97,8 +97,7 @@ void rte_delay_us_callback_register(void (*userfunc)(unsigned int)) rte_delay_us = userfunc; } -static void __attribute__((constructor)) -rte_timer_init(void) +RTE_INIT(rte_timer_init) { /* set rte_delay_us_block as a delay function */ rte_delay_us_callback_register(rte_delay_us_block); diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h index 1afc66e3f..de853e164 100644 --- a/lib/librte_eal/common/include/rte_common.h +++ b/lib/librte_eal/common/include/rte_common.h @@ -108,6 +108,29 @@ typedef uint16_t unaligned_uint16_t; */ #define RTE_SET_USED(x) (void)(x) +/** + * Run function before main() with low priority. + * + * The constructor will be run after prioritized constructors. + * + * @param func + * Constructor function. + */ +#define RTE_INIT(func) \ +static void __attribute__((constructor, used)) func(void) + +/** + * Run function before main() with high priority. + * + * @param func + * Constructor function. + * @param prio + * Priority number must be above 100. + * Lowest number is the first to run. + */ +#define RTE_INIT_PRIO(func, prio) \ +static void __attribute__((constructor(prio), used)) func(void) + /** * Force a function to be inlined */ diff --git a/lib/librte_eal/common/include/rte_eal.h b/lib/librte_eal/common/include/rte_eal.h index c1b8e2fb8..09b66819a 100644 --- a/lib/librte_eal/common/include/rte_eal.h +++ b/lib/librte_eal/common/include/rte_eal.h @@ -335,29 +335,6 @@ enum rte_iova_mode rte_eal_iova_mode(void); const char * rte_eal_mbuf_default_mempool_ops(void); -/** - * Run function before main() with low priority. - * - * The constructor will be run after prioritized constructors. - * - * @param func - * Constructor function. - */ -#define RTE_INIT(func) \ -static void __attribute__((constructor, used)) func(void) - -/** - * Run function before main() with high priority. - * - * @param func - * Constructor function. - * @param prio - * Priority number must be above 100. - * Lowest number is the first to run. - */ -#define RTE_INIT_PRIO(func, prio) \ -static void __attribute__((constructor(prio), used)) func(void) - #ifdef __cplusplus } #endif diff --git a/lib/librte_hash/rte_crc_arm64.h b/lib/librte_hash/rte_crc_arm64.h index 774428be0..a3c216bb7 100644 --- a/lib/librte_hash/rte_crc_arm64.h +++ b/lib/librte_hash/rte_crc_arm64.h @@ -116,8 +116,7 @@ rte_hash_crc_set_alg(uint8_t alg) } /* Setting the best available algorithm */ -static inline void __attribute__((constructor)) -rte_hash_crc_init_alg(void) +RTE_INIT(rte_hash_crc_init_alg) { rte_hash_crc_set_alg(CRC32_ARM64); } diff --git a/lib/librte_hash/rte_hash_crc.h b/lib/librte_hash/rte_hash_crc.h index ea6be5224..4f815aea8 100644 --- a/lib/librte_hash/rte_hash_crc.h +++ b/lib/librte_hash/rte_hash_crc.h @@ -480,8 +480,7 @@ rte_hash_crc_set_alg(uint8_t alg) } /* Setting the best available algorithm */ -static inline void __attribute__((constructor)) -rte_hash_crc_init_alg(void) +RTE_INIT(rte_hash_crc_init_alg) { rte_hash_crc_set_alg(CRC32_SSE42_x64); } diff --git a/lib/librte_net/rte_net_crc.c b/lib/librte_net/rte_net_crc.c index 661fe3225..0c1bf51af 100644 --- a/lib/librte_net/rte_net_crc.c +++ b/lib/librte_net/rte_net_crc.c @@ -205,8 +205,7 @@ rte_net_crc_calc(const void *data, } /* Select highest available crc algorithm as default one */ -static inline void __attribute__((constructor)) -rte_net_crc_init(void) +RTE_INIT(rte_net_crc_init) { enum rte_net_crc_alg alg = RTE_NET_CRC_SCALAR; -- 2.14.2