You are on page 1of 2

Schema chiamate sistema

Libreria NPTL
pthread_create mutex_lock mutex_unlock pthread_exit Clib
sem_wait sem_post return fopen fread fwrite
pthread_join

glibc

clone fork exec* exit wait/waitpid nanosleep open read write

void syscall(syscall_number, ...) {


SYSCALL Passaggio modo U->S
}

void system_call() {}

System call service routines

fork, clone sys_clone exec* sys_execve


mutex_lock, sem_wait, wait/waitpid sys_wait
sys_futex(wait)
pthread_join
nanosleep sys_nanosleep
mutex_unlock, sem_post sys_futex(wakeup)
open sys_open
return, pthread_exit sys_exit sys_read
read
exit sys_exit_group write sys_write
Moduli del sistema operativo
System call Service routines Gestione dello stato Routine dello scheduler
system_call(...) { sys_clone(...) { wake_up/wake_up_process(...) { schedule(...) {
call a servizio opportuno(); check_preempt_cur(); for (ogni task in waitqueue) { prev = CURR;
if (modo_rientro == U && } task->state = PRONTO; if (prev->stato == ATTESA ||
,→ TIF_NEED_RESCHED == 1) { enqueue_task(task); //NN prev terminato) {
schedule(); sys_nanosleep(...) { if (flag==EXCLUSIVE) break; dequeue_task(prev); //NN
} curr->state = ATTESA; } }
SYSRET schedule_timeout(); check_preempt_curr(); next = pick_next_task();
} } } if (next != prev) {
// MACRO
sys_futex(wait, ...) { wait_X(...) { context_switch(prev, next)
Interrupt routines wait_X(...); CURR->state = ATTESA; }
} schedule(); TIF_NEED_RESCHED = 0
void R_int_clock(...) {
// con periodicita' opportuna } }
sys_futex(wakeup, ...) {
CURR->sched_class->task_tick(); wake_up_process(padre); task_tick_X(...) {
// con periodicita' opportuna } Gestione tempo
Controlla_timer(); if (QdT scaduto) {
if (modo_rientro == U && schedule_timeout(...) { resched();
sys_execve(...) {
TIF_NEED_RESCHED == 1) { add_timer(); //NN }
,→ }
schedule(); schedule(); }
} sys_read/write/open(...) { del_timer(); //NN
} check_preempt_curr(...) {
IRET wait_X(...);
if (occorre invocare scheduler) {
} }
Controlla_timer(...) { resched();
void R_int_X(...) { sys_wait(...) { for (ogni timeout creato) { }
wakeup(...); curr->state = ATTESA; if (timeout scaduto) { }
if (modo_rientro == U && schedule(); wakeup_process(...);
} pick_next_task(...) {
,→ TIF_NEED_RESCHED == 1) { }
} for (ogni classe di scheduling cl,
schedule();
sys_exit(...) { } ,→ in ordine gerarchico) {
}
wake_up_process(padre); task = cl->pick_next_task(); //NN
IRET
schedule(); if (task) return task;
}
} }
}
sys_exit_group(...) {
for (tutti i processi resched(...) {
,→ con stesso TGID) { TIF_NEED_RESCHED = 1;
sys_exit(...) }
}
}

You might also like