Changeset 1971
- Timestamp:
- 04/09/08 15:37:35 (8 months ago)
- Location:
- features/performance/src
- Files:
-
- 6 modified
-
common/rdtsc.h (modified) (2 diffs)
-
common/timer.c (modified) (1 diff)
-
common/timer.h (modified) (5 diffs)
-
defines.h.in (modified) (2 diffs)
-
send_packets.c (modified) (6 diffs)
-
sleep.h (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
features/performance/src/common/rdtsc.h
r1970 r1971 106 106 */ 107 107 static inline void 108 rdtsc_sleep(const struct time valsleep)108 rdtsc_sleep(const struct timespec sleep) 109 109 { 110 110 u_int64_t sleep_until; … … 115 115 clicks_per_usec = clicks_per_usec > 0 ? clicks_per_usec : rdtsc_calibrate(0); 116 116 117 sleep_until += clicks_per_usec * TIME VAL_TO_MICROSEC(&sleep);117 sleep_until += clicks_per_usec * TIMESPEC_TO_MICROSEC(&sleep); 118 118 119 119 while (now < sleep_until) -
features/performance/src/common/timer.c
r1970 r1971 54 54 tvp->tv_usec = interval - (tvp->tv_sec * 1000000); 55 55 } 56 57 /* Divide tvs by div, storing the result in tvs */ 58 void timesdiv(struct timespec *tvs, float div) 59 { 60 double interval; 61 62 if (div == 0 || div == 1) 63 return; 64 65 interval = ((double)tvs->tv_sec * 1000000000 + tvs->tv_nsec) / (double)div; 66 tvs->tv_sec = interval / (int)1000000000; 67 tvs->tv_nsec = interval - (tvs->tv_nsec * 1000000000); 68 } 69 -
features/performance/src/common/timer.h
r1970 r1971 52 52 53 53 void timerdiv(struct timeval *tvp, float div); 54 void timesdiv(struct timespec *tvs, float div); 54 55 55 56 /* convert float time to struct timeval *tvp */ … … 69 70 #endif 70 71 72 #ifndef TIMESPEC_TO_TIMEVAL 73 #define TIMESPEC_TO_TIMEVAL(tv, ts) { \ 74 (tv)->tv_sec = (ts)->tv_sec; \ 75 (tv)->tv_usec = (ts)->tv_nsec / 1000; } 76 #endif 77 71 78 /* zero out a timer */ 72 79 #ifndef timerclear 73 80 #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 81 #endif 82 83 /* zero out a timespec */ 84 #ifndef timesclear 85 #define timesclear(tvs) (tvs)->tv_sec = (tvs)->tv_nsec = 0 74 86 #endif 75 87 … … 78 90 #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) 79 91 #endif 92 93 /* is timespec non-zero? */ 94 #ifndef timesisset 95 #define timesisset(tvs) ((tvs)->tv_sec || (tvs)->tv_nsec) 96 #endif 97 80 98 81 99 /* add tvp and uvp and store in vvp */ … … 105 123 #endif 106 124 125 #ifndef timessub 126 #define timessub(tsp, usp, vsp) \ 127 do { \ 128 (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ 129 (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \ 130 if ((vsp)->tv_nsec < 0) { \ 131 (vsp)->tv_sec--; \ 132 (vsp)->tv_nsec += 1000000000; \ 133 } \ 134 } while (0) 135 #endif 136 107 137 /* compare tvp and uvp using cmp */ 108 138 #ifndef timercmp … … 111 141 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ 112 142 ((tvp)->tv_sec cmp (uvp)->tv_sec)) 143 #endif 144 145 #ifndef timescmp 146 #define timescmp(tsp, usp, cmp) \ 147 (((tsp)->tv_sec == (usp)->tv_sec) ? \ 148 ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \ 149 ((tsp)->tv_sec cmp (usp)->tv_sec)) 113 150 #endif 114 151 -
features/performance/src/defines.h.in
r1970 r1971 218 218 #define MILLISEC_TO_TIMEVAL(x, tv) \ 219 219 do { \ 220 (tv)->tv_sec = x/ 1000; \220 (tv)->tv_sec = (x) / 1000; \ 221 221 (tv)->tv_usec = (x * 1000) - ((tv)->tv_sec * 1000000); \ 222 222 } while(0) … … 224 224 #define MICROSEC_TO_TIMEVAL(x, tv) \ 225 225 do { \ 226 (tv)->tv_sec = x/ 1000000; \227 (tv)->tv_usec = x- ((tv)->tv_sec * 1000000); \226 (tv)->tv_sec = (x) / 1000000; \ 227 (tv)->tv_usec = (x) - ((tv)->tv_sec * 1000000); \ 228 228 } while(0) 229 229 230 230 #define NANOSEC_TO_TIMEVAL(x, tv) \ 231 231 do { \ 232 (tv)->tv_sec = x/ 1000000000; \232 (tv)->tv_sec = (x) / 1000000000; \ 233 233 (tv)->tv_usec = (x / 1000) - (tv)->tv_sec * 1000000); \ 234 234 } while(0) 235 235 236 #define NANOSEC_TO_TIMESPEC(x, ts) \ 237 do { \ 238 (ts)->tv_sec = (x) / 1000000000; \ 239 (ts)->tv_nsec = (x) - ((ts)->tv_sec * 1000000000); \ 240 } while(0) 241 242 #define TIMESPEC_TO_MILLISEC(x) (((x)->tv_sec * 1000) + ((x)->tv_nsec / 1000000)) 243 #define TIMESPEC_TO_MICROSEC(x) (((x)->tv_sec * 1000000) + (x)->tv_nsec / 1000) 244 #define TIMESPEC_TO_NANOSEC(x) ((u_int64_t)((x)->tv_sec * 1000000000) + ((u_int64_t)(x)->tv_nsec)) 245 246 247 236 248 #endif /* DEFINES */ -
features/performance/src/send_packets.c
r1970 r1971 327 327 static int adjuster_flipper = 0; 328 328 #ifdef HAVE_TCPREPLAY 329 struct time val adjuster = { 0, OPT_VALUE_SLEEP_ACCEL}329 struct timespec adjuster = { 0, OPT_VALUE_SLEEP_ACCEL * 1000 } 330 330 #else 331 struct time val adjuster = { 0, ADJUSTER_OFFSET};332 #endif 333 static struct time valnap = { 0, 0 };331 struct timespec adjuster = { 0, ADJUSTER_OFFSET * 1000 }; 332 #endif 333 static struct timespec nap = { 0, 0 }; 334 334 static u_int32_t double_up = 0; 335 struct timeval n ow, sleep_until, nap_this_time;336 struct timespec ignore, sleep ;335 struct timeval nap_for, now, sleep_until; 336 struct timespec ignore, sleep, nap_this_time; 337 337 float n; 338 338 static u_int32_t send = 0; /* accellerator. # of packets to send w/o sleeping */ 339 u_int 32_t ppusec; /* packets per usec */339 u_int64_t ppnsec; /* packets per usec */ 340 340 341 341 /* just return if topspeed */ … … 373 373 */ 374 374 if (timerisset(last) && timercmp(time, last, >)) { 375 timersub(time, last, &nap); 376 timerdiv(&nap, options.speed.speed); 375 timersub(time, last, &nap_for); 376 TIMEVAL_TO_TIMESPEC(&nap_for, &nap); 377 timesdiv(&nap, options.speed.speed); 377 378 } 378 379 else { … … 382 383 * last packet. 383 384 */ 384 time rclear(&nap);385 timesclear(&nap); 385 386 } 386 387 break; … … 394 395 n = (float)len / (options.speed.speed * 1024 * 1024 / 8); /* convert Mbps to bps */ 395 396 nap.tv_sec = n; 396 nap.tv_ usec = (n - nap.tv_sec) * 1000000;397 nap.tv_nsec = (n - nap.tv_sec) * 1000000000; 397 398 dbgx(3, "packet size %d\t\tequals %f bps\t\tnap " TIMEVAL_FORMAT, len, n, 398 nap.tv_sec, nap.tv_ usec);399 nap.tv_sec, nap.tv_nsec); 399 400 } 400 401 else { 401 402 /* don't sleep at all for the first packet */ 402 time rclear(&nap);403 timesclear(&nap); 403 404 } 404 405 break; … … 406 407 case SPEED_PACKETRATE: 407 408 /* only need to calculate this the first time */ 408 if (! time risset(&nap)) {409 if (! timesisset(&nap)) { 409 410 /* run in packets/sec */ 410 pp usec = 1000000 / options.speed.speed;411 MICROSEC_TO_TIMEVAL(ppusec, &nap);412 dbgx(1, "sending 1 packet per %lu usec", nap.tv_usec);411 ppnsec = 1000000000 / options.speed.speed; 412 NANOSEC_TO_TIMESPEC(ppnsec, &nap); 413 dbgx(1, "sending 1 packet per %lu nsec", nap.tv_nsec); 413 414 } 414 415 break; … … 439 440 */ 440 441 nap_this_time.tv_sec = nap.tv_sec; 441 nap_this_time.tv_ usec = nap.tv_usec;442 nap_this_time.tv_nsec = nap.tv_nsec; 442 443 443 444 /* apply the adjuster... */ 444 if (time risset(&adjuster)) {445 if (time rcmp(&nap_this_time, &adjuster, >)) {446 time rsub(&nap_this_time, &adjuster, &nap_this_time);447 dbgx(1, "adjusting nap_this_time by %lu usec", adjuster.tv_usec);445 if (timesisset(&adjuster)) { 446 if (timescmp(&nap_this_time, &adjuster, >)) { 447 timessub(&nap_this_time, &adjuster, &nap_this_time); 448 dbgx(1, "adjusting nap_this_time by %lu nsec", adjuster.tv_nsec); 448 449 } else { 449 450 dbg(1, "resetting nap_this_time to 0"); 450 time rclear(&nap_this_time);451 timesclear(&nap_this_time); 451 452 } 452 453 } 453 454 454 455 /* don't sleep if nap = { 0, 0} */ 455 if (!time risset(&nap_this_time))456 if (!timesisset(&nap_this_time)) 456 457 return; 457 458 -
features/performance/src/sleep.h
r1970 r1971 57 57 58 58 static inline void 59 nanosleep_sleep(struct time valnap)59 nanosleep_sleep(struct timespec nap) 60 60 { 61 struct timespec ts; 62 TIMEVAL_TO_TIMESPEC(&nap, &ts); 63 nanosleep(&ts, NULL); 61 nanosleep(&nap, NULL); 64 62 } 65 63 … … 70 68 */ 71 69 static inline void 72 gettimeofday_sleep(struct time valnap)70 gettimeofday_sleep(struct timespec nap) 73 71 { 74 struct timeval now, sleep_until ;72 struct timeval now, sleep_until, nap_for; 75 73 gettimeofday(&now, NULL); 76 timeradd(&now, &nap, &sleep_until); 74 TIMESPEC_TO_TIMEVAL(&nap_for, &nap); 75 timeradd(&now, &nap_for, &sleep_until); 77 76 78 77 do { … … 87 86 88 87 88 /* 89 * Not sure if this is any better then a gettimeofday() loop, but 90 * in order to find out, nap needs to be a timespec (nanosec precision) 91 */ 89 92 static inline void 90 absolute_time_sleep(struct time valnap)93 absolute_time_sleep(struct timespec nap) 91 94 { 92 95 AbsoluteTime sleep_until, naptime, time_left; 96 Nanoseconds nanosec; 93 97 94 naptime = DurationToAbsolute(TIMEVAL_TO_MICROSEC(&nap)); 98 nanosec = UInt64ToUnsignedWide(TIMESPEC_TO_NANOSEC(&nap)); 99 naptime = NanosecondsToAbsolute(nanosec); 95 100 96 101 sleep_until = AddAbsoluteToAbsolute(UpTime(), naptime); 97 102 98 103 do { 99 104 time_left = SubAbsoluteFromAbsolute(sleep_until, UpTime()); … … 112 117 */ 113 118 static inline void 114 select_sleep(const struct time valnap)119 select_sleep(const struct timespec nap) 115 120 { 116 121 struct timeval timeout; 117 122 118 timeout.tv_sec = nap.tv_sec; 119 timeout.tv_usec = nap.tv_usec; 123 TIMESPEC_TO_TIMEVAL(&timeout, &nap); 120 124 121 125 if (select(0, NULL, NULL, NULL, &timeout) < 0) … … 137 141 138 142 static inline void 139 ioport_sleep(const struct time valnap)143 ioport_sleep(const struct timespec nap) 140 144 { 145 struct timeval nap_for; 141 146 u_int32_t usec; 142 147 time_t i; 148 149 TIMESPEC_TO_TIMEVAL(&nap_for, &nap); 143 150 144 151 /* … … 146 153 * use slower 64bit integers or worry about integer overflows. 147 154 */ 148 for (i = 0; i < nap .tv_sec; i ++) {149 usec = SEC_TO_MICROSEC(nap .tv_sec);155 for (i = 0; i < nap_for.tv_sec; i ++) { 156 usec = SEC_TO_MICROSEC(nap_for.tv_sec); 150 157 while (usec > 0) { 151 158 usec --; … … 155 162 156 163 /* process the usec */ 157 usec = nap.tv_ usec;164 usec = nap.tv_nsec / 1000; 158 165 usec --; /* fudge factor for all the above */ 159 166 while (usec > 0) {
