diff --git a/pintos/src/devices/timer.c b/pintos/src/devices/timer.c index 4b986b5dc420e59da15b634eaef51abe149ac611..0f5c229441580d348209605986611daa2c2eae20 100644 --- a/pintos/src/devices/timer.c +++ b/pintos/src/devices/timer.c @@ -102,42 +102,6 @@ timer_elapsed (int64_t then) void timer_sleep (int64_t ticks) { - /*PÅ - - Here we want to add a sleeping thread in our sleep_list. - To do so we need to create and allocate a sleeping thread which we set the - current thread. For the thread to now when to wake up; set its ticks to - the asked sleeping time + ticks since OS booted. - - Depending on if list is empty; insert or insert ordered to use time better. - But "linst_insert_ordered" needs a function ad third augument -> create func - for that purpose. - - Finish with block and free. - - */ -/* - int64_t start = timer_ticks (); - //ASSERT (intr_get_level () == INTR_ON); - enum intr_level old_level; - old_level = intr_disable (); // Disable interrupts. - - struct sleeping_thread sleep_t; - sleep_t.thread = thread_current(); - sleep_t.wake_ticks = start + ticks; - struct list *sleep_list = get_sleep_list(); - - if (list_empty(sleep_list)) { - list_push_front(sleep_list, &sleep_t.elem); - }else { - list_insert_ordered (sleep_list, &(sleep_t.elem), - &cmp_sleep_list_elem, NULL); - } - thread_block(); // Puts thread to sleep until "thread_unblock" is used. -// free(sleep_t); // free memory of sleeping thread - intr_set_level(old_level); // Disable interrupts; needed to remove error. -*/ - //printf("Inside sleep, top \n"); int64_t start = timer_ticks (); ASSERT (intr_get_level () == INTR_ON); enum intr_level old_level; @@ -149,17 +113,14 @@ timer_sleep (int64_t ticks) struct list *sleep_list = get_sleep_list(); if (list_empty(sleep_list)) { - //printf("Inside sleep, if-stat \n"); list_push_front(sleep_list, &sleep_t->elem); }else { - //printf("Inside sleep, else-stat \n"); list_insert_ordered (sleep_list, &(sleep_t->elem), &cmp_sleep_list_elem, NULL); } thread_block(); // Puts thread to sleep until "thread_unblock" is used. free(sleep_t); // free memory of sleeping thread intr_set_level(old_level); // Disable interrupts; needed to remove error. - //printf("Inside sleep, finished \n"); } /* Suspends execution for approximately MS milliseconds. */ @@ -194,18 +155,6 @@ timer_print_stats (void) static void timer_interrupt (struct intr_frame *args UNUSED) { - /*PÅ - - Here we want to loop in sleep_list and see which threads who can wake up - aka: thread_unblock(sleep_t); And remove them from list. - - Since we know (since list is sorted), if the first elem in list doesn't - wake up -> the ones after won't do so either. Therefore we break the loop. - - ++ We want "list_entry()" - good info in list.h where "foo" is our sleep_t - - */ - ticks++; thread_tick (); @@ -217,21 +166,16 @@ timer_interrupt (struct intr_frame *args UNUSED) struct list *sleep_list = get_sleep_list(); struct list_elem *t; - //printf("Inside interrupt, 218 \n" ); for (t = list_begin(sleep_list); t != list_end(sleep_list); t = list_next(t)) { - //printf("Inside interrupt, for loop \n" ); struct sleeping_thread *sleep_t = list_entry (t, struct sleeping_thread, elem); if (sleep_t->wake_ticks <= start) { - //printf("Inside interrupt, if statement \n"); - list_remove(t); - //list_pop_front(sleep_list); + list_remove(t);; thread_unblock(sleep_t->thread); }else{ - //printf("Inside interrupt, break \n"); break; } } diff --git a/pintos/src/threads/thread.h b/pintos/src/threads/thread.h index 076f300c27ddcf433e33b0909db976296535474c..4436bc89b4c16738a1b19d353dd99035b12f2266 100644 --- a/pintos/src/threads/thread.h +++ b/pintos/src/threads/thread.h @@ -105,8 +105,6 @@ struct thread uint32_t *pagedir; /* Page directory. */ #endif - /*PÅ Semaphore for thread, Fr slide 10. */ - struct semaphore *thread_semaphore; /* Owned by thread.c. */ unsigned magic; /* Detects stack overflow. */ diff --git a/pintos/src/userprog/syscall.c b/pintos/src/userprog/syscall.c index dc779ebc375c8abf09899ec080eda78228dec735..f0c392b85e0de1348716dd0c2ad1c7063f652232 100644 --- a/pintos/src/userprog/syscall.c +++ b/pintos/src/userprog/syscall.c @@ -19,7 +19,6 @@ syscall_init (void) void halt(void){ - // printf("Inside halt \n"); power_off(); } @@ -41,14 +40,7 @@ open(const char *file){ if(current_thread->fd_list[fd] == NULL){ current_thread->fd_list[fd] = new_file; return fd; - - //printf("new_file: %c\n", *((char*)new_file)); - //printf("File: %c\n", *file); - //if((char*)new_file == file) { - // printf("test4\n"); - // return fd +2; } - // printf("test5\n"); }; return -1; } @@ -107,7 +99,6 @@ write (int fd, const void*buffer, unsigned size){ return (int)size; } else if ((int)size_left < 200){ - // putbuf((char*)buffer, size_left); putbuf(buffer, size_left); size_left = 0; } @@ -138,9 +129,17 @@ write (int fd, const void*buffer, unsigned size){ return -1; } +pid_t +exec (const char*cmdline) { + // Returns a tid_t, a new tid_t from the new thread that was created through a call to thread_create. + // It also starts the newly created process by calling start_process. + // argument is const char *file_name + tid_t process_execute (const char *cmdline); + // 1. if successful return pid, else -1 (thread_create does exactly that) +} + void exit(int status) { -// printf("%s %d\n", "Status: ", status); thread_exit(); } @@ -148,24 +147,18 @@ exit(int status) { static void syscall_handler (struct intr_frame *f UNUSED) { -// printf("Inside syscall handler \n"); - //int *id = (int*)f->esp; void* sp = f->esp; int id = *((int*)(sp)); sp += 4; - //printf("%d ID nummer -- ", id); - //printf("%d ID int -- ", *id); switch (id) { case SYS_HALT: { - // printf("case halt\n"); halt(); break; } case SYS_CREATE: { - // printf("case create\n"); const char *file = *((char**)(sp)); sp += 4; unsigned size = *((unsigned*)(sp)); @@ -174,28 +167,23 @@ syscall_handler (struct intr_frame *f UNUSED) } case SYS_OPEN: { - // printf("case open\n"); const char *file = *((char**)(sp)); f->eax = open(file); break; } case SYS_CLOSE: { - // printf("case close\n"); - // const char *file = (char*)id; int file = *((int*)sp); close(file); break; } case SYS_READ: { - //printf("case read\n"); int fd = *((int*)(sp)); sp += 4; void *buffer = *((void**)sp); sp += 4; unsigned size = *((unsigned*)(sp)); - //f->eax = read(fd, (char*)buffer, size); f->eax = read(fd, buffer, size); break; } @@ -206,21 +194,21 @@ syscall_handler (struct intr_frame *f UNUSED) void *buffer = *((void**)sp); sp += 4; unsigned size = *((unsigned*)(sp)); - //f->eax = write(fd, (char*)buffer, size); f->eax = write(fd, buffer, size); break; - } + case SYS_EXEC: + { + const char *cmdline= *((char**)(sp)); + f->eax = exec(file); + } + case SYS_EXIT: { id++; int status = id; exit(status); - //printf("case exit\n"); break; } - //default: - //break; } - //thread_exit (); } diff --git a/pintos/src/userprog/syscall.h b/pintos/src/userprog/syscall.h index b4ff32fed9ea5a1ade1c39d3a877ce8ba9cb4d88..db94392da505b839fffa3b42b70702a3af05168b 100644 --- a/pintos/src/userprog/syscall.h +++ b/pintos/src/userprog/syscall.h @@ -10,6 +10,7 @@ int open(const char *file); void close(int fd); int read (int fd, void*buffer, unsigned size); int write (int fd,const void*buffer, unsigned size); +pid_t exec (const char*cmdline); void exit(int status);