| 1 | |
| 2 | |
| 3 | * Artificial memory access program for testing DAMON.
|
| 4 |
|
| 5 |
|
| 6 | #include <stdio.h>
|
| 7 | #include <stdlib.h>
|
| 8 | #include <string.h>
|
| 9 | #include <time.h>
|
| 10 |
|
| 11 | enum access_mode {
|
| 12 | ACCESS_MODE_ONCE,
|
| 13 | ACCESS_MODE_REPEAT,
|
| 14 | };
|
| 15 |
|
| 16 | int main(int argc, char *argv[])
|
| 17 | {
|
| 18 | char **regions;
|
| 19 | clock_t start_clock;
|
| 20 | int nr_regions;
|
| 21 | int sz_region;
|
| 22 | int access_time_ms;
|
| 23 | enum access_mode mode = ACCESS_MODE_ONCE;
|
| 24 |
|
| 25 | int i;
|
| 26 |
|
| 27 | if (argc < 4) {
|
| 28 | printf("Usage: %s <number> <size (bytes)> <time (ms)> [mode]\n",
|
| 29 | argv[0]);
|
| 30 | return -1;
|
| 31 | }
|
| 32 |
|
| 33 | nr_regions = atoi(argv[1]);
|
| 34 | sz_region = atoi(argv[2]);
|
| 35 | access_time_ms = atoi(argv[3]);
|
| 36 |
|
| 37 | if (argc > 4 && !strcmp(argv[4], "repeat"))
|
| 38 | mode = ACCESS_MODE_REPEAT;
|
| 39 |
|
| 40 | regions = malloc(sizeof(*regions) * nr_regions);
|
| 41 | for (i = 0; i < nr_regions; i++)
|
| 42 | regions[i] = malloc(sz_region);
|
| 43 |
|
| 44 | do {
|
| 45 | for (i = 0; i < nr_regions; i++) {
|
| 46 | start_clock = clock();
|
| 47 | while ((clock() - start_clock) * 1000 / CLOCKS_PER_SEC
|
| 48 | < access_time_ms)
|
| 49 | memset(regions[i], i, sz_region);
|
| 50 | }
|
| 51 | } while (mode == ACCESS_MODE_REPEAT);
|
| 52 |
|
| 53 | return 0;
|
| 54 | }
|