日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > linux >内容正文

linux

Linux数据报文接收发送总结4

發(fā)布時(shí)間:2025/4/5 linux 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux数据报文接收发送总结4 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

二、系統(tǒng)初始化

?

Linux驅(qū)動(dòng),內(nèi)核協(xié)議棧等等模塊在具備接收網(wǎng)卡數(shù)據(jù)包之前,要做很多的準(zhǔn)備工作才行。比如要提前創(chuàng)建好ksoftirqd內(nèi)核線程,要注冊(cè)好各個(gè)協(xié)議對(duì)應(yīng)的處理函數(shù),網(wǎng)絡(luò)設(shè)備子系統(tǒng)要提前初始化好,網(wǎng)卡要啟動(dòng)好。只有這些都Ready之后,我們才能真正開始接收數(shù)據(jù)包。那么我們現(xiàn)在來看看這些準(zhǔn)備工作都是怎么做的。

?

Linux的子系統(tǒng)、模塊均定義了一定的啟動(dòng)級(jí)別,在start_kernel函數(shù)中,按順序啟動(dòng)

/* initcalls are now grouped by functionality into separate * subsections. Ordering inside the subsections is determined* by link order. * For backwards compatibility, initcall() puts the call in * the device init subsection.** The `id' arg to __define_initcall() is needed so that multiple initcalls* can point at the same handler without causing duplicate-symbol build errors.*/#define __define_initcall(fn, id) \static initcall_t __initcall_##fn##id __used \__attribute__((__section__(".initcall" #id ".init"))) = fn; \LTO_REFERENCE_INITCALL(__initcall_##fn##id)/** Early initcalls run before initializing SMP.** Only for built-in code, not modules.*/ #define early_initcall(fn) __define_initcall(fn, early)/** A "pure" initcall has no dependencies on anything else, and purely* initializes variables that couldn't be statically initialized.** This only exists for built-in code, not for modules.* Keep main.c:initcall_level_names[] in sync.*/ #define pure_initcall(fn) __define_initcall(fn, 0)#define core_initcall(fn) __define_initcall(fn, 1) #define core_initcall_sync(fn) __define_initcall(fn, 1s) #define postcore_initcall(fn) __define_initcall(fn, 2) #define postcore_initcall_sync(fn) __define_initcall(fn, 2s) #define arch_initcall(fn) __define_initcall(fn, 3) #define arch_initcall_sync(fn) __define_initcall(fn, 3s) #define subsys_initcall(fn) __define_initcall(fn, 4) #define subsys_initcall_sync(fn) __define_initcall(fn, 4s) #define fs_initcall(fn) __define_initcall(fn, 5) #define fs_initcall_sync(fn) __define_initcall(fn, 5s) #define rootfs_initcall(fn) __define_initcall(fn, rootfs) #define device_initcall(fn) __define_initcall(fn, 6) #define device_initcall_sync(fn) __define_initcall(fn, 6s) #define late_initcall(fn) __define_initcall(fn, 7) #define late_initcall_sync(fn) __define_initcall(fn, 7s)#define __initcall(fn) device_initcall(fn)

2.1 創(chuàng)建ksoftirqd內(nèi)核線程

?

Linux的軟中斷都是在專門的內(nèi)核線程(ksoftirqd)中進(jìn)行的,因此我們非常有必要看一下這些進(jìn)程是怎么初始化的,這樣我們才能在后面更準(zhǔn)確地了解收包過程。該進(jìn)程數(shù)量不是1個(gè),而是N個(gè),其中N等于你的機(jī)器的核數(shù)。

?

系統(tǒng)初始化的時(shí)候執(zhí)行spawn_ksoftirq -> smpboot_register_percpu_thread->smpboot_register_percpu_thread_cpumask->__smpboot_create_thread,

該函數(shù)創(chuàng)建出softirqd內(nèi)核線程(位于kernel/softirq.c, 線程主函數(shù)smpboot_thread_fn)。

?

相關(guān)代碼如下:

//file: kernel/softirq.c static struct smp_hotplug_thread softirq_threads = {.store = &ksoftirqd,.thread_should_run = ksoftirqd_should_run,.thread_fn = run_ksoftirqd,.thread_comm = "ksoftirqd/%u",}; static __init int spawn_ksoftirqd(void){register_cpu_notifier(&cpu_nfb); // 為每個(gè)CPU創(chuàng)建一個(gè)處理軟件中斷的線程BUG_ON(smpboot_register_percpu_thread(&softirq_threads));return 0; } early_initcall(spawn_ksoftirqd); // 將函數(shù)放至對(duì)應(yīng)級(jí)別的初始化位置//file : kernel/smp_boot.c static int smpboot_thread_fn(void *data) {struct smpboot_thread_data *td = data;struct smp_hotplug_thread *ht = td->ht;while (1) {set_current_state(TASK_INTERRUPTIBLE);preempt_disable();if (kthread_should_stop()) {__set_current_state(TASK_RUNNING);preempt_enable();/* cleanup must mirror setup */if (ht->cleanup && td->status != HP_THREAD_NONE)ht->cleanup(td->cpu, cpu_online(td->cpu));kfree(td);return 0;}if (kthread_should_park()) {__set_current_state(TASK_RUNNING);preempt_enable();if (ht->park && td->status == HP_THREAD_ACTIVE) {BUG_ON(td->cpu != smp_processor_id());ht->park(td->cpu);td->status = HP_THREAD_PARKED;}kthread_parkme();/* We might have been woken for stop */continue;}BUG_ON(td->cpu != smp_processor_id());/* Check for state change setup */switch (td->status) {case HP_THREAD_NONE:__set_current_state(TASK_RUNNING);preempt_enable();if (ht->setup)ht->setup(td->cpu);td->status = HP_THREAD_ACTIVE;continue;case HP_THREAD_PARKED:__set_current_state(TASK_RUNNING);preempt_enable();if (ht->unpark)ht->unpark(td->cpu);td->status = HP_THREAD_ACTIVE;continue;}if (!ht->thread_should_run(td->cpu)) { // 檢測(cè)軟件是否有可運(yùn)行軟中斷preempt_enable_no_resched();schedule();} else {__set_current_state(TASK_RUNNING);preempt_enable();ht->thread_fn(td->cpu); // 執(zhí)行注冊(cè)的軟件中斷函數(shù)}} }

當(dāng)ksoftirqd被創(chuàng)建出來以后,它就會(huì)進(jìn)入自己的線程循環(huán)函數(shù)ksoftirqd_should_run和run_ksoftirqd了。不停地判斷有沒有軟中斷需要被處理。這里需要注意的一點(diǎn)是,軟中斷不僅僅只有網(wǎng)絡(luò)軟中斷,還有其它類型。

//file: include/linux/interrupt.h enum{HI_SOFTIRQ=0,TIMER_SOFTIRQ,NET_TX_SOFTIRQ,NET_RX_SOFTIRQ,BLOCK_SOFTIRQ,BLOCK_IOPOLL_SOFTIRQ,TASKLET_SOFTIRQ,SCHED_SOFTIRQ,HRTIMER_SOFTIRQ,RCU_SOFTIRQ, };

?

?

總結(jié)

以上是生活随笔為你收集整理的Linux数据报文接收发送总结4的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 日本精品一区视频 | 捆绑束缚调教 | 日韩欧美在线一区二区 | 亚洲精品无码一区二区 | 久久久国产精品一区 | 香蕉视频传媒 | wwwxxxx在线观看 | 国产又粗又猛又爽69xx | 日日碰狠狠添天天爽 | 国产熟女一区二区 | 综合亚洲色图 | 国产剧情在线一区 | 日韩香蕉视频 | 麻豆91在线播放 | 亚洲 欧美 激情 另类 校园 | 精品欧美视频 | av在线资源播放 | 国产精品久久久久久久久久久久午夜片 | 色综合天天综合 | 99人妻碰碰碰久久久久禁片 | 中文字幕不卡视频 | 国产第一精品视频 | zzjj国产精品一区二区 | 大地资源二中文在线影视观看 | 国产精品乱码一区二区 | 日韩一级色片 | 国产黄色av| 夜夜摸夜夜爽 | 国产午夜精品一区二区三区 | 综合久色 | 四虎影裤 | 免费在线看黄网站 | 吃奶摸下的激烈视频 | 精品中文字幕一区 | 在线免费观看国产 | 综合色婷婷| 欧美无砖砖区免费 | 午夜视频h | 国产精品久久久久久久久免费看 | 日本顶级大片 | 麻豆av影视 | 狠狠狠狠狠 | 肌肉猛男裸体gay网站免费 | 五级毛片 | 香蕉视频 | 一级黄色免费网站 | 精品久久久久中文慕人妻 | 欧美一区二区激情视频 | 免费日韩视频 | 欧美18免费视频 | 99ri国产| 糖心logo在线观看 | 男性影院 | 精品视频入口 | 亚洲在线中文字幕 | 添女人荫蒂视频 | 国产视频一区在线观看 | 高清免费视频日本 | 久久久久a | 日韩精品欧美 | a级免费网站| www.久久色 | 一级片在线免费看 | 久久精品国产亚洲av麻豆 | 国产99久久久久久免费看 | 日韩成人午夜 | 亚洲熟妇无码av | 国产伦精品一区二区三区精品 | 亚洲久久久久 | 国产我不卡 | 亚洲精品无码不卡在线播he | 91蝌蚪视频在线 | 久久久久9999 | 日韩黄色在线播放 | 免费视频日韩 | 久久乐视频 | 国产一区二区三区高清 | 日本亚洲欧美 | 欧美高清一区二区三区四区 | 聚色av| 日韩欧美精品国产 | 黑人黄色大片 | 欧美理论片在线观看 | 中文国产视频 | 国产91在线亚洲 | 亚洲一区亚洲二区 | 日本jizzjizz | 欧美性猛交ⅹxxx乱大交3 | 91精品国产乱码久久久张津瑜 | 黄色国产一级片 | 又欲又污又肉又黄短文 | 麻豆美女视频 | av之家在线 | www.操| 欧美色图在线视频 | 人人妻人人澡人人爽欧美一区双 | 饥渴放荡受np公车奶牛 | 69亚洲精品久久久蜜桃小说 | 日本中文字幕在线观看视频 |