__type(value, struct hist);
} hists SEC(".maps");
+#define clamp_umax(VAR, UMAX) \
+ asm volatile ( \
+ "if %0 <= %[max] goto +1\n" \
+ "%0 = %[max]\n" \
+ : "+r"(VAR) \
+ : [max]"i"(UMAX) \
+ )
+
SEC("tp_btf/cpu_frequency")
int BPF_PROG(cpu_frequency, unsigned int state, unsigned int cpu_id)
{
if (cpu_id >= MAX_CPU_NR)
return 0;
+
+ clamp_umax(cpu_id, MAX_CPU_NR - 1);
freqs_mhz[cpu_id] = state / 1000;
return 0;
}
if (cpu >= MAX_CPU_NR)
return 0;
+ clamp_umax(cpu, MAX_CPU_NR - 1);
freq_mhz = freqs_mhz[cpu];
if (!freq_mhz)
return 0;
return -1;
}
links[i] = bpf_program__attach_perf_event(prog, fd);
- if (libbpf_get_error(links[i])) {
- fprintf(stderr, "failed to attach perf event on cpu: "
- "%d\n", i);
- links[i] = NULL;
+ if (!links[i]) {
+ fprintf(stderr, "failed to attach perf event on cpu: %d\n", i);
close(fd);
return -1;
}
printf("\n");
print_linear_hist(bss->syswide.slots, MAX_SLOTS, 0, HIST_STEP_SIZE,
- "syswide");
+ "syswide");
}
int main(int argc, char **argv)
if (err)
return err;
+ libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
libbpf_set_print(libbpf_print_fn);
- err = bump_memlock_rlimit();
- if (err) {
- fprintf(stderr, "failed to increase rlimit: %d\n", err);
- return 1;
- }
-
nr_cpus = libbpf_num_possible_cpus();
if (nr_cpus < 0) {
fprintf(stderr, "failed to get # of possible cpus: '%s'!\n",