| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * arch/s390/appldata/appldata_mem.c | 
 | 3 |  * | 
 | 4 |  * Data gathering module for Linux-VM Monitor Stream, Stage 1. | 
 | 5 |  * Collects data related to memory management. | 
 | 6 |  * | 
| Gerald Schaefer | 5b5dd21 | 2006-06-29 15:08:35 +0200 | [diff] [blame] | 7 |  * Copyright (C) 2003,2006 IBM Corporation, IBM Deutschland Entwicklung GmbH. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 |  * | 
| Gerald Schaefer | 5b5dd21 | 2006-06-29 15:08:35 +0200 | [diff] [blame] | 9 |  * Author: Gerald Schaefer <gerald.schaefer@de.ibm.com> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 |  */ | 
 | 11 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/module.h> | 
 | 13 | #include <linux/init.h> | 
 | 14 | #include <linux/slab.h> | 
 | 15 | #include <linux/errno.h> | 
 | 16 | #include <linux/kernel_stat.h> | 
 | 17 | #include <asm/io.h> | 
 | 18 | #include <linux/pagemap.h> | 
 | 19 | #include <linux/swap.h> | 
 | 20 |  | 
 | 21 | #include "appldata.h" | 
 | 22 |  | 
 | 23 |  | 
 | 24 | #define MY_PRINT_NAME "appldata_mem"		/* for debug messages, etc. */ | 
 | 25 | #define P2K(x) ((x) << (PAGE_SHIFT - 10))	/* Converts #Pages to KB */ | 
 | 26 |  | 
 | 27 | /* | 
 | 28 |  * Memory data | 
 | 29 |  * | 
 | 30 |  * This is accessed as binary data by z/VM. If changes to it can't be avoided, | 
 | 31 |  * the structure version (product ID, see appldata_base.c) needs to be changed | 
 | 32 |  * as well and all documentation and z/VM applications using it must be | 
 | 33 |  * updated. | 
 | 34 |  * | 
 | 35 |  * The record layout is documented in the Linux for zSeries Device Drivers | 
 | 36 |  * book: | 
 | 37 |  * http://oss.software.ibm.com/developerworks/opensource/linux390/index.shtml | 
 | 38 |  */ | 
 | 39 | struct appldata_mem_data { | 
 | 40 | 	u64 timestamp; | 
 | 41 | 	u32 sync_count_1;       /* after VM collected the record data, */ | 
 | 42 | 	u32 sync_count_2;	/* sync_count_1 and sync_count_2 should be the | 
 | 43 | 				   same. If not, the record has been updated on | 
 | 44 | 				   the Linux side while VM was collecting the | 
 | 45 | 				   (possibly corrupt) data */ | 
 | 46 |  | 
 | 47 | 	u64 pgpgin;		/* data read from disk  */ | 
 | 48 | 	u64 pgpgout;		/* data written to disk */ | 
 | 49 | 	u64 pswpin;		/* pages swapped in  */ | 
 | 50 | 	u64 pswpout;		/* pages swapped out */ | 
 | 51 |  | 
 | 52 | 	u64 sharedram;		/* sharedram is currently set to 0 */ | 
 | 53 |  | 
 | 54 | 	u64 totalram;		/* total main memory size */ | 
 | 55 | 	u64 freeram;		/* free main memory size  */ | 
 | 56 | 	u64 totalhigh;		/* total high memory size */ | 
 | 57 | 	u64 freehigh;		/* free high memory size  */ | 
 | 58 |  | 
 | 59 | 	u64 bufferram;		/* memory reserved for buffers, free cache */ | 
 | 60 | 	u64 cached;		/* size of (used) cache, w/o buffers */ | 
 | 61 | 	u64 totalswap;		/* total swap space size */ | 
 | 62 | 	u64 freeswap;		/* free swap space */ | 
 | 63 |  | 
 | 64 | // New in 2.6 --> | 
 | 65 | 	u64 pgalloc;		/* page allocations */ | 
 | 66 | 	u64 pgfault;		/* page faults (major+minor) */ | 
 | 67 | 	u64 pgmajfault;		/* page faults (major only) */ | 
 | 68 | // <-- New in 2.6 | 
 | 69 |  | 
| Gerald Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 70 | } __attribute__((packed)) appldata_mem_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 |  | 
 | 72 |  | 
 | 73 | static inline void appldata_debug_print(struct appldata_mem_data *mem_data) | 
 | 74 | { | 
 | 75 | 	P_DEBUG("--- MEM - RECORD ---\n"); | 
 | 76 | 	P_DEBUG("pgpgin     = %8lu KB\n", mem_data->pgpgin); | 
 | 77 | 	P_DEBUG("pgpgout    = %8lu KB\n", mem_data->pgpgout); | 
 | 78 | 	P_DEBUG("pswpin     = %8lu Pages\n", mem_data->pswpin); | 
 | 79 | 	P_DEBUG("pswpout    = %8lu Pages\n", mem_data->pswpout); | 
 | 80 | 	P_DEBUG("pgalloc    = %8lu \n", mem_data->pgalloc); | 
 | 81 | 	P_DEBUG("pgfault    = %8lu \n", mem_data->pgfault); | 
 | 82 | 	P_DEBUG("pgmajfault = %8lu \n", mem_data->pgmajfault); | 
 | 83 | 	P_DEBUG("sharedram  = %8lu KB\n", mem_data->sharedram); | 
 | 84 | 	P_DEBUG("totalram   = %8lu KB\n", mem_data->totalram); | 
 | 85 | 	P_DEBUG("freeram    = %8lu KB\n", mem_data->freeram); | 
 | 86 | 	P_DEBUG("totalhigh  = %8lu KB\n", mem_data->totalhigh); | 
 | 87 | 	P_DEBUG("freehigh   = %8lu KB\n", mem_data->freehigh); | 
 | 88 | 	P_DEBUG("bufferram  = %8lu KB\n", mem_data->bufferram); | 
 | 89 | 	P_DEBUG("cached     = %8lu KB\n", mem_data->cached); | 
 | 90 | 	P_DEBUG("totalswap  = %8lu KB\n", mem_data->totalswap); | 
 | 91 | 	P_DEBUG("freeswap   = %8lu KB\n", mem_data->freeswap); | 
 | 92 | 	P_DEBUG("sync_count_1 = %u\n", mem_data->sync_count_1); | 
 | 93 | 	P_DEBUG("sync_count_2 = %u\n", mem_data->sync_count_2); | 
 | 94 | 	P_DEBUG("timestamp    = %lX\n", mem_data->timestamp); | 
 | 95 | } | 
 | 96 |  | 
 | 97 | /* | 
 | 98 |  * appldata_get_mem_data() | 
 | 99 |  * | 
 | 100 |  * gather memory data | 
 | 101 |  */ | 
 | 102 | static void appldata_get_mem_data(void *data) | 
 | 103 | { | 
 | 104 | 	/* | 
 | 105 | 	 * don't put large structures on the stack, we are | 
 | 106 | 	 * serialized through the appldata_ops_lock and can use static | 
 | 107 | 	 */ | 
 | 108 | 	static struct sysinfo val; | 
| Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 109 | 	unsigned long ev[NR_VM_EVENT_ITEMS]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | 	struct appldata_mem_data *mem_data; | 
 | 111 |  | 
 | 112 | 	mem_data = data; | 
 | 113 | 	mem_data->sync_count_1++; | 
 | 114 |  | 
| Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 115 | 	all_vm_events(ev); | 
 | 116 | 	mem_data->pgpgin     = ev[PGPGIN] >> 1; | 
 | 117 | 	mem_data->pgpgout    = ev[PGPGOUT] >> 1; | 
 | 118 | 	mem_data->pswpin     = ev[PSWPIN]; | 
 | 119 | 	mem_data->pswpout    = ev[PSWPOUT]; | 
 | 120 | 	mem_data->pgalloc    = ev[PGALLOC_HIGH] + ev[PGALLOC_NORMAL] + | 
 | 121 | 			       ev[PGALLOC_DMA]; | 
 | 122 | 	mem_data->pgfault    = ev[PGFAULT]; | 
 | 123 | 	mem_data->pgmajfault = ev[PGMAJFAULT]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 |  | 
 | 125 | 	si_meminfo(&val); | 
 | 126 | 	mem_data->sharedram = val.sharedram; | 
 | 127 | 	mem_data->totalram  = P2K(val.totalram); | 
 | 128 | 	mem_data->freeram   = P2K(val.freeram); | 
 | 129 | 	mem_data->totalhigh = P2K(val.totalhigh); | 
 | 130 | 	mem_data->freehigh  = P2K(val.freehigh); | 
 | 131 | 	mem_data->bufferram = P2K(val.bufferram); | 
| Christoph Lameter | 347ce43 | 2006-06-30 01:55:35 -0700 | [diff] [blame] | 132 | 	mem_data->cached    = P2K(global_page_state(NR_FILE_PAGES) | 
 | 133 | 				- val.bufferram); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 |  | 
 | 135 | 	si_swapinfo(&val); | 
 | 136 | 	mem_data->totalswap = P2K(val.totalswap); | 
 | 137 | 	mem_data->freeswap  = P2K(val.freeswap); | 
 | 138 |  | 
 | 139 | 	mem_data->timestamp = get_clock(); | 
 | 140 | 	mem_data->sync_count_2++; | 
 | 141 | #ifdef APPLDATA_DEBUG | 
 | 142 | 	appldata_debug_print(mem_data); | 
 | 143 | #endif | 
 | 144 | } | 
 | 145 |  | 
 | 146 |  | 
 | 147 | static struct appldata_ops ops = { | 
 | 148 | 	.ctl_nr    = CTL_APPLDATA_MEM, | 
 | 149 | 	.name      = "mem", | 
 | 150 | 	.record_nr = APPLDATA_RECORD_MEM_ID, | 
 | 151 | 	.size	   = sizeof(struct appldata_mem_data), | 
 | 152 | 	.callback  = &appldata_get_mem_data, | 
 | 153 | 	.data      = &appldata_mem_data, | 
 | 154 | 	.owner     = THIS_MODULE, | 
| Gerald Schaefer | 5b5dd21 | 2006-06-29 15:08:35 +0200 | [diff] [blame] | 155 | 	.mod_lvl   = {0xF0, 0xF0},		/* EBCDIC "00" */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | }; | 
 | 157 |  | 
 | 158 |  | 
 | 159 | /* | 
 | 160 |  * appldata_mem_init() | 
 | 161 |  * | 
 | 162 |  * init_data, register ops | 
 | 163 |  */ | 
 | 164 | static int __init appldata_mem_init(void) | 
 | 165 | { | 
 | 166 | 	int rc; | 
 | 167 |  | 
 | 168 | 	P_DEBUG("sizeof(mem) = %lu\n", sizeof(struct appldata_mem_data)); | 
 | 169 |  | 
 | 170 | 	rc = appldata_register_ops(&ops); | 
 | 171 | 	if (rc != 0) { | 
 | 172 | 		P_ERROR("Error registering ops, rc = %i\n", rc); | 
 | 173 | 	} else { | 
 | 174 | 		P_DEBUG("%s-ops registered!\n", ops.name); | 
 | 175 | 	} | 
 | 176 | 	return rc; | 
 | 177 | } | 
 | 178 |  | 
 | 179 | /* | 
 | 180 |  * appldata_mem_exit() | 
 | 181 |  * | 
 | 182 |  * unregister ops | 
 | 183 |  */ | 
 | 184 | static void __exit appldata_mem_exit(void) | 
 | 185 | { | 
 | 186 | 	appldata_unregister_ops(&ops); | 
 | 187 | 	P_DEBUG("%s-ops unregistered!\n", ops.name); | 
 | 188 | } | 
 | 189 |  | 
 | 190 |  | 
 | 191 | module_init(appldata_mem_init); | 
 | 192 | module_exit(appldata_mem_exit); | 
 | 193 |  | 
 | 194 | MODULE_LICENSE("GPL"); | 
 | 195 | MODULE_AUTHOR("Gerald Schaefer"); | 
 | 196 | MODULE_DESCRIPTION("Linux-VM Monitor Stream, MEMORY statistics"); |