我想编写一个简单的“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/