time: add function to convert between calendar time and broken-down time for universal use
There are many similar code in kernel for one object: convert time between calendar time and broken-down time. Here is some source I found: fs/ncpfs/dir.c fs/smbfs/proc.c fs/fat/misc.c fs/udf/udftime.c fs/cifs/netmisc.c net/netfilter/xt_time.c drivers/scsi/ips.c drivers/input/misc/hp_sdc_rtc.c drivers/rtc/rtc-lib.c arch/ia64/hp/sim/boot/fw-emu.c arch/m68k/mac/misc.c arch/powerpc/kernel/time.c arch/parisc/include/asm/rtc.h ... We can make a common function for this type of conversion, At least we can get following benefit: 1: Make kernel simple and unify 2: Easy to fix bug in converting code 3: Reduce clone of code in future For example, I'm trying to make ftrace display walltime, this patch will make me easy. This code is based on code from glibc-2.6 Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@elte.hu> Cc: Pavel Machek <pavel@ucw.cz> Cc: Andi Kleen <andi@firstfloor.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
此提交包含在:
@@ -155,6 +155,34 @@ extern void timekeeping_leap_insert(int leapsecond);
|
||||
struct tms;
|
||||
extern void do_sys_times(struct tms *);
|
||||
|
||||
/*
|
||||
* Similar to the struct tm in userspace <time.h>, but it needs to be here so
|
||||
* that the kernel source is self contained.
|
||||
*/
|
||||
struct tm {
|
||||
/*
|
||||
* the number of seconds after the minute, normally in the range
|
||||
* 0 to 59, but can be up to 60 to allow for leap seconds
|
||||
*/
|
||||
int tm_sec;
|
||||
/* the number of minutes after the hour, in the range 0 to 59*/
|
||||
int tm_min;
|
||||
/* the number of hours past midnight, in the range 0 to 23 */
|
||||
int tm_hour;
|
||||
/* the day of the month, in the range 1 to 31 */
|
||||
int tm_mday;
|
||||
/* the number of months since January, in the range 0 to 11 */
|
||||
int tm_mon;
|
||||
/* the number of years since 1900 */
|
||||
long tm_year;
|
||||
/* the number of days since Sunday, in the range 0 to 6 */
|
||||
int tm_wday;
|
||||
/* the number of days since January 1, in the range 0 to 365 */
|
||||
int tm_yday;
|
||||
};
|
||||
|
||||
void time_to_tm(time_t totalsecs, int offset, struct tm *result);
|
||||
|
||||
/**
|
||||
* timespec_to_ns - Convert timespec to nanoseconds
|
||||
* @ts: pointer to the timespec variable to be converted
|
||||
|
新增問題並參考
封鎖使用者