-
Notifications
You must be signed in to change notification settings - Fork 0
/
oslabs.h
129 lines (95 loc) · 4.56 KB
/
oslabs.h
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
129
#ifndef CPU_SCHEDULING_LAB_OSLABS_H
#define CPU_SCHEDULING_LAB_OSLABS_H
#include <stdio.h>
#define QUEUEMAX 10
#define MAPMAX 10
#define TABLEMAX 10
#define POOLMAX 10
#define REFERENCEMAX 20
#define MAX(a, b) ( ( a > b ) ? a : b )
#define MIN(a, b) ( ( a > b ) ? b : a )
struct RCB {
int request_id;
int arrival_timestamp;
int cylinder;
int address;
int process_id;
};
struct PCB {
int process_id;
int arrival_timestamp;
int total_bursttime;
int execution_starttime;
int execution_endtime;
int remaining_bursttime;
int process_priority;
};
struct MEMORY_BLOCK {
int start_address;
int end_address;
int segment_size;
int process_id; //0 indicates a free block
};
struct PTE {
int is_valid;
int frame_number;
int arrival_timestamp;
int last_access_timestamp;
int reference_count;
};
struct RCB handle_request_arrival_fcfs(struct RCB request_queue[QUEUEMAX], int
*queue_cnt, struct RCB current_request, struct RCB new_request, int timestamp);
struct RCB handle_request_completion_fcfs(struct RCB request_queue[QUEUEMAX], int
*queue_cnt);
struct RCB handle_request_arrival_sstf(struct RCB request_queue[QUEUEMAX], int
*queue_cnt, struct RCB current_request, struct RCB new_request, int timestamp);
struct RCB handle_request_completion_sstf(struct RCB request_queue[QUEUEMAX], int
*queue_cnt, int current_cylinder);
struct RCB handle_request_arrival_look(struct RCB request_queue[QUEUEMAX], int
*queue_cnt, struct RCB current_request, struct RCB new_request, int timestamp);
struct RCB handle_request_completion_look(struct RCB request_queue[QUEUEMAX], int
*queue_cnt, int current_cylinder, int scan_direction);
struct MEMORY_BLOCK best_fit_allocate(int request_size, struct MEMORY_BLOCK
memory_map[MAPMAX], int *map_cnt, int process_id);
struct MEMORY_BLOCK first_fit_allocate(int request_size, struct MEMORY_BLOCK
memory_map[MAPMAX], int *map_cnt, int process_id);
struct MEMORY_BLOCK worst_fit_allocate(int request_size, struct MEMORY_BLOCK
memory_map[MAPMAX], int *map_cnt, int process_id);
struct MEMORY_BLOCK next_fit_allocate(int request_size, struct MEMORY_BLOCK
memory_map[MAPMAX], int *map_cnt, int process_id, int last_address);
void release_memory(struct MEMORY_BLOCK freed_block, struct MEMORY_BLOCK
memory_map[MAPMAX], int *map_cnt);
int process_page_access_fifo(struct PTE page_table[TABLEMAX], int *table_cnt, int
page_number, int frame_pool[POOLMAX], int *frame_cnt, int current_timestamp);
int count_page_faults_fifo(struct PTE page_table[TABLEMAX], int table_cnt, int
refrence_string[REFERENCEMAX], int reference_cnt, int frame_pool[POOLMAX], int
frame_cnt);
int process_page_access_lru(struct PTE page_table[TABLEMAX], int *table_cnt, int
page_number, int frame_pool[POOLMAX], int *frame_cnt, int current_timestamp);
int count_page_faults_lru(struct PTE page_table[TABLEMAX], int table_cnt, int
refrence_string[REFERENCEMAX], int reference_cnt, int frame_pool[POOLMAX], int
frame_cnt);
int process_page_access_lfu(struct PTE page_table[TABLEMAX], int *table_cnt, int
page_number, int frame_pool[POOLMAX], int *frame_cnt, int current_timestamp);
int count_page_faults_lfu(struct PTE page_table[TABLEMAX], int table_cnt, int
refrence_string[REFERENCEMAX], int reference_cnt, int frame_pool[POOLMAX], int
frame_cnt);
struct PCB handle_process_arrival_pp(struct PCB ready_queue[QUEUEMAX], int *queue_cnt,
struct PCB current_process, struct PCB new_process, int timestamp);
struct PCB handle_process_completion_pp(struct PCB ready_queue[QUEUEMAX], int
*queue_cnt, int timestamp);
struct PCB handle_process_arrival_srtp(struct PCB ready_queue[QUEUEMAX], int *queue_cnt,
struct PCB current_process, struct PCB new_process, int time_stamp);
struct PCB handle_process_completion_srtp(struct PCB ready_queue[QUEUEMAX], int
*queue_cnt, int timestamp);
struct PCB handle_process_arrival_rr(struct PCB ready_queue[QUEUEMAX], int *queue_cnt,
struct PCB current_process, struct PCB new_process, int timestamp,
int time_quantum);
struct PCB handle_process_completion_rr(struct PCB ready_queue[QUEUEMAX], int
*queue_cnt, int timestamp, int time_quantum);
// Custom functions
struct PCB init_pcb(int pid, int ats, int tbt, int est, int eet, int rbt, int pp);
void print_pcb(struct PCB pcb);
int pcb_is_null(struct PCB pcb);
void print_queue(struct PCB ready_queue[QUEUEMAX], int queue_cnt);
#endif //CPU_SCHEDULING_LAB_OSLABS_H