|
| 1 | +/* Test description: |
| 2 | + * This test tries to record the performance numbers with the memory allocator |
| 3 | + * used in EDP. The steps are as follows: |
| 4 | + * Create n threads. Each threads will continuosly allocate a randomly sized |
| 5 | + * buffer, traverse random locations in the buffer and then free it. |
| 6 | + * |
| 7 | + * There are 3 types of threads, small, medium and large. Depending on the type |
| 8 | + * the small threads will allocate and deallocate small sized buffers, and the |
| 9 | + * large threads will allocate and deallocate large sized buffers. The buffer |
| 10 | + * sizes and number of checks are all controlled by some parameters/constants |
| 11 | + * which are there a couple of lines below. |
| 12 | + * |
| 13 | + * The todos before running this test is there in the description of |
| 14 | + * https://fortanix.atlassian.net/browse/RTE-36 (under the heading |
| 15 | + * "Instructions on how to run the test:" ) |
| 16 | + */ |
| 17 | + |
1 | 18 | use rand::Rng;
|
2 | 19 | use std::alloc::{alloc, dealloc, Layout};
|
3 | 20 | use std::ptr;
|
@@ -30,25 +47,63 @@ const TO_MB: usize = TO_KB * 1024;
|
30 | 47 | const TO_GB: usize = TO_MB * 1024;
|
31 | 48 |
|
32 | 49 | /* Set of configurable parameters. These will adjusted as necessary while
|
33 |
| - * recording the performance numbers |
| 50 | + * recording the performance numbers. |
| 51 | + * TODO: Replace the hard coded parameters with command line arguments. |
| 52 | + */ |
| 53 | + |
| 54 | +/* This denotes the number of cpus in the system in which the test is being run. |
| 55 | + * This test will create as many number of threads as there are number of CPUs. |
34 | 56 | */
|
35 | 57 | const NUM_CPUS: usize = 2;
|
36 | 58 |
|
| 59 | +/* This thread creates 3 types of threads. Small, medium and large. Each type of |
| 60 | + * thread will run the loop of allocation and deallocation different number of |
| 61 | + * times. LIMIT_SMALL_THREAD, LIMIT_MEDIUM_THREAD, LIMIT_LARGE_THREAD denotes |
| 62 | + * the number of times small threads, medium threads and large threads run the |
| 63 | + * loop respectively. |
| 64 | + */ |
37 | 65 | const LIMIT_SMALL_THREAD: i32 = 2;
|
38 | 66 | const LIMIT_MEDIUM_THREAD: i32 = 2;
|
39 | 67 | const LIMIT_LARGE_THREAD: i32 = 2;
|
40 | 68 |
|
| 69 | +/* Each type of thread namely, small, medium and large allocates different sizes |
| 70 | + * of memory and hence they have different scan intervals. This scan interval is |
| 71 | + * used in the traverse_buffer function. Large threads have large buffers and |
| 72 | + * their intervals are larger compared to small threads which allocate smaller |
| 73 | + * buffer. SCAN_INTERVAL_SMALL_THREAD, SCAN_INTERVAL_MEDIUM_THREAD, and |
| 74 | + * SCAN_INTERVAL_LARGE_THREAD denote the scan intervals for small threads, |
| 75 | + * medium threads and large threads respectively. |
| 76 | + */ |
41 | 77 | const SCAN_INTERVAL_SMALL_THREAD: usize = 1 * TO_KB;
|
42 | 78 | const SCAN_INTERVAL_MEDIUM_THREAD: usize = 1 * TO_MB;
|
43 | 79 | const SCAN_INTERVAL_LARGE_THREAD: usize = 1 * TO_MB;
|
44 | 80 |
|
45 |
| -const SMALL_THREAD_MEM_START: usize = 1; |
46 |
| -const SMALL_THREAD_MEM_END: usize = 512; |
47 |
| -const MEDIUM_THREAD_MEM_START: usize = 1; |
48 |
| -const MEDIUM_THREAD_MEM_END: usize = 2; |
49 |
| -const LARGE_THREAD_MEM_START: usize = 1; |
50 |
| -const LARGE_THREAD_MEM_END: usize = 2; |
51 | 81 |
|
| 82 | +/* Each thread allocates a random sized buffer. The range of the random sizes |
| 83 | + * depend on the thread type namely small, medium and large. |
| 84 | + * SMALL_THREAD_MEM_START and SMALL_THREAD_MEM_END denote the minium and maximum |
| 85 | + * buffer size of small threads in KB respectively. |
| 86 | + * |
| 87 | + * MEDIUM_THREAD_MEM_START and MEDIUM_THREAD_MEM_END denote the minium and maximum |
| 88 | + * buffer size of medium threads in MB respectively. |
| 89 | + * LARGE_THREAD_MEM_START and LARGE_THREAD_MEM_END denote the minium and maximum |
| 90 | + * buffer size of large threads in GB respectively. |
| 91 | + */ |
| 92 | +const SMALL_THREAD_MEM_START: usize = 1; // in KB |
| 93 | +const SMALL_THREAD_MEM_END: usize = 512; // in KB |
| 94 | +const MEDIUM_THREAD_MEM_START: usize = 1; // in MB |
| 95 | +const MEDIUM_THREAD_MEM_END: usize = 2; // in MB |
| 96 | +const LARGE_THREAD_MEM_START: usize = 1; // in GB |
| 97 | +const LARGE_THREAD_MEM_END: usize = 2; // in GB |
| 98 | + |
| 99 | +/* In traverse_buffer function, we randomly pick up random number of indices in |
| 100 | + * in the buffer and access them. MAX_INDEX_CHECKS_PER_BUFFER denotes the maximum |
| 101 | + * number of checks per buffer. We don't traverse the entire buffer as it will |
| 102 | + * slow down each thread and the threads won't be able to exihibit concurrency |
| 103 | + * during thread allocation and de allocation. Higher the value of |
| 104 | + * MAX_INDEX_CHECKS_PER_BUFFER, slower will be the threads and lesser will be |
| 105 | + * the concurrency. |
| 106 | + */ |
52 | 107 | const MAX_INDEX_CHECKS_PER_BUFFER: usize = 32;
|
53 | 108 |
|
54 | 109 | fn calculate_and_print_stat(
|
@@ -136,23 +191,20 @@ fn worker_thread(
|
136 | 191 | /* Create a random size depending on the memory type */
|
137 | 192 | let (scan_interval, size, limit) = match memsize {
|
138 | 193 | MemSize::Large => {
|
139 |
| - /* buffer size will be from 1GB to 4GB */ |
140 | 194 | (
|
141 | 195 | SCAN_INTERVAL_LARGE_THREAD,
|
142 | 196 | TO_GB * get_random_num(LARGE_THREAD_MEM_START, LARGE_THREAD_MEM_END),
|
143 | 197 | LIMIT_LARGE_THREAD,
|
144 | 198 | )
|
145 | 199 | }
|
146 | 200 | MemSize::Medium => {
|
147 |
| - /* buffer size will be from 8MB to 128 */ |
148 | 201 | (
|
149 | 202 | SCAN_INTERVAL_MEDIUM_THREAD,
|
150 | 203 | TO_MB * get_random_num(MEDIUM_THREAD_MEM_START, MEDIUM_THREAD_MEM_END),
|
151 | 204 | LIMIT_MEDIUM_THREAD,
|
152 | 205 | )
|
153 | 206 | }
|
154 | 207 | MemSize::Small => {
|
155 |
| - /* buffer size will be from 1KB to 512KB */ |
156 | 208 | (
|
157 | 209 | SCAN_INTERVAL_SMALL_THREAD,
|
158 | 210 | TO_KB * get_random_num(SMALL_THREAD_MEM_START, SMALL_THREAD_MEM_END),
|
|
0 commit comments