Hi, I'm trying to understand the RTAI scheduler (rt_schedule()). Could anyone help ? RT_TASK *task, *new_task; RTIME intr_time, now; int prio, delay, preempt; task = new_task = &rt_linux_task; // SETTING DEFAULT PRIORITY TO LINUX PRIORITY ? prio = RT_LINUX_PRIORITY; //ONESHOT mode if (oneshot_timer) { // GETTING ACTUAL TIME + SIGMA rt_time_h = rdtsc() + rt_half_tick; while ((task = task->next)) { if ((task->state & DELAYED) && task->resume_time <= rt_time_h) { // IF TASK IS WAITING FOR A RESSOURCE (SEMAPHORE..) DROP IT // FROM THE TASKS LIST. if (task->state & (SEMAPHORE | SEND | RPC)) { (task->queue.prev)->next = task->queue.next; (task->queue.next)->prev = task->queue.prev; } // DROP ALL STATE VARIABLES TO 0 task->state &= ~(DELAYED | SEMAPHORE | RECEIVE | SEND | RPC | RETURN); } // SELECT THE HIGHTEST PRIORITY TASK THAT IS READY. if (task->state == READY && task->priority < prio) { new_task = task; prio = task->priority; } } Ok, so far, everything is fine except maybe from the // DROP ALL STATE VARIABLES TO 0 task->state &= ~(DELAYED | SEMAPHORE | RECEIVE | SEND | RPC | RETURN); Why do you want to drop this bit field. If a task is waiting for a semaphore, we don't want to give it access to the CPU, right ?? So, why drop the SEMAPHORE bit to 0 ? If its priority is the highest, it will access the CPU and do nothing... preempt = 0; task = &rt_linux_task; intr_time = shot_fired ? rt_times.intr_time : rt_times.intr_time + rt_times.linux_tick; Ok, there, what does shot_fired stand for ? And what intr_time is supposed to mean ? When does a preemption will occur ? I understand that the following lines will check, for each task resume_time E [rt_time_h; intr_time] if the task state is DELAYED and see if its priority is higher than the current one we have but why do we check this time interval, what does it represent ? while ((task = task->next)) { if ((task->state & DELAYED) && task->priority <= prio && task->resume_time < intr_time) { intr_time = task->resume_time; preempt = 1; } } if (preempt || (!shot_fired && (prio == RT_LINUX_PRIORITY))) { shot_fired = 1; if (preempt) { rt_times.intr_time = intr_time; } delay = (int)(rt_times.intr_time - (now = rdtsc())) - tuned.latency; if (delay >= tuned.setup_time_TIMER_CPUNIT) { delay = imuldiv(delay, TIMER_FREQ, tuned.cpu_freq); } else { delay = tuned.setup_time_TIMER_UNIT; rt_times.intr_time = now + (tuned.setup_time_TIMER_CPUNIT); } outb(delay & 0xFF, 0x40); outb(delay >> 8, 0x40); } } Finally, for the ONESHOT mode, what does the delay stands for ? //PERIODIC else { while ((task = task->next)) { if (task->state == READY && task->priority < prio) { new_task = task; prio = task->priority; } } } Ok, this one should be easy to reply to. I understand that in periodic mode, each task is running at the minimal frequency or is a multiple of it but when a task is created and resumed, it will call the rt_schedule function and the current task will be preempted if the new task priority is higher. So, what's the difference between the periodic and one-shot mode ? Each can preempt the current task, each calls rt_schedule for the same reason (end of task, new task...). So ? Thanks Alex. ____________________________________________________________________ Get free email and a permanent address at http://www.netaddress.com/?N=1 -- [rtl] --- To unsubscribe: echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED] -- For more information on Real-Time Linux see: http://www.rtlinux.org/rtlinux/