counter/shm.c \
counter/shm.h \
counter/shm_internal.h \
- counter/shm_types.h \
- counter/smp.c \
- counter/smp.h
+ counter/shm_types.h
libcounter_la_LIBADD = -lrt
ringbuffer/shm.h \
ringbuffer/shm_internal.h \
ringbuffer/shm_types.h \
- ringbuffer/smp.c \
- ringbuffer/smp.h \
ringbuffer/vatomic.h
libringbuffer_la_LIBADD = \
getenv.h \
logging.c \
logging.h \
+ smp.c \
+ smp.h \
strutils.c \
strutils.h \
patient.c
#include "common/align.h"
#include "common/bitmap.h"
-#include "smp.h"
+#include "common/smp.h"
#include "shm.h"
static size_t lttng_counter_get_dimension_nr_elements(struct lib_counter_dimension *dimension)
struct lib_counter_config *config = &counter->config;
struct lib_counter_layout *layout;
- if (cpu < 0 || cpu >= lttng_counter_num_possible_cpus())
+ if (cpu < 0 || cpu >= num_possible_cpus())
return -EINVAL;
if (!(config->alloc & COUNTER_ALLOC_PER_CPU))
int nr_counter_cpu_fds,
const int *counter_cpu_fds)
{
- int nr_cpus = lttng_counter_num_possible_cpus();
+ int nr_cpus = num_possible_cpus();
if (CAA_BITS_PER_LONG != 64 && config->counter_size == COUNTER_SIZE_64_BIT) {
WARN_ON_ONCE(1);
size_t dimension, nr_elem = 1;
int cpu, ret;
int nr_handles = 0;
- int nr_cpus = lttng_counter_num_possible_cpus();
+ int nr_cpus = num_possible_cpus();
if (validate_args(config, nr_dimensions, max_nr_elem,
global_sum_step, global_counter_fd, nr_counter_cpu_fds,
counter->percpu_counters = zmalloc(sizeof(struct lib_counter_layout) * nr_cpus);
if (!counter->percpu_counters)
goto error_alloc_percpu;
- lttng_counter_for_each_possible_cpu(cpu)
+ for_each_possible_cpu(cpu)
counter->percpu_counters[cpu].shm_fd = -1;
}
goto layout_init_error;
}
if ((config->alloc & COUNTER_ALLOC_PER_CPU) && counter_cpu_fds) {
- lttng_counter_for_each_possible_cpu(cpu) {
+ for_each_possible_cpu(cpu) {
ret = lttng_counter_layout_init(counter, cpu, counter_cpu_fds[cpu]);
if (ret)
goto layout_init_error;
struct lib_counter_layout *layout;
int shm_fd;
- if (cpu >= lttng_counter_num_possible_cpus())
+ if (cpu >= num_possible_cpus())
return -1;
layout = &counter->percpu_counters[cpu];
shm_fd = layout->shm_fd;
switch (config->alloc) {
case COUNTER_ALLOC_PER_CPU:
- if (cpu < 0 || cpu >= lttng_counter_num_possible_cpus())
+ if (cpu < 0 || cpu >= num_possible_cpus())
return -EINVAL;
layout = &counter->percpu_counters[cpu];
break;
case COUNTER_ALLOC_PER_CPU | COUNTER_ALLOC_GLOBAL:
if (cpu >= 0) {
- if (cpu >= lttng_counter_num_possible_cpus())
+ if (cpu >= num_possible_cpus())
return -EINVAL;
layout = &counter->percpu_counters[cpu];
} else {
break;
case COUNTER_ALLOC_PER_CPU | COUNTER_ALLOC_GLOBAL: /* Fallthrough */
case COUNTER_ALLOC_PER_CPU:
- lttng_counter_for_each_possible_cpu(cpu) {
+ for_each_possible_cpu(cpu) {
int64_t old = sum;
ret = lttng_counter_read(config, counter, dimension_indexes,
switch (config->alloc) {
case COUNTER_ALLOC_PER_CPU:
- if (cpu < 0 || cpu >= lttng_counter_num_possible_cpus())
+ if (cpu < 0 || cpu >= num_possible_cpus())
return -EINVAL;
layout = &counter->percpu_counters[cpu];
break;
case COUNTER_ALLOC_PER_CPU | COUNTER_ALLOC_GLOBAL:
if (cpu >= 0) {
- if (cpu >= lttng_counter_num_possible_cpus())
+ if (cpu >= num_possible_cpus())
return -EINVAL;
layout = &counter->percpu_counters[cpu];
} else {
switch (config->alloc) {
case COUNTER_ALLOC_PER_CPU: /* Fallthrough */
case COUNTER_ALLOC_PER_CPU | COUNTER_ALLOC_GLOBAL:
- lttng_counter_for_each_possible_cpu(cpu) {
+ for_each_possible_cpu(cpu) {
ret = lttng_counter_clear_cpu(config, counter, dimension_indexes, cpu);
if (ret < 0)
return ret;
+++ /dev/null
-/*
- * SPDX-License-Identifier: LGPL-2.1-only
- *
- * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- * Copyright (C) 2019 Michael Jeanson <mjeanson@efficios.com>
- */
-
-#define _LGPL_SOURCE
-
-#include <unistd.h>
-#include <pthread.h>
-#include "smp.h"
-
-int __lttng_counter_num_possible_cpus;
-
-#if (defined(__GLIBC__) || defined( __UCLIBC__))
-void _lttng_counter_get_num_possible_cpus(void)
-{
- int result;
-
- /* On Linux, when some processors are offline
- * _SC_NPROCESSORS_CONF counts the offline
- * processors, whereas _SC_NPROCESSORS_ONLN
- * does not. If we used _SC_NPROCESSORS_ONLN,
- * getcpu() could return a value greater than
- * this sysconf, in which case the arrays
- * indexed by processor would overflow.
- */
- result = sysconf(_SC_NPROCESSORS_CONF);
- if (result == -1)
- return;
- __lttng_counter_num_possible_cpus = result;
-}
-
-#else
-
-/*
- * The MUSL libc implementation of the _SC_NPROCESSORS_CONF sysconf does not
- * return the number of configured CPUs in the system but relies on the cpu
- * affinity mask of the current task.
- *
- * So instead we use a strategy similar to GLIBC's, counting the cpu
- * directories in "/sys/devices/system/cpu" and fallback on the value from
- * sysconf if it fails.
- */
-
-#include <dirent.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-
-#define __max(a,b) ((a)>(b)?(a):(b))
-
-void _lttng_counter_get_num_possible_cpus(void)
-{
- int result, count = 0;
- DIR *cpudir;
- struct dirent *entry;
-
- cpudir = opendir("/sys/devices/system/cpu");
- if (cpudir == NULL)
- goto end;
-
- /*
- * Count the number of directories named "cpu" followed by and
- * integer. This is the same strategy as glibc uses.
- */
- while ((entry = readdir(cpudir))) {
- if (entry->d_type == DT_DIR &&
- strncmp(entry->d_name, "cpu", 3) == 0) {
-
- char *endptr;
- unsigned long cpu_num;
-
- cpu_num = strtoul(entry->d_name + 3, &endptr, 10);
- if ((cpu_num < ULONG_MAX) && (endptr != entry->d_name + 3)
- && (*endptr == '\0')) {
- count++;
- }
- }
- }
-
-end:
- /*
- * Get the sysconf value as a fallback. Keep the highest number.
- */
- result = __max(sysconf(_SC_NPROCESSORS_CONF), count);
-
- /*
- * If both methods failed, don't store the value.
- */
- if (result < 1)
- return;
- __lttng_counter_num_possible_cpus = result;
-}
-#endif
+++ /dev/null
-/*
- * SPDX-License-Identifier: LGPL-2.1-only
- *
- * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- */
-
-#ifndef _LIBCOUNTER_SMP_H
-#define _LIBCOUNTER_SMP_H
-
-/*
- * 4kB of per-cpu data available.
- */
-#define LTTNG_COUNTER_PER_CPU_MEM_SIZE 4096
-
-extern int __lttng_counter_num_possible_cpus
- __attribute__((visibility("hidden")));
-
-extern void _lttng_counter_get_num_possible_cpus(void)
- __attribute__((visibility("hidden")));
-
-static inline
-int lttng_counter_num_possible_cpus(void)
-{
- if (!__lttng_counter_num_possible_cpus)
- _lttng_counter_get_num_possible_cpus();
- return __lttng_counter_num_possible_cpus;
-}
-
-#define lttng_counter_for_each_possible_cpu(cpu) \
- for ((cpu) = 0; (cpu) < lttng_counter_num_possible_cpus(); (cpu)++)
-
-#endif /* _LIBCOUNTER_SMP_H */
#include <urcu/compiler.h>
#include <urcu/uatomic.h>
-#include "smp.h"
+#include "common/smp.h"
/* Internal helpers */
#include "frontend_internal.h"
#include <urcu/compiler.h>
+#include "lib/lttng-ust/getcpu.h"
#include "frontend.h"
/**
#include "vatomic.h"
#include "backend.h"
#include "frontend.h"
-#include "smp.h"
+#include "common/smp.h"
#include "shm.h"
#include "common/align.h"
#include <lttng/ust-utils.h>
#include <lttng/ust-ringbuffer-context.h>
-#include "smp.h"
+#include "common/smp.h"
#include "ringbuffer-config.h"
#include "vatomic.h"
#include "backend.h"
+++ /dev/null
-/*
- * SPDX-License-Identifier: LGPL-2.1-only
- *
- * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- * Copyright (C) 2019 Michael Jeanson <mjeanson@efficios.com>
- */
-
-#define _LGPL_SOURCE
-#include <unistd.h>
-#include <pthread.h>
-#include "smp.h"
-
-int __num_possible_cpus;
-
-#if (defined(__GLIBC__) || defined( __UCLIBC__))
-void _get_num_possible_cpus(void)
-{
- int result;
-
- /* On Linux, when some processors are offline
- * _SC_NPROCESSORS_CONF counts the offline
- * processors, whereas _SC_NPROCESSORS_ONLN
- * does not. If we used _SC_NPROCESSORS_ONLN,
- * getcpu() could return a value greater than
- * this sysconf, in which case the arrays
- * indexed by processor would overflow.
- */
- result = sysconf(_SC_NPROCESSORS_CONF);
- if (result == -1)
- return;
- __num_possible_cpus = result;
-}
-
-#else
-
-/*
- * The MUSL libc implementation of the _SC_NPROCESSORS_CONF sysconf does not
- * return the number of configured CPUs in the system but relies on the cpu
- * affinity mask of the current task.
- *
- * So instead we use a strategy similar to GLIBC's, counting the cpu
- * directories in "/sys/devices/system/cpu" and fallback on the value from
- * sysconf if it fails.
- */
-
-#include <dirent.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-
-#define __max(a,b) ((a)>(b)?(a):(b))
-
-void _get_num_possible_cpus(void)
-{
- int result, count = 0;
- DIR *cpudir;
- struct dirent *entry;
-
- cpudir = opendir("/sys/devices/system/cpu");
- if (cpudir == NULL)
- goto end;
-
- /*
- * Count the number of directories named "cpu" followed by and
- * integer. This is the same strategy as glibc uses.
- */
- while ((entry = readdir(cpudir))) {
- if (entry->d_type == DT_DIR &&
- strncmp(entry->d_name, "cpu", 3) == 0) {
-
- char *endptr;
- unsigned long cpu_num;
-
- cpu_num = strtoul(entry->d_name + 3, &endptr, 10);
- if ((cpu_num < ULONG_MAX) && (endptr != entry->d_name + 3)
- && (*endptr == '\0')) {
- count++;
- }
- }
- }
-
-end:
- /*
- * Get the sysconf value as a fallback. Keep the highest number.
- */
- result = __max(sysconf(_SC_NPROCESSORS_CONF), count);
-
- /*
- * If both methods failed, don't store the value.
- */
- if (result < 1)
- return;
- __num_possible_cpus = result;
-}
-#endif
+++ /dev/null
-/*
- * SPDX-License-Identifier: LGPL-2.1-only
- *
- * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- */
-
-#ifndef _LIBRINGBUFFER_SMP_H
-#define _LIBRINGBUFFER_SMP_H
-
-#include "lib/lttng-ust/getcpu.h"
-
-/*
- * 4kB of per-cpu data available. Enough to hold the control structures,
- * but not ring buffers.
- */
-#define PER_CPU_MEM_SIZE 4096
-
-extern int __num_possible_cpus
- __attribute__((visibility("hidden")));
-
-extern void _get_num_possible_cpus(void)
- __attribute__((visibility("hidden")));
-
-static inline
-int num_possible_cpus(void)
-{
- if (!__num_possible_cpus)
- _get_num_possible_cpus();
- return __num_possible_cpus;
-}
-
-#define for_each_possible_cpu(cpu) \
- for ((cpu) = 0; (cpu) < num_possible_cpus(); (cpu)++)
-
-#endif /* _LIBRINGBUFFER_SMP_H */
--- /dev/null
+/*
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright (C) 2019 Michael Jeanson <mjeanson@efficios.com>
+ */
+
+#define _LGPL_SOURCE
+#include <unistd.h>
+#include <pthread.h>
+
+#include <urcu/compiler.h>
+
+#include "common/smp.h"
+
+static int num_possible_cpus_cache;
+
+#if (defined(__GLIBC__) || defined( __UCLIBC__))
+static void _get_num_possible_cpus(void)
+{
+ int result;
+
+ /* On Linux, when some processors are offline
+ * _SC_NPROCESSORS_CONF counts the offline
+ * processors, whereas _SC_NPROCESSORS_ONLN
+ * does not. If we used _SC_NPROCESSORS_ONLN,
+ * getcpu() could return a value greater than
+ * this sysconf, in which case the arrays
+ * indexed by processor would overflow.
+ */
+ result = sysconf(_SC_NPROCESSORS_CONF);
+ if (result == -1)
+ return;
+ num_possible_cpus_cache = result;
+}
+
+#else
+
+/*
+ * The MUSL libc implementation of the _SC_NPROCESSORS_CONF sysconf does not
+ * return the number of configured CPUs in the system but relies on the cpu
+ * affinity mask of the current task.
+ *
+ * So instead we use a strategy similar to GLIBC's, counting the cpu
+ * directories in "/sys/devices/system/cpu" and fallback on the value from
+ * sysconf if it fails.
+ */
+
+#include <dirent.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+
+#define __max(a,b) ((a)>(b)?(a):(b))
+
+static void _get_num_possible_cpus(void)
+{
+ int result, count = 0;
+ DIR *cpudir;
+ struct dirent *entry;
+
+ cpudir = opendir("/sys/devices/system/cpu");
+ if (cpudir == NULL)
+ goto end;
+
+ /*
+ * Count the number of directories named "cpu" followed by and
+ * integer. This is the same strategy as glibc uses.
+ */
+ while ((entry = readdir(cpudir))) {
+ if (entry->d_type == DT_DIR &&
+ strncmp(entry->d_name, "cpu", 3) == 0) {
+
+ char *endptr;
+ unsigned long cpu_num;
+
+ cpu_num = strtoul(entry->d_name + 3, &endptr, 10);
+ if ((cpu_num < ULONG_MAX) && (endptr != entry->d_name + 3)
+ && (*endptr == '\0')) {
+ count++;
+ }
+ }
+ }
+
+end:
+ /*
+ * Get the sysconf value as a fallback. Keep the highest number.
+ */
+ result = __max(sysconf(_SC_NPROCESSORS_CONF), count);
+
+ /*
+ * If both methods failed, don't store the value.
+ */
+ if (result < 1)
+ return;
+ num_possible_cpus_cache = result;
+}
+#endif
+
+/*
+ * Returns the total number of CPUs in the system. If the cache is not yet
+ * initialized, get the value from the system through sysconf and cache it.
+ *
+ * If the sysconf call fails, don't populate the cache and return 0.
+ */
+int num_possible_cpus(void)
+{
+ if (caa_unlikely(!num_possible_cpus_cache))
+ _get_num_possible_cpus();
+
+ return num_possible_cpus_cache;
+}
--- /dev/null
+/*
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ */
+
+#ifndef _UST_COMMON_SMP_H
+#define _UST_COMMON_SMP_H
+
+/*
+ * Returns the total number of CPUs in the system. If the cache is not yet
+ * initialized, get the value from the system through sysconf and cache it.
+ *
+ * If the sysconf call fails, don't populate the cache and return 0.
+ */
+int num_possible_cpus(void);
+
+#define for_each_possible_cpu(cpu) \
+ for ((cpu) = 0; (cpu) < num_possible_cpus(); (cpu)++)
+
+#endif /* _UST_COMMON_SMP_H */
#include "lib/lttng-ust/lttng-tracer-core.h"
#include "lib/lttng-ust/lttng-counter-client.h"
-#include "common/counter/smp.h"
+#include "common/smp.h"
#include "common/counter/counter.h"
/*
int ustctl_get_nr_cpu_per_counter(void)
{
- return lttng_counter_num_possible_cpus();
+ return num_possible_cpus();
}
struct ustctl_daemon_counter *