1 MINIX3 SYSTEM TASK MINIX3 SYSTEM TASK Cátedra: Diseño e Implementación de Sistemas Operativos UTN-FRSF Tomado de: Operating Systems Design and Implementation, Third Edition
2 Generalidades 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.
3 Generalidades 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.
4 Mensajes a SYSTASK Message type FromMeaning sys_forkPMA process has forked sys_execPMSet stack pointer after EXEC call sys_exitPMA process has exited sys_nicePMSet scheduling priority sys_privctlRSSet or change privileges sys_tracePM Carry out an operation of the PTRACE call sys_killPM, FS, TTYSend signal to a process after KILL call sys_getksigPMPM is checking for pending signals sys_endksigPMPM has finished processing signal
5 Mensajes a SYSTASK Message typeFromMeaning sys_sigsendPMSend a signal to a process sys_sigreturnPMCleanup after completion of a signal sys_irqctlDriversEnable, disable, or configure interrupt sys_devioDriversRead from or write to an I/O port sys_sdevioDriversRead or write string from/to I/O port sys_vdevioDriversCarry out a vector of I/O requests sys_int86DriversDo a real-mode BIOS call sys_newmapPMSet up a process memory map sys_segctlDriversAdd segment and get selector (far data access)
6 Mensajes a SYSTASK Message typeFromMeaning sys_memsetPMWrite char to memory area sys_umapDriversConvert virtual address to physical address sys_vircopyFS, DriversCopy using pure virtual addressing sys_physcopyDriversCopy using physical addressing sys_virvcopyAnyVector of VCOPY requests sys_physvcopyAnyVector of PHYSCOPY requests sys_timesPMGet uptime and process times sys_setalarmPM, FS, DriversSchedule a synchronous alarm sys_abortPM, TTYPanic: MINIX is unable to continue sys_getinfoAnyRequest system information
7 Mensajes 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.
8 Mensajes 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.
9 Implementacion 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
10 Implementacion de SYSTASK 09786 /* 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 }
11 Implementacion 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; is_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(unsigned)(call_nr-KERNEL_CALL) .", "description": "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; is_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(unsigned)(call_nr-KERNEL_CALL) ." title="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; is_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; iFS read 2.FS->DD Si no esta en cache rw_block() 3.DD->SYSTASK sys_devio 4.SYSTASK->DD ACK 5.SYSTASK->DD INTERRUPT 6.DD->SYSTASK sys_copy from kernel to FS cache 7.SYSTASK->DD ACK 8.DD->FS ACK 9.FS->SYSTASK sys_copy from FS cache to user buffer 10.SYSTASK->FS ACK 11.FS->USER ACK" class="image_link uk-text-large uk-margin-small-left uk-margin-small-right"> 14 Impacto en Performance 1.USER->FS read 2.FS->DD Si no esta en cache rw_block() 3.DD->SYSTASK sys_devio 4.SYSTASK->DD ACK 5.SYSTASK->DD INTERRUPT 6.DD->SYSTASK sys_copy from kernel to FS cache 7.SYSTASK->DD ACK 8.DD->FS ACK 9.FS->SYSTASK sys_copy from FS cache to user buffer 10.SYSTASK->FS ACK 11.FS->USER ACK { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.es/14/4325006/slides/slide_14.jpg", "name": "Impacto en Performance 1.USER->FS read 2.FS->DD Si no esta en cache rw_block() 3.DD->SYSTASK sys_devio 4.SYSTASK->DD ACK 5.SYSTASK->DD INTERRUPT 6.DD->SYSTASK sys_copy from kernel to FS cache 7.SYSTASK->DD ACK 8.DD->FS ACK 9.FS->SYSTASK sys_copy from FS cache to user buffer 10.SYSTASK->FS ACK 11.FS->USER ACK", "description": "Impacto en Performance 1.USER->FS read 2.FS->DD Si no esta en cache rw_block() 3.DD->SYSTASK sys_devio 4.SYSTASK->DD ACK 5.SYSTASK->DD INTERRUPT 6.DD->SYSTASK sys_copy from kernel to FS cache 7.SYSTASK->DD ACK 8.DD->FS ACK 9.FS->SYSTASK sys_copy from FS cache to user buffer 10.SYSTASK->FS ACK 11.FS->USER ACK", "width": "800" } 15 Impacto en Performance 1.USER->FS read 2.FS->SYSTASK sys_copy from FS cache to user buffer 3.SYSTASK->FS ACK 4.FS->USER ACK
12 Implementacion 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 */
13 Implementacion 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 }
14 Impacto en Performance 1.USER->FS read 2.FS->DD Si no esta en cache rw_block() 3.DD->SYSTASK sys_devio 4.SYSTASK->DD ACK 5.SYSTASK->DD INTERRUPT 6.DD->SYSTASK sys_copy from kernel to FS cache 7.SYSTASK->DD ACK 8.DD->FS ACK 9.FS->SYSTASK sys_copy from FS cache to user buffer 10.SYSTASK->FS ACK 11.FS->USER ACK
15 Impacto en Performance 1.USER->FS read 2.FS->SYSTASK sys_copy from FS cache to user buffer 3.SYSTASK->FS ACK 4.FS->USER ACK