2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2024-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 #include "common/getenv.h"
9 #include "common/logging.h"
10 #include "common/populate.h"
12 enum populate_policy
{
16 POPULATE_CPU_POSSIBLE
,
21 static enum populate_policy map_populate_policy
= POPULATE_UNSET
;
23 static void init_map_populate_policy(void)
25 const char *populate_env_str
;
27 if (map_populate_policy
!= POPULATE_UNSET
)
30 populate_env_str
= lttng_ust_getenv("LTTNG_UST_MAP_POPULATE_POLICY");
31 if (!populate_env_str
) {
32 map_populate_policy
= POPULATE_NONE
;
35 if (!strcmp(populate_env_str
, "none")) {
36 map_populate_policy
= POPULATE_NONE
;
37 } else if (!strcmp(populate_env_str
, "cpu_possible")) {
38 map_populate_policy
= POPULATE_CPU_POSSIBLE
;
41 * populate_env_str is an untrusted environment variable
42 * input (can be provided to setuid/setgid binaries), so
43 * don't even try to print it.
45 WARN("Unknown policy for LTTNG_UST_MAP_POPULATE_POLICY environment variable.");
46 map_populate_policy
= POPULATE_UNKNOWN
;
51 * Return the shared page populate policy for global pages. Returns true
52 * if shared memory pages should be pre-populated, false otherwise.
54 bool lttng_ust_map_populate_is_enabled(void)
56 init_map_populate_policy();
58 switch (map_populate_policy
) {
59 case POPULATE_UNKNOWN
: /* Fall-through */
62 case POPULATE_CPU_POSSIBLE
:
71 * Return the shared page populate policy based on the @cpu number
72 * provided as input. Returns true if shared memory pages should be
73 * pre-populated, false otherwise.
75 * The @cpu argument is currently unused except for negative value
76 * validation. It is present to eventually match cpu affinity or cpu
77 * online masks if those features are added in the future.
79 bool lttng_ust_map_populate_cpu_is_enabled(int cpu
)
81 /* Reject invalid cpu number. */
85 return lttng_ust_map_populate_is_enabled();