00001
00009
00010
00011
00012
00013
00014 #ifndef __RRES_TIME_H__
00015 #define __RRES_TIME_H__
00016
00017 #include <asm/param.h>
00018 #include <linux/version.h>
00019 #include "kal_timer.h"
00020
00021 #if (LINUX_VERSION_CODE<KERNEL_VERSION(2,6,0))
00022 #define CPU_KHZ_TYPE unsigned long
00023 #else
00024 #define CPU_KHZ_TYPE unsigned int
00025 #endif
00026 #ifdef QOS_KS
00027 extern CPU_KHZ_TYPE cpu_khz;
00028 #endif
00029
00030 #if !defined(QOS_KS)
00031 # include <sys/time.h>
00032 # include <time.h>
00033 # define do_gettimeofday(__tv) gettimeofday((__tv), NULL);
00034 #endif
00035
00036
00037 static inline long long llimd(long long ll, int mult, int div)
00038 {
00039 __asm__ __volatile (\
00040 "movl %%edx,%%ecx; mull %%esi; movl %%eax,%%ebx; \n\t"
00041 "movl %%ecx,%%eax; movl %%edx,%%ecx; mull %%esi; \n\t"
00042 "addl %%ecx,%%eax; adcl $0,%%edx; divl %%edi; \n\t"
00043 "movl %%eax,%%ecx; movl %%ebx,%%eax; divl %%edi; \n\t"
00044 "sal $1,%%edx; cmpl %%edx,%%edi; movl %%ecx,%%edx; \n\t"
00045 "jge 1f; addl $1,%%eax; adcl $0,%%edx; 1:"
00046 : "=A" (ll)
00047 : "A" (ll), "S" (mult), "D" (div)
00048 : "%ebx", "%ecx");
00049 return ll;
00050 }
00051
00052
00053
00054 static inline unsigned long long int us2clock(unsigned long u)
00055 {
00056 #if LINUX_VERSION_CODE<KERNEL_VERSION(2,6,0)
00057 return llimd(u, cpu_khz, 1000);
00058 #else
00059 return u;
00060 #endif
00061 }
00062
00063 static inline unsigned long int clock2ms(unsigned long long c)
00064 {
00065 #if LINUX_VERSION_CODE<KERNEL_VERSION(2,6,0)
00066 return (unsigned long int)(llimd(c, fast_gettimeoffset_quotient, 1000) >> 32);
00067 #else
00068 return llimd(c, 1, 1000);
00069 #endif
00070 }
00071
00072 static inline unsigned long int clock2us(unsigned long long c)
00073 {
00074 #if LINUX_VERSION_CODE<KERNEL_VERSION(2,6,0)
00075 return (unsigned long int) ((c * fast_gettimeoffset_quotient) >> 32);
00076 #else
00077 return c;
00078 #endif
00079 }
00080
00081 static inline unsigned long int clock2jiffies(unsigned long long c)
00082 {
00083 #if LINUX_VERSION_CODE<KERNEL_VERSION(2,6,0)
00084 c = (c * fast_gettimeoffset_quotient) >> 32;
00085 #endif
00086 return llimd(c, HZ, 1000000);
00087 }
00088
00089 static inline unsigned long long sched_read_clock(void)
00090 {
00091 unsigned long long int res;
00092 #if LINUX_VERSION_CODE<KERNEL_VERSION(2,6,0)
00093 __asm__ __volatile__( "rdtsc" : "=A" (res));
00094 #else
00095 struct timeval tv;
00096
00097 do_gettimeofday(&tv);
00098 res = (unsigned long long int)tv.tv_usec + (unsigned long long int)tv.tv_sec * 1000000LLU;
00099 #endif
00100 return res;
00101 }
00102
00103 static inline unsigned long sched_read_clock_us(void)
00104 {
00105 return clock2us(sched_read_clock());
00106 }
00107
00108 #if LINUX_VERSION_CODE<KERNEL_VERSION(2,6,0)
00109 static inline unsigned long int clock2subjiffies(unsigned long long c)
00110 {
00111 unsigned long long int tmp, tmp1, tmp2;
00112
00113 tmp = (c * fast_gettimeoffset_quotient) >> 32;
00114 tmp1 = llimd(tmp, HZ, 1000000);
00115 tmp2 = llimd(tmp1, 1000000, HZ);
00116 return c - llimd(tmp2, cpu_khz, 1000);
00117 }
00118 #endif
00119
00120
00121 extern kal_time_t sched_time;
00122
00123
00124 static inline void rres_init_time(void) {
00125
00126
00127 }
00128
00135 static inline void rres_sample_time(void) {
00136 sched_time = kal_time_now();
00137
00138 qos_log_debug("Sampled time: " KAL_TIME_FMT, KAL_TIME_FMT_ARG(sched_time));
00139 }
00140
00141 #endif
00142