Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1 | From 65180976c9963432d166b47a0b692260a69c0d47 Mon Sep 17 00:00:00 2001 |
| 2 | From: Qingming Su <qingming.su@windriver.com> |
| 3 | Date: Tue, 19 Aug 2014 05:16:17 -0400 |
| 4 | Subject: [PATCH] lmbench: Can't proceed on some targets |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 5 | |
| 6 | lmbench can't proceed on some targets. The memory check fails because the |
| 7 | memory latency of each page is longer then 10us, which is a time limit set |
| 8 | in the original memsize.c. |
| 9 | |
| 10 | The memory latency is very different on different targets due to the |
| 11 | hardware and current system load. The targets with slower memory |
| 12 | chips or heavy system load need much longer time to read or write |
| 13 | the memory. |
| 14 | |
| 15 | This fix changes the fixed time limit of 10us to a specific value calculated |
| 16 | from the runtime target. |
| 17 | |
| 18 | Also set an upper limit of memory size used for lmbench testing. The memory |
| 19 | check sometimes fails if the target has a large amount of memory, for |
| 20 | example more than 4G. |
| 21 | |
| 22 | Signed-off-by: Qingming Su <qingming.su@windriver.com> |
| 23 | Signed-off-by: Fupan Li <fupan.li@windriver.com> |
| 24 | |
| 25 | Add and reword above comments |
| 26 | |
| 27 | Upstream-status: inappropriate [ configuration ] |
| 28 | |
| 29 | Signed-off-by: Mark Hatle <mark.hatle@windriver.com> |
| 30 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 31 | --- |
| 32 | scripts/config-run | 12 +++++++--- |
| 33 | src/Makefile | 4 ++-- |
| 34 | src/memsize.c | 66 +++++++++++++++++++++++++++++++++++------------------- |
| 35 | 3 files changed, 54 insertions(+), 28 deletions(-) |
| 36 | |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 37 | diff --git a/scripts/config-run b/scripts/config-run |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 38 | index 918cbdf..096ed12 100755 |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 39 | --- a/scripts/config-run |
| 40 | +++ b/scripts/config-run |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 41 | @@ -197,6 +197,12 @@ The bigger the range, the more accurate the results, but larger sizes |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 42 | take somewhat longer to run the benchmark. |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 43 | |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 44 | EOF |
| 45 | + |
| 46 | +# By default, use 512M memory as the upper limit for lmbench test |
| 47 | +if [ $MB -gt 512 ];then |
| 48 | +MB=512 |
| 49 | +fi |
| 50 | + |
| 51 | echo $ECHON "MB [default $MB]: $ECHOC" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 52 | read TMP |
| 53 | if [ X$TMP != X ] |
| 54 | @@ -687,10 +693,10 @@ case $MAIL in |
| 55 | ;; |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 56 | esac |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 57 | |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 58 | -INFO=`../scripts/info` |
| 59 | +INFO=`../scripts/hostinfo` |
| 60 | if [ $MAIL = yes ] |
| 61 | then if [ ! -f $INFO ] |
| 62 | - then cp ../scripts/info-template $INFO |
| 63 | + then cp ../scripts/hostinfo-template $INFO |
| 64 | chmod +w $INFO |
| 65 | REUSE=no |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 66 | else |
| 67 | @@ -733,7 +739,7 @@ EOF |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 68 | then EDITOR=$TMP |
| 69 | fi |
| 70 | if [ X$EDITOR != "none" ] |
| 71 | - then $EDITOR `../scripts/info` |
| 72 | + then $EDITOR `../scripts/hostinfo` |
| 73 | fi |
| 74 | fi |
| 75 | fi |
| 76 | diff --git a/src/Makefile b/src/Makefile |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 77 | index c7e4e3c..d9efd54 100644 |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 78 | --- a/src/Makefile |
| 79 | +++ b/src/Makefile |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 80 | @@ -50,7 +50,7 @@ TARGET=`../scripts/target` |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 81 | BINDIR=../bin/$(OS) |
| 82 | CONFIG=../bin/$(OS)/`../scripts/config` |
| 83 | UTILS=../scripts/target ../scripts/os ../scripts/gnu-os ../scripts/compiler \ |
| 84 | - ../scripts/info ../scripts/info-template ../scripts/version \ |
| 85 | + ../scripts/hostinfo ../scripts/hostinfo-template ../scripts/version \ |
| 86 | ../scripts/config ../scripts/config-run ../scripts/results \ |
| 87 | ../scripts/lmbench ../scripts/make ../scripts/build |
| 88 | INSTALL=cp |
| 89 | @@ -240,7 +240,7 @@ $O/getopt.o : getopt.c $(INCS) |
| 90 | $(COMPILE) -c getopt.c -o $O/getopt.o |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 91 | |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 92 | $(UTILS) : |
| 93 | - -cd ../scripts; make get |
| 94 | + -cd ../scripts; cp info hostinfo; cp info-template hostinfo-template |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 95 | |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 96 | # Do not remove the next line, $(MAKE) depend needs it |
| 97 | # MAKEDEPEND follows |
| 98 | diff --git a/src/memsize.c b/src/memsize.c |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 99 | index eb25a09..82d7faf 100644 |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 100 | --- a/src/memsize.c |
| 101 | +++ b/src/memsize.c |
| 102 | @@ -14,9 +14,12 @@ char *id = "$Id$\n"; |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 103 | |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 104 | #define CHK(x) if ((x) == -1) { perror("x"); exit(1); } |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 105 | |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 106 | -#ifndef TOO_LONG |
| 107 | -#define TOO_LONG 10 /* usecs */ |
| 108 | -#endif |
| 109 | +//#ifndef TOO_LONG |
| 110 | +//#define TOO_LONG 10 /* usecs */ |
| 111 | +//#endif |
| 112 | + |
| 113 | +#define MEMORY_SIZE_1MB (1024 * 1024) |
| 114 | +#define MEMORY_SIZE_8MB (8 * 1024 * 1024) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 115 | |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 116 | int alarm_triggered = 0; |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 117 | |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 118 | @@ -35,10 +38,10 @@ main(int ac, char **av) |
| 119 | size_t delta; |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 120 | |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 121 | if (ac == 2) { |
| 122 | - max = size = bytes(av[1]) * 1024 * 1024; |
| 123 | + max = size = bytes(av[1]) * MEMORY_SIZE_1MB; |
| 124 | } |
| 125 | - if (max < 1024 * 1024) { |
| 126 | - max = size = 1024 * 1024 * 1024; |
| 127 | + if (max < MEMORY_SIZE_1MB) { |
| 128 | + max = size = 1024 * MEMORY_SIZE_1MB; |
| 129 | } |
| 130 | /* |
| 131 | * Binary search down and then binary search up |
| 132 | @@ -48,7 +51,7 @@ main(int ac, char **av) |
| 133 | } |
| 134 | /* delta = size / (2 * 1024 * 1024) */ |
| 135 | for (delta = (size >> 21); delta > 0; delta >>= 1) { |
| 136 | - uint64 sz = (uint64)size + (uint64)delta * 1024 * 1024; |
| 137 | + uint64 sz = (uint64)size + (uint64)delta * MEMORY_SIZE_1MB; |
| 138 | size_t check = sz; |
| 139 | if (max < sz) continue; |
| 140 | if (check < sz || !test_malloc(sz)) break; |
| 141 | @@ -66,41 +69,58 @@ timeit(char *where, size_t size) |
| 142 | { |
| 143 | int sum = 0; |
| 144 | size_t n; |
| 145 | - size_t s_prev; |
| 146 | + size_t s_prev = MEMORY_SIZE_8MB; |
| 147 | size_t range; |
| 148 | - size_t incr = 1024 * 1024; |
| 149 | + size_t incr = MEMORY_SIZE_1MB; |
| 150 | size_t pagesize = getpagesize(); |
| 151 | - unsigned long long s; |
| 152 | - |
| 153 | - if (size < 1024*1024 - 16*1024) { |
| 154 | - fprintf(stderr, "Bad size\n"); |
| 155 | - return; |
| 156 | - } |
| 157 | + size_t time_each_page = 0; |
| 158 | + size_t too_long = 0; |
| 159 | + unsigned long long s; |
| 160 | + |
| 161 | + if (pagesize < MEMORY_SIZE_1MB) |
| 162 | + range = MEMORY_SIZE_1MB; |
| 163 | + else |
| 164 | + range = MEMORY_SIZE_8MB; |
| 165 | + |
| 166 | + incr = MEMORY_SIZE_1MB; |
| 167 | + |
| 168 | + if (size < range) { |
| 169 | + fprintf(stderr, "Bad size\n"); |
| 170 | + return; |
| 171 | + } |
| 172 | + |
| 173 | + //Touch range of memory, get the average time (usec) of operating each memory page on this system |
| 174 | + start(0); |
| 175 | + touchRange(where, range, pagesize); |
| 176 | + sum = stop(0, 0); |
| 177 | + |
| 178 | + if ((time_each_page = sum * pagesize / range) < 1) |
| 179 | + time_each_page = 1; |
| 180 | + //Set the uper limit of time spending on one page |
| 181 | + too_long = 10 * time_each_page; |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 182 | |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 183 | - range = 1024 * 1024; |
| 184 | - incr = 1024 * 1024; |
| 185 | - touchRange(where, range, pagesize); |
| 186 | for (range += incr; range <= size; range += incr) { |
| 187 | n = range / pagesize; |
| 188 | - set_alarm(n * TOO_LONG); |
| 189 | + set_alarm(n * too_long); |
| 190 | touchRange(where + range - incr, incr, pagesize); |
| 191 | clear_alarm(); |
| 192 | - set_alarm(n * TOO_LONG); |
| 193 | + set_alarm(n * too_long); |
| 194 | start(0); |
| 195 | touchRange(where, range, pagesize); |
| 196 | sum = stop(0, 0); |
| 197 | clear_alarm(); |
| 198 | - if ((sum / n) > TOO_LONG || alarm_triggered) { |
| 199 | + if ((sum / n) > too_long || alarm_triggered) { |
| 200 | size = range - incr; |
| 201 | + fprintf(stderr, "Error! Memory testing timeout! Touch one page of memory needs more than %d (usecs)\n ", too_long); |
| 202 | break; |
| 203 | } |
| 204 | - for (s = 8 * 1024 * 1024; s <= range; s_prev = s, s *= 2) |
| 205 | + for (s = s_prev; s <= range; s_prev = s, s *= 2) |
| 206 | if (s < s_prev) break; |
| 207 | incr = s / 8; |
| 208 | if (range < size && size < range + incr) { |
| 209 | incr = size - range; |
| 210 | } |
| 211 | - fprintf(stderr, "%dMB OK\r", (int)(range/(1024*1024))); |
| 212 | + fprintf(stderr, "%dMB OK\r", (int)(range/MEMORY_SIZE_1MB)); |
| 213 | } |
| 214 | fprintf(stderr, "\n"); |
| 215 | printf("%d\n", (int)(size>>20)); |