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