鉴于使用C ++或C,我如何测量在Linux下执行线程切换需要多长时间?有可能吗?

问题描述 投票:0回答:1

考虑到使用C ++或C,我如何测量在Linux下进行线程切换需要多长时间?有可能吗?在大多数平台上,需要多长时间?有人可以给我一些典型的价值吗?

我实际上不想测量线程数量。我希望找到一种实用的方法来测量将一个线程切换到另一个线程的持续时间(不是线程可以运行多长时间)。

[如果您能提供代码,我将不胜感激。

对于这个问题的任何提示,我将不胜感激。

c++ linux-kernel scheduler scheduling schedule
1个回答
0
投票

再见:)

可能,但是您需要对内核代码进行一些更改。因此,openwrt或其他可能对您有利。

您可以看到我的blogsource code解决了该问题。抢占时间表将进行时间检查,如下所示

/*
 * 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:历史记录总时间

© www.soinside.com 2019 - 2024. All rights reserved.