X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=libringbuffer%2Fsmp.h;h=0db9e8418852129eeddea55c87bb24f644023638;hb=bb6e798cb47c1a16dbeaae168903ae9760838815;hp=479a9dc60a01c9810d166ed1944e8fc7dfb4ecb0;hpb=e92f3e285939848f248af08f11a39a04a7fcf852;p=lttng-ust.git diff --git a/libringbuffer/smp.h b/libringbuffer/smp.h index 479a9dc6..0db9e841 100644 --- a/libringbuffer/smp.h +++ b/libringbuffer/smp.h @@ -30,13 +30,55 @@ #define PER_CPU_MEM_SIZE 4096 extern int __num_possible_cpus; + +#define LTTNG_UST_CPUMASK_SIZE 4096 + +/* + * Get the CPU possible mask string from sysfs. + * + * buf: the buffer where the mask will be read. + * max_bytes: the maximum number of bytes to write in the buffer. + * + * Returns the number of bytes read or -1 on error. + */ +int get_possible_cpu_mask_from_sysfs(char *buf, size_t max_bytes) + __attribute__((visibility("hidden"))); + +/* + * Get the number of possible CPUs in the system from either + * sysconf(_SC_NPROCESSORS_CONF) or some other mechanism depending on the libc. + * + * Returns the number of possible CPUs in the system or 0 on error. + */ +int get_num_possible_cpus_fallback(void) + __attribute__((visibility("hidden"))); + +/* + * Get the number of CPUs from the possible cpu mask. + * + * pmask: the mask to parse. + * len: the len of the mask excluding '\0'. + * + * Returns the number of possible CPUs from the mask or 0 on error. + */ +int get_num_possible_cpus_from_mask(const char *pmask, size_t len) + __attribute__((visibility("hidden"))); + extern void _get_num_possible_cpus(void); +/* + * Returns the total number of CPUs in the system. If the cache is not yet + * initialized, get the value from "/sys/devices/system/cpu/possible" or + * fallback to sysconf and cache it. + * + * If all methods fail, don't populate the cache and return 0. + */ static inline int num_possible_cpus(void) { - if (!__num_possible_cpus) + if (caa_unlikely(!__num_possible_cpus)) _get_num_possible_cpus(); + return __num_possible_cpus; }