src/kernel/trap/clock.c
/**
 * @note cpu`s clock interrupt handler.
 * @param trap_frame
 */
@note cpu`s clock interrupt handler.
@note cpu ` s clock interrupt handler .
static void system_s_clock_handler(trap_frame_t * trap_frame){
    thread_t * self = GET_RUNNING_THREAD();
    if(trap_frame!=NULL){
        if(GET_BIT(trap_frame->sstatus,SSTATUS_SPP)){
            atomic_inc(&self->tms.tms_stime);
            if(self->p_thread!=NULL){
                atomic_inc(&self->p_thread->tms.tms_cstime);
            }
        }
        else{
            atomic_inc(&self->tms.tms_utime);
            if(self->p_thread!=NULL) {
                atomic_inc(&self->p_thread->tms.tms_cutime);
            }
        }
    }
    system_clock_t * clock = get_cpu_var_no_preempt(System_S_Clocks);
    if(clock->status == SYSTEM_CLOCK_STATUS_AVAILABLE){
        clock->counter++;
    }
    else if(clock->status == SYSTEM_CLOCK_STATUS_STOP){
    }
    else{
        system_s_clock_stop();
        trap_unregister(get_cpu_id(),PLATFORM_IRQ_S_TIMER,true);
    }
    if(clock->counter >= clock->scheduler_trigger_number){
        clock->counter = 0;
        threads_set_resched();
    }
    clock->time = r_time();
    sbi_set_timer(clock->time + clock->interval);
    intr_on();
}
static void system_s_clock_handler ( trap_frame_t * trap_frame ) { thread_t * self = GET_RUNNING_THREAD ( ) ; if ( trap_frame != NULL ) { if ( GET_BIT ( trap_frame -> sstatus , SSTATUS_SPP ) ) { atomic_inc ( & self -> tms . tms_stime ) ; if ( self -> p_thread != NULL ) { atomic_inc ( & self -> p_thread -> tms . tms_cstime ) ; } } else { atomic_inc ( & self -> tms . tms_utime ) ; if ( self -> p_thread != NULL ) { atomic_inc ( & self -> p_thread -> tms . tms_cutime ) ; } } } system_clock_t * clock = get_cpu_var_no_preempt ( System_S_Clocks ) ; if ( clock -> status == SYSTEM_CLOCK_STATUS_AVAILABLE ) { clock -> counter ++ ; } else if ( clock -> status == SYSTEM_CLOCK_STATUS_STOP ) { } else { system_s_clock_stop ( ) ; trap_unregister ( get_cpu_id ( ) , PLATFORM_IRQ_S_TIMER , true ) ; } if ( clock -> counter >= clock -> scheduler_trigger_number ) { clock -> counter = 0 ; threads_set_resched ( ) ; } clock -> time = r_time ( ) ; sbi_set_timer ( clock -> time + clock -> interval ) ; intr_on ( ) ; }
@note cpu`s clock interrupt handler.
@note cpu ` s clock interrupt handler .
/*
     * TOP HALF with irq off
     * and kernel preempt can`t execute
     * because of irq is off.
     */ // running in kernel mode // running in user mode //the next clock will set in scheduler //STOPPED //DEAD // set the resched flag /*
     * BOTTOM HALF
     */ // turn on irq...