您的位置:首页 > 其它

内核定时机制API之__round_jiffies

2018-02-08 08:22 405 查看
unsigned long __round_jiffies(unsigned long j, int cpu)用户将jiffies 转成HZ的整数倍也就是整秒.
其源码分析如下:
unsigned long __round_jiffies(unsigned long j, int cpu)
{
return round_jiffies_common(j, cpu, false);
}
static unsigned long round_jiffies_common(unsigned long j, int cpu,
bool force_up)
{
int rem;
unsigned long original = j;

j += cpu * 3;

rem = j % HZ;

#这里的force_up等于false,所以这里分解rem < HZ/4 来决定是round_down还是round_up
if (rem < HZ/4 && !force_up) /* round down */
j = j - rem;
else /* round up */
j = j - rem + HZ;

/* now that we have rounded, subtract the extra skew again */
j -= cpu * 3;

/*
* Make sure j is still in the future. Otherwise return the
* unmodified value.
*/
#看当前的jiffies是否已经比形参j快了,一般情况下应该不会,所以这里返回round后的j
return time_is_after_jiffies(j) ? j : original;
}
从这里看到cpu 个数越大,这个函数返回的值越大.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: