内核定时机制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 个数越大,这个函数返回的值越大.
相关文章推荐
- 内核定时机制API之__round_jiffies_relative
- 内核定时机制API之ns_to_timespec64 和 ns_to_timeval
- 内核定时机制API之do_settimeofday64
- 内核定时机制API之del_timer_sync
- 内核定时机制API之get_seconds
- 内核定时机制API之set_normalized_timespec64
- 内核定时机制API之do_gettimeofday
- 内核定时机制API之timespec64_add
- 内核定时机制API之add_timer
- 内核定时机制API之timespec64_compare
- 内核定时机制API之add_timer_on
- 内核定时机制API之current_kernel_time
- 内核定时机制API之del_timer
- 内核定时机制API之getnstimeofday
- 内核定时机制API之msleep 和 msleep_interruptible
- 内核定时机制API之timer_setup
- 内核定时机制API之usleep_range
- 内核定时机制API之mktime
- 内核同步机制API之down_xx
- 内核的定时机制实验