-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput_mode_helper.c
129 lines (113 loc) · 3.93 KB
/
output_mode_helper.c
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <stdio.h>
#include "output_mode_helpers.h"
/* Handle C++ namespaces, ignore if compiled in C
* C++ usually uses this #define to declare the C++ standard.
* It will not be defined if a C compiler is used.
*/
#ifdef __cplusplus
using namespace std;
#endif
/*
* report_virtual2physical(src, dest)
* Given a pair of numbers, output a line:
* src -> dest
* Example usages:
* Map between logical and physical addresses: mapping(logical, physical)
* Map between page number and frame: mapping(page, frame)
*/
void report_virtual2physical(uint32_t src, uint32_t dest) {
fprintf(stdout, "%08X -> %08X\n", src, dest);
fflush(stdout);
}
/*
* report_v2pUsingTLB_PTwalk(src, dest, tlbhit, pthit)
* Given a pair of addresses, hit or miss along the tlb then pagetable walk,
* output a line:
* src -> dest, tlb hit
* src -> dest, tlb miss, pagetable hit
* src -> dest, tlb miss, pagetable miss
* Example usages:
* Report translation/mapping from logical to physical address:
* e.g., report_v2pUsingTLB_PTwalk(logical, physical, false, true)
* tlb miss, pagetable hit
* Report translation/mapping from virtual page number to physical frame:
* e.g., report_v2pUsingTLB_PTwalk(page, frame, false, true)
* tlb miss, pagetable hit
*/
void report_v2pUsingTLB_PTwalk(uint32_t src, uint32_t dest, bool tlbhit, bool pthit) {
fprintf(stdout, "%08X -> %08X, ", src, dest);
if (tlbhit)
fprintf(stdout, "tlb hit\n");
else {
fprintf(stdout, "tlb miss, pagetable %s\n", pthit ? "hit" : "miss");
}
fflush(stdout);
}
/*
* hexnum
* Used for writing out a number in hex, one per line
*/
void hexnum(uint32_t number) {
printf("%08X\n", number);
fflush(stdout);
}
/*
* report_summary
* Write out a mesasge that indicates summary information for the page table.
* page_size - Number of bytes per page
* cacheHits - Number of vpn->pfn mapping found in the TLB
* pageTableHits - Number of times a page was mapped.
* addresses - Number of addresses processed
* frames_used - Number of frames allocated
* bytes - Total number of bytes needed for page table data structure.
* Should include all levels, allocated arrays, etc.
*/
void report_summary(unsigned int page_size,
unsigned int cacheHits,
unsigned int pageTableHits,
unsigned int addresses, unsigned int frames_used,
unsigned int bytes) {
unsigned int misses;
double hit_percent;
printf("Page size: %d bytes\n", page_size);
/* Compute misses (page faults) and hit percentage */
int totalhits = cacheHits + pageTableHits;
misses = addresses - totalhits;
hit_percent = (double)(totalhits) / (double)addresses * 100.0;
printf("Addresses processed: %d\n", addresses);
printf("Cache hits: %d, Page hits: %d, Total hits: %d, Misses: %d\n",
cacheHits, pageTableHits, totalhits, misses);
printf("Total hit percentage: %.2f%%, miss percentage: %.2f%%\n",
hit_percent, 100 - hit_percent);
printf("Frames allocated: %d\n", frames_used);
printf("Bytes used: %d\n", bytes);
fflush(stdout);
}
/*
* report_bitmasks
* Write out bitmasks.
* levels - Number of levels
* masks - Pointer to array of bitmasks
*/
void report_bitmasks(int levels, uint32_t* masks) {
printf("Bitmasks\n");
for (int idx = 0; idx < levels; idx++)
/* show mask entry and move to next */
printf("level %d mask %08X\n", idx, masks[idx]);
fflush(stdout);
}
/*
* report_pagemap
* Write out page numbers and frame number
* levels - specified number of levels in page table
* pages - pages[idx] is the page number associated with level idx (0 < idx < levels)
* frame - page is mapped to specified frame
*/
void report_pagemap(int levels, uint32_t* pages, uint32_t frame) {
/* output pages */
for (int idx = 0; idx < levels; idx++)
printf("%X ", pages[idx]);
/* output frame */
printf("-> %X\n", frame);
fflush(stdout);
}