]>
git.saurik.com Git - apple/xnu.git/blob - tools/tests/perf_index/perfindex-memory.c
1 #include "perf_index.h"
6 #include <sys/sysctl.h>
21 len
= sizeof(my_memsize
);
23 retval
= sysctl(mib
, 2, &my_memsize
, &len
, NULL
, 0);
35 int pgsz
= getpagesize();
37 /* Heuristic: use half the physical memory, hopefully this should work on all
38 * devices. We use the amount of physical memory, rather than some softer
39 * metric, like amount of free memory, so that the memory allocated is always
40 * consistent for a given device.
42 memsize
= hw_memsize();
43 VERIFY(memsize
> 0, "hw_memsize failed");
44 memsize
= memsize
/ 2;
46 memblock
= (char*)malloc(memsize
);
47 VERIFY(memblock
!= NULL
, "malloc failed");
49 memblockfiller
= memblock
;
51 /* Do this manually, to make sure everything is paged in */
52 for (i
= 0; i
< memsize
; i
+= pgsz
) {
53 memblockfiller
[i
] = 1;
56 return PERFINDEX_SUCCESS
;
59 /* figures out what region of memory to copy, so it does interfere with other
62 long long left
= length
;
63 long long region_len
= memsize
/ num_threads
/ 2;
64 long long region_start
= memsize
/ num_threads
* thread_id
/ 2;
67 if (thread_id
< memsize
/ 2 % num_threads
) {
68 region_start
+= thread_id
;
71 region_start
+= memsize
/ 2 % num_threads
;
75 copy_len
= region_len
< left
? region_len
: left
;
76 memcpy(memblock
+ region_start
+ memsize
/ 2, memblock
+ region_start
, copy_len
);
80 return PERFINDEX_SUCCESS
;
85 return PERFINDEX_SUCCESS
;