system call and debugging tools - skkunyx.skku.ac.kr/.../2018/03/syscall-and-kernel-debug.pdf ·...

Post on 27-May-2020

10 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

23

1

Embedded Software Lab.

진주영

jjysienna@gmail.com

Embedded Software Lab.

Operating System

System Call & Debugging Technique

23

2

Embedded Software Lab.

• 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

23

3

Embedded Software Lab.

System Call - example

23

4

Embedded Software Lab.

• 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 (overview)

23

5

Embedded Software Lab.

• cd ${KERNEL_SRC_DIR}/kernel

• vim sysjjy.c

• vim Makefile

System Call – Practice (1)

23

6

Embedded Software Lab.

• cd ${KERNEL_SRC_DIR}/arch/x86/entry/syscalls

• vim syscall_64.tbl

System Call – Practice (2)

The name of Pre-defined System Call

The index of System Call

23

7

Embedded Software Lab.

• cd ${KERNEL_SRC_DIR}/include/linux

• vim syscalls.h

System Call – Practice (3)

23

8

Embedded Software Lab.

System Call – Practice (4)

23

9

Embedded Software Lab.

• 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

Debugging Technique – printk

/proc/kmsg dmesg

23

10

Embedded Software Lab.

• The function shows parameters, returned values and system calls

from each command

• Usage: $ strace command

– Example1: strace ls

– Example2: strace ./application

Debugging Technique – strace

23

11

Embedded Software Lab.

• 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

23

12

Embedded Software Lab.

• example

Debugging Technique – ftrace

$ cat trace_pipe

23

13

Embedded Software Lab.

• 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

23

14

Embedded Software Lab.

• 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 in Linux

${KERNEL_SRC_DIR}/include/linux/sched.h

23

15

Embedded Software Lab.

• 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

23

16

Embedded Software Lab.

• 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

23

17

Embedded Software Lab.

• Memory descriptor(struct mm_struct) includes all information

related to the process address space

Process Address Space in Linux

23

18

Embedded Software Lab.

Process Address Space in Linux

23

19

Embedded Software Lab.

• /proc/[pid]/maps

Process Address Space Information in Linux

※ Reference: show_map()

- ${KERNEL_SRC_DIR}/fs/proc/task_mmu.c

Memory Region 1Memory Region 2Memory Region 3

23

20

Embedded Software Lab.

• /proc/[pid]/smaps

Process Address Space Information in Linux

※ Reference: show_smap()

- ${KERNEL_SRC_DIR}/fs/proc/task_mmu.c

Memory Region 1

Memory Region 2

23

21

Embedded Software Lab.

• Doubly linked list is pre-defined in Linux kernel

– ${KERNEL_SRC_DIR}/include/linux/list.h

– You don’t need to implement linked list

List Head

Example)

23

22

Embedded Software Lab.

• Doubly linked list is pre-defined in Linux kernel

– ${KERNEL_SRC_DIR}/include/linux/list.h

– You don’t need to implement linked list

List Head

23

23

Embedded Software Lab.

• 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

Data Structure in Linux kernel

top related