/* Execute one instruction from each running context. */ void ke_run(void) { struct ctx_t *ctx, *ctx_trav; int flag = 0; /* Run an instruction from every running process */ for (ctx = ke->running_list_head; ctx; ctx = ctx->running_next) { int i; //printf ("out - %p\n", ctx); for ( i = 0 ; i < ctx->instr_slice ; ++i) { if((no_instructions == get_least_interrupt_time()) && least_interrupt!=NULL){ struct interrupt_t* curr_interrupt = get_least_interrupt(); curr_interrupt->details->p_ctx->blocked = 0; printf("program with pid %d unblocked at %d\n",curr_interrupt->details->p_ctx->pid,no_instructions); delete_interrupt(curr_interrupt); } if(!ctx->blocked){ ctx_execute_inst(ctx); no_instructions++; printf("%d,%d\n",ctx->pid,no_instructions); } if (ctx!=ke->running_list_head) break; } } /* Free finished contexts */ while (ke->finished_list_head) ctx_free(ke->finished_list_head); /* Process list of suspended contexts */ ke_process_events(); }
/* Execute one instruction from each running context. */ void ke_run(void) { //printf("ke run called\n"); struct ctx_t *ctx, *ctx_trav; int flag = 0; if(!ke->running_list_head){ if (!print_no_more) { printf("============ Running list empty ! . Fast forward to next interrupt. ============\n"); print_no_more = true; pl = true; } if(!isEmpty()){ isa_inst_count = findMin().instr_no; //printf("non-empty instruction list\n"); handle_top_interrupt(); } else{ if (!print_no_more || (print_no_more && pl)) { printf("Interrupt queue is also empty.\n"); print_no_more = true; pl = false; } } } /* Run an instruction from every running process */ for (ctx = ke->running_list_head; ctx; ctx = ctx->running_next) { print_no_more = false; int i; //printf ("out - %p\n", ctx); //printf("after\n"); printf("[%d] exec instr\n", ctx->pid); for ( i = 0 ; i < ctx->instr_slice ; ++i) { //printf(" non-empty instruction list\n"); handle_top_interrupt(); if(!ctx_get_status(ctx,ctx_running)){ printf("%d no more running\n", ctx->pid); break; } page_in_out_count = 0; fault_count_in_instruction = 0; //value printed in ctx_execute_inst in context.c ctx_execute_inst(ctx); printf("ins_count: %"PRIu64" | [%d] : page_in_out_count : %d\n", isa_inst_count, ctx->pid, page_in_out_count); //if page_in_out_count > 0, then put the process to suspended list and insert an interrupt if(page_in_out_count > 0){ printf("[%d] : Blocking process for page fault\n", ctx->pid); ctx_update_status(isa_ctx, ctx_suspended); struct interrupt in; in.instr_no = isa_inst_count + page_in_out_count * 10; in.type = iocomplete; in.ctx = isa_ctx; insert(in); } // if (ctx!=ke->running_list_head) // break; } } /* Free finished contexts */ while (ke->finished_list_head) ctx_free(ke->finished_list_head); /* Process list of suspended contexts */ ke_process_events(); }