-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathper-cpu.c
43 lines (34 loc) · 863 Bytes
/
per-cpu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
MODULE_LICENSE("GPL");
// Define my per-cpu variable
DEFINE_PER_CPU(int, x);
static int sma_init(void)
{
int num_cpus = num_online_cpus();
int i = 0;
int val;
pr_info("Number of cpus available:%d\n", num_cpus);
for (i = 0; i < num_cpus; i++) {
int value = per_cpu(x, i);
pr_info("Value of x is %d at Processor:%d\n", value, i);
}
val = get_cpu_var(x);
get_cpu_var(x) = 10;
put_cpu_var(x);
this_cpu_inc(x);
pr_info("Printing x value of all processor after updating current processor:%d\n",
smp_processor_id());
for (i = 0; i < num_cpus; i++) {
int value = per_cpu(x, i);
pr_info("Value of x is %d at Processor:%d\n", value, i);
}
return 0;
}
static void sma_exit(void)
{
pr_err("Goodbye, cruel world\n");
}
module_init(sma_init);
module_exit(sma_exit);