-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
93 lines (72 loc) · 2.37 KB
/
main.c
File metadata and controls
93 lines (72 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "hive.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define ALLOCS_PER_PHASE 2500000
static void *ptrs[ALLOCS_PER_PHASE];
void run_phase(const char *name, struct hive_cell *c1, struct hive_cell *c2)
{
printf("\n>>> STARTING PHASE: %s <<<\n", name);
clock_t start = clock();
for (size_t i = 0; i < ALLOCS_PER_PHASE; ++i)
{
size_t size = 16 + (rand() % 240);
int choice = rand() % 2;
void *p = NULL;
if (choice == 0)
{
p = hive_cell_alloc(c1, size);
}
else
{
p = hive_cell_alloc(c2, size);
}
if (p)
{
ptrs[i] = p;
memset(p, (int) i, size);
}
}
clock_t end = clock();
double cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
printf("Phase '%s' took %f seconds\n", name, cpu_time_used);
hive_cell_log_stats(c1);
hive_cell_log_stats(c2);
}
#define RENDERER_SIZE (1024LL * 1024 * 1024)
#define PHYSICS_SIZE (2048LL * 1024 * 1024)
int main(void)
{
srand((unsigned int) time(NULL));
if (!hive_init())
{
fprintf(stderr, "Hive failed to init!\n");
return 1;
}
struct hive_cell *renderer = hive_cell_create("renderer", RENDERER_SIZE);
struct hive_cell *physics = hive_cell_create("physics", PHYSICS_SIZE);
if (!renderer || !physics)
{
return 1;
}
printf("Allocs per phase: %d", ALLOCS_PER_PHASE);
/* ---------------- PHASE 1: COLD START ---------------- */
// This tests first-time page faults and Huge Page creation
run_phase("COLD START", renderer, physics);
/* ---------------- PHASE 2: SOFT RESET ---------------- */
// Just move the cursor back. This is "Warm" because the
// physical RAM is still mapped by the Kernel.
printf("\n[Action] Performing SOFT RESET (Reuse Memory)...\n");
hive_cell_soft_reset(renderer);
hive_cell_soft_reset(physics);
run_phase("WARM REUSE", renderer, physics);
/* ---------------- PHASE 3: HARD RESET ---------------- */
// Use MADV_DONTNEED. This is "Hard" because we give RAM back
// to the OS but keep the virtual addresses.
printf("\n[Action] Performing HARD RESET (Decommit Memory)...\n");
hive_cell_reset(renderer);
hive_cell_reset(physics);
run_phase("HARD RESTART", renderer, physics);
return 0;
}