日韩性视频-久久久蜜桃-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ò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 男人激烈吮乳吃奶爽文 | 香蕉久久夜色精品国产使用方法 | 久久香蕉影院 | 国产成人精 | www.黄色网址.com| 黄色小网站入口 | 在线成人一区 | 97人人爽人人 | 国产精品精品软件视频 | 欧美黑人巨大xxx极品 | 国产精品高潮呻吟av | 成人不卡 | 国产做爰全免费的视频软件 | 久久黄色网| 中文精品一区 | 熟女视频一区 | 亚洲第一福利视频 | 九草视频在线观看 | 免费啪视频在线观看 | 老司机性视频 | av免费观看网| 色欲国产精品一区二区 | 国产精品黄色网 | 特级毛片在线播放 | 熟女毛毛多熟妇人妻aⅴ在线毛片 | 久久精品视频3 | 久视频在线观看 | 中文字幕一区二区av | 日韩高清一二三区 | 岛国片在线免费观看 | 欧洲精品久久 | 大地资源高清播放在线观看 | 婷婷激情小说 | 一级黄色免费片 | 大黄毛片 | 国产色影院 | 特大黑人娇小亚洲女 | 日韩a在线播放 | av免费福利 | 色老头影视 | 久久爱成人 | 欧美在线日韩 | 性猛交╳xxx乱大交 偷偷操不一样的久久 | 国产性自拍 | 成人av男人的天堂 | 国产无套精品 | 精品久久网 | 黄页免费视频 | 国产伦理一区二区 | 亚洲精品乱码久久久久久蜜桃麻豆 | 色偷偷人人澡人人爽人人模 | 玖草在线视频 | 日本高清不卡二区 | 色图插插插 | 午夜888| av在线手机版| 毛片毛片女人毛片毛片 | 精品视频999 | 日韩一区二区不卡视频 | 亚洲最新av网址 | 免费成人av片| 欧美一级特黄aaaaaa | 98超碰在线 | 国产又粗又猛又爽又黄的视频一 | 亚洲第一免费视频 | 国产精品无码中文 | 爱操视频| 久久久九九 | 在线看成人 | 成人av在线网| 久久综合区| 一区二区三区精 | 久久丫精品国产亚洲av不卡 | 日韩免费高清一区二区 | 五月少妇 | 亚洲一区日韩精品 | 久久久免费精品 | 天码人妻一区二区三区在线看 | 日本黄色一级网站 | 不卡的毛片 | 成 人 免费 黄 色 | 国产精品三区在线观看 | 精品自拍偷拍 | 久草网视频 | 天天操天天射天天 | 精品在线视频一区二区三区 | 超碰p | 啪啪福利视频 | 蜜桃久久久aaaa成人网一区 | 亚洲成人精品在线 | 欧美成人一级片 | 午夜视频在线观看免费视频 | 亚洲免费精品视频 | 在线观看毛片av | 337p日本欧洲亚洲大胆精筑 | 欧美日韩国产中文字幕 | 二区中文字幕 | 欧美在线一区二区 | 欧美日韩在线免费视频 |