diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-17 19:09:05 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-17 19:09:05 +0000 |
commit | 459be35234cc24b69309eb0ee22600024c73713e (patch) | |
tree | 15ac4122d9c42ec75ba68d342827e37fcb1306ed /networking/traceroute.c | |
parent | e79dd06782175d50f639180cde5b2c56933aa2ee (diff) | |
download | busybox-w32-459be35234cc24b69309eb0ee22600024c73713e.tar.gz busybox-w32-459be35234cc24b69309eb0ee22600024c73713e.tar.bz2 busybox-w32-459be35234cc24b69309eb0ee22600024c73713e.zip |
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 40533a82d..9fc15d390 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c | |||
@@ -275,7 +275,8 @@ struct hostinfo { | |||
275 | struct outdata { | 275 | struct outdata { |
276 | unsigned char seq; /* sequence number of this packet */ | 276 | unsigned char seq; /* sequence number of this packet */ |
277 | unsigned char ttl; /* ttl packet left with */ | 277 | unsigned char ttl; /* ttl packet left with */ |
278 | struct timeval tv ATTRIBUTE_PACKED; /* time packet left */ | 278 | // UNUSED. Retaining to have the same packet size. |
279 | struct timeval tv_UNUSED ATTRIBUTE_PACKED; /* time packet left */ | ||
279 | }; | 280 | }; |
280 | 281 | ||
281 | struct IFADDRLIST { | 282 | struct IFADDRLIST { |
@@ -533,37 +534,19 @@ findsaddr(const struct sockaddr_in *to, struct sockaddr_in *from) | |||
533 | 534 | ||
534 | */ | 535 | */ |
535 | 536 | ||
536 | /* | ||
537 | * Subtract 2 timeval structs: out = out - in. | ||
538 | * Out is assumed to be >= in. | ||
539 | */ | ||
540 | static inline void | ||
541 | tvsub(struct timeval *out, struct timeval *in) | ||
542 | { | ||
543 | |||
544 | if ((out->tv_usec -= in->tv_usec) < 0) { | ||
545 | --out->tv_sec; | ||
546 | out->tv_usec += 1000000; | ||
547 | } | ||
548 | out->tv_sec -= in->tv_sec; | ||
549 | } | ||
550 | |||
551 | static int | 537 | static int |
552 | wait_for_reply(int sock, struct sockaddr_in *fromp, const struct timeval *tp) | 538 | wait_for_reply(int sock, struct sockaddr_in *fromp) |
553 | { | 539 | { |
554 | fd_set fds; | 540 | fd_set fds; |
555 | struct timeval now, tvwait; | 541 | struct timeval tvwait; |
556 | struct timezone tz; | ||
557 | int cc = 0; | 542 | int cc = 0; |
558 | socklen_t fromlen = sizeof(*fromp); | 543 | socklen_t fromlen = sizeof(*fromp); |
559 | 544 | ||
560 | FD_ZERO(&fds); | 545 | FD_ZERO(&fds); |
561 | FD_SET(sock, &fds); | 546 | FD_SET(sock, &fds); |
562 | 547 | ||
563 | tvwait.tv_sec = tp->tv_sec + waittime; | 548 | tvwait.tv_sec = waittime; |
564 | tvwait.tv_usec = tp->tv_usec; | 549 | tvwait.tv_usec = 0; |
565 | (void)gettimeofday(&now, &tz); | ||
566 | tvsub(&tvwait, &now); | ||
567 | 550 | ||
568 | if (select(sock + 1, &fds, NULL, NULL, &tvwait) > 0) | 551 | if (select(sock + 1, &fds, NULL, NULL, &tvwait) > 0) |
569 | cc = recvfrom(sock, (char *)packet, sizeof(packet), 0, | 552 | cc = recvfrom(sock, (char *)packet, sizeof(packet), 0, |
@@ -609,7 +592,7 @@ in_cksum(uint16_t *addr, int len) | |||
609 | 592 | ||
610 | 593 | ||
611 | static void | 594 | static void |
612 | send_probe(int seq, int ttl, struct timeval *tp) | 595 | send_probe(int seq, int ttl) |
613 | { | 596 | { |
614 | int cc; | 597 | int cc; |
615 | struct udpiphdr *ui, *oui; | 598 | struct udpiphdr *ui, *oui; |
@@ -633,7 +616,8 @@ send_probe(int seq, int ttl, struct timeval *tp) | |||
633 | /* Payload */ | 616 | /* Payload */ |
634 | outdata->seq = seq; | 617 | outdata->seq = seq; |
635 | outdata->ttl = ttl; | 618 | outdata->ttl = ttl; |
636 | memcpy(&outdata->tv, tp, sizeof(outdata->tv)); | 619 | // UNUSED: was storing gettimeofday's result there, but never ever checked it |
620 | /*memcpy(&outdata->tv, tp, sizeof(outdata->tv));*/ | ||
637 | 621 | ||
638 | #if ENABLE_FEATURE_TRACEROUTE_USE_ICMP | 622 | #if ENABLE_FEATURE_TRACEROUTE_USE_ICMP |
639 | if (useicmp) | 623 | if (useicmp) |
@@ -706,7 +690,6 @@ send_probe(int seq, int ttl, struct timeval *tp) | |||
706 | packlen, (struct sockaddr *)&whereto, sizeof(whereto)); | 690 | packlen, (struct sockaddr *)&whereto, sizeof(whereto)); |
707 | if (cc != packlen) { | 691 | if (cc != packlen) { |
708 | bb_info_msg("wrote %s %d chars, ret=%d", hostname, packlen, cc); | 692 | bb_info_msg("wrote %s %d chars, ret=%d", hostname, packlen, cc); |
709 | // (void)fflush(stdout); | ||
710 | } | 693 | } |
711 | } | 694 | } |
712 | 695 | ||
@@ -908,9 +891,9 @@ getaddr(uint32_t *ap, const char *host) | |||
908 | #endif | 891 | #endif |
909 | 892 | ||
910 | static void | 893 | static void |
911 | print_delta_ms(struct timeval *t1p, struct timeval *t2p) | 894 | print_delta_ms(unsigned t1p, unsigned t2p) |
912 | { | 895 | { |
913 | unsigned tt = (t2p->tv_sec - t1p->tv_sec) * 1000000 + (t2p->tv_usec - t1p->tv_usec); | 896 | unsigned tt = t2p - t1p; |
914 | printf(" %u.%03u ms", tt/1000, tt%1000); | 897 | printf(" %u.%03u ms", tt/1000, tt%1000); |
915 | } | 898 | } |
916 | 899 | ||
@@ -1230,17 +1213,17 @@ int traceroute_main(int argc, char **argv) | |||
1230 | printf("%2d ", ttl); | 1213 | printf("%2d ", ttl); |
1231 | for (probe = 0; probe < nprobes; ++probe) { | 1214 | for (probe = 0; probe < nprobes; ++probe) { |
1232 | int cc; | 1215 | int cc; |
1233 | struct timeval t1, t2; | 1216 | unsigned t1; |
1234 | struct timezone tz; | 1217 | unsigned t2; |
1235 | struct ip *ip; | 1218 | struct ip *ip; |
1236 | 1219 | ||
1237 | if (sentfirst && pausemsecs > 0) | 1220 | if (sentfirst && pausemsecs > 0) |
1238 | usleep(pausemsecs * 1000); | 1221 | usleep(pausemsecs * 1000); |
1239 | (void)gettimeofday(&t1, &tz); | 1222 | t1 = monotonic_us(); |
1240 | send_probe(++seq, ttl, &t1); | 1223 | send_probe(++seq, ttl); |
1241 | ++sentfirst; | 1224 | ++sentfirst; |
1242 | while ((cc = wait_for_reply(s, from, &t1)) != 0) { | 1225 | while ((cc = wait_for_reply(s, from)) != 0) { |
1243 | (void)gettimeofday(&t2, &tz); | 1226 | t2 = monotonic_us(); |
1244 | i = packet_ok(packet, cc, from, seq); | 1227 | i = packet_ok(packet, cc, from, seq); |
1245 | /* Skip short packet */ | 1228 | /* Skip short packet */ |
1246 | if (i == 0) | 1229 | if (i == 0) |
@@ -1251,7 +1234,7 @@ int traceroute_main(int argc, char **argv) | |||
1251 | lastaddr = from->sin_addr.s_addr; | 1234 | lastaddr = from->sin_addr.s_addr; |
1252 | ++gotlastaddr; | 1235 | ++gotlastaddr; |
1253 | } | 1236 | } |
1254 | print_delta_ms(&t1, &t2); | 1237 | print_delta_ms(t1, t2); |
1255 | ip = (struct ip *)packet; | 1238 | ip = (struct ip *)packet; |
1256 | if (op & OPT_TTL_FLAG) | 1239 | if (op & OPT_TTL_FLAG) |
1257 | printf(" (%d)", ip->ip_ttl); | 1240 | printf(" (%d)", ip->ip_ttl); |