From 0c2a18458f5a3319ae43618b9414ae3e2fec8f77 Mon Sep 17 00:00:00 2001 From: William Katsak Date: Mon, 4 Apr 2016 09:57:10 -0400 Subject: [PATCH 1/9] cs416-hw2: add empty pthread.h header Signed-off-by: William Katsak --- pthread.h | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 pthread.h diff --git a/pthread.h b/pthread.h new file mode 100644 index 0000000..649f5e6 --- /dev/null +++ b/pthread.h @@ -0,0 +1,7 @@ +#ifndef XV6_PTHREAD +#define XV6_PTHREAD + +// Define all functions and types for pthreads here. +// This can be included in both kernel and user code. + +#endif \ No newline at end of file From a5fd312f3590ed7bd419d879b947a9eb72801ff5 Mon Sep 17 00:00:00 2001 From: William Katsak Date: Tue, 5 Apr 2016 16:55:16 -0400 Subject: [PATCH 2/9] sp16-hw2: add empty pthread.c file Signed-off-by: William Katsak --- pthread.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 pthread.c diff --git a/pthread.c b/pthread.c new file mode 100644 index 0000000..e69de29 From ccdd94090f4e6f76c90bafa82126647396371338 Mon Sep 17 00:00:00 2001 From: William Katsak Date: Tue, 5 Apr 2016 15:25:05 -0400 Subject: [PATCH 3/9] sp16-hw2: add test_clone.c program Signed-off-by: William Katsak --- test_clone.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 test_clone.c diff --git a/test_clone.c b/test_clone.c new file mode 100644 index 0000000..0b87aef --- /dev/null +++ b/test_clone.c @@ -0,0 +1,90 @@ +#include "types.h" +#include "stat.h" +#include "user.h" +#include "fs.h" +#include "fcntl.h" + +#define NUM_THREADS 16 +#define TARGET_COUNT_PER_THREAD 100000 + +void *thread(void *arg) +{ + int i; + int counter; + + sleep(10); + printf(1, "thread %d: started...\n", *(int*)arg); + + for (i=0; i Date: Tue, 5 Apr 2016 16:47:54 -0400 Subject: [PATCH 4/9] sp16-hw2: add test_pthread.c program Signed-off-by: William Katsak --- test_pthread.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 test_pthread.c diff --git a/test_pthread.c b/test_pthread.c new file mode 100644 index 0000000..3097522 --- /dev/null +++ b/test_pthread.c @@ -0,0 +1,82 @@ +#include "types.h" +#include "stat.h" +#include "user.h" +#include "fs.h" +#include "fcntl.h" +#include "pthread.h" + +#define NUM_THREADS 16 +#define TARGET_COUNT_PER_THREAD 100000 + +void *thread(void *arg) +{ + int i; + int counter; + + sleep(10); + printf(1, "thread %d: started...\n", *(int*)arg); + + for (i=0; i Date: Tue, 5 Apr 2016 16:50:09 -0400 Subject: [PATCH 5/9] sp16-hw2: add test_mutex.c program Signed-off-by: William Katsak --- test_mutex.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 test_mutex.c diff --git a/test_mutex.c b/test_mutex.c new file mode 100644 index 0000000..aa12b40 --- /dev/null +++ b/test_mutex.c @@ -0,0 +1,101 @@ +#include "types.h" +#include "stat.h" +#include "user.h" +#include "fs.h" +#include "fcntl.h" +#include "pthread.h" + +#define NUM_THREADS 16 +#define TARGET_COUNT_PER_THREAD 32000 + +uint g_counter; +pthread_mutex_t mutex; + +void *thread(void *arg) +{ + int i; + int counter; + + sleep(10); + printf(1, "thread %d: started...\n", *(int*)arg); + + for (i=0; i Date: Tue, 5 Apr 2016 16:33:34 -0400 Subject: [PATCH 6/9] Makefile: changes for hw2 - Add test programs. - Add pthread.o. - Add -Wno-return-type so the compiler doesn't complain about missing return and/or exit() calls. Signed-off-by: William Katsak --- Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index dd144a3..bf415f9 100644 --- a/Makefile +++ b/Makefile @@ -75,7 +75,7 @@ LD = $(TOOLPREFIX)ld OBJCOPY = $(TOOLPREFIX)objcopy OBJDUMP = $(TOOLPREFIX)objdump #CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -fvar-tracking -fvar-tracking-assignments -O0 -g -Wall -MD -gdwarf-2 -m32 -Werror -fno-omit-frame-pointer +CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -fvar-tracking -fvar-tracking-assignments -O0 -g -Wall -MD -gdwarf-2 -m32 -Werror -fno-omit-frame-pointer -Wno-return-type CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector) ASFLAGS = -m32 -gdwarf-2 -Wa,-divide # FreeBSD ld wants ``elf_i386_fbsd'' @@ -134,7 +134,7 @@ tags: $(OBJS) entryother.S _init vectors.S: vectors.pl perl vectors.pl > vectors.S -ULIB = ulib.o usys.o printf.o umalloc.o +ULIB = ulib.o usys.o printf.o umalloc.o pthread.o _%: %.o $(ULIB) $(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $@ $^ @@ -173,6 +173,9 @@ UPROGS=\ _wc\ _zombie\ _shutdown\ + _test_clone\ + _test_pthread\ + _test_mutex\ fs.img: mkfs README $(UPROGS) ./mkfs fs.img README $(UPROGS) From 2d2df92e0a5b396dd9a3a903e8449210b2db4e21 Mon Sep 17 00:00:00 2001 From: William Katsak Date: Tue, 5 Apr 2016 16:52:56 -0400 Subject: [PATCH 7/9] Makefile: comment out hw2 test programs Signed-off-by: William Katsak --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index bf415f9..38c3895 100644 --- a/Makefile +++ b/Makefile @@ -173,9 +173,9 @@ UPROGS=\ _wc\ _zombie\ _shutdown\ - _test_clone\ - _test_pthread\ - _test_mutex\ +# _test_clone\ +# _test_pthread\ +# _test_mutex\ fs.img: mkfs README $(UPROGS) ./mkfs fs.img README $(UPROGS) From 62f7f59579a621101a75f3720e01dce03fc4f923 Mon Sep 17 00:00:00 2001 From: William Katsak Date: Tue, 5 Apr 2016 17:50:28 -0400 Subject: [PATCH 8/9] sp16-hw2: add required imports to pthread.c Signed-off-by: William Katsak --- pthread.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pthread.c b/pthread.c index e69de29..9442ca0 100644 --- a/pthread.c +++ b/pthread.c @@ -0,0 +1,9 @@ +#include "types.h" +#include "stat.h" +#include "user.h" +#include "fs.h" +#include "fcntl.h" +#include "pthread.h" + +// Implement your pthreads library here. + From f8aeed2fe428b06a70786058acbf171719943be1 Mon Sep 17 00:00:00 2001 From: William Katsak Date: Wed, 6 Apr 2016 09:25:30 -0400 Subject: [PATCH 9/9] sp16-hw2: some small fixes to test programs Signed-off-by: William Katsak --- test_clone.c | 6 ++++++ test_mutex.c | 7 ++++++- test_pthread.c | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/test_clone.c b/test_clone.c index 0b87aef..b7eed42 100644 --- a/test_clone.c +++ b/test_clone.c @@ -85,6 +85,12 @@ int main(int argc, char **argv) printf(1, "TEST FAILED!\n"); } + // Clean up memory + for (i=0; i