From 6c165d7296c76f31708bb9238e462691289e1cd1 Mon Sep 17 00:00:00 2001 From: Mina Beigi Date: Sun, 17 Oct 2021 00:15:26 +0330 Subject: [PATCH] Added read count test --- Makefile | 6 ++++-- defs.h | 2 +- getProcCountTest.c | 11 +++++++++++ getProcCount.c => getReadCountTest.c | 3 ++- proc.c | 8 ++++++-- sysfile.c | 4 ++-- sysproc.c | 2 +- 7 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 getProcCountTest.c rename getProcCount.c => getReadCountTest.c (57%) diff --git a/Makefile b/Makefile index cd11eeb..51f32cf 100644 --- a/Makefile +++ b/Makefile @@ -182,7 +182,8 @@ UPROGS=\ _wc\ _zombie\ _sysTest\ - _getProcCount\ + _getProcCountTest\ + _getReadCountTest\ fs.img: mkfs README $(UPROGS) ./mkfs fs.img README $(UPROGS) @@ -256,7 +257,8 @@ EXTRA=\ README dot-bochsrc *.pl toc.* runoff runoff1 runoff.list\ .gdbinit.tmpl gdbutil\ sysTest.c\ - getProcCount.c\ + getProcCountTest.c\ + getReadCountTest.c\ dist: rm -rf dist diff --git a/defs.h b/defs.h index fdc513d..94adcdd 100644 --- a/defs.h +++ b/defs.h @@ -122,7 +122,7 @@ void wakeup(void*); void yield(void); int getHelloWorld(void); int getProcCount(void); -int getReadCount(void); +int getReadCount(int); // swtch.S void swtch(struct context**, struct context*); diff --git a/getProcCountTest.c b/getProcCountTest.c new file mode 100644 index 0000000..c66ecf7 --- /dev/null +++ b/getProcCountTest.c @@ -0,0 +1,11 @@ +#include "types.h" +#include "stat.h" +#include "user.h" +#include "fcntl.h" + +int main(void) +{ + int result = getProcCount(); + printf(1, "number of processes = %d\n", result); + exit(); +} \ No newline at end of file diff --git a/getProcCount.c b/getReadCountTest.c similarity index 57% rename from getProcCount.c rename to getReadCountTest.c index 2a2121b..2797351 100644 --- a/getProcCount.c +++ b/getReadCountTest.c @@ -5,6 +5,7 @@ int main(void) { - printf(1, "Number of processes: %d", getProcCount); + int result = getReadCount(); + printf(1, "Number of reads: %d", result); exit(); } \ No newline at end of file diff --git a/proc.c b/proc.c index 94f2898..0a41867 100644 --- a/proc.c +++ b/proc.c @@ -546,12 +546,16 @@ getProcCount(void) struct proc *p; int counter=0; - acquire(&ptable.lock); for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->state != UNUSED){ counter = counter+1; } } - release(&ptable.lock); return counter; +} + +int +getReadCount(int readCount) +{ + return readCount; } \ No newline at end of file diff --git a/sysfile.c b/sysfile.c index 740b645..9a85bdd 100644 --- a/sysfile.c +++ b/sysfile.c @@ -16,7 +16,7 @@ #include "file.h" #include "fcntl.h" -readCount = 0; +int readCount = 0; // Fetch the nth word-sized system call argument as a file descriptor // and return both the descriptor and the corresponding struct file. @@ -74,7 +74,7 @@ sys_read(void) struct file *f; int n; char *p; - readCount = readCount + 1; + readCount ++; if(argfd(0, 0, &f) < 0 || argint(2, &n) < 0 || argptr(1, &p, n) < 0) return -1; diff --git a/sysproc.c b/sysproc.c index ade965b..31326f4 100644 --- a/sysproc.c +++ b/sysproc.c @@ -107,5 +107,5 @@ sys_getProcCount(void) int sys_getReadCount(void) { - return readCount; + return getReadCount(readCount); } \ No newline at end of file