简体   繁体   English

从Linux内核启动的时间

[英]Time from startup in linux kernel

I would like to retrieve time passed since kernel's start (in kernel space). 我想检索自内核启动以来(内核空间中)经过的时间。 It should be the match the time printk(); 它应该与时间printk();匹配printk(); is using (For example: [ 5.832000] message ). 正在使用(例如: [ 5.832000] message )。

jiffies provide different time, so I am not sure it fits me. jiffies提供不同的时间,所以我不确定是否适合我。

How can I achieve this? 我该如何实现?

What about using get_monotonic_boottime ? 使用get_monotonic_boottime怎么get_monotonic_boottime jiffies are initialized to 5 minutes before boot to ensure that there is an overflow soon after booting and detect bugs. jiffies初始化为启动前5分钟,以确保启动后不久有溢出并检测错误。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM