-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.c
More file actions
545 lines (470 loc) · 12.7 KB
/
error.c
File metadata and controls
545 lines (470 loc) · 12.7 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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
#include "iopm.h"
#include "error.h"
#include "main.h"
#include "init.h"
void error_victim_partition_flag(int cluster) {
if (CLUSTER[cluster].victim_partition_num < PARTITION_PER_CLUSTER + 2) {
int i;
_partition *temp = CLUSTER[cluster].victim_partition_list;
for (i = 0; i < CLUSTER[cluster].victim_partition_num; i++) {
assert(PVB[temp->partition_num].victim_partition_flag == 1);
temp = temp->next;
}
}
else {
int i;
_partition *temp = CLUSTER[cluster].victim_partition_list;
for (i = 0; i < PARTITION_PER_CLUSTER + 2; i++) {
assert(PVB[temp->partition_num].victim_partition_flag == 1);
temp = temp->next;
}
for (i = PARTITION_PER_CLUSTER + 2; i < CLUSTER[cluster].victim_partition_num; i++) {
assert(PVB[temp->partition_num].victim_partition_flag == 0);
temp = temp->next;
}
}
}
void error_cluster_vicitm_valid_increase_with_p(int cluster, int old_p) {
if (CLUSTER[cluster].victim_partition_list != NULL) {
_partition *t = CLUSTER[cluster].victim_partition_list;
int prev = -1;
int prev_p = -1;
int count = 0;
assert(prev <= PVB[t->partition_num].valid);
t = t->next;
while (t->partition_num != CLUSTER[cluster].victim_partition_list->partition_num) {
if(t->partition_num == old_p)
assert(prev <= PVB[t->partition_num].valid +1);
else
assert(prev <= PVB[t->partition_num].valid);
if (prev_p != -1) {
assert(prev_p != t->partition_num);
}
prev_p = t->partition_num;
prev = PVB[t->partition_num].valid;
t = t->next;
}
}
}
void error_cluster_vicitm_valid_increase(int cluster) {
if (CLUSTER[cluster].victim_partition_list != NULL) {
_partition *t = CLUSTER[cluster].victim_partition_list;
int prev = -1;
int prev_p = -1;
int count = 0;
assert(prev <= PVB[t->partition_num].valid);
t = t->next;
while (t->partition_num != CLUSTER[cluster].victim_partition_list->partition_num) {
assert(prev <= PVB[t->partition_num].valid);
if (prev_p != -1) {
assert(prev_p != t->partition_num);
}
prev_p = t->partition_num;
prev = PVB[t->partition_num].valid;
t = t->next;
}
}
}
void error_cluster_vicitm_valid(int cluster) {
if (CLUSTER[cluster].victim_partition_list != NULL) {
_partition *t = CLUSTER[cluster].victim_partition_list;
int victim_valid_count = 0;
int i;
if (CLUSTER[cluster].victim_partition_num <= PARTITION_PER_CLUSTER + 2) {
for (i = 0; i<CLUSTER[cluster].victim_partition_num; i++) {
victim_valid_count = victim_valid_count + PVB[t->partition_num].valid;
t = t->next;
}
}
else {
for (i = 0; i< PARTITION_PER_CLUSTER + 2; i++) {
victim_valid_count = victim_valid_count + PVB[t->partition_num].valid;
t = t->next;
}
}
assert(CLUSTER[cluster].victim_valid >= 0);
//assert(CLUSTER[cluster].victim_valid <= CLUSTER[cluster].valid);
assert(victim_valid_count == CLUSTER[cluster].victim_valid);
}
}
void error_block_invalid(int block) {
int i;
int count = 0;
for (i = 0; i < PAGE_PER_BLOCK; i++) {
if (PB[block].valid[i] == 1) {
count++;
}
}
assert(count == 128 - BIT[block].invalid);
}
void error_cluster_move_check(int cluster) {
int flag = 0;
int valid = CLUSTER[cluster].victim_valid;
if (valid < PAGE_PER_CLUSTER) {
_cluster *temp = victim_cluster_pool[valid];
if (victim_cluster_pool[valid] != NULL) {
if (victim_cluster_pool[valid]->cluster_num == cluster) {
flag = 1;
}
else {
temp = temp->next;
while (temp->cluster_num != victim_cluster_pool[valid]->cluster_num) {
if (cluster == temp->cluster_num) {
flag = 1;
}
temp = temp->next;
}
}
assert(flag == 1);
}
}
}
void error_free_block_pool() {
int count = 1;
_block *temp = free_block_pool;
temp = temp->next;
while (temp->block_num != free_block_pool->block_num) {
count++;
temp = temp->next;
}
assert(count == free_block);
}
void check_free_block() {
if (free_block == 0) {
printf("[Error] No Free Block!\n");
getchar();
//exit(1);
}
}
int error_partition_valid(int partition) {
int count =0;
return count;
}
void error_LPN_PPN(int LPN, int PPN) {
//if (PB[PPN / PAGE_PER_BLOCK].PPN2LPN[PPN%PAGE_PER_BLOCK] != LPN) {
// printf("[ERROR] LPN doesn't match with PPN\n");
// getchar();
//exit(1);
//}
assert(PB[PPN / PAGE_PER_BLOCK].PPN2LPN[PPN%PAGE_PER_BLOCK] == LPN);
}
void error_PPN(int PPN, int partition, int flag) {
if (PPN == -1) {
printf("[ERROR] wrong PPN. PPN = -1\n");
getchar();
//exit(1);
}
}
void error_victim_valid(int victim_block) {
if (BIT[victim_block].invalid <= 0) {
printf("[ERROR] victim block has no valid pages\n");
getchar();
//exit(1);
}
}
void error_PVB_valid(int partition) {
if (PVB[partition].valid > PARTITION_SIZE / PAGE_SIZE) {
printf("PVB[partition].valid > PARTITION_SIZE / PAGE_SIZE\n");
getchar();
//exit(1);
}
}
void error_PartitionGC_increase(int num, int partition) {
if (num != PVB[partition].valid) {
printf("error\n wrong valid pages num\n");
getchar();
//exit(1);
}
}
#if 0
void cluster_count(int cluster) {
if(CLUSTER[cluster].victim_partition_list!= NULL){
_partition *t = CLUSTER[cluster].victim_partition_list;
int count = 0;
while (t->next->partition_num != CLUSTER[cluster].victim_partition_list->partition_num) {
count++;
t = t->next;
}
assert(count + 1 == CLUSTER[cluster].victim_partition_num);
}
}
void cluster_vicitm_valid_increase(int cluster) {
if (CLUSTER[cluster].victim_partition_list != NULL) {
_partition *t = CLUSTER[cluster].victim_partition_list;
int prev = -1;
int prev_p = -1;
int count = 0;
while (t->next->partition_num != CLUSTER[cluster].victim_partition_list->partition_num) {
assert(prev <= PVB[t->partition_num].valid);
if (prev_p != -1) {
assert(prev_p != t->partition_num);
}
prev_p = t->partition_num;
prev = PVB[t->partition_num].valid;
t = t->next;
}
}
}
void cluster_vicitm_valid(int cluster) {
if (CLUSTER[cluster].victim_partition_list != NULL) {
_partition *t = CLUSTER[cluster].victim_partition_list;
int victim_valid_count = 0;
int i;
if (CLUSTER[cluster].victim_partition_num <= PARTITION_PER_CLUSTER + 2) {
for (i = 0; i<CLUSTER[cluster].victim_partition_num; i++) {
victim_valid_count = victim_valid_count + PVB[t->partition_num].valid;
t = t->next;
}
}
else {
for (i = 0; i< PARTITION_PER_CLUSTER + 2; i++) {
victim_valid_count = victim_valid_count + PVB[t->partition_num].valid;
t = t->next;
}
}
assert(CLUSTER[cluster].victim_valid >= 0);
assert(CLUSTER[cluster].victim_valid <= CLUSTER[cluster].valid);
assert(victim_valid_count == CLUSTER[cluster].victim_valid);
}
}
void partition_valid_check(int partition) {
int j;
int p = partition;
int count = 0;
if (PVB[p].endPPN != -1) {
if (PVB[p].blocknum == 1) {
int block = PVB[p].block[0];
int start_off = PVB[p].startPPN % 128;
int end_off = PVB[p].endPPN % 128;
if (end_off != -1) {
for (j = start_off; j <= end_off; j++) {
if (PB[block].valid[j] == 1) {
count++;
}
}
assert(count == PVB[p].valid);
}
}
else {
int block = PVB[p].block[0];
int start_off = PVB[p].startPPN % 128;
int end_off = PVB[p].endPPN % 128;
for (j = start_off; j < 128; j++) {
if (PB[block].valid[j] == 1) {
count++;
}
}
//end
int block_num = PVB[p].blocknum;
block = PVB[p].block[block_num - 1];
for (j = 0; j <= end_off; j++) {
if (PB[block].valid[j] == 1) {
count++;
}
}
// middle
block_num = PVB[p].blocknum;
int k;
for (k = 1; k < block_num - 1; k++) {
int block = PVB[p].block[k];
for (j = 0; j <= end_off; j++) {
if (PB[block].valid[j] == 1) {
count++;
}
}
}
assert(count == PVB[p].valid);
}
}
}
void victim_partition_flag_check(int cluster) {
if (CLUSTER[cluster].victim_partition_list != NULL) {
_partition *t = CLUSTER[cluster].victim_partition_list;
int victim_valid_count = 0;
int i,j;
if (CLUSTER[cluster].victim_partition_num <= PARTITION_PER_CLUSTER + 2) {
for (i = 0; i<CLUSTER[cluster].victim_partition_num; i++) {
int p = t->partition_num;
assert(PVB[p].victim_partition_flag == 1);
int count = 0;
if (PVB[p].blocknum == 1) {
int block = PVB[p].block[0];
int start_off = PVB[p].startPPN % 128;
int end_off = PVB[p].endPPN % 128;
for (j = start_off; j <= end_off; j++) {
if (PB[block].valid[j] == 1) {
count++;
}
}
assert(count == PVB[p].valid);
}
else {
int block = PVB[p].block[0];
int start_off = PVB[p].startPPN % 128;
int end_off = PVB[p].endPPN % 128;
for (j = start_off; j < 128; j++) {
if (PB[block].valid[j] == 1) {
count++;
}
}
//end
int block_num = PVB[p].blocknum;
block = PVB[p].block[block_num-1];
for (j = 0; j <= end_off; j++) {
if (PB[block].valid[j] == 1) {
count++;
}
}
// middle
block_num = PVB[p].blocknum;
int k;
for (k = 1; k < block_num - 1; k++) {
int block = PVB[p].block[k];
for (j = 0; j <= end_off; j++) {
if (PB[block].valid[j] == 1) {
count++;
}
}
}
assert(count == PVB[p].valid);
}
t = t->next;
}
}
else {
for (i = 0; i< PARTITION_PER_CLUSTER + 2; i++) {
int p = t->partition_num;
assert(PVB[p].victim_partition_flag == 1);
int count = 0;
if (PVB[p].blocknum == 1) {
int block = PVB[p].block[0];
int start_off = PVB[p].startPPN % 128;
int end_off = PVB[p].endPPN % 128;
for (j = start_off; j <= end_off; j++) {
if (PB[block].valid[j] == 1) {
count++;
}
}
assert(count == PVB[p].valid);
}
else {
int block = PVB[p].block[0];
int start_off = PVB[p].startPPN % 128;
int end_off = PVB[p].endPPN % 128;
for (j = start_off; j < 128; j++) {
if (PB[block].valid[j] == 1) {
count++;
}
}
//end
int block_num = PVB[p].blocknum;
block = PVB[p].block[block_num - 1];
for (j = 0; j <= end_off; j++) {
if (PB[block].valid[j] == 1) {
count++;
}
}
// middle
block_num = PVB[p].blocknum;
int k;
for (k = 1; k < block_num - 1; k++) {
int block = PVB[p].block[k];
for (j = 0; j <= end_off; j++) {
if (PB[block].valid[j] == 1) {
count++;
}
}
}
assert(count == PVB[p].valid);
}
assert(PVB[t->partition_num].victim_partition_flag == 1);
t = t->next;
}
}
}
}
void cluster_remove_check(int cluster, int valid) {
if (valid < PAGE_PER_CLUSTER) {
_cluster *temp = victim_cluster_pool[valid];
if (victim_cluster_pool[valid] != NULL) {
while (temp->next->cluster_num != victim_cluster_pool[valid]->cluster_num) {
assert(temp->cluster_num != cluster);
temp = temp->next;
}
}
}
}
void victim_cluster_pool_cluster(int cluster) {
int victim = CLUSTER[cluster].victim_valid;
int count = 0;
if (victim < PAGE_PER_CLUSTER) {
_cluster *temp = victim_cluster_pool[victim];
if (victim_cluster_pool[victim] != NULL) {
if (temp->next->cluster_num == victim_cluster_pool[victim]->cluster_num) {
count = 1;
}
else {
count = 1;
while (temp->next->cluster_num != victim_cluster_pool[victim]->cluster_num) {
count++;
assert(CLUSTER[temp->cluster_num].victim_valid == victim);
temp = temp->next;
}
}
}
// check the victim_cluster_pool_num and number of real member in victim_cluster_pool
assert(count == victim_cluster_pool_num[victim]);
}
}
void error_total_cluster() {
int i;
int j;
int flag = 1;
for (j = 0; j < NUMBER_CLUSTER; j++) {
int vic = CLUSTER[j].victim_valid;
if (vic < PAGE_PER_CLUSTER && victim_cluster_pool[vic]!=NULL) {
_cluster *temp = victim_cluster_pool[vic]->next;
while (temp->cluster_num != victim_cluster_pool[vic]->cluster_num) {
if (j == temp->cluster_num) {
flag = 0;
break;
}
temp = temp->next;
}
if (j == victim_cluster_pool[vic]->cluster_num) {
flag = 0;
}
assert(flag == 0);
}
flag = 1;
}
}
void check_PVB(int cluster) {
if (CLUSTER[cluster].victim_partition_list != NULL) {
_partition *t = CLUSTER[cluster].victim_partition_list;
int victim_valid_count = 0;
int i;
for (i = 0; i<CLUSTER[cluster].victim_partition_num; i++) {
assert(PVB[t->partition_num].victim_partition_list->next->partition_num == t->next->partition_num);
assert(PVB[t->partition_num].victim_partition_list->prev->partition_num == t->prev->partition_num);
t = t->next;
}
}
}
void SIT_debug() {
int i;
int j;
for (i = 0; i < NUMBER_STREAM; i++) {
for (j = 0; j < NUMBER_STREAM; j++) {
if (j != i && SIT[i].recentPartition !=-1 && SIT[j].recentPartition != -1) {
assert(SIT[i].recentPartition != SIT[j].recentPartition);
}
}
}
}
void check_free_partition_pool() {
}
void COUNT_write(int write) {
assert(COUNT.write != write);
}
#endif