您的位置:首页 > 其它

内核定时机制API之getnstimeofday

2018-02-14 08:23 423 查看
static inline void getnstimeofday(struct timespec *ts)用于获得系统当前时间
并以timespec结构体的形式返回给用户.
其源码分析如下:
static inline void getnstimeofday(struct timespec *ts)
{
getnstimeofday64(ts);
}
直接调用getnstimeofday64
void getnstimeofday64(struct timespec64 *ts)
{
WARN_ON(__getnstimeofday64(ts));
}
又直接调用__getnstimeofday64,注意这里__getnstimeofday64 不能返回非0值,否则视为失败
int __getnstimeofday64(struct timespec64 *ts)
{
struct timekeeper *tk = &tk_core.timekeeper;
unsigned long seq;
u64 nsecs;

do {
seq = read_seqcount_begin(&tk_core.seq);

ts->tv_sec = tk->xtime_sec;
nsecs = timekeeping_get_ns(&tk->tkr_mono);

} while (read_seqcount_retry(&tk_core.seq, seq));

ts->tv_nsec = 0;
timespec64_add_ns(ts, nsecs);

/*
* Do not bail out early, in case there were callers still using
* the value, even in the face of the WARN_ON.
*/
#这个函数唯一可能失败的地方就是timekeeping 处于suspend中。
if (unlikely(timekeeping_suspended))
return -EAGAIN;
return 0;
}
这个函数我们之前分析过,主要从timekeeper中回去当前时间,然后转成timespec64,返回给用户
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: