linux系统缺页中断次数统计(OpenEuler) 您所在的位置:网站首页 利用外部中断统计中断次数 linux系统缺页中断次数统计(OpenEuler)

linux系统缺页中断次数统计(OpenEuler)

2024-06-16 04:49| 来源: 网络整理| 查看: 265

OpenEuler20.03 统计缺页中断次数

本文参考Centos7实现缺页中断具体步骤

下载解压linux-4.19.90版本linux内核

下载linux-4.19.90.tar.xz压缩包发送到/usr/src目录下(可以用filezilla)

进入/usr/src目录解压缩

tar -xvJf linux-4.19.90.tar.xz

解压结果

解压结束后进入linux-4.19.90目录中

修改源码 修改arch/x86/mm/fault.c文件

利用grep找到__do_page_fault的位置

cat -n arch/x86/mm/fault.c | grep __do_page_fault

__do_page_fault 利用vim编辑器进入文件中在该函数上定义pfcount变量 定义pfcount 在__do_page_fault函数中找到good_area,令pfcount自增 pfcount++

修改include/linux/mm.h文件

在extern int page_cluster;语句之后插入

extern unsigned long volatile pfcount;

mm.h

修改kernel/kallsyms.c文件

在kernel/kallsyms.c文件尾插入EXPORT_SYMBOL(pfcount);

echo 'EXPORT_SYMBOL(pfcount);'>>kernel/kallsyms.c 编译内核

确认自身的OpenEuler空闲空间足够(建议提前扩展磁盘容量)

安装ncurses-devel elfutils-libelf-devel openssl-devel yum install ncurses-devel elfutils-libelf-devel openssl-devel -y

这里部分OpenEuler的yum工具可能并不能正常使用,用下面的代码覆盖掉 /etc/yum.repos.d/openEuler_x86_64.repo并执行(如果该目录下有其他文件建议删除掉) (如果yum makecache不能正常执行检查自己的dns是否有问题)

yum makecache #generic-repos is licensed under the Mulan PSL v2. #You can use this software according to the terms and conditions of the Mulan PSL v2. #You may obtain a copy of Mulan PSL v2 at: # http://license.coscl.org.cn/MulanPSL2 #THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR #IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR #PURPOSE. #See the Mulan PSL v2 for more details. [OS] name=OS baseurl=http://repo.openeuler.org/openEuler-20.03-LTS/OS/$basearch/ enabled=1 gpgcheck=1 gpgkey=http://repo.openeuler.org/openEuler-20.03-LTS/OS/$basearch/RPM-GPG-KEY-openEuler [everything] name=everything baseurl=http://repo.openeuler.org/openEuler-20.03-LTS/everything/$basearch/ enabled=1 gpgcheck=1 gpgkey=http://repo.openeuler.org/openEuler-20.03-LTS/everything/$basearch/RPM-GPG-KEY-openEuler [EPOL] name=EPOL baseurl=http://repo.openeuler.org/openEuler-20.03-LTS/EPOL/$basearch/ enabled=1 gpgcheck=1 gpgkey=http://repo.openeuler.org/openEuler-20.03-LTS/OS/$basearch/RPM-GPG-KEY-openEuler [debuginfo] name=debuginfo baseurl=http://repo.openeuler.org/openEuler-20.03-LTS/debuginfo/$basearch/ enabled=1 gpgcheck=1 gpgkey=http://repo.openeuler.org/openEuler-20.03-LTS/debuginfo/$basearch/RPM-GPG-KEY-openEuler [source] name=source baseurl=http://repo.openeuler.org/openEuler-20.03-LTS/source/ enabled=1 gpgcheck=1 gpgkey=http://repo.openeuler.org/openEuler-20.03-LTS/source/RPM-GPG-KEY-openEuler [update] name=update baseurl=http://repo.openeuler.org/openEuler-20.03-LTS/update/$basearch/ enabled=0 gpgcheck=1 gpgkey=http://repo.openeuler.org/openEuler-20.03-LTS/OS/$basearch/RPM-GPG-KEY-openEuler 产生.config文件

(如果不是第一次编译或者编译出错需执行make mrproper)

make menuconfig

进入如下界面 编译内核 进入Enable loadable module support 设置参数 如果Module signature verification为*号则按空格取消,其余不变,保存退出(不然可能会出现证书验证的问题)

编译内核

安装bc

yum install bc -y

在主目录下执行make(后面的j8为8线程,单make大概需编译3小时,多线程可减少编译时间,可结合自己电脑配置决定线程数)

make -j8

等待make结束后(内核和模块都会被编译,因此不需要再单独编译模块)

安装模块 make INSTALL_MOD_STRIP=1 modules_install 安装内核 make INSTALL_MOD_STRIP=1 install 安装完成

查看

重启 编写读取pfcount与jiffies的文件 进入自己安装的内核

进入内核

编写c程序 #include #include #include #include #include #include #include #include extern unsigned long volatile pfcount; static int my_proc_show(struct seq_file* m, void* v) { seq_printf(m, "The pfcount is %ld and jiffies is %ld!\n", pfcount,jiffies); return 0; } static int my_proc_open(struct inode* inode, struct file* file) { return single_open(file, my_proc_show, NULL); } static struct file_operations my_fops = { .owner = THIS_MODULE, .open = my_proc_open, .release = single_release, .read = seq_read, .llseek = seq_lseek, }; static int __init my_init(void) { struct proc_dir_entry* file = proc_create("readpfcount",0x0644, NULL, &my_fops); if (!file) { printk("proc_create failed.\n"); return -ENOMEM; } return 0; } static void __exit my_exit(void) { remove_proc_entry("readpfcount", NULL); } module_init(my_init); module_exit(my_exit); MODULE_LICENSE("GPL"); 编写Makefile ifneq ($(KERNELRELEASE),) obj-m:=readpfcount.o else KDIR:= /lib/modules/$(shell uname -r)/build KVER?=$(shell uname -r) PWD:= $(shell pwd) default: $(MAKE) -C $(KDIR) M=$(PWD) modules clean: $(MAKE) -C $(KDIR) M=$(PWD) clean endif make编译readpfcount.c文件 安装模块 insmod readpfcount.ko

利用命令lsmod可以看见模块已被安装 lsmod

查看pfcount与jiffies值 cat /proc/readpfcount

cat

实验完成


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有