Messages in this thread Patch in this message | | | Date | Tue, 02 Nov 1999 20:30:39 +0100 | From | Michael Schimek <> | Subject | Unadjusted system time |
| |
Hi all,
For the new multimedia interfaces we need some global system clock for timestamping and synchronization purposes. It has been argued the time-of-day clock is inappropriate since not guaranteed to increase monotonically. Thus we (people working on the V4L2 and ALSA projects) would like to implement a clock similar to SGI's Unadjusted System Time for Linux.
UST is basically the same as time-of-day, except that it counts system uptime in units of nanoseconds, can be read only and values are passed in 64 bit containers. A more in-depth discussion is available at <http://reality.sgi.com/cpirazzi_engr/lg/time/intro.html>.
Below you see my naive idea how to add it (also on my page <http://millennium.diads.com/mschimek/ust>), please tell me what you think.
I'm not on this list, CC please.
V4L2: <http://millennium.diads.com/bdirks/v4l2.htm> ALSA: <http://www.alsa-project.arg>
diff -BdNPru linux-2.2/arch/i386/kernel/entry.S linux-2.2u/arch/i386/kernel/entry.S --- linux/arch/i386/kernel/entry.S Fri Oct 22 05:59:56 1999 +++ linux-2.2.13u/arch/i386/kernel/entry.S Fri Oct 22 06:15:15 1999 @@ -562,6 +562,7 @@ .long SYMBOL_NAME(sys_ni_syscall) /* streams1 */ .long SYMBOL_NAME(sys_ni_syscall) /* streams2 */ .long SYMBOL_NAME(sys_vfork) /* 190 */ + .long SYMBOL_NAME(sys_getusttodpair) /* * NOTE!! This doesn't have to be exact - we just have @@ -569,6 +570,6 @@ * entries. Don't panic if you notice that this hasn't * been shrunk every time we add a new system call. */ - .rept NR_syscalls-190 + .rept NR_syscalls-191 .long SYMBOL_NAME(sys_ni_syscall) .endr diff -BdNPru linux-2.2/arch/i386/kernel/time.c linux-2.2u/arch/i386/kernel/time.c --- linux/arch/i386/kernel/time.c Fri Oct 22 05:59:57 1999 +++ linux-2.2.13u/arch/i386/kernel/time.c Fri Oct 22 06:15:15 1999 @@ -261,6 +261,36 @@ tv->tv_usec = usec; } +void do_getusttodpair(stamp_t *ust, struct timeval *tv) +{ + extern volatile unsigned long lost_ticks; + unsigned long flags; + unsigned long usec, sec; + + read_lock_irqsave(&xtime_lock, flags); + usec = do_gettimeoffset(); + { + unsigned long lost = lost_ticks; + if (lost) + usec += lost * (1000000 / HZ); + } + if (ust) + *ust = ustime + (stamp_t) usec * 1000L; + sec = xtime.tv_sec; + usec += xtime.tv_usec; + read_unlock_irqrestore(&xtime_lock, flags); + + if (tv) { + while (usec >= 1000000) { + usec -= 1000000; + sec++; + } + + tv->tv_sec = sec; + tv->tv_usec = usec; + } +} + void do_settimeofday(struct timeval *tv) { write_lock_irq(&xtime_lock); diff -BdNPru linux-2.2/include/asm-i386/unistd.h linux-2.2u/include/asm-i386/unistd.h --- linux/include/asm-i386/unistd.h Sat May 29 09:11:31 1999 +++ linux-2.2.13u/include/asm-i386/unistd.h Fri Oct 22 06:15:15 1999 @@ -195,6 +195,7 @@ #define __NR_getpmsg 188 /* some people actually want streams */ #define __NR_putpmsg 189 /* some people actually want streams */ #define __NR_vfork 190 +#define __NR_getusttodpair 191 /* user-visible error numbers are in the range -1 - -122: see <asm-i386/errno.h> */ diff -BdNPru linux-2.2/include/linux/sched.h linux-2.2u/include/linux/sched.h --- linux/include/linux/sched.h Fri Oct 22 06:02:10 1999 +++ linux-2.2.13u/include/linux/sched.h Fri Oct 22 06:15:15 1999 @@ -473,6 +473,7 @@ extern unsigned long itimer_ticks; extern unsigned long itimer_next; extern struct timeval xtime; +extern stamp_t ustime; extern void do_timer(struct pt_regs *); extern unsigned int * prof_buffer; diff -BdNPru linux-2.2/include/linux/time.h linux-2.2u/include/linux/time.h --- linux/include/linux/time.h Sat May 29 09:07:50 1999 +++ linux-2.2.13u/include/linux/time.h Fri Oct 22 06:15:15 1999 @@ -89,4 +89,16 @@ struct timeval it_value; /* current value */ }; +/* UST */ + +#ifndef STAMP_T +#define STAMP_T +typedef __s64 stamp_t; +#endif + +#ifdef __KERNEL__ +extern void do_getusttodpair(stamp_t *ust, struct timeval *tv); +#define do_getust(ust) do_getusttodpair(ust,NULL) +#endif + #endif diff -BdNPru linux-2.2/kernel/ksyms.c linux-2.2u/kernel/ksyms.c --- linux/kernel/ksyms.c Fri Oct 22 06:02:11 1999 +++ linux-2.2.13u/kernel/ksyms.c Fri Oct 22 06:15:15 1999 @@ -402,6 +402,7 @@ /* time */ EXPORT_SYMBOL(get_fast_time); +EXPORT_SYMBOL(do_getusttodpair); /* library functions */ EXPORT_SYMBOL(strnicmp); diff -BdNPru linux-2.2/kernel/sched.c linux-2.2u/kernel/sched.c --- linux/kernel/sched.c Fri Oct 22 06:02:11 1999 +++ linux-2.2.13u/kernel/sched.c Fri Oct 22 06:15:15 1999 @@ -47,10 +47,14 @@ unsigned securebits = SECUREBITS_DEFAULT; /* systemwide security settings */ long tick = (1000000 + HZ/2) / HZ; /* timer interrupt period */ +long ustick = (1000000000 + HZ/2) / HZ; /* The current time */ volatile struct timeval xtime __attribute__ ((aligned (16))); +/* Unadjusted system time */ +volatile stamp_t ustime; + /* Don't completely fail for HZ > 500. */ int tickadj = 500/HZ ? : 1; /* microsecs */ @@ -1396,6 +1400,7 @@ do { ticks--; update_wall_time_one_tick(); + ustime += ustick; } while (ticks); if (xtime.tv_usec >= 1000000) { diff -BdNPru linux-2.2/kernel/time.c linux-2.2u/kernel/time.c --- linux/kernel/time.c Fri Oct 22 06:02:12 1999 +++ linux-2.2.13u/kernel/time.c Fri Oct 22 06:15:15 1999 @@ -128,6 +128,44 @@ return 0; } +#if !defined(__i386__) /* arch's that do not support it */ + +void do_getusttodpair(stamp_t *ust, struct timeval *tv) +{ + struct timeval ktv; + + if (!tv) + tv = &ktv; + + do_gettimeofday(tv); + + if (ust) { + *ust = (stamp_t) tv->tv_sec * 1000000L + tv->tv_usec; + *ust *= 1000L; + } +} + +#endif + +asmlinkage int sys_getusttodpair(stamp_t *ust, struct timeval *tv, struct timezone *tz) +{ + stamp_t kust; + struct timeval ktv; + + do_getusttodpair(&kust, &ktv); + + if (ust) + if (copy_to_user(ust, &kust, sizeof(kust))) + return -EFAULT; + if (tv) + if (copy_to_user(tv, &ktv, sizeof(ktv))) + return -EFAULT; + if (tz) + if (copy_to_user(tz, &sys_tz, sizeof(sys_tz))) + return -EFAULT; + return 0; +} + /* * Adjust the time obtained from the CMOS to be UTC time instead of * local time. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |