clock_gettime不能即时更新 [英] clock_gettime can not update instantly
问题描述
更新
检查时间分辨率后,我们试图在内核空间调试问题。
After checking the time resolution, we tried to debug the problem in kernel space.
unsigned long long task_sched_runtime(struct task_struct *p)
{
unsigned long flags;
struct rq *rq;
u64 ns = 0;
rq = task_rq_lock(p, &flags);
ns = p->se.sum_exec_runtime + do_task_delta_exec(p, rq);
task_rq_unlock(rq, &flags);
//printk("task_sched runtime\n");
return ns;
}
我们的新的实验表明,该时间 P-GT&; se.sum_exec_runtime
不更新即时。但是,如果我们添加的printk()
在函数内部。时间将即时更新。
Our new experiment shows that the time p->se.sum_exec_runtime
is not updated instantly. But if we add printk()
inside the function. the time will be updated instantly.
旧
我们正在开发一个Android程序。
然而,时间的函数来测量 threadCpuTimenanos()
是我们的平台上并不总是正确的。
We are developing an Android program.
However, the time measured by the function threadCpuTimenanos()
is not always correct on our platform.
试验后,我们发现,从时间 clock_gettime
不更新立即返回。
即使经过多次而循环迭代,我们得到的还是时间不会改变。
After experimenting, we found that the time returned from clock_gettime
is not updated instantly.
Even after several while loop iterations, the time we get still doesn't change.
下面是我们的示例code:
Here's our sample code:
while(1)
{
test = 1;
test = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &now);
printf(" clock gettime test 1 %lx, %lx , ret = %d\n",now.tv_sec , now.tv_nsec,test );
pre = now.tv_nsec;
sleep(1);
}
这code运行在x86 PC上还好。不过,这并不正确地在我们的嵌入式平台的ARM Cortex-A9内核2.6.35.13运行。
This code runs okay on an x86 PC. But it does not run correctly in our embedded platform ARM Cortex-A9 with kernel 2.6.35.13.
任何想法?
推荐答案
我改为使用CLOCK_MONOTONIC_RAW的clock_gettime,分配线程一个CPU,我得到不同的值。
我也有一个双核Cortex-A9工作
I changed the clock_gettime to use the CLOCK_MONOTONIC_RAW , assigned the thread to one CPU and I get different values. I am also working with a dual cortex-A9
while(1)
{
test = 1;
test = clock_gettime(CLOCK_MONOTONIC_RAW, &now);
printf(" clock gettime test 1 %lx, %lx , ret = %d\n",now.tv_sec , now.tv_nsec, test );
pre = now.tv_nsec;
sleep(1);
}
这篇关于clock_gettime不能即时更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!