-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathass1.patch
More file actions
2525 lines (2389 loc) · 52.8 KB
/
ass1.patch
File metadata and controls
2525 lines (2389 loc) · 52.8 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
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
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/Makefile b/Makefile
index 09d790c..dd5da0e 100644
--- a/Makefile
+++ b/Makefile
@@ -181,6 +181,11 @@ UPROGS=\
_usertests\
_wc\
_zombie\
+ _helloworld\
+ _memsizetest\
+ _checkPartC\
+ _policy\
+ _sanity\
fs.img: mkfs README $(UPROGS)
./mkfs fs.img README $(UPROGS)
@@ -250,6 +255,7 @@ qemu-nox-gdb: fs.img xv6.img .gdbinit
EXTRA=\
mkfs.c ulib.c user.h cat.c echo.c forktest.c grep.c kill.c\
ln.c ls.c mkdir.c rm.c stressfs.c usertests.c wc.c zombie.c\
+ helloworld.c memsizetest.c checkPartC.c policy.c sanity.c\
printf.c umalloc.c\
README dot-bochsrc *.pl toc.* runoff runoff1 runoff.list\
.gdbinit.tmpl gdbutil\
diff --git a/cat.c b/cat.c
index 5ddc820..e74de1a 100644
--- a/cat.c
+++ b/cat.c
@@ -12,12 +12,12 @@ cat(int fd)
while((n = read(fd, buf, sizeof(buf))) > 0) {
if (write(1, buf, n) != n) {
printf(1, "cat: write error\n");
- exit();
+ exit(1);
}
}
if(n < 0){
printf(1, "cat: read error\n");
- exit();
+ exit(1);
}
}
@@ -28,16 +28,16 @@ main(int argc, char *argv[])
if(argc <= 1){
cat(0);
- exit();
+ exit(0);
}
for(i = 1; i < argc; i++){
if((fd = open(argv[i], 0)) < 0){
printf(1, "cat: cannot open %s\n", argv[i]);
- exit();
+ exit(1);
}
cat(fd);
close(fd);
}
- exit();
+ exit(0);
}
diff --git a/checkPartC.c b/checkPartC.c
new file mode 100644
index 0000000..fbd9567
--- /dev/null
+++ b/checkPartC.c
@@ -0,0 +1,29 @@
+#include "types.h"
+#include "stat.h"
+#include "user.h"
+
+int main(){
+ int pid;
+ printf(1, "Brachol & Nitz ###TEST### for PART3\n");
+ pid = fork();
+ if(pid < 0)
+ printf(1, "ERROR forking ERROR\n");
+ if(pid == 0)
+ {
+ char *str;
+ printf(1, "HOLA IM A KID\n");
+ memsize();
+ str = (char *) malloc(2048);
+ memsize();
+ free(str);
+ printf(1, "ADIOS IM A KID\n");
+ exit(666);
+
+ }
+ int status;
+ wait(&status);
+ printf(1, "HOLA IM A FATHER\n");
+ memsize();
+ printf(1, "the status is: %d", status);
+ exit(0);
+ }
\ No newline at end of file
diff --git a/defs.h b/defs.h
index 82fb982..721c873 100644
--- a/defs.h
+++ b/defs.h
@@ -10,6 +10,13 @@ struct sleeplock;
struct stat;
struct superblock;
+struct perf {
+int ps_priority;
+int stime;
+int retime;
+int rtime;
+}perf;
+
// bio.c
void binit(void);
struct buf* bread(uint, uint);
@@ -104,7 +111,7 @@ int pipewrite(struct pipe*, char*, int);
//PAGEBREAK: 16
// proc.c
int cpuid(void);
-void exit(void);
+void exit(int);
int fork(void);
int growproc(int);
int kill(int);
@@ -117,9 +124,15 @@ void sched(void);
void setproc(struct proc*);
void sleep(void*, struct spinlock*);
void userinit(void);
-int wait(void);
+int wait(int*);
void wakeup(void*);
void yield(void);
+void memsize(void);
+int set_ps_priority(int);
+int policy(int);
+int set_cfs_priority(int);
+void update_statistics(void);
+int proc_info(struct perf*);
// swtch.S
void swtch(struct context**, struct context*);
@@ -188,3 +201,4 @@ void clearpteu(pde_t *pgdir, char *uva);
// number of elements in fixed-size array
#define NELEM(x) (sizeof(x)/sizeof((x)[0]))
+int sched_type;
\ No newline at end of file
diff --git a/echo.c b/echo.c
index 806dee0..eed68a0 100644
--- a/echo.c
+++ b/echo.c
@@ -9,5 +9,5 @@ main(int argc, char *argv[])
for(i = 1; i < argc; i++)
printf(1, "%s%s", argv[i], i+1 < argc ? " " : "\n");
- exit();
+ exit(0);
}
diff --git a/forktest.c b/forktest.c
index 8bc984d..164d963 100644
--- a/forktest.c
+++ b/forktest.c
@@ -25,24 +25,24 @@ forktest(void)
if(pid < 0)
break;
if(pid == 0)
- exit();
+ exit(0);
}
if(n == N){
printf(1, "fork claimed to work N times!\n", N);
- exit();
+ exit(0);
}
for(; n > 0; n--){
- if(wait() < 0){
+ if(wait(null) < 0){
printf(1, "wait stopped early\n");
- exit();
+ exit(1);
}
}
- if(wait() != -1){
+ if(wait(null) != -1){
printf(1, "wait got too many\n");
- exit();
+ exit(1);
}
printf(1, "fork test OK\n");
@@ -52,5 +52,5 @@ int
main(void)
{
forktest();
- exit();
+ exit(0);
}
diff --git a/grep.c b/grep.c
index adc4835..d354f2a 100644
--- a/grep.c
+++ b/grep.c
@@ -43,24 +43,24 @@ main(int argc, char *argv[])
if(argc <= 1){
printf(2, "usage: grep pattern [file ...]\n");
- exit();
+ exit(1);
}
pattern = argv[1];
if(argc <= 2){
grep(pattern, 0);
- exit();
+ exit(0);
}
for(i = 2; i < argc; i++){
if((fd = open(argv[i], 0)) < 0){
printf(1, "grep: cannot open %s\n", argv[i]);
- exit();
+ exit(1);
}
grep(pattern, fd);
close(fd);
}
- exit();
+ exit(0);
}
// Regexp matcher from Kernighan & Pike,
diff --git a/helloworld.c b/helloworld.c
new file mode 100755
index 0000000..9eb8004
--- /dev/null
+++ b/helloworld.c
@@ -0,0 +1,8 @@
+#include "types.h"
+#include "stat.h"
+#include "user.h"
+
+int main(){
+ printf(1, "Hello World XV6\n");
+ exit(0);
+ }
\ No newline at end of file
diff --git a/init.c b/init.c
index 046b551..7c93422 100644
--- a/init.c
+++ b/init.c
@@ -24,14 +24,14 @@ main(void)
pid = fork();
if(pid < 0){
printf(1, "init: fork failed\n");
- exit();
+ exit(1);
}
if(pid == 0){
exec("sh", argv);
printf(1, "init: exec sh failed\n");
- exit();
+ exit(1);
}
- while((wpid=wait()) >= 0 && wpid != pid)
+ while((wpid=wait(null)) >= 0 && wpid != pid)
printf(1, "zombie!\n");
}
}
diff --git a/kill.c b/kill.c
index 364f6af..875916c 100644
--- a/kill.c
+++ b/kill.c
@@ -9,9 +9,9 @@ main(int argc, char **argv)
if(argc < 2){
printf(2, "usage: kill pid...\n");
- exit();
+ exit(1);
}
for(i=1; i<argc; i++)
kill(atoi(argv[i]));
- exit();
+ exit(0);
}
diff --git a/ln.c b/ln.c
index cf8a64e..fb17c3b 100644
--- a/ln.c
+++ b/ln.c
@@ -7,9 +7,9 @@ main(int argc, char *argv[])
{
if(argc != 3){
printf(2, "Usage: ln old new\n");
- exit();
+ exit(1);
}
if(link(argv[1], argv[2]) < 0)
printf(2, "link %s %s: failed\n", argv[1], argv[2]);
- exit();
+ exit(0);
}
diff --git a/ls.c b/ls.c
index 2862913..27742c2 100644
--- a/ls.c
+++ b/ls.c
@@ -77,9 +77,9 @@ main(int argc, char *argv[])
if(argc < 2){
ls(".");
- exit();
+ exit(0);
}
for(i=1; i<argc; i++)
ls(argv[i]);
- exit();
+ exit(0);
}
diff --git a/memsizetest.c b/memsizetest.c
new file mode 100644
index 0000000..eb12a55
--- /dev/null
+++ b/memsizetest.c
@@ -0,0 +1,17 @@
+#include "types.h"
+#include "stat.h"
+#include "user.h"
+
+
+int main(){
+ memsize();
+ char *str;
+
+ printf(1, "Allocating more memory\n");
+ str = (char *) malloc(2048);
+ memsize();
+ printf(1, "Freeing memory\n");
+ free(str);
+ memsize();
+ exit(0);
+ }
\ No newline at end of file
diff --git a/mkdir.c b/mkdir.c
index 6e4c954..2d90781 100644
--- a/mkdir.c
+++ b/mkdir.c
@@ -9,7 +9,7 @@ main(int argc, char *argv[])
if(argc < 2){
printf(2, "Usage: mkdir files...\n");
- exit();
+ exit(1);
}
for(i = 1; i < argc; i++){
@@ -19,5 +19,5 @@ main(int argc, char *argv[])
}
}
- exit();
+ exit(0);
}
diff --git a/policy.c b/policy.c
new file mode 100644
index 0000000..9d705a1
--- /dev/null
+++ b/policy.c
@@ -0,0 +1,23 @@
+#include "types.h"
+#include "stat.h"
+#include "user.h"
+
+ int main (int argc, char *argv[]) {
+ const char *num_to_names[3];
+ num_to_names[0] = "Default";
+ num_to_names[1] = "Priority";
+ num_to_names[2] = "CFS";
+ if(argc!=2)
+ printf(1, "Please provide input\n");
+ else
+ {
+ int num;
+ num = atoi(argv[1]);
+ if(policy(num)==0)
+ printf(1, "Policy has been successfully changed to - %s Policy\n", num_to_names[num]);
+ else
+ printf(1, "Error replacing policy, no such a policy number (%d)\n", num);
+
+ }
+ exit(0);
+ }
\ No newline at end of file
diff --git a/proc.c b/proc.c
index 806b1b1..4646688 100644
--- a/proc.c
+++ b/proc.c
@@ -6,6 +6,9 @@
#include "x86.h"
#include "proc.h"
#include "spinlock.h"
+#ifndef __LONG_LONG_MAX__
+#define __LONG_LONG_MAX__
+#endif
struct {
struct spinlock lock;
@@ -20,6 +23,54 @@ extern void trapret(void);
static void wakeup1(void *chan);
+
+void
+update_statistics(void){
+ struct proc *p;
+ acquire(&ptable.lock); //DOC: sleeplock1
+ for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
+ switch(p->state)
+ {
+ case RUNNING:
+ p->rtime = p->rtime + 1;
+ break;
+ case SLEEPING:
+ p->stime = p->stime + 1;
+ break;
+ case RUNNABLE:
+ p->retime = p->retime + 1;
+ break;
+ default:
+ break;
+ }
+ }
+ release(&ptable.lock);
+}
+
+int
+get_minimum_accumulator(void)
+{
+ struct proc *p;
+ long long cur_min = 0;
+ int at_least_one = 0;
+ for(p = ptable.proc; p < &ptable.proc[NPROC]; p++)
+ {
+ if(p->state == RUNNABLE || p->state == RUNNING)
+ {
+ if(at_least_one == 0)
+ cur_min = p->accumulator;
+ at_least_one = 1;
+ if(p->accumulator < cur_min)
+ cur_min = p->accumulator;
+ }
+ }
+ return cur_min;
+}
+int calculate_run_time_ratio(struct proc *p)
+{
+ return (p->rtime * p->decay_factor)/(p->rtime + p->stime + p->retime);
+}
+
void
pinit(void)
{
@@ -88,7 +139,13 @@ allocproc(void)
found:
p->state = EMBRYO;
p->pid = nextpid++;
-
+ //priority
+ p->ps_priority = 5;
+ p->decay_factor = 1;
+ p->stime = 0;
+ p->retime = 0;
+ p->rtime = 0;
+ p->accumulator = get_minimum_accumulator();
release(&ptable.lock);
// Allocate kernel stack.
@@ -199,6 +256,7 @@ fork(void)
np->sz = curproc->sz;
np->parent = curproc;
*np->tf = *curproc->tf;
+ np->decay_factor = curproc->decay_factor;
// Clear %eax so that fork returns 0 in the child.
np->tf->eax = 0;
@@ -225,7 +283,7 @@ fork(void)
// An exited process remains in the zombie state
// until its parent calls wait() to find out it exited.
void
-exit(void)
+exit(int exit_status)
{
struct proc *curproc = myproc();
struct proc *p;
@@ -246,6 +304,7 @@ exit(void)
iput(curproc->cwd);
end_op();
curproc->cwd = 0;
+ curproc->exit_status = exit_status;
acquire(&ptable.lock);
@@ -270,7 +329,7 @@ exit(void)
// Wait for a child process to exit and return its pid.
// Return -1 if this process has no children.
int
-wait(void)
+wait(int *exit_status)
{
struct proc *p;
int havekids, pid;
@@ -295,6 +354,8 @@ wait(void)
p->name[0] = 0;
p->killed = 0;
p->state = UNUSED;
+ if (exit_status != null)
+ *exit_status = p->exit_status;
release(&ptable.lock);
return pid;
}
@@ -311,6 +372,26 @@ wait(void)
}
}
+
+void
+scheduler_non_dependency_commands(struct proc *p, struct cpu *c)
+{
+ // Switch to chosen process. It is the process's job
+ // to release ptable.lock and then reacquire it
+ // before jumping back to us.
+ c->proc = p;
+ switchuvm(p);
+ p->state = RUNNING;
+
+ swtch(&(c->scheduler), p->context);
+ switchkvm();
+ p->accumulator = p->accumulator + p->ps_priority;
+ // Process is done running for now.
+ // It should have changed its p->state before coming back.
+ c->proc = 0;
+}
+
+
//PAGEBREAK: 42
// Per-CPU process scheduler.
// Each CPU calls scheduler() after setting itself up.
@@ -325,36 +406,62 @@ scheduler(void)
struct proc *p;
struct cpu *c = mycpu();
c->proc = 0;
-
+ sched_type = 0;
for(;;){
- // Enable interrupts on this processor.
- sti();
-
- // Loop over process table looking for process to run.
- acquire(&ptable.lock);
- for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
- if(p->state != RUNNABLE)
- continue;
-
- // Switch to chosen process. It is the process's job
- // to release ptable.lock and then reacquire it
- // before jumping back to us.
- c->proc = p;
- switchuvm(p);
- p->state = RUNNING;
-
- swtch(&(c->scheduler), p->context);
- switchkvm();
-
- // Process is done running for now.
- // It should have changed its p->state before coming back.
- c->proc = 0;
- }
- release(&ptable.lock);
+ // Enable interrupts on this processor.
+ sti();
+
+
+ // Loop over process table looking for process to run.
+ acquire(&ptable.lock);
+ if(sched_type == 0)
+ {
+ //round robin:
+ for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
+ if(sched_type != 0)
+ break;
+ if(p->state != RUNNABLE)
+ continue;
+ scheduler_non_dependency_commands(p, c);
+ }
+ }
+ else if(sched_type == 1)
+ {
+ long long min_acc =__LONG_LONG_MAX__;
+ for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
+ if(p->accumulator < min_acc && p->state == RUNNABLE)
+ min_acc = p->accumulator;
+ }
+ for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
+ if(p->accumulator == min_acc && p->state == RUNNABLE)
+ {
+ scheduler_non_dependency_commands(p, c);
+ break;
+ }
+ }
+ }
+ else if(sched_type == 2)
+ {
+ int min_ratio = 2147483647;
+ for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
+ if(calculate_run_time_ratio(p) < min_ratio && p->state == RUNNABLE)
+ min_ratio = calculate_run_time_ratio(p);
+ }
+ for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
+ if(calculate_run_time_ratio(p) == min_ratio && p->state == RUNNABLE)
+ {
+ scheduler_non_dependency_commands(p, c);
+ break;
+ }
+ }
+ }
+ release(&ptable.lock);
}
}
+
+
// Enter scheduler. Must hold only ptable.lock
// and have changed proc->state. Saves and restores
// intena because intena is a property of this
@@ -461,7 +568,10 @@ wakeup1(void *chan)
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++)
if(p->state == SLEEPING && p->chan == chan)
+ {
+ p->accumulator = get_minimum_accumulator();
p->state = RUNNABLE;
+ }
}
// Wake up all processes sleeping on chan.
@@ -532,3 +642,53 @@ procdump(void)
cprintf("\n");
}
}
+
+void
+memsize(void)
+{
+ cprintf("The process is using: %dB\n", myproc()->sz);
+}
+
+int
+set_ps_priority(int priority)
+{
+ if(priority < 1 || priority > 10)
+ return -1;
+ struct proc *curproc = myproc();
+ curproc->ps_priority = priority;
+ return 0;
+}
+
+
+
+int policy(int policy_num)
+{
+ if(policy_num<0 || policy_num>2)
+ return -1;
+ sched_type = policy_num;
+ return 0;
+}
+int
+set_cfs_priority(int priority)
+{
+ if(priority == 1)
+ myproc()->decay_factor = 0.75;
+ else if(priority == 2)
+ myproc()->decay_factor = 1.0;
+ else if(priority == 3)
+ myproc()->decay_factor = 1.25;
+ else
+ return -1;
+ return 0;
+
+}
+
+int
+proc_info(struct perf *p)
+{
+ p->ps_priority = myproc()->ps_priority;
+ p->stime = myproc()->stime;
+ p->retime = myproc()->retime;
+ p->rtime = myproc()->rtime;
+ return 0;
+}
diff --git a/proc.h b/proc.h
index 1647114..619b7b9 100644
--- a/proc.h
+++ b/proc.h
@@ -49,6 +49,14 @@ struct proc {
struct file *ofile[NOFILE]; // Open files
struct inode *cwd; // Current directory
char name[16]; // Process name (debugging)
+ int exit_status; // Process exit status
+ long long accumulator; // Process accumulator
+ double decay_factor; // Process cfs priority
+ int ps_priority; // Process ps priority
+ int stime;
+ int retime;
+ int rtime;
+
};
// Process memory is laid out contiguously, low addresses first:
diff --git a/rm.c b/rm.c
index 4fd33c8..1e6daec 100644
--- a/rm.c
+++ b/rm.c
@@ -9,7 +9,7 @@ main(int argc, char *argv[])
if(argc < 2){
printf(2, "Usage: rm files...\n");
- exit();
+ exit(1);
}
for(i = 1; i < argc; i++){
@@ -19,5 +19,5 @@ main(int argc, char *argv[])
}
}
- exit();
+ exit(0);
}
diff --git a/sanity.c b/sanity.c
new file mode 100644
index 0000000..7e27842
--- /dev/null
+++ b/sanity.c
@@ -0,0 +1,67 @@
+#include "types.h"
+#include "stat.h"
+#include "user.h"
+
+void child_to_do(struct perf* p)
+{
+int i = 1000000;
+int dummy = 0;
+while(i--)
+{
+ printf(1, "");
+ dummy+=i;
+}
+proc_info(p);
+printf(1, "%d %d %d %d %d\n", getpid(), p->ps_priority, p->stime, p->retime, p->rtime);
+
+}
+
+int main(){
+ printf(1, "PID # PS_PRIORITY # STIME # RETIME # RTIME\n");
+ struct perf* p1_perf = (struct perf*)malloc(sizeof(struct perf));
+ struct perf* p2_perf = (struct perf*)malloc(sizeof(struct perf));
+ struct perf* p3_perf = (struct perf*)malloc(sizeof(struct perf));
+ int pid1;
+ int pid2;
+ int pid3;
+ pid1 = fork();
+ if(pid1 < 0)
+ printf(1, "ERROR forking ERROR\n");
+ else if(pid1 == 0)
+ {
+ set_cfs_priority(3);
+ set_ps_priority(10);
+ child_to_do(p1_perf);
+ }
+ else
+ {
+ pid2 = fork();
+ if(pid2 < 0)
+ printf(1, "ERROR forking ERROR\n");
+ else if(pid2 == 0)
+ {
+ set_cfs_priority(2);
+ set_ps_priority(5);
+ child_to_do(p2_perf);
+ }
+ else
+ {
+ pid3 = fork();
+ if(pid3 < 0)
+ printf(1, "ERROR forking ERROR\n");
+ else if(pid3 == 0)
+ {
+ set_cfs_priority(1);
+ set_ps_priority(1);
+ child_to_do(p3_perf);
+ }
+ else
+ {
+ wait(null);
+ wait(null);
+ wait(null);
+ }
+ }
+ }
+ exit(0);
+ }
diff --git a/sh.c b/sh.c
index 054bab9..1d8273c 100644
--- a/sh.c
+++ b/sh.c
@@ -65,7 +65,7 @@ runcmd(struct cmd *cmd)
struct redircmd *rcmd;
if(cmd == 0)
- exit();
+ exit(0);
switch(cmd->type){
default:
@@ -74,7 +74,7 @@ runcmd(struct cmd *cmd)
case EXEC:
ecmd = (struct execcmd*)cmd;
if(ecmd->argv[0] == 0)
- exit();
+ exit(0);
exec(ecmd->argv[0], ecmd->argv);
printf(2, "exec %s failed\n", ecmd->argv[0]);
break;
@@ -84,7 +84,7 @@ runcmd(struct cmd *cmd)
close(rcmd->fd);
if(open(rcmd->file, rcmd->mode) < 0){
printf(2, "open %s failed\n", rcmd->file);
- exit();
+ exit(1);
}
runcmd(rcmd->cmd);
break;
@@ -93,7 +93,7 @@ runcmd(struct cmd *cmd)
lcmd = (struct listcmd*)cmd;
if(fork1() == 0)
runcmd(lcmd->left);
- wait();
+ wait(null);
runcmd(lcmd->right);
break;
@@ -117,8 +117,8 @@ runcmd(struct cmd *cmd)
}
close(p[0]);
close(p[1]);
- wait();
- wait();
+ wait(null);
+ wait(null);
break;
case BACK:
@@ -127,7 +127,7 @@ runcmd(struct cmd *cmd)
runcmd(bcmd->cmd);
break;
}
- exit();
+ exit(0);
}
int
@@ -166,16 +166,16 @@ main(void)
}
if(fork1() == 0)
runcmd(parsecmd(buf));
- wait();
+ wait(null);
}
- exit();
+ exit(0);
}
void
panic(char *s)
{
printf(2, "%s\n", s);
- exit();
+ exit(0);
}
int
diff --git a/stressfs.c b/stressfs.c
index c0a4743..98e221e 100644
--- a/stressfs.c
+++ b/stressfs.c
@@ -43,7 +43,7 @@ main(int argc, char *argv[])
read(fd, data, sizeof(data));
close(fd);
- wait();
+ wait(null);
- exit();
+ exit(0);
}
diff --git a/syscall.c b/syscall.c
index ee85261..1aafe08 100644
--- a/syscall.c
+++ b/syscall.c
@@ -103,6 +103,11 @@ extern int sys_unlink(void);
extern int sys_wait(void);
extern int sys_write(void);
extern int sys_uptime(void);
+extern int sys_memsize(void);
+extern int sys_set_ps_priority(void);
+extern int sys_policy(void);
+extern int sys_set_cfs_priority(void);
+extern int sys_proc_info(void);
static int (*syscalls[])(void) = {
[SYS_fork] sys_fork,
@@ -126,6 +131,11 @@ static int (*syscalls[])(void) = {
[SYS_link] sys_link,
[SYS_mkdir] sys_mkdir,
[SYS_close] sys_close,
+[SYS_memsize] sys_memsize,
+[SYS_set_ps_priority] sys_set_ps_priority,
+[SYS_policy] sys_policy,
+[SYS_set_cfs_priority] sys_set_cfs_priority,
+[SYS_proc_info] sys_proc_info,
};
void
@@ -143,3 +153,4 @@ syscall(void)
curproc->tf->eax = -1;
}
}
+
diff --git a/syscall.h b/syscall.h
index bc5f356..6204115 100644
--- a/syscall.h
+++ b/syscall.h
@@ -20,3 +20,8 @@
#define SYS_link 19
#define SYS_mkdir 20
#define SYS_close 21
+#define SYS_memsize 22
+#define SYS_set_ps_priority 23
+#define SYS_policy 24
+#define SYS_set_cfs_priority 25
+#define SYS_proc_info 26
\ No newline at end of file
diff --git a/sysproc.c b/sysproc.c
index 0686d29..ac772da 100644
--- a/sysproc.c
+++ b/sysproc.c
@@ -16,14 +16,20 @@ sys_fork(void)
int
sys_exit(void)
{
- exit();
+ int exit_status;
+ if (argint(0, &exit_status) < 0)
+ return -1;
+ exit(exit_status);
return 0; // not reached
}
int
sys_wait(void)
{
- return wait();
+ int *exit_status;
+ if (argptr(0, (char**)&exit_status, 4) < 0)
+ return -1;
+ return wait(exit_status);
}
int
@@ -89,3 +95,46 @@ sys_uptime(void)
release(&tickslock);
return xticks;
}
+
+void
+sys_memsize(void)
+{
+ memsize();
+}
+
+int
+sys_set_ps_priority(void)
+{
+ int priority;
+
+ if(argint(0, &priority) < 0)
+ return -1;
+ return set_ps_priority(priority);