Cleanup: always use sysconf to get the page size
authorMichael Jeanson <mjeanson@efficios.com>
Wed, 6 Oct 2021 16:30:25 +0000 (12:30 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 15 Oct 2021 20:03:32 +0000 (16:03 -0400)
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 <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/main.c
src/common/align.h
src/common/defaults.c
tests/regression/tools/trigger/hidden/hidden_trigger.c
tests/utils/testapp/gen-syscall-events/gen-syscall-events.c

index 868f9a4a9261cff9e68458d2e0c33ba9aa1f12fa..4effb3ce9f4cc703ff8c8e498b59ee63933e8939 100644 (file)
@@ -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);
        }
index 024faf7fb5d9e32b6a39114d484e42c27d1ee9e4..dff6c91d69b23a166954ea6f74146f94dde3bde9 100644 (file)
@@ -9,13 +9,6 @@
 #define _LTTNG_ALIGN_H
 
 #include "bug.h"
-#include <unistd.h>
-#include <limits.h>
-
-#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
index 4a5fef8689bc776e7aaa68be161f4e8ceeae4505..2550784cf1b01cf834f695e51e16c3cadf58d7a7 100644 (file)
 
 #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)
index 5395dd22441cd94e744dcf935c5f5b5102baf6c8..8edd97ab2a22f2f79cb48efc886d2d2d37979489 100644 (file)
@@ -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;
index 1a2882f99780bf4ed865c4be2842199763a7c59e..6a246867d39c824422e0db778ecdf85ef46528fc 100644 (file)
@@ -37,7 +37,7 @@ void prefault_string(const char *p)
                 * for reading.
                 */
                asm volatile("" : : "m"(*p));
-               p += PAGE_SIZE;
+               p += sysconf(_SC_PAGE_SIZE);
        }
 }
 
This page took 0.030074 seconds and 4 git commands to generate.