给定使用 C++ 或 C,我如何测量在 linux 下进行线程切换需要多长时间?可能吗?
Given using C++ or C, how could I measure how long it takes to do a thread switch under linux?Is it possible?
使用 C++ 或 C 给定,我如何测量在 Linux 下进行线程切换需要多长时间?可能吗?最多平台,需要多长时间?谁能给我一些典型的价值?
我确实不想测量线程量子。我希望找到一种实用的方法来测量将一个线程转移到另一个线程的持续时间(而不是线程可以运行多长时间(。
如果您能提供代码,我将不胜感激。
如果能就此问题提供任何提示,我将不胜感激。
再见 :)
这是可能的,但您需要对内核代码进行一些更改。所以 openwrt 或其他东西可能对你有好处。
您可以看到我的博客和源代码来解决问题。抢占时间表会做时间检查,如下所示
/*
* Preempt the current task with a newly woken task if needed:
*/
static void
check_preempt_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr)
{
unsigned long ideal_runtime, delta_exec;
struct sched_entity *se;
s64 delta;
ideal_runtime = sched_slice(cfs_rq, curr);
delta_exec = curr->sum_exec_runtime - curr->prev_sum_exec_runtime;
if (delta_exec > ideal_runtime) {
resched_curr(rq_of(cfs_rq));
/*
* The current task ran long enough, ensure it doesn't get
* re-elected due to buddy favours.
*/
clear_buddies(cfs_rq, curr);
return;
}
/*
* Ensure that a task that missed wakeup preemption by a
* narrow margin doesn't have to wait for a full slice.
* This also mitigates buddy induced latencies under load.
*/
if (delta_exec < sysctl_sched_min_granularity)
return;
se = __pick_first_entity(cfs_rq);
delta = curr->vruntime - se->vruntime;
if (delta < 0)
return;
if (delta > ideal_runtime)
resched_curr(rq_of(cfs_rq));
}
在这里,我们有几个时间对您有帮助
ideal_runtime:此任务在此计划周期内运行的时间
sum_exec_runtime:任务运行的总时间
prev_sum_exec_runtime : 历史总时间
相关文章:
- 我使用 OpenMP 的线程越多,执行时间就越长,这是怎么回事?
- 给定使用 C++ 或 C,我如何测量在 linux 下进行线程切换需要多长时间?可能吗?
- 将线程锁定很长时间
- 即使长时间等待,C++线程也不会加入
- 锁通过线程保留的时间太长
- 在关闭应用程序期间正确关闭线程,该线程可能会运行很长时间的循环
- 使用多个线程的并行向量乘法比顺序乘法需要更长的时间
- C++线程安全时间计数类
- 如何在英特尔TBB中拥有长时间等待的线程
- 具有随机数总和的多线程执行时间
- C++11 线程:剩余时间的睡眠
- 如何使生成的线程拖延足够长的时间以使生成线程执行某些操作
- 单独线程中的 GetDC 函数需要很长时间才能返回
- 线程运行时间最少
- 在Windows下,线程的创建和终止需要多长时间
- 多线程变化需要更长的时间
- 如何终止长时间运行的Qt线程
- C++ 线程执行时间和另一个线程中的执行线程
- 多线程程序比单线程程序执行时间更长
- c++线程等待时间