Skip to content

Commit 61a3414

Browse files
authored
Merge pull request #2482 from hodgesds/percpu-cpufreq
percpu: Add helper to get cpufreq_policy
2 parents 6df03a2 + b91d8bf commit 61a3414

File tree

1 file changed

+48
-25
lines changed

1 file changed

+48
-25
lines changed

scheds/include/scx/percpu.bpf.h

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,51 +24,74 @@ extern struct sugov_cpu sugov_cpu __ksym __weak;
2424
extern struct psi_group_cpu psi_group_cpu __ksym __weak;
2525
extern struct kernel_stat kernel_stat __ksym __weak;
2626
extern struct kernel_cpustat kernel_cpustat __ksym __weak;
27+
extern struct cpufreq_policy* cpufreq_cpu_data __ksym __weak;
2728

28-
#define DEFINE_PER_CPU_PTR_FUNC(func_name, type, var_name) \
29-
type *func_name(s32 cpu) { \
30-
type *ptr; \
31-
if (!&var_name) \
32-
return NULL; \
33-
ptr = bpf_per_cpu_ptr(&var_name, cpu); \
34-
if (!ptr) \
35-
return NULL; \
36-
return ptr; \
29+
30+
#define DEFINE_PER_CPU_PTR_FUNC(func_name, type, var_name) \
31+
type *func_name(s32 cpu) \
32+
{ \
33+
type *ptr; \
34+
\
35+
if (!&var_name) \
36+
return NULL; \
37+
\
38+
ptr = bpf_per_cpu_ptr(&var_name, cpu); \
39+
if (!ptr) \
40+
return NULL; \
41+
return ptr; \
42+
}
43+
44+
45+
#define DEFINE_PER_CPU_PTR_PTR_FUNC(func_name, type, per_cpu_var_name) \
46+
static __always_inline type func_name(s32 cpu) \
47+
{ \
48+
type *ptr_to_per_cpu_var = bpf_per_cpu_ptr(&per_cpu_var_name, cpu); \
49+
\
50+
if (!ptr_to_per_cpu_var) \
51+
return NULL; \
52+
return *ptr_to_per_cpu_var; \
3753
}
3854

39-
#define DEFINE_PER_CPU_VAL_FUNC(func_name, type, var_name) \
40-
type func_name(s32 cpu) { \
41-
type *ptr; \
42-
ptr = bpf_per_cpu_ptr(&var_name, cpu); \
43-
if (!ptr) \
44-
return -EINVAL; \
45-
return *ptr; \
55+
56+
#define DEFINE_PER_CPU_VAL_FUNC(func_name, type, var_name) \
57+
type func_name(s32 cpu) { \
58+
type *ptr; \
59+
\
60+
ptr = bpf_per_cpu_ptr(&var_name, cpu); \
61+
if (!ptr) \
62+
return -EINVAL; \
63+
return *ptr; \
4664
}
4765

4866
#define DEFINE_THIS_CPU_VAL_FUNC(orig_func_name) \
4967
static inline typeof(orig_func_name(0)) this_##orig_func_name(void) { \
50-
return orig_func_name(bpf_get_smp_processor_id()); \
68+
return orig_func_name(bpf_get_smp_processor_id()); \
5169
}
5270

5371
#define DEFINE_THIS_CPU_PTR_FUNC(orig_func_name) \
5472
static inline typeof(orig_func_name(0)) this_##orig_func_name(void) { \
55-
return orig_func_name(bpf_get_smp_processor_id()); \
73+
return orig_func_name(bpf_get_smp_processor_id()); \
5674
}
5775

5876
DEFINE_PER_CPU_VAL_FUNC(cpu_llc_size, int, sd_llc_size)
5977
DEFINE_PER_CPU_VAL_FUNC(cpu_llc_id, int, sd_llc_id)
6078
DEFINE_PER_CPU_VAL_FUNC(cpu_priority, int, sched_core_priority)
61-
DEFINE_PER_CPU_PTR_FUNC(cpu_sugov, struct sugov_cpu, sugov_cpu)
62-
DEFINE_PER_CPU_PTR_FUNC(cpu_psi_group, struct psi_group_cpu, psi_group_cpu)
63-
DEFINE_PER_CPU_PTR_FUNC(cpu_kernel_stat, struct kernel_stat, kernel_stat)
79+
80+
DEFINE_PER_CPU_PTR_PTR_FUNC(cpu_cpufreq_policy, struct cpufreq_policy*, cpufreq_cpu_data)
81+
6482
DEFINE_PER_CPU_PTR_FUNC(cpu_kernel_cpustat, struct kernel_cpustat, kernel_cpustat)
83+
DEFINE_PER_CPU_PTR_FUNC(cpu_kernel_stat, struct kernel_stat, kernel_stat)
84+
DEFINE_PER_CPU_PTR_FUNC(cpu_psi_group, struct psi_group_cpu, psi_group_cpu)
85+
DEFINE_PER_CPU_PTR_FUNC(cpu_sugov, struct sugov_cpu, sugov_cpu)
6586

66-
DEFINE_THIS_CPU_VAL_FUNC(cpu_llc_size)
6787
DEFINE_THIS_CPU_VAL_FUNC(cpu_llc_id)
88+
DEFINE_THIS_CPU_VAL_FUNC(cpu_llc_size)
6889
DEFINE_THIS_CPU_VAL_FUNC(cpu_priority)
69-
DEFINE_THIS_CPU_PTR_FUNC(cpu_sugov)
70-
DEFINE_THIS_CPU_PTR_FUNC(cpu_psi_group)
71-
DEFINE_THIS_CPU_PTR_FUNC(cpu_kernel_stat)
90+
91+
DEFINE_THIS_CPU_PTR_FUNC(cpu_cpufreq_policy)
7292
DEFINE_THIS_CPU_PTR_FUNC(cpu_kernel_cpustat)
93+
DEFINE_THIS_CPU_PTR_FUNC(cpu_kernel_stat)
94+
DEFINE_THIS_CPU_PTR_FUNC(cpu_psi_group)
95+
DEFINE_THIS_CPU_PTR_FUNC(cpu_sugov)
7396

7497
#endif /* BPF_PERCPU_H */

0 commit comments

Comments
 (0)