1 23
Operating System System Call & Debugging Technique
진주영 [email protected] Embedded Software Lab.
Embedded Software Lab. 2 System Call 23
• 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
Embedded Software Lab. 3 System Call - example 23
Embedded Software Lab. 4 System Call – Practice (overview) 23
• 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
Embedded Software Lab. 5 System Call – Practice (1) 23
• cd ${KERNEL_SRC_DIR}/kernel • vim sysjjy.c
• vim Makefile
Embedded Software Lab. 6 System Call – Practice (2) 23
• cd ${KERNEL_SRC_DIR}/arch/x86/entry/syscalls • vim syscall_64.tbl
The index of System Call The name of Pre-defined System Call
Embedded Software Lab. 7 System Call – Practice (3) 23
• cd ${KERNEL_SRC_DIR}/include/linux • vim syscalls.h
Embedded Software Lab. 8 System Call – Practice (4) 23
Embedded Software Lab. 9 Debugging Technique – printk 23
• 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
Embedded Software Lab. 10 Debugging Technique – strace 23
• The function shows parameters, returned values and system calls from each command • Usage: $ strace command – Example1: strace ls – Example2: strace ./application
Embedded Software Lab. 11 Debugging Technique – ftrace 23
• 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
Embedded Software Lab. 12 Debugging Technique – ftrace 23
• example
$ cat trace_pipe
Embedded Software Lab. 13 Process 23
• 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
Embedded Software Lab. 14 Process in Linux 23
${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);
Embedded Software Lab. 15 Process Address Space 23
• 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
Embedded Software Lab. 16 Process Address Space in Linux 23
• 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
Embedded Software Lab. 17 Process Address Space in Linux 23
• Memory descriptor(struct mm_struct) includes all information
related to the process address space …
Embedded Software Lab. 18 Process Address Space in Linux 23
Embedded Software Lab. 19 Process Address Space Information in Linux 23
※ Reference: show_map() • /proc/[pid]/maps - ${KERNEL_SRC_DIR}/fs/proc/task_mmu.c
Memory Region 1 Memory Region 2
Memory Region 3 …
Embedded Software Lab. 20 Process Address Space Information in Linux 23
※ Reference: show_smap() • /proc/[pid]/smaps - ${KERNEL_SRC_DIR}/fs/proc/task_mmu.c
Memory Region 1
Memory Region 2
Embedded Software Lab. 21 List Head 23
• 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)
Embedded Software Lab. 22 List Head 23
• Doubly linked list is pre-defined in Linux kernel – ${KERNEL_SRC_DIR}/include/linux/list.h – You don’t need to implement linked list
Embedded Software Lab. 23 Data Structure in Linux kernel 23
• 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
Embedded Software Lab.