From: Michael Jeanson Date: Wed, 6 Oct 2021 16:30:25 +0000 (-0400) Subject: Cleanup: always use sysconf to get the page size X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=81663f073dbfb4b61c06a0ceb8ca33c4fc41b1c5;p=lttng-tools.git Cleanup: always use sysconf to get the page size Use 'sysconf(_SC_PAGE_SIZE)' across the code base which is works on all our supported platforms. Change-Id: I4231d45e0b03301de1274c0a5a4903cd17b4a80a Signed-off-by: Michael Jeanson Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 868f9a4a9..4effb3ce9 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -1472,9 +1472,9 @@ int main(int argc, char **argv) goto exit_set_signal_handler; } - the_page_size = sysconf(_SC_PAGESIZE); + the_page_size = sysconf(_SC_PAGE_SIZE); if (the_page_size < 0) { - PERROR("sysconf _SC_PAGESIZE"); + PERROR("sysconf _SC_PAGE_SIZE"); the_page_size = LONG_MAX; WARN("Fallback page size to %ld", the_page_size); } diff --git a/src/common/align.h b/src/common/align.h index 024faf7fb..dff6c91d6 100644 --- a/src/common/align.h +++ b/src/common/align.h @@ -9,13 +9,6 @@ #define _LTTNG_ALIGN_H #include "bug.h" -#include -#include - -#ifndef PAGE_SIZE /* Cygwin limits.h defines its own PAGE_SIZE. */ -#define PAGE_SIZE sysconf(_SC_PAGE_SIZE) -#endif - /* * Align value to the next multiple of align. Returns val if it already is a diff --git a/src/common/defaults.c b/src/common/defaults.c index 4a5fef868..2550784cf 100644 --- a/src/common/defaults.c +++ b/src/common/defaults.c @@ -14,35 +14,49 @@ #include "defaults.h" #include "macros.h" -#include "align.h" #include "error.h" static int pthread_attr_init_done; static pthread_attr_t tattr; +static size_t get_page_size(void) +{ + const long ret = sysconf(_SC_PAGE_SIZE); + + if (ret < 0) { + /* + * Fatal error since there is no safe way to recover from this. + */ + PERROR("Failed to get system page size using sysconf(_SC_PAGE_SIZE)"); + abort(); + } + + return (size_t) ret; +} + size_t default_get_channel_subbuf_size(void) { - return max(_DEFAULT_CHANNEL_SUBBUF_SIZE, PAGE_SIZE); + return max(_DEFAULT_CHANNEL_SUBBUF_SIZE, get_page_size()); } size_t default_get_metadata_subbuf_size(void) { - return max(DEFAULT_METADATA_SUBBUF_SIZE, PAGE_SIZE); + return max(DEFAULT_METADATA_SUBBUF_SIZE, get_page_size()); } size_t default_get_kernel_channel_subbuf_size(void) { - return max(DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE, PAGE_SIZE); + return max(DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE, get_page_size()); } size_t default_get_ust_pid_channel_subbuf_size(void) { - return max(DEFAULT_UST_PID_CHANNEL_SUBBUF_SIZE, PAGE_SIZE); + return max(DEFAULT_UST_PID_CHANNEL_SUBBUF_SIZE, get_page_size()); } size_t default_get_ust_uid_channel_subbuf_size(void) { - return max(DEFAULT_UST_UID_CHANNEL_SUBBUF_SIZE, PAGE_SIZE); + return max(DEFAULT_UST_UID_CHANNEL_SUBBUF_SIZE, get_page_size()); } pthread_attr_t *default_pthread_attr(void) diff --git a/tests/regression/tools/trigger/hidden/hidden_trigger.c b/tests/regression/tools/trigger/hidden/hidden_trigger.c index 5395dd224..8edd97ab2 100644 --- a/tests/regression/tools/trigger/hidden/hidden_trigger.c +++ b/tests/regression/tools/trigger/hidden/hidden_trigger.c @@ -70,7 +70,7 @@ int setup_session_with_size_rotation_schedule(const char *session_output_path) .name = TEST_CHANNEL_NAME, .enabled = 1, .attr.overwrite = -1, - .attr.subbuf_size = sysconf(_SC_PAGESIZE) * 8, + .attr.subbuf_size = sysconf(_SC_PAGE_SIZE) * 8, .attr.num_subbuf = 8, .attr.output = LTTNG_EVENT_MMAP, }; @@ -123,7 +123,7 @@ int setup_session_with_size_rotation_schedule(const char *session_output_path) * time. */ rotation_status = lttng_rotation_schedule_size_threshold_set_threshold( - rotation_schedule, sysconf(_SC_PAGESIZE) * 4096); + rotation_schedule, sysconf(_SC_PAGE_SIZE) * 4096); if (rotation_status != LTTNG_ROTATION_STATUS_OK) { fail("Failed to set size threshold of session rotation schedule"); ret = -1; diff --git a/tests/utils/testapp/gen-syscall-events/gen-syscall-events.c b/tests/utils/testapp/gen-syscall-events/gen-syscall-events.c index 1a2882f99..6a246867d 100644 --- a/tests/utils/testapp/gen-syscall-events/gen-syscall-events.c +++ b/tests/utils/testapp/gen-syscall-events/gen-syscall-events.c @@ -37,7 +37,7 @@ void prefault_string(const char *p) * for reading. */ asm volatile("" : : "m"(*p)); - p += PAGE_SIZE; + p += sysconf(_SC_PAGE_SIZE); } }