Пример #1
0
void *lat_ctx2_thread0(void *ptr)
{
	int tmp_iterations;
	Pr_Time overhead;
	Pr_Time time_spent, tmp, total_time;
	
	/* Obtain the timing overhead */
	printf("Task0: Hello, let's init_timing()\n");
	init_timing();

	/* Calculate the number of executions of do_overhead1() that can
	 * be done in 1 second */
	 
	tmp_iterations = generate_iterations (&do_overhead1, 1);
	printf("%d complete iterations in 1 second\n", tmp_iterations);
	
	/* Now obtains the token passing overhead */
	tmp_iterations >>= 1;
	overhead = 0.0;
	do_overhead2(tmp_iterations, &overhead);
	
	/* After obtaining all the overheads, it launches the context swith latency
	 * measuring process */
	do_context_switch(NUM_ITERATIONS, &time_spent);
	
	/* Now, it calculates the context swith latency time */
	printf("Time spent: %d\n", (uint32)time_spent.Micros());
	tmp = (float)(overhead.Secns() * (float)(NUM_ITERATIONS * NUM_TASKS));
	printf("Total overhead: %d\n", (uint32)tmp.Micros());
	time_spent -= tmp;

	total_time = (float)(time_spent.Secns() / (NUM_ITERATIONS * NUM_TASKS));
	
	printf("Latency of context switch: %d usecs\n", (uint32)total_time.Micros());
	
	Testlat_ctx2.End();
	
    return NULL;
}
Пример #2
0
void context_switch(struct kthread * new_thread)
{
    /*
     * For switching to the new task
     * Math state must be saved,
     */
    math_state_save((struct fpu_state *)&current_thread->kt_fps);
    math_state_restore(&new_thread->kt_fps);

    // Save cr0
    current_thread->kt_cr0 = get_cr0();
    // Change current process inf necessary
    current_process = new_thread->kt_process;

    new_thread->kt_schedinf.sc_state = THREAD_STATE_RUNNING;
    gdt_table[new_thread->kt_tssdesc >> 3].b &= 0xfffffdff;
    current_thread = new_thread;

    do_context_switch(new_thread->kt_tssdesc, new_thread->kt_cr0, new_thread->kt_tss->cr3);

    // process any pending timeout events
    return;
}