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/pscan.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/pscan.c')
-rw-r--r-- | networking/pscan.c | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/networking/pscan.c b/networking/pscan.c index 10bf3b606..9fa6993e8 100644 --- a/networking/pscan.c +++ b/networking/pscan.c | |||
@@ -17,19 +17,6 @@ | |||
17 | #define DERR(...) ((void)0) | 17 | #define DERR(...) ((void)0) |
18 | #endif | 18 | #endif |
19 | 19 | ||
20 | /* return time in usec */ | ||
21 | // TODO: move to libbb and use in traceroute, zcip, arping etc | ||
22 | // (maybe also use absolute monotonic clock - no time warps | ||
23 | // due to admin resetting date/time?) | ||
24 | static unsigned gettimeofday_us(void) | ||
25 | { | ||
26 | struct timeval now; | ||
27 | |||
28 | if (gettimeofday(&now, NULL)) | ||
29 | return 0; | ||
30 | return (now.tv_sec * 1000000 + now.tv_usec); | ||
31 | } | ||
32 | |||
33 | static const char *port_name(unsigned port) | 20 | static const char *port_name(unsigned port) |
34 | { | 21 | { |
35 | struct servent *server; | 22 | struct servent *server; |
@@ -40,6 +27,9 @@ static const char *port_name(unsigned port) | |||
40 | return "unknown"; | 27 | return "unknown"; |
41 | } | 28 | } |
42 | 29 | ||
30 | /* We don't expect to see 1000+ seconds delay, unsigned is enough */ | ||
31 | #define MONOTONIC_US() ((unsigned)monotonic_us()) | ||
32 | |||
43 | int pscan_main(int argc, char **argv); | 33 | int pscan_main(int argc, char **argv); |
44 | int pscan_main(int argc, char **argv) | 34 | int pscan_main(int argc, char **argv) |
45 | { | 35 | { |
@@ -91,7 +81,7 @@ int pscan_main(int argc, char **argv) | |||
91 | /* Nonblocking connect typically "fails" with errno == EINPROGRESS */ | 81 | /* Nonblocking connect typically "fails" with errno == EINPROGRESS */ |
92 | ndelay_on(s); | 82 | ndelay_on(s); |
93 | DMSG("connect to port %u", port); | 83 | DMSG("connect to port %u", port); |
94 | start = gettimeofday_us(); | 84 | start = MONOTONIC_US(); |
95 | if (connect(s, &lsap->sa, lsap->len) == 0) { | 85 | if (connect(s, &lsap->sa, lsap->len) == 0) { |
96 | /* Unlikely, for me even localhost fails :) */ | 86 | /* Unlikely, for me even localhost fails :) */ |
97 | DMSG("connect succeeded"); | 87 | DMSG("connect succeeded"); |
@@ -110,15 +100,15 @@ int pscan_main(int argc, char **argv) | |||
110 | closed_ports++; | 100 | closed_ports++; |
111 | break; | 101 | break; |
112 | } | 102 | } |
113 | DERR("port %u errno %d @%u", port, errno, gettimeofday_us() - start); | 103 | DERR("port %u errno %d @%u", port, errno, MONOTONIC_US() - start); |
114 | if ((gettimeofday_us() - start) > rtt_4) | 104 | if ((MONOTONIC_US() - start) > rtt_4) |
115 | break; | 105 | break; |
116 | /* Can sleep (much) longer than specified delay. | 106 | /* Can sleep (much) longer than specified delay. |
117 | * We check rtt BEFORE we usleep, otherwise | 107 | * We check rtt BEFORE we usleep, otherwise |
118 | * on localhost we'll do zero writes done (!) | 108 | * on localhost we'll do zero writes done (!) |
119 | * before we exceed (rather small) rtt */ | 109 | * before we exceed (rather small) rtt */ |
120 | usleep(rtt_4/8); | 110 | usleep(rtt_4/8); |
121 | DMSG("write to port %u @%u", port, gettimeofday_us() - start); | 111 | DMSG("write to port %u @%u", port, MONOTONIC_US() - start); |
122 | if (write(s, " ", 1) >= 0) { /* We were able to write to the socket */ | 112 | if (write(s, " ", 1) >= 0) { /* We were able to write to the socket */ |
123 | open: | 113 | open: |
124 | open_ports++; | 114 | open_ports++; |
@@ -126,13 +116,13 @@ int pscan_main(int argc, char **argv) | |||
126 | break; | 116 | break; |
127 | } | 117 | } |
128 | } | 118 | } |
129 | DMSG("out of loop @%u", gettimeofday_us() - start); | 119 | DMSG("out of loop @%u", MONOTONIC_US() - start); |
130 | 120 | ||
131 | /* Estimate new rtt - we don't want to wait entire timeout | 121 | /* Estimate new rtt - we don't want to wait entire timeout |
132 | * for each port. *4 allows for rise in net delay. | 122 | * for each port. *4 allows for rise in net delay. |
133 | * We increase rtt quickly (*4), decrease slowly (4/8 == 1/2) | 123 | * We increase rtt quickly (*4), decrease slowly (4/8 == 1/2) |
134 | * because we don't want to accidentally miss ports. */ | 124 | * because we don't want to accidentally miss ports. */ |
135 | rtt_4 = (gettimeofday_us() - start) * 4; | 125 | rtt_4 = (MONOTONIC_US() - start) * 4; |
136 | if (rtt_4 < min_rtt) | 126 | if (rtt_4 < min_rtt) |
137 | rtt_4 = min_rtt; | 127 | rtt_4 = min_rtt; |
138 | if (rtt_4 > timeout) | 128 | if (rtt_4 > timeout) |