diff options
author | Denis Vlasenko | 2007-06-17 19:09:05 +0000 |
---|---|---|
committer | Denis Vlasenko | 2007-06-17 19:09:05 +0000 |
commit | 459be35234cc24b69309eb0ee22600024c73713e (patch) | |
tree | 15ac4122d9c42ec75ba68d342827e37fcb1306ed /networking/traceroute.c | |
parent | e79dd06782175d50f639180cde5b2c56933aa2ee (diff) | |
download | busybox-459be35234cc24b69309eb0ee22600024c73713e.zip busybox-459be35234cc24b69309eb0ee22600024c73713e.tar.gz |
hwclock: size optimizations
libbb/time.c: new file, introducing monotonic_us()
pscan, traceroute, arping: use it instead of gettimeofday
ping, zcip: TODO
function old new delta
monotonic_us - 89 +89
find_pair 164 180 +16
.rodata 129747 129763 +16
refresh 1144 1152 +8
............
timeout 8 4 -4
static.start 8 4 -4
last 8 4 -4
parse_conf 1303 1284 -19
time_main 1149 1124 -25
gettimeofday_us 39 - -39
arping_main 2042 1969 -73
hwclock_main 594 501 -93
catcher 485 380 -105
traceroute_main 4300 4117 -183
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 8/11 up/down: 157/-562) Total: -405 bytes
Diffstat (limited to 'networking/traceroute.c')
-rw-r--r-- | networking/traceroute.c | 53 |
1 files changed, 18 insertions, 35 deletions
diff --git a/networking/traceroute.c b/networking/traceroute.c index 40533a8..9fc15d3 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c @@ -275,7 +275,8 @@ struct hostinfo { struct outdata { unsigned char seq; /* sequence number of this packet */ unsigned char ttl; /* ttl packet left with */ - struct timeval tv ATTRIBUTE_PACKED; /* time packet left */ +// UNUSED. Retaining to have the same packet size. + struct timeval tv_UNUSED ATTRIBUTE_PACKED; /* time packet left */ }; struct IFADDRLIST { @@ -533,37 +534,19 @@ findsaddr(const struct sockaddr_in *to, struct sockaddr_in *from) */ -/* - * Subtract 2 timeval structs: out = out - in. - * Out is assumed to be >= in. - */ -static inline void -tvsub(struct timeval *out, struct timeval *in) -{ - - if ((out->tv_usec -= in->tv_usec) < 0) { - --out->tv_sec; - out->tv_usec += 1000000; - } - out->tv_sec -= in->tv_sec; -} - static int -wait_for_reply(int sock, struct sockaddr_in *fromp, const struct timeval *tp) +wait_for_reply(int sock, struct sockaddr_in *fromp) { fd_set fds; - struct timeval now, tvwait; - struct timezone tz; + struct timeval tvwait; int cc = 0; socklen_t fromlen = sizeof(*fromp); FD_ZERO(&fds); FD_SET(sock, &fds); - tvwait.tv_sec = tp->tv_sec + waittime; - tvwait.tv_usec = tp->tv_usec; - (void)gettimeofday(&now, &tz); - tvsub(&tvwait, &now); + tvwait.tv_sec = waittime; + tvwait.tv_usec = 0; if (select(sock + 1, &fds, NULL, NULL, &tvwait) > 0) cc = recvfrom(sock, (char *)packet, sizeof(packet), 0, @@ -609,7 +592,7 @@ in_cksum(uint16_t *addr, int len) static void -send_probe(int seq, int ttl, struct timeval *tp) +send_probe(int seq, int ttl) { int cc; struct udpiphdr *ui, *oui; @@ -633,7 +616,8 @@ send_probe(int seq, int ttl, struct timeval *tp) /* Payload */ outdata->seq = seq; outdata->ttl = ttl; - memcpy(&outdata->tv, tp, sizeof(outdata->tv)); +// UNUSED: was storing gettimeofday's result there, but never ever checked it + /*memcpy(&outdata->tv, tp, sizeof(outdata->tv));*/ #if ENABLE_FEATURE_TRACEROUTE_USE_ICMP if (useicmp) @@ -706,7 +690,6 @@ send_probe(int seq, int ttl, struct timeval *tp) packlen, (struct sockaddr *)&whereto, sizeof(whereto)); if (cc != packlen) { bb_info_msg("wrote %s %d chars, ret=%d", hostname, packlen, cc); -// (void)fflush(stdout); } } @@ -908,9 +891,9 @@ getaddr(uint32_t *ap, const char *host) #endif static void -print_delta_ms(struct timeval *t1p, struct timeval *t2p) +print_delta_ms(unsigned t1p, unsigned t2p) { - unsigned tt = (t2p->tv_sec - t1p->tv_sec) * 1000000 + (t2p->tv_usec - t1p->tv_usec); + unsigned tt = t2p - t1p; printf(" %u.%03u ms", tt/1000, tt%1000); } @@ -1230,17 +1213,17 @@ int traceroute_main(int argc, char **argv) printf("%2d ", ttl); for (probe = 0; probe < nprobes; ++probe) { int cc; - struct timeval t1, t2; - struct timezone tz; + unsigned t1; + unsigned t2; struct ip *ip; if (sentfirst && pausemsecs > 0) usleep(pausemsecs * 1000); - (void)gettimeofday(&t1, &tz); - send_probe(++seq, ttl, &t1); + t1 = monotonic_us(); + send_probe(++seq, ttl); ++sentfirst; - while ((cc = wait_for_reply(s, from, &t1)) != 0) { - (void)gettimeofday(&t2, &tz); + while ((cc = wait_for_reply(s, from)) != 0) { + t2 = monotonic_us(); i = packet_ok(packet, cc, from, seq); /* Skip short packet */ if (i == 0) @@ -1251,7 +1234,7 @@ int traceroute_main(int argc, char **argv) lastaddr = from->sin_addr.s_addr; ++gotlastaddr; } - print_delta_ms(&t1, &t2); + print_delta_ms(t1, t2); ip = (struct ip *)packet; if (op & OPT_TTL_FLAG) printf(" (%d)", ip->ip_ttl); |