Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Data gathering module for Linux-VM Monitor Stream, Stage 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Collects data related to memory management.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright IBM Corp. 2003, 2006
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Author: Gerald Schaefer <gerald.schaefer@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/kernel_stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/swap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "appldata.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define P2K(x) ((x) << (PAGE_SHIFT - 10))	/* Converts #Pages to KB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * Memory data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * This is accessed as binary data by z/VM. If changes to it can't be avoided,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * the structure version (product ID, see appldata_base.c) needs to be changed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * as well and all documentation and z/VM applications using it must be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * updated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) struct appldata_mem_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	u64 timestamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	u32 sync_count_1;       /* after VM collected the record data, */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	u32 sync_count_2;	/* sync_count_1 and sync_count_2 should be the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 				   same. If not, the record has been updated on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 				   the Linux side while VM was collecting the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 				   (possibly corrupt) data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	u64 pgpgin;		/* data read from disk  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	u64 pgpgout;		/* data written to disk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	u64 pswpin;		/* pages swapped in  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	u64 pswpout;		/* pages swapped out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	u64 sharedram;		/* sharedram is currently set to 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	u64 totalram;		/* total main memory size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	u64 freeram;		/* free main memory size  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	u64 totalhigh;		/* total high memory size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	u64 freehigh;		/* free high memory size  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	u64 bufferram;		/* memory reserved for buffers, free cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	u64 cached;		/* size of (used) cache, w/o buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	u64 totalswap;		/* total swap space size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	u64 freeswap;		/* free swap space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) // New in 2.6 -->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	u64 pgalloc;		/* page allocations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	u64 pgfault;		/* page faults (major+minor) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	u64 pgmajfault;		/* page faults (major only) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) // <-- New in 2.6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * appldata_get_mem_data()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * gather memory data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) static void appldata_get_mem_data(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	 * don't put large structures on the stack, we are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	 * serialized through the appldata_ops_mutex and can use static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	static struct sysinfo val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	unsigned long ev[NR_VM_EVENT_ITEMS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	struct appldata_mem_data *mem_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	mem_data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	mem_data->sync_count_1++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	all_vm_events(ev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	mem_data->pgpgin     = ev[PGPGIN] >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	mem_data->pgpgout    = ev[PGPGOUT] >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	mem_data->pswpin     = ev[PSWPIN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	mem_data->pswpout    = ev[PSWPOUT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	mem_data->pgalloc    = ev[PGALLOC_NORMAL];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	mem_data->pgalloc    += ev[PGALLOC_DMA];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	mem_data->pgfault    = ev[PGFAULT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	mem_data->pgmajfault = ev[PGMAJFAULT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	si_meminfo(&val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	mem_data->sharedram = val.sharedram;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	mem_data->totalram  = P2K(val.totalram);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	mem_data->freeram   = P2K(val.freeram);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	mem_data->totalhigh = P2K(val.totalhigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	mem_data->freehigh  = P2K(val.freehigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	mem_data->bufferram = P2K(val.bufferram);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	mem_data->cached    = P2K(global_node_page_state(NR_FILE_PAGES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 				- val.bufferram);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	si_swapinfo(&val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	mem_data->totalswap = P2K(val.totalswap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	mem_data->freeswap  = P2K(val.freeswap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	mem_data->timestamp = get_tod_clock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	mem_data->sync_count_2++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static struct appldata_ops ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	.name      = "mem",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	.record_nr = APPLDATA_RECORD_MEM_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	.size	   = sizeof(struct appldata_mem_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	.callback  = &appldata_get_mem_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	.owner     = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	.mod_lvl   = {0xF0, 0xF0},		/* EBCDIC "00" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  * appldata_mem_init()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  * init_data, register ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static int __init appldata_mem_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	ops.data = kzalloc(sizeof(struct appldata_mem_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (!ops.data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	ret = appldata_register_ops(&ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		kfree(ops.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  * appldata_mem_exit()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  * unregister ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static void __exit appldata_mem_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	appldata_unregister_ops(&ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	kfree(ops.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) module_init(appldata_mem_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) module_exit(appldata_mem_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) MODULE_AUTHOR("Gerald Schaefer");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) MODULE_DESCRIPTION("Linux-VM Monitor Stream, MEMORY statistics");