From: Jérémie Galarneau Date: Tue, 20 Oct 2015 15:08:54 +0000 (-0400) Subject: Don't initialize defaults in library constructor X-Git-Tag: v2.8.0-rc1~247 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=78d8fb4ff7f6bfd6bf84994bd94a0edec6de0825;p=lttng-tools.git Don't initialize defaults in library constructor This is done so lttng-tools has no dependency on constructors being run, such as in the case of a static build. Signed-off-by: Jérémie Galarneau --- diff --git a/src/common/defaults.c b/src/common/defaults.c index e670eeb0f..d131971ec 100644 --- a/src/common/defaults.c +++ b/src/common/defaults.c @@ -21,33 +21,40 @@ #include "defaults.h" #include "macros.h" +#include "align.h" -size_t default_channel_subbuf_size; -size_t default_metadata_subbuf_size; -size_t default_kernel_channel_subbuf_size; -size_t default_ust_pid_channel_subbuf_size; -size_t default_ust_uid_channel_subbuf_size; +static size_t default_channel_subbuf_size; +static size_t default_metadata_subbuf_size; +static size_t default_kernel_channel_subbuf_size; +static size_t default_ust_pid_channel_subbuf_size; +static size_t default_ust_uid_channel_subbuf_size; -static void __attribute__((constructor)) init_defaults(void) +LTTNG_HIDDEN +size_t default_get_channel_subbuf_size(void) { - /* - * The libringbuffer won't accept subbuf sizes smaller than the page size. - * If the default subbuf size is smaller, replace it by the page size. - */ - long page_size = sysconf(_SC_PAGESIZE); - - if (page_size < 0) { - page_size = 0; - } - - default_channel_subbuf_size = - max(_DEFAULT_CHANNEL_SUBBUF_SIZE, page_size); - default_metadata_subbuf_size = - max(DEFAULT_METADATA_SUBBUF_SIZE, page_size); - default_kernel_channel_subbuf_size = - max(DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE, page_size); - default_ust_pid_channel_subbuf_size = - max(DEFAULT_UST_PID_CHANNEL_SUBBUF_SIZE, page_size); - default_ust_uid_channel_subbuf_size = - max(DEFAULT_UST_UID_CHANNEL_SUBBUF_SIZE, page_size); + return max(_DEFAULT_CHANNEL_SUBBUF_SIZE, PAGE_SIZE); +} + +LTTNG_HIDDEN +size_t default_get_metadata_subbuf_size(void) +{ + return max(DEFAULT_METADATA_SUBBUF_SIZE, PAGE_SIZE); +} + +LTTNG_HIDDEN +size_t default_get_kernel_channel_subbuf_size(void) +{ + return max(DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE, PAGE_SIZE); +} + +LTTNG_HIDDEN +size_t default_get_ust_pid_channel_subbuf_size(void) +{ + return max(DEFAULT_UST_PID_CHANNEL_SUBBUF_SIZE, PAGE_SIZE); +} + +LTTNG_HIDDEN +size_t default_get_ust_uid_channel_subbuf_size(void) +{ + return max(DEFAULT_UST_UID_CHANNEL_SUBBUF_SIZE, PAGE_SIZE); } diff --git a/src/common/defaults.h b/src/common/defaults.h index cba94c916..6bf06becd 100644 --- a/src/common/defaults.h +++ b/src/common/defaults.h @@ -1,6 +1,7 @@ /* * Copyright (C) 2011 - David Goulet * Mathieu Desnoyers + * 2015 - Jérémie Galarneau * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2 only, @@ -19,6 +20,8 @@ #ifndef _DEFAULTS_H #define _DEFAULTS_H +#include + /* Default unix group name for tracing. */ #define DEFAULT_TRACING_GROUP "tracing" @@ -303,23 +306,14 @@ /* Default runas worker name */ #define DEFAULT_RUN_AS_WORKER_NAME "lttng-runas" -extern size_t default_channel_subbuf_size; -extern size_t default_metadata_subbuf_size; -extern size_t default_ust_pid_channel_subbuf_size; -extern size_t default_ust_uid_channel_subbuf_size; -extern size_t default_kernel_channel_subbuf_size; - /* * Returns the default subbuf size. * * This function depends on a value that is set at constructor time, so it is * unsafe to call it from another constructor. */ -static inline -size_t default_get_channel_subbuf_size(void) -{ - return default_channel_subbuf_size; -} +LTTNG_HIDDEN +size_t default_get_channel_subbuf_size(void); /* * Returns the default metadata subbuf size. @@ -327,11 +321,8 @@ size_t default_get_channel_subbuf_size(void) * This function depends on a value that is set at constructor time, so it is * unsafe to call it from another constructor. */ -static inline -size_t default_get_metadata_subbuf_size(void) -{ - return default_metadata_subbuf_size; -} +LTTNG_HIDDEN +size_t default_get_metadata_subbuf_size(void); /* * Returns the default subbuf size for the kernel domain. @@ -339,11 +330,8 @@ size_t default_get_metadata_subbuf_size(void) * This function depends on a value that is set at constructor time, so it is * unsafe to call it from another constructor. */ -static inline -size_t default_get_kernel_channel_subbuf_size(void) -{ - return default_kernel_channel_subbuf_size; -} +LTTNG_HIDDEN +size_t default_get_kernel_channel_subbuf_size(void); /* * Returns the default subbuf size for the UST domain per PID. @@ -351,11 +339,8 @@ size_t default_get_kernel_channel_subbuf_size(void) * This function depends on a value that is set at constructor time, so it is * unsafe to call it from another constructor. */ -static inline -size_t default_get_ust_pid_channel_subbuf_size(void) -{ - return default_ust_pid_channel_subbuf_size; -} +LTTNG_HIDDEN +size_t default_get_ust_pid_channel_subbuf_size(void); /* * Returns the default subbuf size for the UST domain per UID. @@ -363,10 +348,7 @@ size_t default_get_ust_pid_channel_subbuf_size(void) * This function depends on a value that is set at constructor time, so it is * unsafe to call it from another constructor. */ -static inline -size_t default_get_ust_uid_channel_subbuf_size(void) -{ - return default_ust_uid_channel_subbuf_size; -} +LTTNG_HIDDEN +size_t default_get_ust_uid_channel_subbuf_size(void); #endif /* _DEFAULTS_H */