Example #1
0
/* Execute one instruction from each running context. */
void ke_run(void)
{
	struct ctx_t *ctx, *ctx_trav; 
	int k = 0;

	/* Run an instruction from every running process */
	for (k=0, ctx = ke->suspended_list_head; ctx; ctx = ctx->suspended_next, k++);
	//printf ("Instruction number: %lld, suspended processes:%d, queue_size: %d\n", instr_num, k, sched_count);
	for (ctx = ke->running_list_head; ctx; ctx = ctx->running_next) {
		int i;
		for ( i = 0 ; i < ctx->instr_slice && ctx_get_status(ctx, ctx_running); ++i) {
			while (interrupts_exist() && instr_num >= next_interrupt_num())
				handle_interrupt (pop_interrupt());
			
			ctx_execute_inst(ctx);
			instr_num++;
		}
	}
	
	/* Free finished contexts */
	while (ke->finished_list_head)
		ctx_free(ke->finished_list_head);
	
	/* Process list of suspended contexts */
	//ke_process_events();
	while (!(ke->running_list_head) && interrupts_exist()) {
		//printf ("Instruction number updated from %lld to %lld\n", instr_num, next_interrupt_num());
		instr_num = next_interrupt_num();
		handle_interrupt(pop_interrupt());
	}
}
Example #2
0
/* 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();

}
Example #3
0
/* 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();

}
Example #4
0
/* Execute one instruction from each running context. */
void ke_run(void)
{
  struct ctx_t *ctx, *ctx_trav; 
  int flag = 0;
  ctx = ke->running_list_head;
  if (!ctx) {
    printf ("Running List is Empty\n");
    if (!my_top(interrupt_list)) {
      /* Free finished contexts */
      while (ke->finished_list_head)
	ctx_free(ke->finished_list_head);
	
      /* Process list of suspended contexts */
      // ke_process_events();

      return;
    }
    else {
      num_instr_executed = my_top(interrupt_list)->inst_no;
      struct ctx_t *interrupting_process_context = my_top(interrupt_list)->ctx;
      if (!ctx_get_status(interrupting_process_context, ctx_suspended))
	{
	  printf("suspended process is not suspended which means we don't know what is happening\n");
	  fflush(stdout);							
	  return;
	}
      printf("Inside the ISR2\n"); 
      fflush(stdout);			
      ke_list_remove(ke_list_suspended, interrupting_process_context);
      //ctx_set_status(interrupting_process_context, ctx_running);
      interrupting_process_context->status = ctx_running;
      ke_list_insert_tail(ke_list_running, interrupting_process_context);
      my_delete(interrupt_list);
      /* Free finished contexts */
      while (ke->finished_list_head)
	ctx_free(ke->finished_list_head);

      // comment this ??	
      /* Process list of suspended contexts */
      // ke_process_events();

      return;
    }
  }
  /* Run an instruction from every running process */
  while (ctx) {
    struct ctx_t * ctx_temp = ctx->running_next;
    int i;
    //printf ("out - %p\n", ctx);
    for ( i = 0 ; i < ctx->instr_slice ; ++i) {
      if (ctx_get_status(ctx, ctx_suspended)) {
	printf("Process suspended\n");
	break;
      }
			
      if (ctx_get_status(ctx, ctx_finished)) {
	break;
      }

			
      // CHECK IF THERE ARE INTERRUPTS WAITING TO HAPPEN
      node* interrupt_list_head = my_top(interrupt_list);
      while (interrupt_list_head != NULL && interrupt_list_head->inst_no <= num_instr_executed)
	{
	  printf ("Instruction number %d\n", interrupt_list_head->inst_no);
	  // service interrupt here
	  struct ctx_t *interrupting_process_context = interrupt_list_head->ctx;
	  if (!ctx_get_status(interrupting_process_context, ctx_suspended))
	    {
	      printf("suspended process is not suspended which means we don't know what is happening\n");
	      fflush(stdout);							
	      return;
	    }
				
	  printf("Inside the ISR1\n"); 
	  fflush(stdout);
	  ke_list_remove(ke_list_suspended, interrupting_process_context);
	  //ctx_set_status(interrupting_process_context, ctx_running);
	  interrupting_process_context->status = ctx_running;
	  ke_list_insert_tail(ke_list_running, interrupting_process_context);
	  my_delete(interrupt_list);
	  interrupt_list_head = my_top(interrupt_list);
	}
			
      fflush(stdout);
      ctx_execute_inst(ctx);
      num_instr_executed++;
      fflush(stdout);
    }
    ctx = ctx_temp;
  }

	
  /* Free finished contexts */
  while (ke->finished_list_head)
    ctx_free(ke->finished_list_head);
	
  /* Process list of suspended contexts */
  // ke_process_events();

}