c - 如何获取 xv6 中内核启动后的系统调用次数?

标签 c linux operating-system posix fork

我想编写一个简单的“C”程序来查找操作系统启动后的系统调用次数。我正在跟踪其他系统调用,例如 fork() 或 getpid() 并基本上复制它们的大部分内容。我不确定应该在哪里/何时增加计数器?有什么例子吗?

在 kernel/syscall.c 中定义计数器并相应地增加它是一个好主意吗?

void
syscall(void)
{
  int num;
  counter++; //mona
  num = proc->tf->eax;
  if(num > 0 && num < NELEM(syscalls) && syscalls[num] != NULL) {
    proc->tf->eax = syscalls[num]();
  } else {
    cprintf("%d %s: unknown sys call %d\n",
            proc->pid, proc->name, num);
    proc->tf->eax = -1;
  }
}

这也是我迄今为止在 kernel/sysproc.c 中用于简单系统调用的代码:

sys_getsyscallinfo(void)
{

 return counter;  //mona
}

但是我收到此错误:

kernel/sysproc.c: In function ‘sys_getsyscallinfo’:
kernel/sysproc.c:48: error: ‘counter’ undeclared (first use in this function)
kernel/sysproc.c:48: error: (Each undeclared identifier is reported only once
kernel/sysproc.c:48: error: for each function it appears in.)
make: *** [kernel/sysproc.o] Error 1

最佳答案

我在kernel/defs.h中将计数器变量定义为extern int,并在系统调用定义中将其用作kernel/sysproc.c中的返回值,并且增加了它,所有陷阱处理都在 kernel/syscall.c 中完成。我希望它有帮助。

关于c - 如何获取 xv6 中内核启动后的系统调用次数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18821107/

相关文章:

linux - 如何在 Linux 上使用 clone() 创建一个真正的线程?

operating-system - 虚拟化中的资源浪费

c - 基于堆栈的缓冲区溢出漏洞

python - 如何使用 python 变量而不是硬编码值创建 ctypes 变量?

c - 静态存储在内存中的全局变量在哪里?

c - 虚拟鼠标和 eventX

使用 KVM 进行 Linux 内核开发

php - Mysql连接VLAN外的外部/远程服务器

c++ - 为什么 ret 指令数大于调用指令数?

android - 最低要求 SDK - 百分比