Changeset 679 for GPL/trunk/lib32/timer.c
- Timestamp:
- Mar 18, 2021, 8:57:36 PM (4 years ago)
- Location:
- GPL/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GPL/trunk
- Property svn:mergeinfo changed
/GPL/branches/uniaud32-linux-3.2.102 (added) merged: 611-614 /GPL/branches/uniaud32-next (added) merged: 615-678
- Property svn:mergeinfo changed
-
GPL/trunk/lib32/timer.c
r445 r679 30 30 #include <asm/io.h> 31 31 #include <linux/time.h> 32 #include <linux/math64.h> 33 #include <linux/clocksource.h> 32 34 33 35 #define LINUX … … 36 38 #include <dbgos2.h> 37 39 40 #pragma pack(1) 41 #include "infoseg.h" 42 #pragma pack() 43 extern PVOID KernSISData; 44 #define KernSISData ((struct InfoSegGDT *)&KernSISData) 45 38 46 static long jiffiems = 1000/HZ; 39 47 static long lasttime = 0; … … 47 55 long delta, newtime, remainder; 48 56 49 newtime = os2gettimemsec();57 newtime = KernSISData->SIS_MsCount; 50 58 delta = newtime - lasttime; 51 59 … … 95 103 { 96 104 #if 0 97 tv->tv_sec = 0; // os2gettimesec();98 tv->tv_usec = os2gettimemsec()* 1000;105 tv->tv_sec = 0; //KernSISData->SIS_BigTime; 106 tv->tv_usec = KernSISData->SIS_MsCount * 1000; 99 107 #else /* r.ihle patch */ 100 unsigned u = os2gettimemsec();108 unsigned u = KernSISData->SIS_MsCount; 101 109 tv->tv_sec = u / 1000; 102 110 tv->tv_usec = (u % 1000) * 1000; … … 140 148 //****************************************************************************** 141 149 //****************************************************************************** 150 151 /** 152 * ns_to_timespec - Convert nanoseconds to timespec 153 * @nsec: the nanoseconds value to be converted 154 * 155 * Returns the timespec representation of the nsec parameter. 156 */ 157 struct timespec ns_to_timespec(const s64 nsec) 158 { 159 struct timespec ts; 160 s32 rem; 161 162 if (!nsec) { 163 ts.tv_sec = 0; 164 ts.tv_nsec = 0; 165 return ts; 166 } 167 168 ts.tv_sec = div_s64_rem(nsec, NSEC_PER_SEC, &rem); 169 if (unlikely(rem < 0)) { 170 ts.tv_sec--; 171 rem += NSEC_PER_SEC; 172 } 173 ts.tv_nsec = rem; 174 175 return ts; 176 } 177 178 179 //****************************************************************************** 180 //****************************************************************************** 181 182 /** 183 * ns_to_timespec - Convert nanoseconds to timespec 184 * @nsec: the nanoseconds value to be converted 185 * 186 * Returns the timespec representation of the nsec parameter. 187 */ 188 struct timespec64 ns_to_timespec64(const s64 nsec) 189 { 190 struct timespec64 ts; 191 s32 rem; 192 193 if (!nsec) { 194 ts.tv_sec = 0; 195 ts.tv_nsec = 0; 196 return ts; 197 } 198 199 ts.tv_sec = div_s64_rem(nsec, NSEC_PER_SEC, &rem); 200 if (unlikely(rem < 0)) { 201 ts.tv_sec--; 202 rem += NSEC_PER_SEC; 203 } 204 ts.tv_nsec = rem; 205 206 return ts; 207 } 208 //****************************************************************************** 209 //****************************************************************************** 210 211 void timecounter_init(struct timecounter *tc, 212 const struct cyclecounter *cc, 213 u64 start_tstamp) 214 { 215 tc->cc = cc; 216 tc->cycle_last = cc->read(cc); 217 tc->nsec = start_tstamp; 218 } 219 220 /** 221 * timecounter_read_delta - get nanoseconds since last call of this function 222 * @tc: Pointer to time counter 223 * 224 * When the underlying cycle counter runs over, this will be handled 225 * correctly as long as it does not run over more than once between 226 * calls. 227 * 228 * The first call to this function for a new time counter initializes 229 * the time tracking and returns an undefined result. 230 */ 231 static u64 timecounter_read_delta(struct timecounter *tc) 232 { 233 cycle_t cycle_now, cycle_delta; 234 u64 ns_offset; 235 236 /* read cycle counter: */ 237 cycle_now = tc->cc->read(tc->cc); 238 239 /* calculate the delta since the last timecounter_read_delta(): */ 240 cycle_delta = (cycle_now - tc->cycle_last) & tc->cc->mask; 241 242 /* convert to nanoseconds: */ 243 ns_offset = cyclecounter_cyc2ns(tc->cc, cycle_delta); 244 245 /* update time stamp of timecounter_read_delta() call: */ 246 tc->cycle_last = cycle_now; 247 248 return ns_offset; 249 } 250 251 u64 timecounter_read(struct timecounter *tc) 252 { 253 u64 nsec; 254 255 /* increment time by nanoseconds since last call */ 256 nsec = timecounter_read_delta(tc); 257 nsec += tc->nsec; 258 tc->nsec = nsec; 259 260 return nsec; 261 } 262 263 /** 264 * set_normalized_timespec - set timespec sec and nsec parts and normalize 265 * 266 * @ts: pointer to timespec variable to be set 267 * @sec: seconds to set 268 * @nsec: nanoseconds to set 269 * 270 * Set seconds and nanoseconds field of a timespec variable and 271 * normalize to the timespec storage format 272 * 273 * Note: The tv_nsec part is always in the range of 274 * 0 <= tv_nsec < NSEC_PER_SEC 275 * For negative values only the tv_sec field is negative ! 276 */ 277 void set_normalized_timespec64(struct timespec64 *ts, time64_t sec, s64 nsec) 278 { 279 while (nsec >= NSEC_PER_SEC) { 280 /* 281 * The following asm() prevents the compiler from 282 * optimising this loop into a modulo operation. See 283 * also __iter_div_u64_rem() in include/linux/time.h 284 */ 285 // asm("" : "+rm"(nsec)); 286 nsec -= NSEC_PER_SEC; 287 ++sec; 288 } 289 while (nsec < 0) { 290 // asm("" : "+rm"(nsec)); 291 nsec += NSEC_PER_SEC; 292 --sec; 293 } 294 ts->tv_sec = sec; 295 ts->tv_nsec = nsec; 296 }
Note:
See TracChangeset
for help on using the changeset viewer.