-
Notifications
You must be signed in to change notification settings - Fork 0
/
proc.c
executable file
·832 lines (656 loc) · 26 KB
/
proc.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
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
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
/**
* Author: Brandon Sleater
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "types.h"
#include "mem_man.c"
#include "proc.h"
#include <time.h>
#include "sys_time.c"
#define MAX_PROCS 100
static u16 high_head;
static u16 high_tail;
static u16 med_head;
static u16 med_tail;
static u16 low_head;
static u16 low_tail;
static u16 blocked_list;
static u16 PROC_POINT = 0;
FILE *outFile;
typedef struct
{
u64 _t; // time to which process is allowed to run
u32 *_code_addr;
u32 *_code_time;
u32 *_data_addr;
u32 *_data_time;
} run_time;
struct
{
u64 _start_time;
u32 _run_time;
u32 _code_size;
u32 _data_size;
u32 _priority;
} proc_init[100] =
{
{ 10ul, 5100000, 20000000, 30000000, 1 },
{ 10000000001ul, 6200000, 40000000, 20000000, 2 },
{ 10000000200ul, 7300000, 60000000, 10000000, 3 },
{ 80000000013ul, 8400000, 80000000, 90000000, 1 },
{ 80000000014ul, 9500000, 10000000, 80000000, 2 },
{ 80000000015ul, 5600000, 20000000, 70000000, 3 },
{ 200000000016ul, 6700000, 30000000, 60000000, 1 },
{ 200000000107ul, 7800000, 40000000, 50000000, 2 },
{ 200000000801ul, 8900000, 50000000, 40000000, 3 },
{ 200000009001ul, 9600000, 60000000, 30000000, 1 },
{ 800000000000ul, 5500000, 70000000, 20000000, 2 },
{ 800000000001ul, 6400000, 80000000, 10000000, 3 },
{ 800000000002ul, 7300000, 90000000, 50000000, 1 },
{ 800000000003ul, 8200000, 10000000, 40000000, 2 },
{ 800000000004ul, 9000000, 20000000, 30000000, 3 },
{ 1200000000025ul, 5400000, 30000000, 20000000, 1 },
{ 1200000000026ul, 6000000, 40000000, 10000000, 2 },
{ 1200000000027ul, 7666660, 50000000, 60000000, 3 },
{ 1200000000028ul, 8400000, 60000000, 30000000, 1 },
{ 1200000000029ul, 9200000, 70000000, 10000000, 2 },
{ 1200000000010ul, 5000000, 20000000, 30000000, 1 },
{ 2000000000011ul, 6100000, 40000000, 20000000, 2 },
{ 2000000000102ul, 7200000, 60000000, 10000000, 3 },
{ 2000000000301ul, 8300000, 80000000, 90000000, 1 },
{ 2000000000401ul, 9400000, 10000000, 80000000, 2 },
{ 2000000050001ul, 5500000, 20000000, 70000000, 3 },
{ 2000000060001ul, 6600000, 30000000, 60000000, 1 },
{ 2000000070001ul, 7700000, 40000000, 50000000, 2 },
{ 3000000000018ul, 8800000, 50000000, 40000000, 3 },
{ 3000000000019ul, 9900000, 60000000, 30000000, 1 },
{ 3000000000020ul, 5000000, 70000000, 20000000, 2 },
{ 3000000000021ul, 6900000, 80000000, 10000000, 3 },
{ 3000000000022ul, 7800000, 90000000, 50000000, 1 },
{ 3000000000023ul, 8700000, 10000000, 40000000, 2 },
{ 3000000000024ul, 9600000, 20000000, 30000000, 3 },
{ 3000000000025ul, 5500000, 30000000, 20000000, 1 },
{ 5000000001026ul, 6400000, 40000000, 10000000, 2 },
{ 5000000002027ul, 7300000, 50000000, 60000000, 3 },
{ 5000000003028ul, 8200000, 60000000, 30000000, 1 },
{ 5000000004029ul, 9100000, 70000000, 10000000, 2 },
{ 5000000005010ul, 5000000, 20000000, 30000000, 1 },
{ 5000000006011ul, 6600000, 40000000, 20000000, 2 },
{ 5000000007012ul, 7500000, 60000000, 10000000, 3 },
{ 5000000008013ul, 8400000, 80000000, 90000000, 1 },
{ 5000000009014ul, 9300000, 10000000, 80000000, 2 },
{ 7000000000005ul, 5200000, 20000000, 70000000, 3 },
{ 7000000000016ul, 6100000, 30000000, 60000000, 1 },
{ 7000000000118ul, 8000000, 50000000, 40000000, 3 },
{ 7000000001019ul, 9600000, 60000000, 30000000, 1 },
{ 7000000010020ul, 5500000, 70000000, 20000000, 2 },
{ 7000000020021ul, 6400000, 80000000, 10000000, 3 },
{ 7000000030022ul, 7300000, 90000000, 50000000, 1 },
{ 7000000040023ul, 8200000, 10000000, 40000000, 2 },
{ 7000000050017ul, 7100000, 40000000, 50000000, 2 },
{ 7000000060024ul, 9000000, 20000000, 30000000, 3 },
{ 9000000000025ul, 5600000, 30000000, 20000000, 1 },
{ 9000000000026ul, 6500000, 40000000, 10000000, 2 },
{ 9000000000027ul, 7400000, 50000000, 60000000, 3 },
{ 9000000000028ul, 8300000, 60000000, 30000000, 1 },
{ 9000000000029ul, 9200000, 70000000, 10000000, 2 },
{ 9000000000110ul, 5100000, 20000000, 30000000, 1 },
{ 9000000000111ul, 6000000, 40000000, 20000000, 2 },
{ 9000000000112ul, 7600000, 60000000, 10000000, 3 },
{ 9000000000113ul, 8500000, 80000000, 90000000, 1 },
{ 9000000000114ul, 9400000, 10000000, 80000000, 2 },
{ 9000000000115ul, 5300000, 20000000, 70000000, 3 },
{ 11000000001016ul, 6200000, 30000000, 60000000, 1 },
{ 11000000002017ul, 7100000, 40000000, 50000000, 2 },
{ 11000000003018ul, 8000000, 50000000, 40000000, 3 },
{ 11000000010019ul, 9300000, 60000000, 30000000, 1 },
{ 11000000020020ul, 5000000, 70000000, 20000000, 2 },
{ 11000000030021ul, 6600000, 80000000, 10000000, 3 },
{ 11000000040022ul, 7200000, 90000000, 50000000, 1 },
{ 11000000050023ul, 8400000, 10000000, 40000000, 2 },
{ 11000000060024ul, 9100000, 20000000, 30000000, 3 },
{ 11000000070025ul, 5000000, 30000000, 20000000, 1 },
{ 11000000080026ul, 6000000, 40000000, 10000000, 2 },
{ 11000000090027ul, 7000000, 50000000, 60000000, 3 },
{ 14000000003028ul, 8000000, 60000000, 30000000, 1 },
{ 14000000004029ul, 9900000, 70000000, 10000000, 2 },
{ 14000000005010ul, 5800000, 20000000, 30000000, 1 },
{ 14000000006011ul, 6600000, 40000000, 20000000, 2 },
{ 14000000010012ul, 7300000, 60000000, 10000000, 3 },
{ 14000000020013ul, 8000000, 80000000, 90000000, 1 },
{ 14000000030014ul, 9000000, 10000000, 80000000, 2 },
{ 14000000040015ul, 5000000, 20000000, 70000000, 3 },
{ 14000000050016ul, 6000000, 30000000, 60000000, 1 },
{ 14000000060017ul, 7600000, 40000000, 50000000, 2 },
{ 14000000070018ul, 8300000, 50000000, 40000000, 3 },
{ 14000000080019ul, 9300000, 60000000, 30000000, 1 },
{ 14000000090020ul, 5600000, 70000000, 20000000, 2 },
{ 15000000010021ul, 6300000, 80000000, 10000000, 3 },
{ 15000000020022ul, 7000000, 90000000, 50000000, 1 },
{ 15000000030023ul, 8000000, 10000000, 40000000, 2 },
{ 15000000040024ul, 9000000, 20000000, 30000000, 3 },
{ 15000000050025ul, 5100000, 30000000, 20000000, 1 },
{ 15000000060026ul, 6300000, 40000000, 10000000, 2 },
{ 15000000070027ul, 7500000, 50000000, 60000000, 3 },
{ 15000000080028ul, 8300000, 60000000, 30000000, 1 },
{ 15000000090029ul, 9400000, 70000000, 10000000, 2 }
};
void checkBlockList() {
u16 temp = blocked_list;
while (temp) {
if (temp = mem[temp]._proc._next) {
printf("CHECK: temp:\t%llu\n", temp);
printf("CHECK: mem[temp]._proc._arrid:\t%llu\n", mem[temp]._proc._arrid);
int x = 1 / 0;
}
temp = mem[temp]._proc._next;
}
printf("\n");
}
u32 new_code_addr( u32 addr, u32 limit )
{
static u32 x[32] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 8, 16
};
u32 r = rand( );
addr = ( r & 64 ) ? addr + x[r & 31] : addr - x[r & 31];
return ( addr > limit ) ? addr = r % limit : addr;
}
u64 new_code_time( )
{
return 50 + ( rand( ) & 0xfff );
}
u32 new_data_addr( u32 addr, u32 base, u32 limit )
{
static u32 x[32] = { 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4,
5, 5, 6, 6, 7, 7, 8, 8, 9, 10, 11, 12, 16, 20, 28, 40
};
u32 r = rand( );
addr = ( r & 64 ) ? addr + x[r & 31] : addr - x[r & 31];
return ( ( base < addr ) || ( addr > limit ) ) ?
addr = base + ( r % ( limit - base ) ) : addr;
}
u64 new_data_time( )
{
return 100 + ( rand( ) & 0x1fff );
}
/**
Build and configure a new process
*/
u16 new_proc( u64 start_time, u32 run_time, u32 code_size, u32 data_size, u32 priority )
{
// If the current time is less than the processes start time, don't make it
if ( get_time() < start_time )
{
return 0;
}
// Figure out how many blocks it needs
u64 size = code_size + data_size;
u16 blocks = size >> 22;
if ( size & ( ( 1 << 22 ) - 1 ) )
{
blocks++;
}
// A page for the process to live in
u16 proc_page = page_alloc( 1 );
printf("NEW PROC: proc_page:\t%llu\n", proc_page);
// Allocate space with disk chunks
if ( vas_alloc( mem[proc_page]._proc._sbt, blocks ) )
{
}
else
{
// There wasn't enough space, free up the pages and exit
page_free( proc_page );
return 0;
}
// A page for the l1
u16 l1_page = page_alloc( 1 );
printf("NEW PROC: l1_page:\t%llu\n", l1_page);
// Setup the page time
mem[proc_page]._proc._pid = start_time;
// Actual start time
mem[proc_page]._proc._curtm = get_time( );
// Set id
mem[proc_page]._proc._arrid = PROC_POINT;
// Setup page table index (l1)
mem[proc_page]._proc._pti = l1_page;
// Set size of vas blocks
mem[proc_page]._proc._vas = blocks;
// Setup code size
mem[proc_page]._proc._cs = code_size;
// Setup data size
mem[proc_page]._proc._ds = data_size;
// Setup net time
mem[proc_page]._proc._nt = run_time;
// Original net time
mem[proc_page]._proc._ntf = run_time;
// Set page fault count
mem[proc_page]._proc._fault = 0;
// Setup proc priority
mem[proc_page]._proc._priority = priority;
// Set the mem_man properties for the process page
mem_man[proc_page]._pinned = 1;
mem_man[proc_page]._l1i = l1_page;
// Set the mem_man properties for the l1 page
mem_man[l1_page]._proc = proc_page;
mem_man[l1_page]._pinned = 1;
return proc_page;
}
/**
Execute a process
*/
void process_exec ( u16 index, u64 t )
{
printf("PROC EXEC: index:\t%llu\n", index);
// If processes run time is complete, print out its stats and delete it
if ( mem[index]._proc._nt <= 0
|| mem[index]._proc._nt > mem[index]._proc._ntf )
{
u64 complete = get_time( );
fprintf( outFile, "Process ID: %d \t Expected Start Time: %llu \t\t Actual Start Time: %llu \t\t Completed at: %llu \t\t Should have ran for: %llu \t Page Faults: %i\n",
mem[index]._proc._arrid, mem[index]._proc._pid, mem[index]._proc._curtm, complete, mem[index]._proc._ntf, mem[index]._proc._fault );
delete_proc( index );
return;
}
u32 code_trans = virt_to_phys( mem[index]._proc._ca, index, 0 ); // 0 is read
u32 data_trans = virt_to_phys( mem[index]._proc._da, index, 0 );
// Page fault
if ( !code_trans
&& mem[index]._proc._ca )
{
// Increment page fault count
mem[index]._proc._fault++;
blocked_enq( index );
checkBlockList();
return;
}
// Page fault
if ( !data_trans
&& mem[index]._proc._da )
{
// Increment page fault count
mem[index]._proc._fault++;
blocked_enq( index );
checkBlockList();
return;
}
while ( 1 )
{
u32 t_t_t = t - get_time( ); //time_till_timer
// If code time is less than data time
if ( mem[index]._proc._ct < mem[index]._proc._dt )
{
if ( mem[index]._proc._ct > t_t_t )
{
mem[index]._proc._nt -= t_t_t;
mem[index]._proc._ct -= t_t_t;
mem[index]._proc._dt -= t_t_t;
ready_enq( index );
return;
}
set_time( get_time( ) + mem[index]._proc._ct );
mem[index]._proc._nt -= mem[index]._proc._ct;
mem[index]._proc._dt -= mem[index]._proc._ct;
mem[index]._proc._ca = new_code_addr( mem[index]._proc._ca, mem[index]._proc._cs );
mem[index]._proc._ct = new_code_time( );
code_trans = virt_to_phys( mem[index]._proc._ca, index, 0 );
if ( !code_trans )
{
// Increment page fault count
mem[index]._proc._fault++;
blocked_enq( index );
checkBlockList();
return;
}
}
else if ( mem[index]._proc._dt > t_t_t )
{
mem[index]._proc._nt -= t_t_t;
mem[index]._proc._ct -= t_t_t;
mem[index]._proc._dt -= t_t_t;
ready_enq( index );
return;
}
else
{
set_time( get_time( ) + mem[index]._proc._dt );
mem[index]._proc._nt -= mem[index]._proc._dt;
mem[index]._proc._ct -= mem[index]._proc._dt;
mem[index]._proc._da = new_data_addr( mem[index]._proc._da, mem[index]._proc._cs, mem[index]._proc._ds );
mem[index]._proc._dt = new_data_time( );
data_trans = virt_to_phys( mem[index]._proc._da, index, 1 ); // Write
if ( !data_trans )
{
// Increment page fault count
mem[index]._proc._fault++;
blocked_enq( index );
checkBlockList();
return;
}
}
}
}
/**
Set the queues to 0 at beginning of program
*/
void initialize_queues( )
{
blocked_list = 0;
high_head = 0;
high_tail = 0;
med_head = 0;
med_tail = 0;
low_head = 0;
low_tail = 0;
}
/**
Putting a process on the blocked list
*/
void blocked_enq( u16 index )
{
printf("mem[index]._proc._next:\t%llu\n", mem[index]._proc._next);
// Temporary pointer to head of blocked list
u16 temp = blocked_list;
// Situation 1: The blocked list is empty
if ( !blocked_list )
{
// Set head to the new process
blocked_list = index;
}
else if ( mem[index]._proc._time < mem[blocked_list]._proc._time )
{
// Add new process to head of the list
mem[index]._proc._next = blocked_list;
blocked_list = index;
}
else
{
// Trying to find where to place the process
while ( mem[temp]._proc._next
&& mem[index]._proc._time > mem[mem[temp]._proc._next]._proc._time )
{
temp = mem[temp]._proc._next;
}
u16 tempnext = mem[temp]._proc._next;
// Then set the temps "next" to point to the new process
mem[temp]._proc._next = index;
// Set the new processes "next" to the temps "next"
mem[index]._proc._next = tempnext;
}
}
/**
Take process off the blocked list
*/
void blocked_deq( )
{
// Get current time
u64 CURR_TIME = get_time( );
// Start at the head of the list
u16 curr_head = blocked_list;
// No other process to point to
if ( curr_head
&& !mem[curr_head]._proc._next
&& mem[curr_head]._proc._time <= CURR_TIME)
{
ready_enq( curr_head );
curr_head = 0;
}
else
{
while ( curr_head
&& mem[curr_head]._proc._next
&& mem[curr_head]._proc._time <= CURR_TIME )
{
u16 next = mem[curr_head]._proc._next;
mem[curr_head]._proc._next = 0;
ready_enq( curr_head );
// Move to the next item
curr_head = next;
}
}
blocked_list = curr_head;
}
/**
Put the process on the ready queue
*/
void ready_enq( u16 index )
{
mem[index]._proc._next = 0;
// Determine its priority
switch ( mem[index]._proc._priority )
{
// High Priority
case 1 :
if ( high_tail )
{
mem[high_tail]._proc._next = index;
}
high_tail = index;
if ( !high_head )
{
high_head = high_tail;
}
break;
// Medium Priority
case 2 :
if ( med_tail )
{
mem[med_tail]._proc._next = index;
}
med_tail = index;
if ( !med_head )
{
med_head = med_tail;
}
break;
// Low Priority
case 3 :
if ( low_tail )
{
mem[low_tail]._proc._next = index;
}
low_tail = index;
if ( !low_head )
{
low_head = low_tail;
}
break;
}
}
/**
Take process off the ready queue
*/
u16 ready_deq( u16 priority )
{
u16 temp_proc;
switch ( priority )
{
// High Priority
case 1:
temp_proc = high_head;
mem[temp_proc]._proc._next = 0;
high_head = mem[temp_proc]._proc._next;
// Process to be ran
return temp_proc;
break;
// Medium Priority
case 2:
temp_proc = med_head;
mem[temp_proc]._proc._next = 0;
med_head = mem[temp_proc]._proc._next;
return temp_proc;
break;
// Low Priority
case 3:
temp_proc = low_head;
mem[temp_proc]._proc._next = 0;
low_head = mem[temp_proc]._proc._next;
return temp_proc;
break;
}
}
void printBlockedList() {
u16 temp = blocked_list;
printf("head of list = %llu\n", mem[temp]._proc._time);
while (temp) {
temp = mem[temp]._proc._next;
printf("next in list = %i\t%llu\n", temp, mem[temp]._proc._time);
}
printf("\n");
}
/**
Runs it all
*/
void scheduler( )
{
u16 temp_proc;
// While we have stuff on the queues or list
while ( blocked_list
|| high_head
|| med_head
|| low_head )
{
if ( blocked_list
&& !high_head
&& !med_head
&& !low_head )
{
printf("******************\n");
printf("CURRENT_TIME:\t%llu\n", get_time());
printf("SET_TIME TO: mem[blocked_list]._proc._time:\t%llu\n", mem[blocked_list]._proc._time);
printf("******************\n");
set_time( mem[blocked_list]._proc._time );
printf("before deq\n");
printf("mem[blocked_list]._proc._arrid:\t%i\n", mem[blocked_list]._proc._arrid);
printf("mem[mem[blocked_list]._proc._next]._proc._arrid:\t%i\n", mem[mem[blocked_list]._proc._next]._proc._arrid);
printf("mem[mem[mem[blocked_list]._proc._next]._proc._next]._proc._arrid:\t%i\n", mem[mem[mem[blocked_list]._proc._next]._proc._next]._proc._arrid);
printf("get_time():\t%llu\n", get_time());
blocked_deq( );
printf("after deq\n");
}
// High priority
u8 count = 0;
while ( high_head
&& count < 4 )
{
printf("RUNNING HIGH\n");
temp_proc = ready_deq( 1 );
printf("mem[temp_proc]._proc._next:\t%llu\n", mem[temp_proc]._proc._next);
if ( mem[temp_proc]._proc._next ) {
int x = 1 / 0;
}
printf("starting execute process with: %i\n", temp_proc);
process_exec( temp_proc, get_time( ) + 2500 );
printf("starting blocked in high\n");
blocked_deq( );
printf("done with blocked in high\n");
count++;
}
// Med priority
count = 0;
while ( med_head
&& count < 2 )
{
printf("RUNNING MED\n");
temp_proc = ready_deq( 2 );
process_exec( temp_proc, get_time( ) + 2500 );
blocked_deq( );
count++;
}
// Low priority
count = 0;
while ( low_head
&& count < 1 )
{
printf("RUNNING LOW\n");
temp_proc = ready_deq( 3 );
process_exec( temp_proc, get_time( ) + 2500 );
blocked_deq( );
count++;
}
// Try to make other processes with currents
u16 result = 1;
while ( result && PROC_POINT < MAX_PROCS )
{
printf("IN WHILE - get_time():\t%llu\n", get_time());
printf("proc_init[PROC_POINT]._start_time:\t%llu\n", proc_init[PROC_POINT]._start_time);
result = new_proc( proc_init[PROC_POINT]._start_time, proc_init[PROC_POINT]._run_time, proc_init[PROC_POINT]._code_size, proc_init[PROC_POINT]._data_size, proc_init[PROC_POINT]._priority );
printf("result:\t%llu\n", result);
//printf("get_time():\t%llu\n", get_time());
//printf("proc_init[PROC_POINT]._start_time:\t%llu\n\n\n", proc_init[PROC_POINT]._start_time);
// Proc is ready to start, we got something back, put it on the queue
if ( result )
{
printf("----------------------------------------------\n");
printf("WHILE - New Process Index #:\t%i\n", PROC_POINT);
printf("proc_init[PROC_POINT]._start_time:\t%llu\n", proc_init[PROC_POINT]._start_time);
printf("----------------------------------------------\n");
PROC_POINT++;
ready_enq( result );
}
}
// Nothing on queues and list but we haven't ran all the processes
if ( PROC_POINT < MAX_PROCS
&& !blocked_list
&& !high_head
&& !med_head
&& !low_head )
{
printf("----------------------------------------------\n");
printf("CURRENT TIME BEFORE SET:\t%llu\n", get_time());
set_time( proc_init[PROC_POINT]._start_time );
temp_proc = new_proc( proc_init[PROC_POINT]._start_time, proc_init[PROC_POINT]._run_time, proc_init[PROC_POINT]._code_size, proc_init[PROC_POINT]._data_size, proc_init[PROC_POINT]._priority );
printf("IF - New Process Index #:\t%i\n", PROC_POINT);
printf("NEW PROCESSES START TIME:\t%llu\n", proc_init[PROC_POINT]._start_time);
printf("CURRENT TIME AFTER SET:\t\t%llu\n", get_time());
printf("----------------------------------------------\n\n\n");
PROC_POINT++;
printf("high_head:\t%i\n", high_head);
printf("med_head:\t%i\n", med_head);
printf("low_head:\t%i\n", low_head);
printf("mem[high_head]._proc._next:\t%i\n", mem[high_head]._proc._next);
printf("mem[med_head]._proc._next:\t%i\n", mem[med_head]._proc._next);
printf("mem[low_head]._proc._next:\t%i\n", mem[low_head]._proc._next);
ready_enq( temp_proc );
printf("high_head:\t%i\n", high_head);
printf("med_head:\t%i\n", med_head);
printf("low_head:\t%i\n", low_head);
printf("mem[high_head]._proc._next:\t%i\n", mem[high_head]._proc._next);
printf("mem[med_head]._proc._next:\t%i\n", mem[med_head]._proc._next);
printf("mem[low_head]._proc._next:\t%i\n", mem[low_head]._proc._next);
}
}
printf("FINISHED EXECUTING\n");
}
/**
Start and intialize it all
*/
int main( )
{
u32 i;
// Seed the random generator for unique non-repeating numbers
//srand( time( NULL ) );
// Setup the file we write our data too
outFile = fopen( "output.txt", "w" );
// Setup our queues
initialize_queues( );
// Setup the pages
for ( i = 1; i < PAGE_COUNT; i++ )
{
page_free(i);
}
// Jump to the first processes time
set_time( proc_init[PROC_POINT]._start_time );
// Create the processes
u16 proc1 = new_proc( proc_init[PROC_POINT]._start_time, proc_init[PROC_POINT]._run_time, proc_init[PROC_POINT]._code_size, proc_init[PROC_POINT]._data_size, proc_init[PROC_POINT]._priority );
printf("MAIN - New Process Index #:\t%i\n\n", PROC_POINT);
// Increment our pointer
PROC_POINT++;
// Put the new process on the queue
ready_enq( proc1 );
// Start it up
scheduler( );
}