]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - arch/s390/appldata/appldata_os.c
sched/headers: Prepare for new header dependencies before moving code to <linux/sched...
[mirror_ubuntu-focal-kernel.git] / arch / s390 / appldata / appldata_os.c
CommitLineData
1da177e4 1/*
1da177e4
LT
2 * Data gathering module for Linux-VM Monitor Stream, Stage 1.
3 * Collects misc. OS related data (CPU utilization, running processes).
4 *
a53c8fab 5 * Copyright IBM Corp. 2003, 2006
1da177e4 6 *
5b5dd21a 7 * Author: Gerald Schaefer <gerald.schaefer@de.ibm.com>
1da177e4
LT
8 */
9
e7534b0e
GS
10#define KMSG_COMPONENT "appldata"
11#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12
1da177e4
LT
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/slab.h>
16#include <linux/errno.h>
17#include <linux/kernel_stat.h>
18#include <linux/netdevice.h>
19#include <linux/sched.h>
4f17722c 20#include <linux/sched/loadavg.h>
1f38d613 21#include <asm/appldata.h>
1da177e4
LT
22#include <asm/smp.h>
23
24#include "appldata.h"
25
26
1da177e4
LT
27#define LOAD_INT(x) ((x) >> FSHIFT)
28#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
29
30/*
31 * OS data
32 *
33 * This is accessed as binary data by z/VM. If changes to it can't be avoided,
34 * the structure version (product ID, see appldata_base.c) needs to be changed
35 * as well and all documentation and z/VM applications using it must be
36 * updated.
37 *
38 * The record layout is documented in the Linux for zSeries Device Drivers
39 * book:
40 * http://oss.software.ibm.com/developerworks/opensource/linux390/index.shtml
41 */
42struct appldata_os_per_cpu {
43 u32 per_cpu_user; /* timer ticks spent in user mode */
44 u32 per_cpu_nice; /* ... spent with modified priority */
45 u32 per_cpu_system; /* ... spent in kernel mode */
46 u32 per_cpu_idle; /* ... spent in idle mode */
47
5b5dd21a 48 /* New in 2.6 */
1da177e4
LT
49 u32 per_cpu_irq; /* ... spent in interrupts */
50 u32 per_cpu_softirq; /* ... spent in softirqs */
51 u32 per_cpu_iowait; /* ... spent while waiting for I/O */
5b5dd21a
GS
52
53 /* New in modification level 01 */
54 u32 per_cpu_steal; /* ... stolen by hypervisor */
55 u32 cpu_id; /* number of this CPU */
f26d583e 56} __attribute__((packed));
1da177e4
LT
57
58struct appldata_os_data {
59 u64 timestamp;
60 u32 sync_count_1; /* after VM collected the record data, */
61 u32 sync_count_2; /* sync_count_1 and sync_count_2 should be the
62 same. If not, the record has been updated on
63 the Linux side while VM was collecting the
64 (possibly corrupt) data */
65
66 u32 nr_cpus; /* number of (virtual) CPUs */
67 u32 per_cpu_size; /* size of the per-cpu data struct */
68 u32 cpu_offset; /* offset of the first per-cpu data struct */
69
70 u32 nr_running; /* number of runnable threads */
71 u32 nr_threads; /* number of threads */
72 u32 avenrun[3]; /* average nr. of running processes during */
73 /* the last 1, 5 and 15 minutes */
74
5b5dd21a 75 /* New in 2.6 */
1da177e4
LT
76 u32 nr_iowait; /* number of blocked threads
77 (waiting for I/O) */
1da177e4
LT
78
79 /* per cpu data */
80 struct appldata_os_per_cpu os_cpu[0];
f26d583e 81} __attribute__((packed));
1da177e4
LT
82
83static struct appldata_os_data *appldata_os_data;
84
5b5dd21a 85static struct appldata_ops ops = {
5b5dd21a
GS
86 .name = "os",
87 .record_nr = APPLDATA_RECORD_OS_ID,
88 .owner = THIS_MODULE,
89 .mod_lvl = {0xF0, 0xF1}, /* EBCDIC "01" */
90};
91
1da177e4 92
1da177e4
LT
93/*
94 * appldata_get_os_data()
95 *
96 * gather OS data
97 */
98static void appldata_get_os_data(void *data)
99{
5b5dd21a 100 int i, j, rc;
1da177e4 101 struct appldata_os_data *os_data;
5b5dd21a 102 unsigned int new_size;
1da177e4
LT
103
104 os_data = data;
105 os_data->sync_count_1++;
106
1da177e4
LT
107 os_data->nr_threads = nr_threads;
108 os_data->nr_running = nr_running();
109 os_data->nr_iowait = nr_iowait();
110 os_data->avenrun[0] = avenrun[0] + (FIXED_1/200);
111 os_data->avenrun[1] = avenrun[1] + (FIXED_1/200);
112 os_data->avenrun[2] = avenrun[2] + (FIXED_1/200);
113
114 j = 0;
115 for_each_online_cpu(i) {
116 os_data->os_cpu[j].per_cpu_user =
7fb1327e 117 nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_USER]);
1da177e4 118 os_data->os_cpu[j].per_cpu_nice =
7fb1327e 119 nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_NICE]);
1da177e4 120 os_data->os_cpu[j].per_cpu_system =
7fb1327e 121 nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM]);
1da177e4 122 os_data->os_cpu[j].per_cpu_idle =
7fb1327e 123 nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_IDLE]);
1da177e4 124 os_data->os_cpu[j].per_cpu_irq =
7fb1327e 125 nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_IRQ]);
1da177e4 126 os_data->os_cpu[j].per_cpu_softirq =
7fb1327e 127 nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ]);
1da177e4 128 os_data->os_cpu[j].per_cpu_iowait =
7fb1327e 129 nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_IOWAIT]);
5b5dd21a 130 os_data->os_cpu[j].per_cpu_steal =
7fb1327e 131 nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_STEAL]);
5b5dd21a 132 os_data->os_cpu[j].cpu_id = i;
1da177e4
LT
133 j++;
134 }
135
5b5dd21a
GS
136 os_data->nr_cpus = j;
137
138 new_size = sizeof(struct appldata_os_data) +
139 (os_data->nr_cpus * sizeof(struct appldata_os_per_cpu));
140 if (ops.size != new_size) {
141 if (ops.active) {
142 rc = appldata_diag(APPLDATA_RECORD_OS_ID,
143 APPLDATA_START_INTERVAL_REC,
144 (unsigned long) ops.data, new_size,
145 ops.mod_lvl);
d3ae942d 146 if (rc != 0)
e7534b0e
GS
147 pr_err("Starting a new OS data collection "
148 "failed with rc=%d\n", rc);
5b5dd21a
GS
149
150 rc = appldata_diag(APPLDATA_RECORD_OS_ID,
151 APPLDATA_STOP_REC,
152 (unsigned long) ops.data, ops.size,
153 ops.mod_lvl);
154 if (rc != 0)
e7534b0e
GS
155 pr_err("Stopping a faulty OS data "
156 "collection failed with rc=%d\n", rc);
5b5dd21a
GS
157 }
158 ops.size = new_size;
159 }
1aae0560 160 os_data->timestamp = get_tod_clock();
1da177e4 161 os_data->sync_count_2++;
1da177e4
LT
162}
163
164
1da177e4
LT
165/*
166 * appldata_os_init()
167 *
168 * init data, register ops
169 */
170static int __init appldata_os_init(void)
171{
5b5dd21a 172 int rc, max_size;
1da177e4 173
5b5dd21a 174 max_size = sizeof(struct appldata_os_data) +
6967037b 175 (num_possible_cpus() * sizeof(struct appldata_os_per_cpu));
5b5dd21a 176 if (max_size > APPLDATA_MAX_REC_SIZE) {
e7534b0e
GS
177 pr_err("Maximum OS record size %i exceeds the maximum "
178 "record size %i\n", max_size, APPLDATA_MAX_REC_SIZE);
1da177e4
LT
179 rc = -ENOMEM;
180 goto out;
181 }
1da177e4 182
c2f0e8c8 183 appldata_os_data = kzalloc(max_size, GFP_KERNEL | GFP_DMA);
1da177e4 184 if (appldata_os_data == NULL) {
1da177e4
LT
185 rc = -ENOMEM;
186 goto out;
187 }
1da177e4
LT
188
189 appldata_os_data->per_cpu_size = sizeof(struct appldata_os_per_cpu);
190 appldata_os_data->cpu_offset = offsetof(struct appldata_os_data,
191 os_cpu);
1da177e4
LT
192
193 ops.data = appldata_os_data;
5b5dd21a 194 ops.callback = &appldata_get_os_data;
1da177e4 195 rc = appldata_register_ops(&ops);
d3ae942d 196 if (rc != 0)
1da177e4 197 kfree(appldata_os_data);
1da177e4
LT
198out:
199 return rc;
200}
201
202/*
203 * appldata_os_exit()
204 *
205 * unregister ops
206 */
207static void __exit appldata_os_exit(void)
208{
209 appldata_unregister_ops(&ops);
210 kfree(appldata_os_data);
1da177e4
LT
211}
212
213
214module_init(appldata_os_init);
215module_exit(appldata_os_exit);
216
217MODULE_LICENSE("GPL");
218MODULE_AUTHOR("Gerald Schaefer");
219MODULE_DESCRIPTION("Linux-VM Monitor Stream, OS statistics");