diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-01-12 12:52:30 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-01-12 12:52:30 +0100 |
| commit | f2c8aa6676ebedc34b2cd5089ce6f13c16db1277 (patch) | |
| tree | bc728f22666ee367d1c6c085a6cf65570881636c | |
| parent | cb23d93c6845df3f2733a32caa4194e60ef871a7 (diff) | |
| download | busybox-w32-f2c8aa6676ebedc34b2cd5089ce6f13c16db1277.tar.gz busybox-w32-f2c8aa6676ebedc34b2cd5089ce6f13c16db1277.tar.bz2 busybox-w32-f2c8aa6676ebedc34b2cd5089ce6f13c16db1277.zip | |
libbb: introduce and use monotonic_ms
function old new delta
monotonic_ms - 60 +60
process_stdin 433 443 +10
display_speed 85 90 +5
nmeter_main 672 674 +2
builtin_type 114 116 +2
bb__parsespent 117 119 +2
ifplugd_main 1110 1109 -1
acpid_main 441 440 -1
chat_main 1361 1359 -2
doCommands 2458 2449 -9
arpping 466 450 -16
run_command 268 234 -34
readcmd 1072 1034 -38
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 5/7 up/down: 81/-101) Total: -20 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | include/libbb.h | 1 | ||||
| -rw-r--r-- | libbb/time.c | 12 | ||||
| -rw-r--r-- | miscutils/time.c | 4 | ||||
| -rw-r--r-- | networking/udhcp/arpping.c | 4 | ||||
| -rw-r--r-- | shell/ash.c | 4 |
5 files changed, 19 insertions, 6 deletions
diff --git a/include/libbb.h b/include/libbb.h index e07bb52f6..11596346d 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
| @@ -249,6 +249,7 @@ extern int *const bb_errno; | |||
| 249 | 249 | ||
| 250 | unsigned long long monotonic_ns(void) FAST_FUNC; | 250 | unsigned long long monotonic_ns(void) FAST_FUNC; |
| 251 | unsigned long long monotonic_us(void) FAST_FUNC; | 251 | unsigned long long monotonic_us(void) FAST_FUNC; |
| 252 | unsigned long long monotonic_ms(void) FAST_FUNC; | ||
| 252 | unsigned monotonic_sec(void) FAST_FUNC; | 253 | unsigned monotonic_sec(void) FAST_FUNC; |
| 253 | 254 | ||
| 254 | extern void chomp(char *s) FAST_FUNC; | 255 | extern void chomp(char *s) FAST_FUNC; |
diff --git a/libbb/time.c b/libbb/time.c index 82a0fa1fa..45ae6f3a7 100644 --- a/libbb/time.c +++ b/libbb/time.c | |||
| @@ -175,6 +175,12 @@ unsigned long long FAST_FUNC monotonic_us(void) | |||
| 175 | get_mono(&ts); | 175 | get_mono(&ts); |
| 176 | return ts.tv_sec * 1000000ULL + ts.tv_nsec/1000; | 176 | return ts.tv_sec * 1000000ULL + ts.tv_nsec/1000; |
| 177 | } | 177 | } |
| 178 | unsigned long long FAST_FUNC monotonic_ms(void) | ||
| 179 | { | ||
| 180 | struct timespec ts; | ||
| 181 | get_mono(&ts); | ||
| 182 | return ts.tv_sec * 1000ULL + ts.tv_nsec/1000000; | ||
| 183 | } | ||
| 178 | unsigned FAST_FUNC monotonic_sec(void) | 184 | unsigned FAST_FUNC monotonic_sec(void) |
| 179 | { | 185 | { |
| 180 | struct timespec ts; | 186 | struct timespec ts; |
| @@ -196,6 +202,12 @@ unsigned long long FAST_FUNC monotonic_us(void) | |||
| 196 | gettimeofday(&tv, NULL); | 202 | gettimeofday(&tv, NULL); |
| 197 | return tv.tv_sec * 1000000ULL + tv.tv_usec; | 203 | return tv.tv_sec * 1000000ULL + tv.tv_usec; |
| 198 | } | 204 | } |
| 205 | unsigned long long FAST_FUNC monotonic_ms(void) | ||
| 206 | { | ||
| 207 | struct timeval tv; | ||
| 208 | gettimeofday(&tv, NULL); | ||
| 209 | return tv.tv_sec * 1000ULL + tv.tv_usec / 1000; | ||
| 210 | } | ||
| 199 | unsigned FAST_FUNC monotonic_sec(void) | 211 | unsigned FAST_FUNC monotonic_sec(void) |
| 200 | { | 212 | { |
| 201 | return time(NULL); | 213 | return time(NULL); |
diff --git a/miscutils/time.c b/miscutils/time.c index 342173609..5ea0f064b 100644 --- a/miscutils/time.c +++ b/miscutils/time.c | |||
| @@ -70,7 +70,7 @@ static void resuse_end(pid_t pid, resource_t *resp) | |||
| 70 | return; | 70 | return; |
| 71 | } | 71 | } |
| 72 | } | 72 | } |
| 73 | resp->elapsed_ms = (monotonic_us() / 1000) - resp->elapsed_ms; | 73 | resp->elapsed_ms = monotonic_ms() - resp->elapsed_ms; |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | static void printargv(char *const *argv) | 76 | static void printargv(char *const *argv) |
| @@ -371,7 +371,7 @@ static void run_command(char *const *cmd, resource_t *resp) | |||
| 371 | void (*interrupt_signal)(int); | 371 | void (*interrupt_signal)(int); |
| 372 | void (*quit_signal)(int); | 372 | void (*quit_signal)(int); |
| 373 | 373 | ||
| 374 | resp->elapsed_ms = monotonic_us() / 1000; | 374 | resp->elapsed_ms = monotonic_ms(); |
| 375 | pid = vfork(); /* Run CMD as child process. */ | 375 | pid = vfork(); /* Run CMD as child process. */ |
| 376 | if (pid < 0) | 376 | if (pid < 0) |
| 377 | bb_perror_msg_and_die("fork"); | 377 | bb_perror_msg_and_die("fork"); |
diff --git a/networking/udhcp/arpping.c b/networking/udhcp/arpping.c index 4af8534bd..548796e2b 100644 --- a/networking/udhcp/arpping.c +++ b/networking/udhcp/arpping.c | |||
| @@ -88,7 +88,7 @@ int FAST_FUNC arpping(uint32_t test_nip, | |||
| 88 | timeout_ms = 2000; | 88 | timeout_ms = 2000; |
| 89 | do { | 89 | do { |
| 90 | int r; | 90 | int r; |
| 91 | unsigned prevTime = monotonic_us(); | 91 | unsigned prevTime = monotonic_ms(); |
| 92 | 92 | ||
| 93 | pfd[0].events = POLLIN; | 93 | pfd[0].events = POLLIN; |
| 94 | r = safe_poll(pfd, 1, timeout_ms); | 94 | r = safe_poll(pfd, 1, timeout_ms); |
| @@ -119,7 +119,7 @@ int FAST_FUNC arpping(uint32_t test_nip, | |||
| 119 | break; | 119 | break; |
| 120 | } | 120 | } |
| 121 | } | 121 | } |
| 122 | timeout_ms -= ((unsigned)monotonic_us() - prevTime) / 1000; | 122 | timeout_ms -= (unsigned)monotonic_ms() - prevTime; |
| 123 | } while (timeout_ms > 0); | 123 | } while (timeout_ms > 0); |
| 124 | 124 | ||
| 125 | ret: | 125 | ret: |
diff --git a/shell/ash.c b/shell/ash.c index b47f0e881..e668f41e1 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
| @@ -12619,7 +12619,7 @@ readcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
| 12619 | backslash = 0; | 12619 | backslash = 0; |
| 12620 | #if ENABLE_ASH_READ_TIMEOUT | 12620 | #if ENABLE_ASH_READ_TIMEOUT |
| 12621 | if (timeout) /* NB: ensuring end_ms is nonzero */ | 12621 | if (timeout) /* NB: ensuring end_ms is nonzero */ |
| 12622 | end_ms = ((unsigned)(monotonic_us() / 1000) + timeout) | 1; | 12622 | end_ms = ((unsigned)monotonic_ms() + timeout) | 1; |
| 12623 | #endif | 12623 | #endif |
| 12624 | STARTSTACKSTR(p); | 12624 | STARTSTACKSTR(p); |
| 12625 | do { | 12625 | do { |
| @@ -12630,7 +12630,7 @@ readcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
| 12630 | struct pollfd pfd[1]; | 12630 | struct pollfd pfd[1]; |
| 12631 | pfd[0].fd = fd; | 12631 | pfd[0].fd = fd; |
| 12632 | pfd[0].events = POLLIN; | 12632 | pfd[0].events = POLLIN; |
| 12633 | timeout = end_ms - (unsigned)(monotonic_us() / 1000); | 12633 | timeout = end_ms - (unsigned)monotonic_ms(); |
| 12634 | if ((int)timeout <= 0 /* already late? */ | 12634 | if ((int)timeout <= 0 /* already late? */ |
| 12635 | || safe_poll(pfd, 1, timeout) != 1 /* no? wait... */ | 12635 | || safe_poll(pfd, 1, timeout) != 1 /* no? wait... */ |
| 12636 | ) { /* timed out! */ | 12636 | ) { /* timed out! */ |
