This source file includes following definitions.
- appldata_get_os_data
- appldata_os_init
- appldata_os_exit
1
2
3
4
5
6
7
8
9
10
11 #define KMSG_COMPONENT "appldata"
12 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13
14 #include <linux/module.h>
15 #include <linux/init.h>
16 #include <linux/slab.h>
17 #include <linux/errno.h>
18 #include <linux/kernel_stat.h>
19 #include <linux/netdevice.h>
20 #include <linux/sched.h>
21 #include <linux/sched/loadavg.h>
22 #include <linux/sched/stat.h>
23 #include <asm/appldata.h>
24 #include <asm/smp.h>
25
26 #include "appldata.h"
27
28
29
30
31
32
33
34
35
36
37
38
39
40 struct appldata_os_per_cpu {
41 u32 per_cpu_user;
42 u32 per_cpu_nice;
43 u32 per_cpu_system;
44 u32 per_cpu_idle;
45
46
47 u32 per_cpu_irq;
48 u32 per_cpu_softirq;
49 u32 per_cpu_iowait;
50
51
52 u32 per_cpu_steal;
53 u32 cpu_id;
54 } __attribute__((packed));
55
56 struct appldata_os_data {
57 u64 timestamp;
58 u32 sync_count_1;
59 u32 sync_count_2;
60
61
62
63
64 u32 nr_cpus;
65 u32 per_cpu_size;
66 u32 cpu_offset;
67
68 u32 nr_running;
69 u32 nr_threads;
70 u32 avenrun[3];
71
72
73
74 u32 nr_iowait;
75
76
77
78 struct appldata_os_per_cpu os_cpu[0];
79 } __attribute__((packed));
80
81 static struct appldata_os_data *appldata_os_data;
82
83 static struct appldata_ops ops = {
84 .name = "os",
85 .record_nr = APPLDATA_RECORD_OS_ID,
86 .owner = THIS_MODULE,
87 .mod_lvl = {0xF0, 0xF1},
88 };
89
90
91
92
93
94
95
96 static void appldata_get_os_data(void *data)
97 {
98 int i, j, rc;
99 struct appldata_os_data *os_data;
100 unsigned int new_size;
101
102 os_data = data;
103 os_data->sync_count_1++;
104
105 os_data->nr_threads = nr_threads;
106 os_data->nr_running = nr_running();
107 os_data->nr_iowait = nr_iowait();
108 os_data->avenrun[0] = avenrun[0] + (FIXED_1/200);
109 os_data->avenrun[1] = avenrun[1] + (FIXED_1/200);
110 os_data->avenrun[2] = avenrun[2] + (FIXED_1/200);
111
112 j = 0;
113 for_each_online_cpu(i) {
114 os_data->os_cpu[j].per_cpu_user =
115 nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_USER]);
116 os_data->os_cpu[j].per_cpu_nice =
117 nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_NICE]);
118 os_data->os_cpu[j].per_cpu_system =
119 nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM]);
120 os_data->os_cpu[j].per_cpu_idle =
121 nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_IDLE]);
122 os_data->os_cpu[j].per_cpu_irq =
123 nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_IRQ]);
124 os_data->os_cpu[j].per_cpu_softirq =
125 nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ]);
126 os_data->os_cpu[j].per_cpu_iowait =
127 nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_IOWAIT]);
128 os_data->os_cpu[j].per_cpu_steal =
129 nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_STEAL]);
130 os_data->os_cpu[j].cpu_id = i;
131 j++;
132 }
133
134 os_data->nr_cpus = j;
135
136 new_size = sizeof(struct appldata_os_data) +
137 (os_data->nr_cpus * sizeof(struct appldata_os_per_cpu));
138 if (ops.size != new_size) {
139 if (ops.active) {
140 rc = appldata_diag(APPLDATA_RECORD_OS_ID,
141 APPLDATA_START_INTERVAL_REC,
142 (unsigned long) ops.data, new_size,
143 ops.mod_lvl);
144 if (rc != 0)
145 pr_err("Starting a new OS data collection "
146 "failed with rc=%d\n", rc);
147
148 rc = appldata_diag(APPLDATA_RECORD_OS_ID,
149 APPLDATA_STOP_REC,
150 (unsigned long) ops.data, ops.size,
151 ops.mod_lvl);
152 if (rc != 0)
153 pr_err("Stopping a faulty OS data "
154 "collection failed with rc=%d\n", rc);
155 }
156 ops.size = new_size;
157 }
158 os_data->timestamp = get_tod_clock();
159 os_data->sync_count_2++;
160 }
161
162
163
164
165
166
167
168 static int __init appldata_os_init(void)
169 {
170 int rc, max_size;
171
172 max_size = sizeof(struct appldata_os_data) +
173 (num_possible_cpus() * sizeof(struct appldata_os_per_cpu));
174 if (max_size > APPLDATA_MAX_REC_SIZE) {
175 pr_err("Maximum OS record size %i exceeds the maximum "
176 "record size %i\n", max_size, APPLDATA_MAX_REC_SIZE);
177 rc = -ENOMEM;
178 goto out;
179 }
180
181 appldata_os_data = kzalloc(max_size, GFP_KERNEL | GFP_DMA);
182 if (appldata_os_data == NULL) {
183 rc = -ENOMEM;
184 goto out;
185 }
186
187 appldata_os_data->per_cpu_size = sizeof(struct appldata_os_per_cpu);
188 appldata_os_data->cpu_offset = offsetof(struct appldata_os_data,
189 os_cpu);
190
191 ops.data = appldata_os_data;
192 ops.callback = &appldata_get_os_data;
193 rc = appldata_register_ops(&ops);
194 if (rc != 0)
195 kfree(appldata_os_data);
196 out:
197 return rc;
198 }
199
200
201
202
203
204
205 static void __exit appldata_os_exit(void)
206 {
207 appldata_unregister_ops(&ops);
208 kfree(appldata_os_data);
209 }
210
211
212 module_init(appldata_os_init);
213 module_exit(appldata_os_exit);
214
215 MODULE_LICENSE("GPL");
216 MODULE_AUTHOR("Gerald Schaefer");
217 MODULE_DESCRIPTION("Linux-VM Monitor Stream, OS statistics");