access_memory_even.c 870 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Artificial memory access program for testing DAMON.
  4. *
  5. * Receives number of regions and size of each region from user. Allocate the
  6. * regions and repeatedly access even numbered (starting from zero) regions.
  7. */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <time.h>
  12. int main(int argc, char *argv[])
  13. {
  14. char **regions;
  15. clock_t start_clock;
  16. int nr_regions;
  17. int sz_region;
  18. int access_time_ms;
  19. int i;
  20. if (argc != 3) {
  21. printf("Usage: %s <number> <size (bytes)>\n", argv[0]);
  22. return -1;
  23. }
  24. nr_regions = atoi(argv[1]);
  25. sz_region = atoi(argv[2]);
  26. regions = malloc(sizeof(*regions) * nr_regions);
  27. for (i = 0; i < nr_regions; i++)
  28. regions[i] = malloc(sz_region);
  29. while (1) {
  30. for (i = 0; i < nr_regions; i++) {
  31. if (i % 2 == 0)
  32. memset(regions[i], i, sz_region);
  33. }
  34. }
  35. return 0;
  36. }