核心執行緒是怎麼執行

2021-06-16 10:09:30 字數 1395 閱讀 5036

pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)  通過這個函式可以建立核心執行緒,執行乙個指定函式fn。

但是這個fn是怎麼執行的了?

pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)

接著do_fork->copy_process(clone_flags, stack_start, regs, stack_size, child_tidptr, null, trace);->copy_thread(clone_flags, stack_start, stack_size, p, regs);

int

copy_thread(unsigned long clone_flags, unsigned long stack_start,

unsigned long stk_sz, struct task_struct *p, struct pt_regs *regs)

而kernel_thread_helper定義為找到,但注釋已經說的很清楚了,如下:

/*

* shuffle the argument into the correct register before calling the

* thread function. r4 is the thread argument, r5 is the pointer to

* the thread function, and r6 points to the exit function.

*/extern void kernel_thread_helper(void);

asm( ".pushsection .text\n"

" .align\n"

" .type kernel_thread_helper, #function\n"

"kernel_thread_helper:\n"

#ifdef config_trace_irqflags

" bl trace_hardirqs_on\n"

#endif

" msr cpsr_c, r7\n"

" mov r0, r4\n"

" mov lr, r6\n"

" mov pc, r5\n" //將fn賦值給pc,終於原形畢露了

" .size kernel_thread_helper, . - kernel_thread_helper\n"

" .popsection");

先弄到這,當然還有很多程序切換的細節未提到。

Struts是怎麼執行的?

然後actionservlet根據struts config.xml的配置資訊,呼叫loginaction物件去處理這個請求,在此之前,它會將頁面表單的請求資料封裝到loginactionform物件中,並傳遞給loginaction loginaction返回乙個actionforward物件,包...

執行不息的核心執行緒kthread

上節中,我們成功地編譯執行了乙個linux模組。可惜的是,它只有兩個函式,hello init在模組載入時呼叫,hello exit 在模組解除安裝時呼叫。這樣下去,模組縱使有天大的本事,也只能壓縮在這兩個函式中。為了避免這種悲劇發生,本節就來學習一種讓模組在載入後能一直執行下去的方法 核心執行緒。...

執行不息的核心執行緒kthread

要建立乙個核心執行緒有許多種方法,我們這裡要學的是最簡單的一種。開啟include linux kthread.h,你就看到了它全部的api,一共三個函式。structtask struct kthread run int threadfn void data void data,const cha...