Xen添加hypercall获取page_fault次数

 

1. 首先注册一个hypercall调用号。
xen/include/public/xen.h
 #define __HYPERVISOR_kexec_op             37
+#define __HYPERVISOR_print                   38

2.更新系统调用表
/xen/arch/x86/x86_32/entry.S
ENTRY(hypercall_table)
       
   .long do_kexec_op
+  .long do_print_string

ENTRY(hypercall_args_table)

   .byte 2 /* do_kexec_op          */
+  .byte 1

3. 定义函数头文件
/xen/include/asm-x86/hypercall.h

extern int
do_kexec(
    unsigned long op, unsigned arg1, XEN_GUEST_HANDLE(void) uarg);

+extern int
+do_print(void);

4.在/xen/arch/x86/traps.c 中
添加一个全局变量
long mynr_page_fault=0;

在do_page_fault()函数中统计次数,每执行一次,mynr_page_fault加1.


自定义函数
int do_print(void)

{

    printk("#####################test begin/n");

    printk("nr_page_fault: %ld/n",mynr_page_fault);

    return 1;

}
然后make dist、make install,制作初始化启动盘。

 

5、编辑一个print.c文件,在用户空间测试用。

 

#include <stdio.h>  
#include <stdlib.h>  
#include <errno.h>  
#include <sys/ioctl.h>  
#include <sys/types.h>  
#include <fcntl.h>  
#include <string.h>  
#include <xenctrl.h>  
#include <xen/sys/privcmd.h>  
int main()  
{  
    int fd, ret;       
    privcmd_hypercall_t hcall = {  
        __HYPERVISOR_print_string,
        {0,0,0,0,0}  
    };  
    fd = open("/proc/xen/privcmd", O_RDWR);  
    if (fd < 0)
 {  
        perror("open");  
        exit(1);  
    } else 
        printf("fd = %d/n", fd);  
    ret = ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, &hcall);  
    printf("ret = %d/n", ret);  
}

 

6、测试
[root@locahost ~] gcc -o a print.c

[root@locahost ~] ./a

[root@locahost ~] xm dm|tail -n 1

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值