Thursday, May 3, 2018

jiffies / time in linux kernel


https://cyberglory.wordpress.com/2011/08/21/jiffies-in-linux-kernel/

* jiffies will not be increased if timer interruption is disabled

#include <linux/time.h>

static s64 get_ns(void)
{
struct timespec ts;
getnstimeofday(&ts);
return timespec_to_ns(&ts);
}

unsigned long before, after;
unsigned int interval;

before = jiffies;
poll_wait(file, &runtime->sleep, wait);
after = jiffies;

interval = jiffies_to_usecs(after - before);

################################################

#include <linux/rtc.h>

struct timeval time;
unsigned long local_time;
 struct rtc_time tm_val;

do_gettimeofday(&time);
local_time = (u32)(time.tv_sec - (sys_tz.tz_minuteswest * 60));
rtc_time_to_tm(local_time, &tm_val);

printk(" @ (%04d-%02d-%02d %02d:%02d:%02d)\n", tm_val.tm_year + 1900, tm_val.tm_mon + 1,       tm_val.tm_mday, tm_val.tm_hour, tm_val.tm_min, tm_val.tm_sec);

################################################

struct timeval now;
struct tm tm_val;

do_gettimeofday(&now);
time_to_tm(now.tv_sec, 0, &tm_val);
printk(KERN_INFO "%d/%d %02d:%02d:%02d Days since 1 Jan: %d\n", tm_val.tm_mon + 1,
    1900 + tm_val.tm_year, tm_val.tm_hour, tm_val.tm_min,
    tm_val.tm_sec, tm_val.tm_yday);






No comments:

Post a Comment