获取内核时间片ID

获取内核时间片ID

背景:在我的内核驱动程序中,我发现用于跟踪错误的时间测量存在差异。我确信这是因为在一次尝试中,驱动程序被中断,不得不暂停,直到下一个时间片。
现在我很好奇我是否能追踪到这一点。

我的问题更像是一个一般想法,而不是一个实际问题:
是否可以获得当前时间片ID或类似的东西?

这是一个小的伪代码示例,说明了我如何使用此代码进行调试。

long starttime = get_time();  // Just a function to get the time
long timeslice_id = get_scheduler_timeslice();  // This is what I am looking for

do_lengthy_things();

print("Code took %d ms to run.", get_time() - starttime);

if (get_scheduler_timeslice() != timeslice_id)
  print("There was a task switch while running this code, don't wonder about the time.");

相关内容