00001
00002
00003
00004
00005
00006 #ifndef __TIME_H__
00007 #define __TIME_H__
00008
00009 extern unsigned long cpu_khz;
00010 extern unsigned long fast_gettimeoffset_quotient;
00011
00012 static inline long long llimd(long long ll, int mult, int div);
00013
00014
00015 static inline unsigned long long int us2clock(unsigned long u)
00016 {
00017 return llimd(u, cpu_khz, 1000);
00018 }
00019
00020 static inline unsigned long int clock2ms(unsigned long long c)
00021 {
00022 return (unsigned long int)(llimd(c, fast_gettimeoffset_quotient, 1000) >> 32);
00023 }
00024
00025 static inline unsigned long int clock2us(unsigned long long c)
00026 {
00027 return (unsigned long int) ((c * fast_gettimeoffset_quotient) >> 32);
00028 }
00029
00030 static inline unsigned long int clock2jiffies(unsigned long long c)
00031 {
00032 unsigned long long int tmp;
00033
00034 tmp = (c * fast_gettimeoffset_quotient) >> 32;
00035 return llimd(tmp, HZ, 1000000);
00036 }
00037
00038 static inline unsigned long int clock2subjiffies(unsigned long long c)
00039 {
00040 unsigned long long int tmp, tmp1, tmp2;
00041
00042 tmp = (c * fast_gettimeoffset_quotient) >> 32;
00043 tmp1 = llimd(tmp, HZ, 1000000);
00044 tmp2 = llimd(tmp1, 1000000, HZ);
00045 return c - llimd(tmp2, cpu_khz, 1000);
00046 }
00047
00048 static inline unsigned long long sched_read_clock(void)
00049 {
00050 unsigned long long res;
00051
00052 __asm__ __volatile__( "rdtsc" : "=A" (res));
00053 return res;
00054 }
00055
00056 static inline unsigned long sched_read_clock_us(void)
00057 {
00058 return clock2us(sched_read_clock());
00059 }
00060
00061
00062 static inline long long llimd(long long ll, int mult, int div)
00063 {
00064 __asm__ __volatile (\
00065 "movl %%edx,%%ecx; mull %%esi; movl %%eax,%%ebx; \n\t"
00066 "movl %%ecx,%%eax; movl %%edx,%%ecx; mull %%esi; \n\t"
00067 "addl %%ecx,%%eax; adcl $0,%%edx; divl %%edi; \n\t"
00068 "movl %%eax,%%ecx; movl %%ebx,%%eax; divl %%edi; \n\t"
00069 "sal $1,%%edx; cmpl %%edx,%%edi; movl %%ecx,%%edx; \n\t"
00070 "jge 1f; addl $1,%%eax; adcl $0,%%edx; 1:"
00071 : "=A" (ll)
00072 : "A" (ll), "S" (mult), "D" (div)
00073 : "%ebx", "%ecx");
00074 return ll;
00075 }
00076
00077 #endif