2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Data gathering module for Linux-VM Monitor Stream, Stage 1.
|
|
|
|
* Collects misc. OS related data (CPU utilization, running processes).
|
|
|
|
*
|
2012-07-20 09:15:04 +00:00
|
|
|
* Copyright IBM Corp. 2003, 2006
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
2006-06-29 13:08:35 +00:00
|
|
|
* Author: Gerald Schaefer <gerald.schaefer@de.ibm.com>
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
|
2008-12-25 12:39:41 +00:00
|
|
|
#define KMSG_COMPONENT "appldata"
|
|
|
|
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/kernel_stat.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/sched.h>
|
2006-09-20 13:59:26 +00:00
|
|
|
#include <asm/appldata.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <asm/smp.h>
|
|
|
|
|
|
|
|
#include "appldata.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define LOAD_INT(x) ((x) >> FSHIFT)
|
|
|
|
#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* OS data
|
|
|
|
*
|
|
|
|
* This is accessed as binary data by z/VM. If changes to it can't be avoided,
|
|
|
|
* the structure version (product ID, see appldata_base.c) needs to be changed
|
|
|
|
* as well and all documentation and z/VM applications using it must be
|
|
|
|
* updated.
|
|
|
|
*
|
|
|
|
* The record layout is documented in the Linux for zSeries Device Drivers
|
|
|
|
* book:
|
|
|
|
* http://oss.software.ibm.com/developerworks/opensource/linux390/index.shtml
|
|
|
|
*/
|
|
|
|
struct appldata_os_per_cpu {
|
|
|
|
u32 per_cpu_user; /* timer ticks spent in user mode */
|
|
|
|
u32 per_cpu_nice; /* ... spent with modified priority */
|
|
|
|
u32 per_cpu_system; /* ... spent in kernel mode */
|
|
|
|
u32 per_cpu_idle; /* ... spent in idle mode */
|
|
|
|
|
2006-06-29 13:08:35 +00:00
|
|
|
/* New in 2.6 */
|
2005-04-16 22:20:36 +00:00
|
|
|
u32 per_cpu_irq; /* ... spent in interrupts */
|
|
|
|
u32 per_cpu_softirq; /* ... spent in softirqs */
|
|
|
|
u32 per_cpu_iowait; /* ... spent while waiting for I/O */
|
2006-06-29 13:08:35 +00:00
|
|
|
|
|
|
|
/* New in modification level 01 */
|
|
|
|
u32 per_cpu_steal; /* ... stolen by hypervisor */
|
|
|
|
u32 cpu_id; /* number of this CPU */
|
2005-06-04 22:43:33 +00:00
|
|
|
} __attribute__((packed));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
struct appldata_os_data {
|
|
|
|
u64 timestamp;
|
|
|
|
u32 sync_count_1; /* after VM collected the record data, */
|
|
|
|
u32 sync_count_2; /* sync_count_1 and sync_count_2 should be the
|
|
|
|
same. If not, the record has been updated on
|
|
|
|
the Linux side while VM was collecting the
|
|
|
|
(possibly corrupt) data */
|
|
|
|
|
|
|
|
u32 nr_cpus; /* number of (virtual) CPUs */
|
|
|
|
u32 per_cpu_size; /* size of the per-cpu data struct */
|
|
|
|
u32 cpu_offset; /* offset of the first per-cpu data struct */
|
|
|
|
|
|
|
|
u32 nr_running; /* number of runnable threads */
|
|
|
|
u32 nr_threads; /* number of threads */
|
|
|
|
u32 avenrun[3]; /* average nr. of running processes during */
|
|
|
|
/* the last 1, 5 and 15 minutes */
|
|
|
|
|
2006-06-29 13:08:35 +00:00
|
|
|
/* New in 2.6 */
|
2005-04-16 22:20:36 +00:00
|
|
|
u32 nr_iowait; /* number of blocked threads
|
|
|
|
(waiting for I/O) */
|
|
|
|
|
|
|
|
/* per cpu data */
|
|
|
|
struct appldata_os_per_cpu os_cpu[0];
|
2005-06-04 22:43:33 +00:00
|
|
|
} __attribute__((packed));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
static struct appldata_os_data *appldata_os_data;
|
|
|
|
|
2006-06-29 13:08:35 +00:00
|
|
|
static struct appldata_ops ops = {
|
|
|
|
.name = "os",
|
|
|
|
.record_nr = APPLDATA_RECORD_OS_ID,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.mod_lvl = {0xF0, 0xF1}, /* EBCDIC "01" */
|
|
|
|
};
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* appldata_get_os_data()
|
|
|
|
*
|
|
|
|
* gather OS data
|
|
|
|
*/
|
|
|
|
static void appldata_get_os_data(void *data)
|
|
|
|
{
|
2006-06-29 13:08:35 +00:00
|
|
|
int i, j, rc;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct appldata_os_data *os_data;
|
2006-06-29 13:08:35 +00:00
|
|
|
unsigned int new_size;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
os_data = data;
|
|
|
|
os_data->sync_count_1++;
|
|
|
|
|
|
|
|
os_data->nr_threads = nr_threads;
|
|
|
|
os_data->nr_running = nr_running();
|
|
|
|
os_data->nr_iowait = nr_iowait();
|
|
|
|
os_data->avenrun[0] = avenrun[0] + (FIXED_1/200);
|
|
|
|
os_data->avenrun[1] = avenrun[1] + (FIXED_1/200);
|
|
|
|
os_data->avenrun[2] = avenrun[2] + (FIXED_1/200);
|
|
|
|
|
|
|
|
j = 0;
|
|
|
|
for_each_online_cpu(i) {
|
|
|
|
os_data->os_cpu[j].per_cpu_user =
|
2011-11-28 16:45:17 +00:00
|
|
|
cputime_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_USER]);
|
2005-04-16 22:20:36 +00:00
|
|
|
os_data->os_cpu[j].per_cpu_nice =
|
2011-11-28 16:45:17 +00:00
|
|
|
cputime_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_NICE]);
|
2005-04-16 22:20:36 +00:00
|
|
|
os_data->os_cpu[j].per_cpu_system =
|
2011-11-28 16:45:17 +00:00
|
|
|
cputime_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM]);
|
2005-04-16 22:20:36 +00:00
|
|
|
os_data->os_cpu[j].per_cpu_idle =
|
2011-11-28 16:45:17 +00:00
|
|
|
cputime_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_IDLE]);
|
2005-04-16 22:20:36 +00:00
|
|
|
os_data->os_cpu[j].per_cpu_irq =
|
2011-11-28 16:45:17 +00:00
|
|
|
cputime_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_IRQ]);
|
2005-04-16 22:20:36 +00:00
|
|
|
os_data->os_cpu[j].per_cpu_softirq =
|
2011-11-28 16:45:17 +00:00
|
|
|
cputime_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ]);
|
2005-04-16 22:20:36 +00:00
|
|
|
os_data->os_cpu[j].per_cpu_iowait =
|
2011-11-28 16:45:17 +00:00
|
|
|
cputime_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_IOWAIT]);
|
2006-06-29 13:08:35 +00:00
|
|
|
os_data->os_cpu[j].per_cpu_steal =
|
2011-11-28 16:45:17 +00:00
|
|
|
cputime_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_STEAL]);
|
2006-06-29 13:08:35 +00:00
|
|
|
os_data->os_cpu[j].cpu_id = i;
|
2005-04-16 22:20:36 +00:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
|
2006-06-29 13:08:35 +00:00
|
|
|
os_data->nr_cpus = j;
|
|
|
|
|
|
|
|
new_size = sizeof(struct appldata_os_data) +
|
|
|
|
(os_data->nr_cpus * sizeof(struct appldata_os_per_cpu));
|
|
|
|
if (ops.size != new_size) {
|
|
|
|
if (ops.active) {
|
|
|
|
rc = appldata_diag(APPLDATA_RECORD_OS_ID,
|
|
|
|
APPLDATA_START_INTERVAL_REC,
|
|
|
|
(unsigned long) ops.data, new_size,
|
|
|
|
ops.mod_lvl);
|
2008-07-14 07:59:34 +00:00
|
|
|
if (rc != 0)
|
2008-12-25 12:39:41 +00:00
|
|
|
pr_err("Starting a new OS data collection "
|
|
|
|
"failed with rc=%d\n", rc);
|
2006-06-29 13:08:35 +00:00
|
|
|
|
|
|
|
rc = appldata_diag(APPLDATA_RECORD_OS_ID,
|
|
|
|
APPLDATA_STOP_REC,
|
|
|
|
(unsigned long) ops.data, ops.size,
|
|
|
|
ops.mod_lvl);
|
|
|
|
if (rc != 0)
|
2008-12-25 12:39:41 +00:00
|
|
|
pr_err("Stopping a faulty OS data "
|
|
|
|
"collection failed with rc=%d\n", rc);
|
2006-06-29 13:08:35 +00:00
|
|
|
}
|
|
|
|
ops.size = new_size;
|
|
|
|
}
|
2013-01-30 08:49:40 +00:00
|
|
|
os_data->timestamp = get_tod_clock();
|
2005-04-16 22:20:36 +00:00
|
|
|
os_data->sync_count_2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* appldata_os_init()
|
|
|
|
*
|
|
|
|
* init data, register ops
|
|
|
|
*/
|
|
|
|
static int __init appldata_os_init(void)
|
|
|
|
{
|
2006-06-29 13:08:35 +00:00
|
|
|
int rc, max_size;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-06-29 13:08:35 +00:00
|
|
|
max_size = sizeof(struct appldata_os_data) +
|
|
|
|
(NR_CPUS * sizeof(struct appldata_os_per_cpu));
|
|
|
|
if (max_size > APPLDATA_MAX_REC_SIZE) {
|
2008-12-25 12:39:41 +00:00
|
|
|
pr_err("Maximum OS record size %i exceeds the maximum "
|
|
|
|
"record size %i\n", max_size, APPLDATA_MAX_REC_SIZE);
|
2005-04-16 22:20:36 +00:00
|
|
|
rc = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-06-08 16:58:09 +00:00
|
|
|
appldata_os_data = kzalloc(max_size, GFP_KERNEL | GFP_DMA);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (appldata_os_data == NULL) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
appldata_os_data->per_cpu_size = sizeof(struct appldata_os_per_cpu);
|
|
|
|
appldata_os_data->cpu_offset = offsetof(struct appldata_os_data,
|
|
|
|
os_cpu);
|
|
|
|
|
|
|
|
ops.data = appldata_os_data;
|
2006-06-29 13:08:35 +00:00
|
|
|
ops.callback = &appldata_get_os_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
rc = appldata_register_ops(&ops);
|
2008-07-14 07:59:34 +00:00
|
|
|
if (rc != 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
kfree(appldata_os_data);
|
|
|
|
out:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* appldata_os_exit()
|
|
|
|
*
|
|
|
|
* unregister ops
|
|
|
|
*/
|
|
|
|
static void __exit appldata_os_exit(void)
|
|
|
|
{
|
|
|
|
appldata_unregister_ops(&ops);
|
|
|
|
kfree(appldata_os_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module_init(appldata_os_init);
|
|
|
|
module_exit(appldata_os_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Gerald Schaefer");
|
|
|
|
MODULE_DESCRIPTION("Linux-VM Monitor Stream, OS statistics");
|