Commit | Line | Data |
---|---|---|
74cc1f59 | 1 | /* |
4159f029 | 2 | * SPDX-License-Identifier: MIT |
74cc1f59 MJ |
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 | ||
feac7204 MJ |
10 | #define LTTNG_UST_CPUMASK_SIZE 4096 |
11 | ||
fb0f6ca9 MJ |
12 | /* |
13 | * Get a CPU 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 | * path: file path to read the mask from. | |
18 | * | |
19 | * Returns the number of bytes read or -1 on error. | |
20 | */ | |
21 | int get_cpu_mask_from_sysfs(char *buf, size_t max_bytes, const char *path) | |
22 | __attribute__((visibility("hidden"))); | |
23 | ||
66dbdc34 MJ |
24 | /* |
25 | * Get the CPU possible mask string from sysfs. | |
26 | * | |
27 | * buf: the buffer where the mask will be read. | |
28 | * max_bytes: the maximum number of bytes to write in the buffer. | |
29 | * | |
30 | * Returns the number of bytes read or -1 on error. | |
31 | */ | |
32 | int get_possible_cpu_mask_from_sysfs(char *buf, size_t max_bytes) | |
33 | __attribute__((visibility("hidden"))); | |
34 | ||
fb0f6ca9 MJ |
35 | /* |
36 | * Get the highest CPU id from sysfs. | |
37 | * | |
38 | * Iterate on all the folders in "/sys/devices/system/cpu" that start with | |
39 | * "cpu" followed by an integer, keep the highest CPU id encountered during | |
40 | * this iteration and add 1 to get a number of CPUs. | |
41 | * | |
42 | * Returns the highest CPU id, or -1 on error. | |
43 | */ | |
44 | int get_max_cpuid_from_sysfs(void) | |
45 | __attribute__((visibility("hidden"))); | |
46 | ||
47 | int _get_max_cpuid_from_sysfs(const char *path) | |
48 | __attribute__((visibility("hidden"))); | |
49 | ||
66dbdc34 MJ |
50 | /* |
51 | * Get the number of possible CPUs in the system from either | |
52 | * sysconf(_SC_NPROCESSORS_CONF) or some other mechanism depending on the libc. | |
53 | * | |
54 | * Returns the number of possible CPUs in the system or 0 on error. | |
55 | */ | |
56 | int get_num_possible_cpus_fallback(void) | |
57 | __attribute__((visibility("hidden"))); | |
58 | ||
59 | /* | |
a616fb4e | 60 | * Get the highest CPU id from a CPU mask. |
66dbdc34 MJ |
61 | * |
62 | * pmask: the mask to parse. | |
63 | * len: the len of the mask excluding '\0'. | |
64 | * | |
a616fb4e | 65 | * Returns the highest CPU id from the mask or -1 on error. |
66dbdc34 | 66 | */ |
a616fb4e | 67 | int get_max_cpuid_from_mask(const char *pmask, size_t len) |
66dbdc34 MJ |
68 | __attribute__((visibility("hidden"))); |
69 | ||
74cc1f59 | 70 | /* |
a616fb4e MJ |
71 | * Returns the length of an array that could contain a per-CPU element for each |
72 | * possible CPU id for the lifetime of the process. | |
73 | * | |
74 | * We currently assume CPU ids are contiguous up the maximum CPU id. | |
75 | * | |
76 | * If the cache is not yet initialized, get the value from | |
77 | * "/sys/devices/system/cpu/possible" or fallback to sysconf and cache it. | |
74cc1f59 | 78 | * |
66dbdc34 | 79 | * If all methods fail, don't populate the cache and return 0. |
74cc1f59 | 80 | */ |
a616fb4e | 81 | int get_possible_cpus_array_len(void) |
95fa2ba4 | 82 | __attribute__((visibility("hidden"))); |
74cc1f59 MJ |
83 | |
84 | #define for_each_possible_cpu(cpu) \ | |
a616fb4e | 85 | for ((cpu) = 0; (cpu) < get_possible_cpus_array_len(); (cpu)++) |
74cc1f59 MJ |
86 | |
87 | #endif /* _UST_COMMON_SMP_H */ |