【发布时间】:2016-02-25 08:59:24
【问题描述】:
我想检索自内核启动以来经过的时间(在内核空间中)。应该是printk(); 使用的时间匹配(例如:[ 5.832000] message)。
jiffies 提供不同的时间,所以我不确定它是否适合我。
我怎样才能做到这一点?
【问题讨论】:
标签: c time linux-kernel
我想检索自内核启动以来经过的时间(在内核空间中)。应该是printk(); 使用的时间匹配(例如:[ 5.832000] message)。
jiffies 提供不同的时间,所以我不确定它是否适合我。
我怎样才能做到这一点?
【问题讨论】:
标签: c time linux-kernel
使用get_monotonic_boottime 怎么样? jiffies会在开机前5分钟初始化,以保证开机后很快就有溢出并检测bug。
【讨论】:
printk implementation lies in kernel/printk/printk.c souce file.
Here it uses following structure before writing log into buffer which we see in console.
struct printk_log {
u64 ts_nsec; /* timestamp in nanoseconds */
u16 len; /* length of entire record */
u16 text_len; /* length of text buffer */
u16 dict_len; /* length of dictionary buffer */
u8 facility; /* syslog facility */
u8 flags:5; /* internal record flags */
u8 level:3; /* syslog level */
};
ts_nsec -> This parameter is set by function "local_clock" which in turn calls "Sched_clock" [ defined in /kernel/sched/clock.c ].
unsigned long long __weak sched_clock(void)
{
return (unsigned long long)(jiffies - INITIAL_JIFFIES)
* (NSEC_PER_SEC / HZ);
}
#define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
i think this will give you more insight about the printk logging
【讨论】: