1 Operating System System Call & Debugging Technique 진주영 jjysienna@gmail.com
System Call 2 A way for user-space programs to interact with the kernel System Call enables application programs in user-mode to use functionalities in kernel When one calls system call, system mode will be changed from user-mode to kernel-mode After the job finishes, the mode will be back to user-mode and carry on doing jobs which has been on hold
System Call - example 3
System Call Practice (overview) 4 3 Steps for implementation of your own system call Define a system call Register the system call to SYSCALL table Call it in a user-level application
System Call Practice (1) 5 cd ${KERNEL_SRC_DIR}/kernel vim sysjjy.c vim Makefile
System Call Practice (2) 6 cd ${KERNEL_SRC_DIR}/arch/x86/entry/syscalls vim syscall_64.tbl The index of System Call The name of Pre-defined System Call
System Call Practice (3) 7 cd ${KERNEL_SRC_DIR}/include/linux vim syscalls.h
System Call Practice (4) 8
Debugging Technique printk 9 The function whose job is printing in Kernel The function works similarly to printf() function in C library This function can be called everywhere in kernel We can check logs, printed by printk(), by commands such as /proc/kmsg, printk trace, dmesg /proc/kmsg dmesg
Debugging Technique strace 10 The function shows parameters, returned values and system calls from each command Usage: $ strace command Example1: strace ls Example2: strace./application
Debugging Technique ftrace 11 The function is used to debug or trace the actions in kernel Event tracing (interrupt, scheduling, filesystem, ) Kernel function tracing (all kernel functions, stack usage, ) Latency tracing (wakeup, wakeup_rt, irqsoft, preemptoff, ) /sys/kernel/debug/tracing /sys/kernel/debug/tracing/events
Debugging Technique ftrace 12 example $ cat trace_pipe
Process 13 Processor: Central Processing Unit (CPU) ex. Pentium, Core i7 Program: instruction set to let the computer work Process: executing instance of the program and all context which is produced during executing the instance
Process in Linux 14 ${KERNEL_SRC_DIR}/include/linux/sched.h struct task_struct Process Descriptor Represents a process and maintains the information of a process Current macro You can get the task_struct of current process using current macro in kernel ex. printk( %d, current->pid);
Process Address Space 15 Each process has its own process address space that consists of all virtual addresses that the process is allowed to use The interval of virtual addresses = Memory region
Process Address Space in Linux 16 Memory descriptor(struct mm_struct) includes all information related to the process address space Linux implements a memory region as an object (struct vm_area_struct) struct mm_struct and struct vm_area_struct are defined in ${KERNEL_SRC_DIR}/include/linux/mm_types.h
Process Address Space in Linux 17 Memory descriptor(struct mm_struct) includes all information related to the process address space
Process Address Space in Linux 18
Process Address Space Information in Linux 19 /proc/[pid]/maps Reference: show_map() - ${KERNEL_SRC_DIR}/fs/proc/task_mmu.c Memory Region 1 Memory Region 2 Memory Region 3
Process Address Space Information in Linux 20 /proc/[pid]/smaps Reference: show_smap() - ${KERNEL_SRC_DIR}/fs/proc/task_mmu.c Memory Region 1 Memory Region 2
List Head 21 Doubly linked list is pre-defined in Linux kernel ${KERNEL_SRC_DIR}/include/linux/list.h You don t need to implement linked list Example)
List Head 22 Doubly linked list is pre-defined in Linux kernel ${KERNEL_SRC_DIR}/include/linux/list.h You don t need to implement linked list
Data Structure in Linux kernel There are many data structure to be pre-defined in Linux kernel Example) Doubly Linked List: ${KERNEL_SRC_DIR}/include/linux/list.h Bitmap: ${KERNEL_SRC_DIR}/include/linux/bitmap.h Red-Black Tree: ${KERNEL_SRC_DIR}/include/linux/rbtree.h Radix Tree: ${KERNEL_SRC_DIR}/include/linux/radix-tree.h Hash Table: ${KERNEL_SRC_DIR}/include/linux/hashtable.h