View
214
Download
0
Category
Preview:
Citation preview
MINIX3MINIX3SYSTEM TASKSYSTEM TASK
Cátedra: Diseño e Implementación de
Sistemas Operativos UTN-FRSF
Tomado de: Operating Systems Design and Implementation, Third Edition
GeneralidadesGeneralidades
• Como consecuencias de que la mayor cantidad de componentes están fuera del kernel como procesos independientes, ellos están inhibidos de realizar ciertas operaciones privilegidadas.
Manipulación de Tablas del Kernel Operaciones de Entrada/Salida Copias de areas de memoria entre procesos
•La solución es que el kernel ofrezca esos servicios a Drivers y Servers (no a procesos de usuario ordinarios).
• Estos servicios se brindan a traves de un proceso que se llama SYSTEM TASK (SYSTASK) que es un representante del kernel.
• SYSTASK se compila en el mismo binario que el kernel y accede a todas sus variables y funciones.
GeneralidadesGeneralidades• Un ejemplo de uso de la SYSTASK por parte de un Device Driver en modo usuario es el uso de la Kernel call sys_irqctl para instalar un handler de interrupción.
•En realidad lo que hace la SYSTASK es instalar un generic_handler que se encarga de notificar a la tarea correspondiente del Device Driver.
• El programa main() de la SYSTASK funciona en forma similar al resto de las tareas. Es un loop que espera una petición a través de un mensaje, despacha el procedimiento correspondiente y retorna una respuesta.
• El programa main() se encuentra en system.c del directorio del kernel. El resto de los procedimientos en el directorio system.
Mensajes a SYSTASKMensajes a SYSTASK
Message type
From Meaning
sys_fork PM A process has forked
sys_exec PM Set stack pointer after EXEC call
sys_exit PM A process has exited
sys_nice PM Set scheduling priority
sys_privctl RS Set or change privileges
sys_trace PMCarry out an operation of the PTRACE
call
sys_kill PM, FS, TTY Send signal to a process after KILL call
sys_getksig PM PM is checking for pending signals
sys_endksig PM PM has finished processing signal
Mensajes a SYSTASKMensajes a SYSTASK
Message type From Meaning
sys_sigsend PM Send a signal to a process
sys_sigreturn PM Cleanup after completion of a signal
sys_irqctl Drivers Enable, disable, or configure interrupt
sys_devio Drivers Read from or write to an I/O port
sys_sdevio Drivers Read or write string from/to I/O port
sys_vdevio Drivers Carry out a vector of I/O requests
sys_int86 Drivers Do a real-mode BIOS call
sys_newmap PM Set up a process memory map
sys_segctl Drivers Add segment and get selector (far data access)
Mensajes a SYSTASKMensajes a SYSTASK
Message type From Meaning
sys_memset PM Write char to memory area
sys_umap Drivers Convert virtual address to physical address
sys_vircopy FS, Drivers Copy using pure virtual addressing
sys_physcopy Drivers Copy using physical addressing
sys_virvcopy Any Vector of VCOPY requests
sys_physvcopy Any Vector of PHYSCOPY requests
sys_times PM Get uptime and process times
sys_setalarm PM, FS, Drivers Schedule a synchronous alarm
sys_abort PM, TTY Panic: MINIX is unable to continue
sys_getinfo Any Request system information
Mensajes a SYSTASKMensajes a SYSTASK
• Los Kernel Calls sys_irqctl, sys_devio, sys_sdevio, y sys_vdevio son provistos por MINIX3 para soportar los Device Drivers en espacio de usuario.
• sys_newmap es invocado por el PM cuando ha cambiado la memoria asignada al proceso, por lo tanto el Kernel debe actualizar sus tablas.
• Sys_segctl y sys_memset brindan una forma segura de que el proceso pueda acceder a areas de memoria fuera de su espacio de usuario. El area de memoria desde 0xa0000 to 0xfffff se reserva para dispositivos de E/S. Sys_segctl es usaso por los Device Drivers para obtener el Selector del Segmento que le permitirá acceder a ese rango de memoria.
Mensajes a SYSTASKMensajes a SYSTASK
• sys_memset se usa para escribir datos en un area de memoria que no le pertenece al proceso, como por ejemplo para poner Ceros en ella.
•Sys_umap convierte direcciones virtuales en direcciones físicas.
•Sys_vircopy y sys_physcopy copian regiones de memoria utilizando direccionamiento virtual o físico.
•sys_virvcopy y sys_physvcopy son las versiones vectorizadas de las previsas.
•sys_getinfo maneja un amplio rango de pedidos de información al Kernel.
Implementacion de SYSTASKImplementacion de SYSTASK 09753 /*===========================================================================* 09754 * sys_task * 09755 *===========================================================================*/ 09756 PUBLIC void sys_task() 09757 { 09758 /* Main entry point of sys_task. Get the message and dispatch on type. */ 09759 static message m; 09760 register int result; 09761 register struct proc *caller_ptr; 09762 unsigned int call_nr; 09763 int s; 09765 /* Initialize the system task. */ 09766 initialize(); 09768 while (TRUE) { 09769 /* Get work. Block and wait until a request message arrives. */ 09770 receive(ANY, &m); 09771 call_nr = (unsigned) m.m_type - KERNEL_CALL; 09772 caller_ptr = proc_addr(m.m_source); 09773 09774 /* See if the caller made a valid request and try to handle it. */ 09775 if (! (priv(caller_ptr)->s_call_mask & (1<<call_nr))) { 09776 kprintf("SYSTEM: request %d from %d denied.\n", call_nr,m.m_source); 09777 result = ECALLDENIED; /* illegal message type */ 09778 } else if (call_nr >= NR_SYS_CALLS) { /* check call number */ 09779 kprintf("SYSTEM: illegal request %d from %d.\n", call_nr,m.m_source); 09780 result = EBADREQUEST; /* illegal message type */ 09781 } 09782 else { 09783 result = (*call_vec[call_nr])(&m); /* handle the kernel call */ 09784 }
Implementacion de SYSTASKImplementacion de SYSTASK09786 /* Send a reply, unless inhibited by a handler function. Use the kernel 09787 * function lock_send() to prevent a system call trap. The destination 09788 * is known to be blocked waiting for a message. 09789 */ 09790 if (result != EDONTREPLY) { 09791 m.m_type = result; /* report status of call */ 09792 if (OK != (s=lock_send(m.m_source, &m))) { 09793 kprintf("SYSTEM, reply to %d failed: %d\n", m.m_source, s); 09794 } 09795 } 09796 } 09797 }
Implementacion de SYSTASKImplementacion de SYSTASK 09747 #define map(call_nr, handler) \ 09748 {extern int dummy[NR_SYS_CALLS>(unsigned)(call_nr-KERNEL_CALL) ? 1:-1];} \ 09749 call_vec[(call_nr-KERNEL_CALL)] = (handler)
09799 /*===========================================================================* 09800 * initialize * 09801 *===========================================================================*/ 09802 PRIVATE void initialize(void) 09803 { 09804 register struct priv *sp; 09805 int i; 09806 09807 /* Initialize IRQ handler hooks. Mark all hooks available. */ 09808 for (i=0; i<NR_IRQ_HOOKS; i++) { 09809 irq_hooks[i].proc_nr = NONE; 09810 } 09811 09812 /* Initialize all alarm timers for all processes. */ 09813 for (sp=BEG_PRIV_ADDR; sp < END_PRIV_ADDR; sp++) { 09814 tmr_inittimer(&(sp->s_alarm_timer)); 09815 } 09816 09817 /* Initialize the call vector to a safe default handler. Some kernel calls 09818 * may be disabled or nonexistant. Then explicitly map known calls to their 09819 * handler functions. This is done with a macro that gives a compile error 09820 * if an illegal call number is used. The ordering is not important here. 09821 */ 09822 for (i=0; i<NR_SYS_CALLS; i++) { 09823 call_vec[i] = do_unused; 09824 }
Implementacion de SYSTASKImplementacion de SYSTASK 09826 /* Process management. */ 09827 map(SYS_FORK, do_fork); /* a process forked a new process */ 09828 map(SYS_EXEC, do_exec); /* update process after execute */ 09829 map(SYS_EXIT, do_exit); /* clean up after process exit */ 09830 map(SYS_NICE, do_nice); /* set scheduling priority */ 09831 map(SYS_PRIVCTL, do_privctl); /* system privileges control */ 09832 map(SYS_TRACE, do_trace); /* request a trace operation */ 09833 09834 /* Signal handling. */ 09835 map(SYS_KILL, do_kill); /* cause a process to be signaled */ 09836 map(SYS_GETKSIG, do_getksig); /* PM checks for pending signals */ 09837 map(SYS_ENDKSIG, do_endksig); /* PM finished processing signal */ 09838 map(SYS_SIGSEND, do_sigsend); /* start POSIX-style signal */ 09839 map(SYS_SIGRETURN, do_sigreturn); /* return from POSIX-style signal */ 09840 09841 /* Device I/O. */ 09842 map(SYS_IRQCTL, do_irqctl); /* interrupt control operations */ 09843 map(SYS_DEVIO, do_devio); /* inb, inw, inl, outb, outw, outl */ 09844 map(SYS_SDEVIO, do_sdevio); /* phys_insb, _insw, _outsb, _outsw */ 09845 map(SYS_VDEVIO, do_vdevio); /* vector with devio requests */ 09846 map(SYS_INT86, do_int86); /* real-mode BIOS calls */ 09847 09848 /* Memory management. */ 09849 map(SYS_NEWMAP, do_newmap); /* set up a process memory map */ 09850 map(SYS_SEGCTL, do_segctl); /* add segment and get selector */ 09851 map(SYS_MEMSET, do_memset); /* write char to memory area */
Implementacion de SYSTASKImplementacion de SYSTASK 09853 /* Copying. */ 09854 map(SYS_UMAP, do_umap); /* map virtual to physical address */ 09855 map(SYS_VIRCOPY, do_vircopy); /* use pure virtual addressing */ 09856 map(SYS_PHYSCOPY, do_physcopy); /* use physical addressing */ 09857 map(SYS_VIRVCOPY, do_virvcopy); /* vector with copy requests */ 09858 map(SYS_PHYSVCOPY, do_physvcopy); /* vector with copy requests */ 09859 09860 /* Clock functionality. */ 09861 map(SYS_TIMES, do_times); /* get uptime and process times */ 09862 map(SYS_SETALARM, do_setalarm); /* schedule a synchronous alarm */ 09863 09864 /* System control. */ 09865 map(SYS_ABORT, do_abort); /* abort MINIX */ 09866 map(SYS_GETINFO, do_getinfo); /* request system information */ 09867 }
Impacto en PerformanceImpacto en Performance
1. USER->FS read2. FS->DD Si no esta en cache
rw_block()3. DD->SYSTASK sys_devio4. SYSTASK->DD ACK5. SYSTASK->DD INTERRUPT6. DD->SYSTASK sys_copy from
kernel to FS cache7. SYSTASK->DD ACK8. DD->FS ACK9. FS->SYSTASK sys_copy from FS
cache to user buffer10. SYSTASK->FS ACK11. FS->USER ACK
Impacto en PerformanceImpacto en Performance
1. USER->FS read2. FS->SYSTASK sys_copy from FS
cache to user buffer3. SYSTASK->FS ACK4. FS->USER ACK
Recommended