diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-14 18:49:23 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-14 18:54:30 +0100 |
commit | c7b858ff8d2e8b2d785f74b2d319bc9c839f4faa (patch) | |
tree | 9ad109d5999444dfb3a281678b6b63d2570a76cd /miscutils | |
parent | fd3c512f88d43e6633bd3c3110cfa0bb321adaa8 (diff) | |
download | busybox-w32-c7b858ff8d2e8b2d785f74b2d319bc9c839f4faa.tar.gz busybox-w32-c7b858ff8d2e8b2d785f74b2d319bc9c839f4faa.tar.bz2 busybox-w32-c7b858ff8d2e8b2d785f74b2d319bc9c839f4faa.zip |
libbb: add and use infrastructure for fixed page size optimization
function old new delta
procps_scan 1121 1118 -3
getpagesize 6 - -6
rpm_main 1037 1027 -10
rpm2cpio_main 120 110 -10
ptok 38 21 -17
time_main 1282 1261 -21
mkswap_main 317 278 -39
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/6 up/down: 0/-106) Total: -106 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/devmem.c | 2 | ||||
-rw-r--r-- | miscutils/hexedit.c | 14 | ||||
-rw-r--r-- | miscutils/time.c | 7 |
3 files changed, 10 insertions, 13 deletions
diff --git a/miscutils/devmem.c b/miscutils/devmem.c index e8dce5225..f9f0276bc 100644 --- a/miscutils/devmem.c +++ b/miscutils/devmem.c | |||
@@ -75,7 +75,7 @@ int devmem_main(int argc UNUSED_PARAM, char **argv) | |||
75 | bb_show_usage(); /* one of bb_strtouXX failed */ | 75 | bb_show_usage(); /* one of bb_strtouXX failed */ |
76 | 76 | ||
77 | fd = xopen("/dev/mem", argv[3] ? (O_RDWR | O_SYNC) : (O_RDONLY | O_SYNC)); | 77 | fd = xopen("/dev/mem", argv[3] ? (O_RDWR | O_SYNC) : (O_RDONLY | O_SYNC)); |
78 | mapped_size = page_size = getpagesize(); | 78 | mapped_size = page_size = bb_getpagesize(); |
79 | offset_in_page = (unsigned)target & (page_size - 1); | 79 | offset_in_page = (unsigned)target & (page_size - 1); |
80 | if (offset_in_page + width > page_size) { | 80 | if (offset_in_page + width > page_size) { |
81 | /* This access spans pages. | 81 | /* This access spans pages. |
diff --git a/miscutils/hexedit.c b/miscutils/hexedit.c index 898d77376..f8ff9b62b 100644 --- a/miscutils/hexedit.c +++ b/miscutils/hexedit.c | |||
@@ -31,7 +31,8 @@ struct globals { | |||
31 | int fd; | 31 | int fd; |
32 | unsigned height; | 32 | unsigned height; |
33 | unsigned row; | 33 | unsigned row; |
34 | unsigned pagesize; | 34 | IF_VARIABLE_ARCH_PAGESIZE(unsigned pagesize;) |
35 | #define G_pagesize cached_pagesize(G.pagesize) | ||
35 | uint8_t *baseaddr; | 36 | uint8_t *baseaddr; |
36 | uint8_t *current_byte; | 37 | uint8_t *current_byte; |
37 | uint8_t *eof_byte; | 38 | uint8_t *eof_byte; |
@@ -46,15 +47,6 @@ struct globals { | |||
46 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ | 47 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ |
47 | } while (0) | 48 | } while (0) |
48 | 49 | ||
49 | //TODO: move to libbb | ||
50 | #if defined(__x86_64__) || defined(i386) | ||
51 | # define G_pagesize 4096 | ||
52 | # define INIT_PAGESIZE() ((void)0) | ||
53 | #else | ||
54 | # define G_pagesize (G.pagesize) | ||
55 | # define INIT_PAGESIZE() ((void)(G.pagesize = getpagesize())) | ||
56 | #endif | ||
57 | |||
58 | /* hopefully there aren't arches with PAGE_SIZE > 64k */ | 50 | /* hopefully there aren't arches with PAGE_SIZE > 64k */ |
59 | #define G_mapsize (64*1024) | 51 | #define G_mapsize (64*1024) |
60 | 52 | ||
@@ -262,7 +254,7 @@ int hexedit_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | |||
262 | int hexedit_main(int argc UNUSED_PARAM, char **argv) | 254 | int hexedit_main(int argc UNUSED_PARAM, char **argv) |
263 | { | 255 | { |
264 | INIT_G(); | 256 | INIT_G(); |
265 | INIT_PAGESIZE(); | 257 | INIT_PAGESIZE(G.pagesize); |
266 | 258 | ||
267 | get_terminal_width_height(-1, NULL, &G.height); | 259 | get_terminal_width_height(-1, NULL, &G.height); |
268 | if (1) { | 260 | if (1) { |
diff --git a/miscutils/time.c b/miscutils/time.c index d15d363f3..0006c59d8 100644 --- a/miscutils/time.c +++ b/miscutils/time.c | |||
@@ -111,6 +111,10 @@ static void printargv(char *const *argv) | |||
111 | This is funky since the pagesize could be less than 1K. | 111 | This is funky since the pagesize could be less than 1K. |
112 | Note: Some machines express getrusage statistics in terms of K, | 112 | Note: Some machines express getrusage statistics in terms of K, |
113 | others in terms of pages. */ | 113 | others in terms of pages. */ |
114 | #ifdef BB_ARCH_FIXED_PAGESIZE | ||
115 | # define pagesize BB_ARCH_FIXED_PAGESIZE | ||
116 | # define ptok(pagesize, pages) ptok(pages) | ||
117 | #endif | ||
114 | static unsigned long ptok(const unsigned pagesize, const unsigned long pages) | 118 | static unsigned long ptok(const unsigned pagesize, const unsigned long pages) |
115 | { | 119 | { |
116 | unsigned long tmp; | 120 | unsigned long tmp; |
@@ -124,6 +128,7 @@ static unsigned long ptok(const unsigned pagesize, const unsigned long pages) | |||
124 | tmp = pages * pagesize; /* Larger first, */ | 128 | tmp = pages * pagesize; /* Larger first, */ |
125 | return tmp / 1024; /* then smaller. */ | 129 | return tmp / 1024; /* then smaller. */ |
126 | } | 130 | } |
131 | #undef pagesize | ||
127 | 132 | ||
128 | /* summarize: Report on the system use of a command. | 133 | /* summarize: Report on the system use of a command. |
129 | 134 | ||
@@ -177,7 +182,7 @@ static void summarize(const char *fmt, char **command, resource_t *resp) | |||
177 | { | 182 | { |
178 | unsigned vv_ms; /* Elapsed virtual (CPU) milliseconds */ | 183 | unsigned vv_ms; /* Elapsed virtual (CPU) milliseconds */ |
179 | unsigned cpu_ticks; /* Same, in "CPU ticks" */ | 184 | unsigned cpu_ticks; /* Same, in "CPU ticks" */ |
180 | unsigned pagesize = getpagesize(); | 185 | unsigned pagesize = bb_getpagesize(); |
181 | 186 | ||
182 | /* Impossible: we do not use WUNTRACED flag in wait()... | 187 | /* Impossible: we do not use WUNTRACED flag in wait()... |
183 | if (WIFSTOPPED(resp->waitstatus)) | 188 | if (WIFSTOPPED(resp->waitstatus)) |