File tree 11 files changed +91
-18
lines changed
11 files changed +91
-18
lines changed Original file line number Diff line number Diff line change @@ -183,6 +183,7 @@ UPROGS=\
183
183
_zombie\
184
184
_getParentIDtest\
185
185
_getChildrentest\
186
+ _getSyscallCounterTest\
186
187
187
188
fs.img : mkfs README $(UPROGS )
188
189
./mkfs fs.img README $(UPROGS )
@@ -255,6 +256,7 @@ EXTRA=\
255
256
printf.c umalloc.c\
256
257
getParentIDtest.c\
257
258
getChildrentest.c\
259
+ getSyscallCounterTest.c\
258
260
README dot-bochsrc *.pl toc.* runoff runoff1 runoff.list\
259
261
.gdbinit.tmpl gdbutil\
260
262
Original file line number Diff line number Diff line change @@ -120,8 +120,9 @@ void userinit(void);
120
120
int wait (void );
121
121
void wakeup (void * );
122
122
void yield (void );
123
- int getparentid (void );
124
- int getChildren (char * ptr );
123
+ int getparentid (void ); // (Added)
124
+ int getChildren (char * ptr ); // (Added)
125
+ int getSyscallCounter (int syscallNo ); // (Added)
125
126
126
127
// swtch.S
127
128
void swtch (struct context * * , struct context * );
Original file line number Diff line number Diff line change
1
+ # include "types.h"
2
+ # include "stat.h"
3
+ # include "user.h"
4
+
5
+
6
+ int main (void )
7
+ {
8
+ int p ;
9
+
10
+ printf (1 , "Parent process sys_fork count = %d\n" , getSyscallCounter (1 ));
11
+
12
+ p = fork ();
13
+
14
+ if (p == 0 )
15
+ {
16
+ printf (1 , "Child process sys_fork count = %d\n" , getSyscallCounter (1 ));
17
+
18
+ for (int i = 0 ; i < 16 ; i ++ )
19
+ getpid ();
20
+
21
+ printf (1 , "child sys_getpid count %d\n" , getSyscallCounter (11 ));
22
+ }
23
+ else
24
+ {
25
+ wait ();
26
+ printf (1 , "parent fork count %d\n" , getSyscallCounter (1 ));
27
+ sleep (1 );
28
+ printf (1 , "parent sys_sleep count %d\n" , getSyscallCounter (13 ));
29
+ }
30
+ printf (1 , "process sys_wait count = %d\n" , getSyscallCounter (3 ));
31
+ printf (1 , "process sys_syscallcounter count = %d\n" , getSyscallCounter (24 ));
32
+
33
+ exit ();
34
+
35
+ return 0 ;
36
+ }
Original file line number Diff line number Diff line change @@ -533,6 +533,7 @@ procdump(void)
533
533
}
534
534
}
535
535
536
+ // return parent ID of a process (Added)
536
537
int
537
538
getparentid (void )
538
539
{
@@ -541,6 +542,7 @@ getparentid(void)
541
542
return chlid_pid ;
542
543
}
543
544
545
+ // return children ID of a process (Added)
544
546
int
545
547
getChildren (char * ptr )
546
548
{
@@ -557,4 +559,15 @@ getChildren(char * ptr)
557
559
}
558
560
}
559
561
return 1 ;
562
+ }
563
+
564
+ // return occurrence of a syscall for current process (Added)
565
+ int
566
+ getSyscallCounter (int syscallNo ){
567
+
568
+ struct proc * curproc = myproc ();
569
+ int occurrence ;
570
+
571
+ occurrence = curproc -> syscall_occurrence [syscallNo - 1 ];
572
+ return occurrence ;
560
573
}
Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ struct proc {
49
49
struct file * ofile [NOFILE ]; // Open files
50
50
struct inode * cwd ; // Current directory
51
51
char name [16 ]; // Process name (debugging)
52
+ int syscall_occurrence [24 ]; // save occurrence of each syscall (Added)
52
53
};
53
54
54
55
// Process memory is laid out contiguously, low addresses first:
Original file line number Diff line number Diff line change @@ -103,8 +103,9 @@ extern int sys_unlink(void);
103
103
extern int sys_wait (void );
104
104
extern int sys_write (void );
105
105
extern int sys_uptime (void );
106
- extern int sys_getparentid (void );
107
- extern int sys_getChildren (void );
106
+ extern int sys_getparentid (void ); // Added
107
+ extern int sys_getChildren (void ); // Added
108
+ extern int sys_getSyscallCounter (void ); // Added
108
109
109
110
static int (* syscalls [])(void ) = {
110
111
[SYS_fork ] sys_fork ,
@@ -128,8 +129,9 @@ static int (*syscalls[])(void) = {
128
129
[SYS_link ] sys_link ,
129
130
[SYS_mkdir ] sys_mkdir ,
130
131
[SYS_close ] sys_close ,
131
- [SYS_getparentid ] sys_getparentid ,
132
- [SYS_getChildren ] sys_getChildren
132
+ [SYS_getparentid ] sys_getparentid , // (Added)
133
+ [SYS_getChildren ] sys_getChildren , // (Added)
134
+ [SYS_getSyscallCounter ] sys_getSyscallCounter // (Added)
133
135
};
134
136
135
137
void
@@ -140,6 +142,7 @@ syscall(void)
140
142
141
143
num = curproc -> tf -> eax ;
142
144
if (num > 0 && num < NELEM (syscalls ) && syscalls [num ]) {
145
+ curproc -> syscall_occurrence [num - 1 ]++ ; // (Added)
143
146
curproc -> tf -> eax = syscalls [num ]();
144
147
} else {
145
148
cprintf ("%d %s: unknown sys call %d\n" ,
Original file line number Diff line number Diff line change 20
20
#define SYS_link 19
21
21
#define SYS_mkdir 20
22
22
#define SYS_close 21
23
- #define SYS_getparentid 22
24
- #define SYS_getChildren 23
23
+ #define SYS_getparentid 22 // (Added)
24
+ #define SYS_getChildren 23 // (Added)
25
+ #define SYS_getSyscallCounter 24 // (Added)
Original file line number Diff line number Diff line change @@ -421,7 +421,7 @@ sys_exec(void)
421
421
422
422
int
423
423
sys_pipe (void )
424
- {
424
+ {
425
425
int * fd ;
426
426
struct file * rf , * wf ;
427
427
int fd0 , fd1 ;
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ sys_fork(void)
15
15
16
16
int
17
17
sys_exit (void )
18
- {
18
+ {
19
19
exit ();
20
20
return 0 ; // not reached
21
21
}
@@ -28,8 +28,8 @@ sys_wait(void)
28
28
29
29
int
30
30
sys_kill (void )
31
- {
32
- int pid ;
31
+ {
32
+ int pid ;
33
33
34
34
if (argint (0 , & pid ) < 0 )
35
35
return -1 ;
@@ -38,13 +38,13 @@ sys_kill(void)
38
38
39
39
int
40
40
sys_getpid (void )
41
- {
41
+ {
42
42
return myproc ()-> pid ;
43
43
}
44
44
45
45
int
46
46
sys_sbrk (void )
47
- {
47
+ {
48
48
int addr ;
49
49
int n ;
50
50
@@ -81,7 +81,7 @@ sys_sleep(void)
81
81
// since start.
82
82
int
83
83
sys_uptime (void )
84
- {
84
+ {
85
85
uint xticks ;
86
86
87
87
acquire (& tickslock );
@@ -90,12 +90,14 @@ sys_uptime(void)
90
90
return xticks ;
91
91
}
92
92
93
+ // return parent ID of a process (Added)
93
94
int
94
95
sys_getparentid (void )
95
96
{
96
97
return getparentid ();
97
98
}
98
99
100
+ // return children ID of a process (Added)
99
101
int
100
102
sys_getChildren (void )
101
103
{
@@ -106,4 +108,16 @@ sys_getChildren(void)
106
108
107
109
getChildren (ptr );
108
110
return 1 ;
111
+ }
112
+
113
+ // return occurrence of a syscall for current process (Added)
114
+ int
115
+ sys_getSyscallCounter ()
116
+ {
117
+ int syscallNo ;
118
+
119
+ if (argint (0 , & syscallNo ) < 0 )
120
+ return -1 ;
121
+
122
+ return getSyscallCounter (syscallNo );
109
123
}
Original file line number Diff line number Diff line change @@ -23,8 +23,9 @@ int getpid(void);
23
23
char * sbrk (int );
24
24
int sleep (int );
25
25
int uptime (void );
26
- int getparentid (void );
27
- int getChildren (char * ptr );
26
+ int getparentid (void ); // (Added)
27
+ int getChildren (char * ptr ); // (Added)
28
+ int getSyscallCounter (int syscallNo ); // (Added)
28
29
29
30
// ulib.c
30
31
int stat (const char * , struct stat * );
Original file line number Diff line number Diff line change @@ -30,4 +30,5 @@ SYSCALL(sbrk)
30
30
SYSCALL (sleep)
31
31
SYSCALL (uptime)
32
32
SYSCALL (getparentid)
33
- SYSCALL (getChildren)
33
+ SYSCALL (getChildren)
34
+ SYSCALL (getSyscallCounter)
You can’t perform that action at this time.
0 commit comments