diff --git a/os161-base-2.0.2/build/userland/testbin/palin/palin b/os161-base-2.0.2/build/userland/testbin/palin/palin index 2b713d5..3ffbf0b 100755 Binary files a/os161-base-2.0.2/build/userland/testbin/palin/palin and b/os161-base-2.0.2/build/userland/testbin/palin/palin differ diff --git a/os161-base-2.0.2/build/userland/testbin/palin/palin.o b/os161-base-2.0.2/build/userland/testbin/palin/palin.o index 00b0217..56be2c1 100644 Binary files a/os161-base-2.0.2/build/userland/testbin/palin/palin.o and b/os161-base-2.0.2/build/userland/testbin/palin/palin.o differ diff --git a/os161-base-2.0.2/kern/include/thread.h b/os161-base-2.0.2/kern/include/thread.h index 48ca76d..5c86e59 100644 --- a/os161-base-2.0.2/kern/include/thread.h +++ b/os161-base-2.0.2/kern/include/thread.h @@ -39,7 +39,7 @@ #include #include #include - +#include "opt-monitor.h" struct cpu; /* get machine-dependent defs */ @@ -144,6 +144,13 @@ int thread_fork(const char *name, struct proc *proc, void (*func)(void *, unsigned long), void *data1, unsigned long data2); + +#if OPT_MONITOR +int thread_fork_tocpu(const char *name, struct proc *proc, + void (*func)(void *, unsigned long), + void *data1, unsigned long data2); + +#endif /* * Cause the current thread to exit. * Interrupts need not be disabled. diff --git a/os161-base-2.0.2/kern/main/menu.c b/os161-base-2.0.2/kern/main/menu.c index 3a7f133..ff7ad53 100644 --- a/os161-base-2.0.2/kern/main/menu.c +++ b/os161-base-2.0.2/kern/main/menu.c @@ -123,7 +123,7 @@ common_prog(int nargs, char **args) return ENOMEM; } - result = thread_fork(args[0] /* thread name */, + result = thread_fork_tocpu(args[0] /* thread name */, proc /* new process */, cmd_progthread /* thread function */, args /* thread arg */, nargs /* thread arg */); @@ -172,7 +172,7 @@ monitor_prog(int nargs, char **args) } proc_setmonitor(proc, 0); monitor_addproc(proc); - result = thread_fork(args[0] /* thread name */, + result = thread_fork_tocpu(args[0] /* thread name */, proc /* new process */, cmd_progthread /* thread function */, args /* thread arg */, nargs /* thread arg */); diff --git a/os161-base-2.0.2/kern/proc/monitor.c b/os161-base-2.0.2/kern/proc/monitor.c index cf175d7..e53697d 100644 --- a/os161-base-2.0.2/kern/proc/monitor.c +++ b/os161-base-2.0.2/kern/proc/monitor.c @@ -34,6 +34,7 @@ static struct _monitor{ int active; struct proc *proc[MAX_PROC+1]; int last_i; + int count; struct spinlock lk; } monitor; @@ -45,7 +46,7 @@ void monitor_check(void *ptr, unsigned long nargs){ while(1){ int i = 0; - while(i < monitor.last_i){ + while(i < monitor.last_i && monitor.count != 0){ spinlock_acquire(&monitor.lk); struct proc* p = monitor.proc[i]; spinlock_release(&monitor.lk); @@ -54,7 +55,8 @@ void monitor_check(void *ptr, unsigned long nargs){ continue; } evaluate_features(); - uint32_t n = random()%10000; + //uint32_t n = random()%10000; + uint32_t n = 1; if(n == 1){ spinlock_acquire(&p->p_lock); p->faulty = 1; @@ -62,7 +64,6 @@ void monitor_check(void *ptr, unsigned long nargs){ n = 0; } i++; - //kprintf("Ciao sono il thread di controllo\n"); } thread_yield(); } @@ -121,6 +122,7 @@ int monitor_start(void){ spinlock_init(&monitor.lk); monitor.active=1; monitor.last_i=0; + monitor.count=0; char args[20]="dummy"; // Open fake driver files int result = vfs_open((char *) ds_names[0], O_RDONLY, 0, &v); @@ -150,6 +152,7 @@ int monitor_addproc(struct proc* proc){ if (monitor.proc[i] == NULL) { monitor.proc[i] = proc; monitor.last_i = i+1; + monitor.count++; break; } i++; @@ -163,6 +166,7 @@ int monitor_removeproc(struct proc* p){ for(i=0;it_cpu = curthread->t_cpu; /* Attach the new thread to its process */ @@ -545,6 +543,68 @@ thread_fork(const char *name, return 0; } +#if OPT_MONITOR + +int +thread_fork_tocpu(const char *name, + struct proc *proc, + void (*entrypoint)(void *data1, unsigned long data2), + void *data1, unsigned long data2) +{ + struct thread *newthread; + int result; + struct cpu *c; + unsigned numcpus; + + newthread = thread_create(name); + if (newthread == NULL) { + return ENOMEM; + } + + /* Allocate a stack */ + newthread->t_stack = kmalloc(STACK_SIZE); + if (newthread->t_stack == NULL) { + thread_destroy(newthread); + return ENOMEM; + } + thread_checkstack_init(newthread); + + /* + * Now we clone various fields from the parent thread. + */ + + + numcpus = cpuarray_num(&allcpus); + c = cpuarray_get(&allcpus, numcpus-1); + newthread->t_cpu = c; + + /* Attach the new thread to its process */ + if (proc == NULL) { + proc = curthread->t_proc; + } + result = proc_addthread(proc, newthread); + if (result) { + /* thread_destroy will clean up the stack */ + thread_destroy(newthread); + return result; + } + + /* + * Because new threads come out holding the cpu runqueue lock + * (see notes at bottom of thread_switch), we need to account + * for the spllower() that will be done releasing it. + */ + newthread->t_iplhigh_count++; + + /* Set up the switchframe so entrypoint() gets called */ + switchframe_init(newthread, entrypoint, data1, data2); + + /* Lock the current cpu's run queue and make the new thread runnable */ + thread_make_runnable(newthread, false); + + return 0; +} +#endif /* * High level, machine-independent context switch code. * @@ -722,6 +782,7 @@ thread_switch(threadstate_t newstate, struct wchan *wc, struct spinlock *lk) /* Turn interrupts back on. */ splx(spl); #if OPT_MONITOR + int fault = proc_fault(); if(fault){ diff --git a/os161-base-2.0.2/userland/testbin/palin/palin.c b/os161-base-2.0.2/userland/testbin/palin/palin.c index 6bc476c..e9e4dc6 100644 --- a/os161-base-2.0.2/userland/testbin/palin/palin.c +++ b/os161-base-2.0.2/userland/testbin/palin/palin.c @@ -175,7 +175,7 @@ main(void) { char *start, *end; - printf("Welcome to the palindrome tester!\n"); + printf("Welcome to the palindrome tester by Simone!\n"); printf("I will take a large palindrome and test it.\n"); printf("Here it is:\n"); printf("%s\n", palindrome);