xuke123 发表于 2015-10-12 07:21:30

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、测试
gcc -o a print.c
   ./a
   xm dm|tail -n 1
  
  
  
             版权声明:本文为博主原创文章,未经博主允许不得转载。
页: [1]
查看完整版本: Xen添加hypercall获取page_fault次数