Commit | Line | Data |
---|---|---|
74cc1f59 MJ |
1 | /* |
2 | * SPDX-License-Identifier: LGPL-2.1-only | |
3 | * | |
4 | * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
5 | */ | |
6 | ||
7 | #ifndef _UST_COMMON_SMP_H | |
8 | #define _UST_COMMON_SMP_H | |
9 | ||
73beabae MJ |
10 | #define LTTNG_UST_CPUMASK_SIZE 4096 |
11 | ||
022c53ed MJ |
12 | /* |
13 | * Get the CPU possible mask string from sysfs. | |
14 | * | |
15 | * buf: the buffer where the mask will be read. | |
16 | * max_bytes: the maximum number of bytes to write in the buffer. | |
17 | * | |
18 | * Returns the number of bytes read or -1 on error. | |
19 | */ | |
20 | int get_possible_cpu_mask_from_sysfs(char *buf, size_t max_bytes) | |
21 | __attribute__((visibility("hidden"))); | |
22 | ||
23 | /* | |
24 | * Get the number of possible CPUs in the system from either | |
25 | * sysconf(_SC_NPROCESSORS_CONF) or some other mechanism depending on the libc. | |
26 | * | |
27 | * Returns the number of possible CPUs in the system or 0 on error. | |
28 | */ | |
29 | int get_num_possible_cpus_fallback(void) | |
30 | __attribute__((visibility("hidden"))); | |
31 | ||
32 | /* | |
79030bb7 | 33 | * Get the highest CPU id from a CPU mask. |
022c53ed MJ |
34 | * |
35 | * pmask: the mask to parse. | |
36 | * len: the len of the mask excluding '\0'. | |
37 | * | |
79030bb7 | 38 | * Returns the highest CPU id from the mask or -1 on error. |
022c53ed | 39 | */ |
79030bb7 | 40 | int get_max_cpuid_from_mask(const char *pmask, size_t len) |
022c53ed MJ |
41 | __attribute__((visibility("hidden"))); |
42 | ||
74cc1f59 | 43 | /* |
79030bb7 MJ |
44 | * Returns the length of an array that could contain a per-CPU element for each |
45 | * possible CPU id for the lifetime of the process. | |
46 | * | |
47 | * We currently assume CPU ids are contiguous up the maximum CPU id. | |
48 | * | |
49 | * If the cache is not yet initialized, get the value from | |
50 | * "/sys/devices/system/cpu/possible" or fallback to sysconf and cache it. | |
74cc1f59 | 51 | * |
022c53ed | 52 | * If all methods fail, don't populate the cache and return 0. |
74cc1f59 | 53 | */ |
79030bb7 | 54 | int get_possible_cpus_array_len(void) |
95fa2ba4 | 55 | __attribute__((visibility("hidden"))); |
74cc1f59 MJ |
56 | |
57 | #define for_each_possible_cpu(cpu) \ | |
79030bb7 | 58 | for ((cpu) = 0; (cpu) < get_possible_cpus_array_len(); (cpu)++) |
74cc1f59 MJ |
59 | |
60 | #endif /* _UST_COMMON_SMP_H */ |