본문 바로가기

리눅스 커널의 구조와 원리

(88)
[리눅스커널] IRQ 스레드를 생성하는 샘플 코드 살펴보기 IRQ 스레드 생성 예제 코드 분석 이번에는 IRQ 스레드를 생성하는 예제 코드를 소개합니다. 실제 request_threaded_irq() 함수를 호출해서 IRQ 스레드를 생성하는 과정을 살펴보겠습니다. 분석할 코드는 다음과 같습니다.[https://elixir.bootlin.com/linux/v4.14.30/source/drivers/usb/dwc3/gadget.c]1 static int dwc3_gadget_start(struct usb_gadget *g,2 struct usb_gadget_driver *driver)3 {4 struct dwc3 *dwc = gadget_to_dwc(g);5 unsigned long flags;6 int ret = 0;7 int irq;89 irq = dwc->ir..
[리눅스커널] IRQ 스레드(threaded IRQ)에 대한 소개 IRQ 스레드란리눅스 커널을 익히는 과정에서 만나는 걸림돌 중 하나가 어려운 용어입니다. 어려운 개념을 낯선 용어로 설명하니 이해하기 어렵죠. IRQ Thread의 의미를 알기 전에 IRQ란 용어부터 알아볼까요? IRQ는 Interrupt Request의 약자로 하드웨어에서 발생한 인터럽트를 처리 한다는 의미입니다. 조금 더 구체적으로 인터럽트 발생 후 인터럽트 핸들러까지 처리하는 흐름입니다.  IRQ Thread란 뭘까요? 인터럽트 핸들러에서는 처리하면 오래 걸리는 일을 수행하는 프로세스입니다. 인터럽트 후반부 처리를 위한 인터럽트 처리 전용 프로세스입니다. 리눅스 커널에서는 IRQ Thread를 irq_thread라고도 합니다. 리눅스 커널 커뮤니티에서는 threaded IRQ 방식이라고도 합니다. ..
[리눅스커널] 인터럽트 후반부 기법은 왜 적용할까? 인터럽트 후반부 기법을 적용하는 이유 인터러트 후반부 기법을 쓰는 이유에 대해 알아보기 전에 커널이 인터럽트를 어떤 방식으로 처리하는지 살펴볼 필요가 있습니다. 5장에서 배운 내용을 정리해보겠습니다.   1. 인터럽트가 발생하면 커널은 실행 중인 프로세스를 멈추고 인터럽트 벡터를 실행해서 인터럽트 핸들러를 실행합니다.   2. 인터럽트 핸들러는 짧고 빨리 실행해야 합니다.   3. 인터럽트를 처리하는 구간이 인터럽트 컨택스트인데 이를 in_interrupt() 함수가 알려줍니다. 인터럽트 후반부 기법을 적용해야 하는 이유는 인터럽트 컨택스트에서 빨리 실행을 끝내야 하기 때문입니다. 인터럽트는 실행 중인 코드를 멈추고 인터럽트를 핸들링하기 때문입니다. 자연스럽게 임베디드 리눅스 개발자뿐만 아니라 임베디드 ..
[LinuxKernel][ARM] char buf[32]; vs char buf[32]={0}; Quite interesting patch was released under the following url.https://source.codeaurora.org/quic/la/kernel/msm-3.18/commit/?h=rel/msm-3.18&id=a0039b1e721b7b3ee1cbe7f7f9d44d451ac74543 The detailed patch is to initialize the stack array with a different way as below.-------------------------------------------------------------------------------------usb : dwc3: Initialize kernel stack variables pro..
[LinuxKernel][ARM] Aarch64: How stack is pushed in Aarch64? [1]: SP address is now FFFFFFEB67BE7A40[2]: With "str x21,[SP,#-0x30]!" instruction, the stack is pushed up to 0x30 byte.[3]: X19 and X20 is pushed into stack.[4]: X29 and X30 is pushed into stack. 15 collision = find_worker_executing_work(pool, work);16 if (unlikely(collision)) {17 move_linked_works(work, &collision->scheduled, NULL);18 return;19 } ZSX:FFFFFF8B40CE71B8|F81D0FF5 set_next_entity:..
[LinuxKernel] Crash-Utility: add new command "ps -e" Why I added new features to crash tool?Sometimes, some linux kernel in another platform are missing struct task_struct.sched_info.last_arrival element. For this matter, it is hard to know how the processes are executed at the time of order.The "ps -e" command allows for listing the process at the time of order based on execution launching time.crash> ps -eps: exec_start - task_struct.se.exec_sta..
[LinuxKernel] Trace32(T32) How to use offsetof/container_of macro? OverviewWhen debugging ramdump with stability issues, I have been spending most of time casting various data structure as belows.v.v %s (struct task_struct*)0xC1917FCCFor this matter, I made several macros to minimize the debugging time.The definition of the macro is below.sYmbol.NEW.MACRO offsetof(type,member) ((int)(&((type*)0)->member))sYmbol.NEW.MACRO container_of(ptr,type,member) ((type *)(..
[LinuxKernel][Spinlock] spin_lock(): in-depth code review Now, let me look into the spinlock implmentation in more details.After analyzing the assembly code, R2 is key debugging signature which is the original value of spinlock owner. Code Review: arch_spin_lock(part 1) -> If the spinlock is acquired sucessfully.Let me assume tickets.next=0x0, tickets.owner=0x0(spinlock is not held) before _raw_spin_lock() is executed[1]: R2: (raw_spinlock_t *)lock is ..