zoukankan      html  css  js  c++  java
  • 内核当前时间

    current_kernel_time

    struct timespec current_kernel_time(void)
    {
        struct timespec now;
        unsigned long seq;
    
        do {
            seq = read_seqbegin(&xtime_lock);
    
            now = xtime;
        } while (read_seqretry(&xtime_lock, seq));
    
        return now;
    }

    do_gettimeofday

    struct timespec {
        __kernel_time_t tv_sec;         /* seconds */
        long        tv_nsec;        /* nanoseconds */
    };
    
    void do_gettimeofday(struct timeval *tv)
    {
        struct timespec now;
    
        getnstimeofday(&now);
        tv->tv_sec = now.tv_sec;
        tv->tv_usec = now.tv_nsec/1000;
    }
    
    void getnstimeofday(struct timespec *ts)
    {
        unsigned long seq;
        s64 nsecs;
    
        WARN_ON(timekeeping_suspended);
    
        do {
            seq = read_seqbegin(&xtime_lock);
    
            *ts = xtime;
            nsecs = timekeeping_get_ns();
    
            /* If arch requires, add in gettimeoffset() */
            nsecs += arch_gettimeoffset();
    
        } while (read_seqretry(&xtime_lock, seq));
    
        timespec_add_ns(ts, nsecs);
    }

    rtc_time_to_tm

    struct rtc_time {
        int tm_sec;
        int tm_min;
        int tm_hour;
        int tm_mday;
        int tm_mon;
        int tm_year;
        int tm_wday;
        int tm_yday;
        int tm_isdst;
    };
    
    int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time)
    {
        *time = mktime(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
                tm->tm_hour, tm->tm_min, tm->tm_sec);
        return 0;
    }

    rtc_time_to_tm

    void rtc_time_to_tm(unsigned long time, struct rtc_time *tm)
    {
        unsigned int month, year;
        int days;
    
        days = time / 86400;
        time -= (unsigned int) days * 86400;
    
        /* day of the week, 1970-01-01 was a Thursday */
        tm->tm_wday = (days + 4) % 7;
    
        year = 1970 + days / 365;
        days -= (year - 1970) * 365
            + LEAPS_THRU_END_OF(year - 1)
            - LEAPS_THRU_END_OF(1970 - 1);
        if (days < 0) {
            year -= 1;
            days += 365 + is_leap_year(year);
        }
        tm->tm_year = year - 1900;
        tm->tm_yday = days + 1;
    
        for (month = 0; month < 11; month++) {
            int newdays;
    
            newdays = days - rtc_month_days(month, year);
            if (newdays < 0)
                break;
            days = newdays;
        }
        tm->tm_mon = month;
        tm->tm_mday = days + 1;
    
        tm->tm_hour = time / 3600;
        time -= tm->tm_hour * 3600;
        tm->tm_min = time / 60;
        tm->tm_sec = time - tm->tm_min * 60;
    }
  • 相关阅读:
    Symfony Component HttpKernel Exception AccessDeniedHttpException This action is unauthorized.
    AngularJs ng-repeat中使用ng-model
    JS数组排序sort()方法同时按照两种方式排序的用法
    MongoDB
    Node基本学习
    小程序 五 组件使用
    小程序 四 事件类型
    小程序 二 template模板(代码复用)
    小程序 wxs 脚本语言(2种使用方式)
    小程序初体验 wx:for
  • 原文地址:https://www.cnblogs.com/zhangxuechao/p/11709653.html
Copyright © 2011-2022 走看看