Linux Audio

Check our new training course

Linux debugging, profiling, tracing and performance analysis training

Mar 24-27, 2025, special US time zones
Register
Loading...
Note: File does not exist in v3.1.
 1#ifndef __BPF_UTIL__
 2#define __BPF_UTIL__
 3
 4#include <stdio.h>
 5#include <stdlib.h>
 6#include <string.h>
 7#include <errno.h>
 8
 9static inline unsigned int bpf_num_possible_cpus(void)
10{
11	static const char *fcpu = "/sys/devices/system/cpu/possible";
12	unsigned int start, end, possible_cpus = 0;
13	char buff[128];
14	FILE *fp;
15
16	fp = fopen(fcpu, "r");
17	if (!fp) {
18		printf("Failed to open %s: '%s'!\n", fcpu, strerror(errno));
19		exit(1);
20	}
21
22	while (fgets(buff, sizeof(buff), fp)) {
23		if (sscanf(buff, "%u-%u", &start, &end) == 2) {
24			possible_cpus = start == 0 ? end + 1 : 0;
25			break;
26		}
27	}
28
29	fclose(fp);
30	if (!possible_cpus) {
31		printf("Failed to retrieve # possible CPUs!\n");
32		exit(1);
33	}
34
35	return possible_cpus;
36}
37
38#endif /* __BPF_UTIL__ */