diff --git a/lagarto-ox.nix b/lagarto-ox.nix index bc494f5..ab96e84 100644 --- a/lagarto-ox.nix +++ b/lagarto-ox.nix @@ -92,9 +92,10 @@ # while [ 1 ]; do xxd -s $((0x1bfff0000 - 0x60000000)) \ # -l 4 /dev/qdma34000-MM-1; sleep 0.2; done preDeviceCommands = - # Run our memtool to hang the kernel here. + # Run our memtool to hang the kernel here. Set the maximum block + # size to 64K. '' - memtool + memtool $((64 * 1024)) '' + '' diff --git a/memtool.c b/memtool.c index b5b6f2a..7dd347a 100644 --- a/memtool.c +++ b/memtool.c @@ -22,13 +22,14 @@ struct block *front = NULL; struct block *tail = NULL; long nblocks = 0; long nbytes = 0; +long maxsize = MAX_SIZE; static int allocate(void) { - long n = (long) rand() % MAX_SIZE; - /* Constraint the size */ - n = n % MAX_SIZE; + /* Constraint the number of elements based on the maxsize */ + long maxn = maxsize / sizeof(uint32_t); + long n = (long) rand() % maxn; size_t size = sizeof(struct block) + n * sizeof(uint32_t); @@ -106,14 +107,20 @@ torture(void) c = '-'; } - printf("iter %ld, nblocks %ld, nbytes %.1fM (%c)\n", - iter, nblocks, (double) nbytes / (1024. * 1024.), + printf("iter=%ld nblocks=%ld allocated=%ldK (%c)\n", + iter, nblocks, nbytes / 1024, c); } } int main(int argc, char *argv[]) { + if (argc > 1) + maxsize = atol(argv[1]); + + printf("memtool v1.0.0 maxsize=%ldK\n", maxsize / 1024); + torture(); + return 0; }