一区二区三区三上|欧美在线视频五区|国产午夜无码在线观看视频|亚洲国产裸体网站|无码成年人影视|亚洲AV亚洲AV|成人开心激情五月|欧美性爱内射视频|超碰人人干人人上|一区二区无码三区亚洲人区久久精品

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

Linux內(nèi)核結(jié)構(gòu)介紹

CHANBAEK ? 來源:南山府嵌入式 ? 作者:小秋秋 ? 2023-04-14 11:59 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

說明

通常情況下,Linux內(nèi)核的結(jié)構(gòu)被認(rèn)為包含以下11個主要層次:

硬件抽象層

提供了與硬件交互的接口,包括設(shè)備驅(qū)動程序和中斷控制器等。 HAL層的主要功能是隱藏硬件細(xì)節(jié),為其他層提供一個硬件無關(guān)的接口,使內(nèi)核能夠在不同的硬件平臺上運(yùn)行。

系統(tǒng)調(diào)用接口層

提供了與用戶空間程序交互的接口,包括系統(tǒng)調(diào)用和進(jìn)程管理等。 SCI層是內(nèi)核與用戶空間之間的接口,它允許用戶空間程序向內(nèi)核發(fā)出請求,以獲取系統(tǒng)資源或執(zhí)行某些操作。

進(jìn)程管理層

管理進(jìn)程和線程,包括調(diào)度、同步和通信等。 PM層負(fù)責(zé)調(diào)度進(jìn)程和線程的執(zhí)行,控制進(jìn)程之間的同步和通信,以及提供進(jìn)程間共享資源的機(jī)制。

進(jìn)程調(diào)度層負(fù)責(zé)管理系統(tǒng)中的進(jìn)程,包括進(jìn)程的創(chuàng)建、銷毀、調(diào)度等操作。 它是內(nèi)核的一個核心模塊,也是系統(tǒng)性能的關(guān)鍵因素之一。

進(jìn)程調(diào)度層的代碼位于 kernel/sched/ 目錄下,主要文件包括 sched.c、task.ccgroup_sched.c 等。

內(nèi)存管理層

管理系統(tǒng)的物理內(nèi)存和虛擬內(nèi)存,包括內(nèi)存分配和釋放等。 MM層的主要任務(wù)是為進(jìn)程提供內(nèi)存,同時保護(hù)進(jìn)程的內(nèi)存空間不被其他進(jìn)程破壞。

它是內(nèi)核的一個核心模塊,也是系統(tǒng)性能的關(guān)鍵因素之一。

內(nèi)存管理層的代碼位于 mm/ 目錄下,主要文件包括 mmap.cpage_alloc.cvmalloc.c 等。

文件系統(tǒng)層

提供了對文件系統(tǒng)的支持,包括EXT4、FAT32等文件系統(tǒng)的實(shí)現(xiàn)。 FS層的主要功能是管理文件和目錄,提供對文件的讀寫訪問,并控制文件的權(quán)限和安全性。

文件系統(tǒng)層的代碼位于 fs/ 目錄下,主要文件包括 file.c、namei.csuper.c 等。

網(wǎng)絡(luò)層

實(shí)現(xiàn)網(wǎng)絡(luò)協(xié)議棧,包括TCP/IP、UDP等協(xié)議的實(shí)現(xiàn)。 NET層提供了網(wǎng)絡(luò)通信的功能,包括數(shù)據(jù)包的發(fā)送和接收、網(wǎng)絡(luò)連接的管理以及網(wǎng)絡(luò)安全等。

網(wǎng)絡(luò)協(xié)議棧層的代碼位于 net/ 目錄下,主要文件包括 core.c、ipv4/ipv6/ 等。

設(shè)備驅(qū)動層

提供與硬件設(shè)備交互的接口,包括輸入/輸出設(shè)備驅(qū)動程序、網(wǎng)絡(luò)設(shè)備驅(qū)動程序等。 DD層負(fù)責(zé)將內(nèi)核與硬件設(shè)備連接起來,允許內(nèi)核對硬件設(shè)備進(jìn)行訪問和控制。

設(shè)備驅(qū)動層的代碼位于 drivers/ 目錄下,根據(jù)設(shè)備類型的不同,代碼被組織到不同的子目錄中,例如網(wǎng)絡(luò)設(shè)備的驅(qū)動代碼位于 drivers/net/ 目錄下。

中斷處理層

處理硬件中斷,包括中斷的注冊、響應(yīng)和處理等。 IH層負(fù)責(zé)管理中斷處理程序,確保系統(tǒng)能夠快速、準(zhǔn)確地響應(yīng)硬件中斷。

虛擬化層

實(shí)現(xiàn)虛擬化技術(shù),包括KVM、Xen等虛擬化平臺的實(shí)現(xiàn)。 VIRT層提供了虛擬化的能力,允許在同一物理主機(jī)上運(yùn)行多個虛擬機(jī),并提供虛擬機(jī)管理和資源調(diào)度的功能。

虛擬化層的代碼位于 virt/ 目錄下,主要文件包括 virtio.c、kvm/xen/

安全子系統(tǒng)層

提供了安全機(jī)制和策略的實(shí)現(xiàn),包括SELinux、AppArmor等安全子系統(tǒng)的實(shí)現(xiàn)。 SEC層為內(nèi)核提供了安全的保護(hù)機(jī)制,確保系統(tǒng)資源的安全性和機(jī)密性。

安全模塊層的代碼位于 security/ 目錄下,主要文件包括 security.ccapability.cselinux/ 等。

調(diào)試和診斷層

提供了內(nèi)核調(diào)試和診斷工具的支持,包括kdump、crash等工具的實(shí)現(xiàn)。 D&D層為開發(fā)人員提供了內(nèi)核調(diào)試和診斷的功能,以便快速識別和修復(fù)內(nèi)核問題。

其實(shí)分層不一定是這樣的,因?yàn)長inux內(nèi)核之間是相互交錯的,所以分層不一定,從網(wǎng)上也可以看到有的是分了4層,有的七層不等。 當(dāng)然也可以按照模塊來分,其實(shí)都差不多,可能是我剛接觸有些還不太明白。

硬件抽象層

1// include/linux/platform_device.h
 2
 3#ifndef _LINUX_PLATFORM_DEVICE_H
 4#define _LINUX_PLATFORM_DEVICE_H
 5
 6struct resource;
 7struct platform_device_id;
 8struct device;
 9
10/**
11 * struct platform_device - platform-level device structure
12 * @name: name of device (mandatory)
13 * @id: id of the device, usually derived from ACPI or device tree
14 * @dev: associated device structure (optional)
15 * @num_resources: number of resources associated with the device
16 * @resource: resource configuration of the device
17 * @dev.parent: parent device (optional)
18 * @driver_override: driver override name (optional)
19 * @dma_mask: dma mask (optional)
20 * @coherent_dma_mask: coherent dma mask (optional)
21 * @id_entry: identity of the device (optional)
22 * @driver_data: driver specific data
23 * @fwnode: firmware node pointer for the device node
24 * @pm_domain: power management domain of the device
25 * @extcon_dev: external connector device associated with platform device
26 *
27 * NOTE: @id_entry is for the use of platform bus only; other bus types should
28 * use their own means to associate a driver with a device.
29 */
30struct platform_device {
31    const char      *name;
32    int         id;
33    struct device       dev;
34    u32         num_resources;
35    struct resource     *resource;
36    struct device_node  *of_node;
37    struct device       *parent;
38    const char      *driver_override;
39    const u64       *dma_mask;
40    const u64       *coherent_dma_mask;
41    const struct platform_device_id *id_entry;
42    void            *driver_data;
43    struct fwnode_handle    *fwnode;
44    struct pm_domain    *pm_domain;
45#ifdef CONFIG_EXTCON
46    struct extcon_dev   *extcon_dev;
47#endif
48};
49
50/**
51 * platform_device_register() - register a platform-level device
52 * @pdev: platform-level device structure to register
53 *
54 * This function registers a platform-level device with the kernel. The device
55 * will be bound to an appropriate driver if one is available.
56 *
57 * Return: 0 on success, error code on failure.
58 */
59int platform_device_register(struct platform_device *pdev);
60
61/**
62 * platform_device_unregister() - unregister a platform-level device
63 * @pdev: platform-level device structure to unregister
64 *
65 * This function unregisters a platform-level device from the kernel. If the
66 * device was bound to a driver, the driver will be unbound from the device.
67 */
68void platform_device_unregister(struct platform_device *pdev);
69
70#endif /* _LINUX_PLATFORM_DEVICE_H */

設(shè)備驅(qū)動層

1// include/linux/device.h
 2
 3/**
 4 * struct device_driver - The basic device driver structure
 5 * @name:    Name of the device driver
 6 * @bus:    Type of bus device is on
 7 * @owner:    Module owner
 8 * @mod_name:    Used for built-in modules
 9 * @probe:    Initializes a given device
10 * @remove:    Reverses the effect of probe
11 * @shutdown:    Tear down a device prior to system shutdown
12 * @suspend:    Prepares a device for power saving mode
13 * @resume:    Wake up a device from power saving mode
14 * @groups:    Optional sysfs attribute groups
15 * @of_match_table: Matching table for OF devices
16 * @acpi_match_table: Matching table for ACPI devices
17 * @pm:        Device power management operations
18 * @probe_type: Type of probe to be used
19 * @suppress_bind_attrs: Suppress the binding/unbinding attributes
20 * @driverfs_dev: Optional driverfs device link
21 * @percpu_ref: Optional percpu reference count
22 * @p: private driver data (of the driver core)
23 * @fwnode: firmware node pointer for the device node
24 * @legacy: if true, a driver bound by OF style match will match legacy platform devices
25 * @no_driver_policy: policy for devices with missing driver
26 * @bus_rescan_devices: pointer to bus specific rescan devices function
27 * @dev_groups: Optional device specific sysfs attribute groups
28 * @sriov_configure: Optional callback for SR-IOV PF driver to configure VFs
29 * @coherent_dma_masks: Optional list of DMA masks this driver supports.
30 *                      The list should be terminated with a mask of 0.
31 *                      If the driver sets a dma_mask, it should be
32 *                      included in this list.
33 */
34struct device_driver {
35    const char *name;
36    struct bus_type *bus;
37    struct module *owner;
38    const char *mod_name;   /* used for built-in modules */
39    const struct of_device_id *of_match_table;
40    const struct acpi_device_id *acpi_match_table;
41    int (*probe) (struct device *dev);
42    int (*remove) (struct device *dev);
43    void (*shutdown) (struct device *dev);
44    int (*suspend) (struct device *dev, pm_message_t state);
45    int (*resume) (struct device *dev);
46    const struct attribute_group **groups;
47    const struct dev_pm_ops *pm;
48
49    /* Set of flags used to determine driver state */
50    unsigned int driver_features;
51    enum probe_type probe_type:2;
52    unsigned int suppress_bind_attrs:1;
53    struct driver_private *p;
54
55    /* For driver core */
56    struct device_driver *next;
57    struct driver_attribute *dyn_attrs;
58#ifdef CONFIG_SYSFS
59    struct kobject kobj;
60#endif
61#ifdef CONFIG_DEBUG_DRIVER
62    unsigned long _priv[4];
63#endif
64    struct fwnode_handle *fwnode;
65    unsigned int legacy:1;
66    enum no_driver_policy no_driver_policy:2;
67    void (*bus_rescan_devices)(struct device_driver *drv);
68    const struct attribute_group **dev_groups;
69
70#ifdef CONFIG_PCI_IOV
71    int (*sriov_configure)(struct pci_dev *dev, int num_vfs);
72#endif
73    const u64 *coherent_dma_masks;
74};
75
76/**
77 * driver_register - register a device driver with the system.
78 * @drv: driver structure
79 *
80 * Returns zero on success, or a negative error code.
81 */
82int driver_register(struct device_driver *drv);
83
84/**
85 * driver_unregister - unregister a driver from the driver core.
86 * @drv: driver structure to unregister
87 */
88void driver_unregister(struct device_driver *drv);
聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報(bào)投訴
  • 內(nèi)核
    +關(guān)注

    關(guān)注

    3

    文章

    1416

    瀏覽量

    41446
  • 接口
    +關(guān)注

    關(guān)注

    33

    文章

    9005

    瀏覽量

    153778
  • Linux
    +關(guān)注

    關(guān)注

    87

    文章

    11511

    瀏覽量

    213858
  • 文件
    +關(guān)注

    關(guān)注

    1

    文章

    579

    瀏覽量

    25376
  • 線程
    +關(guān)注

    關(guān)注

    0

    文章

    508

    瀏覽量

    20229
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評論

    相關(guān)推薦
    熱點(diǎn)推薦

    Linux內(nèi)核開發(fā)工具介紹

    進(jìn)行嵌入式Linux產(chǎn)品開發(fā),往往需要對內(nèi)核進(jìn)行裁剪和定制,以滿足嵌入式產(chǎn)品的功能和性能需求。本文介紹幾種閱讀Linux內(nèi)核源碼的工具和方法
    發(fā)表于 12-29 15:20 ?4869次閱讀
    <b class='flag-5'>Linux</b><b class='flag-5'>內(nèi)核</b>開發(fā)工具<b class='flag-5'>介紹</b>

    一文詳解Linux內(nèi)核源碼組織結(jié)構(gòu)

    概要:本文內(nèi)容包含Linux源碼樹結(jié)構(gòu)分析、Linux Makefile分析、Kconfig文件分析、Linux內(nèi)核配置選項(xiàng)分析。這些知識是
    的頭像 發(fā)表于 05-10 19:28 ?6197次閱讀

    Linux內(nèi)核結(jié)構(gòu)詳解

    ,打印警告或錯誤信息的過程,還有系統(tǒng)的調(diào)試?yán)痰鹊取O到y(tǒng)數(shù)據(jù)結(jié)構(gòu)linux內(nèi)核的實(shí)現(xiàn)中,有一些數(shù)據(jù)結(jié)構(gòu)使用頻度較高,他們是:task_struct.
    發(fā)表于 07-11 16:59

    Linux內(nèi)核源碼目錄結(jié)構(gòu)

    Linux體系結(jié)構(gòu)Linux內(nèi)核結(jié)構(gòu)Linux內(nèi)核
    發(fā)表于 12-30 07:22

    linux 5.4.31為例來介紹一下linux內(nèi)核目錄結(jié)構(gòu)

    ,它是Linux內(nèi)核的概述和編譯命令說明。readme的說明更加針對X86等通用的平臺,對于某些特殊的體系結(jié)構(gòu),可能有些特殊的地方。內(nèi)核源碼很復(fù)雜,包含多級目錄,形成一個龐大的樹狀
    發(fā)表于 02-16 07:30

    Linux內(nèi)核教程

    本章學(xué)習(xí)目標(biāo)掌握LINUX內(nèi)核版本的含義理解并掌握進(jìn)程的概念掌握管道的概念及實(shí)現(xiàn)了解內(nèi)核的數(shù)據(jù)結(jié)構(gòu)了解LINUX
    發(fā)表于 04-10 16:59 ?0次下載

    Linux內(nèi)核學(xué)習(xí)起步課件

    Linux內(nèi)核學(xué)習(xí)起步介紹
    發(fā)表于 04-10 17:22 ?0次下載

    Linux 內(nèi)核數(shù)據(jù)結(jié)構(gòu):位圖(Bitmap)

    除了各種鏈?zhǔn)胶蜆湫螖?shù)據(jù)結(jié)構(gòu),Linux內(nèi)核還提供了位圖接口。位圖在Linux內(nèi)核中大量使用。下面的源代碼文件包含這些
    發(fā)表于 05-14 17:24 ?3629次閱讀

    你知道Linux內(nèi)核數(shù)據(jù)結(jié)構(gòu)中雙向鏈表的作用?

    Linux 內(nèi)核提供一套雙向鏈表的實(shí)現(xiàn),你可以在 include/linux/list.h 中找到。我們以雙向鏈表著手開始介紹 Linux
    發(fā)表于 05-14 17:27 ?1998次閱讀

    如何使用Linux內(nèi)核實(shí)現(xiàn)USB驅(qū)動程序框架

    Linux內(nèi)核提供了完整的USB驅(qū)動程序框架。USB總線采用樹形結(jié)構(gòu),在一條總線上只能有唯一的主機(jī)設(shè)備。 Linux內(nèi)核從主機(jī)和設(shè)備兩個角度
    發(fā)表于 11-06 17:59 ?20次下載
    如何使用<b class='flag-5'>Linux</b><b class='flag-5'>內(nèi)核</b>實(shí)現(xiàn)USB驅(qū)動程序框架

    Linux內(nèi)核結(jié)構(gòu)詳細(xì)說明

    Linux內(nèi)核結(jié)構(gòu)Linux內(nèi)核主要由五個子系統(tǒng)組成:進(jìn)程調(diào)度,內(nèi)存管理,虛擬文件系統(tǒng),網(wǎng)絡(luò)接口,進(jìn)程間通信。1進(jìn)程調(diào)度( SCHED):控
    發(fā)表于 11-10 17:35 ?16次下載

    STM32MP157 Linux系統(tǒng)移植開發(fā)篇7:Linux內(nèi)核目錄結(jié)構(gòu)詳解

    ,它是Linux內(nèi)核的概述和編譯命令說明。readme的說明更加針對X86等通用的平臺,對于某些特殊的體系結(jié)構(gòu),可能有些特殊的地方。內(nèi)核源碼很復(fù)雜,包含多級目錄,形成一個龐大的樹狀
    發(fā)表于 12-17 18:29 ?10次下載
    STM32MP157 <b class='flag-5'>Linux</b>系統(tǒng)移植開發(fā)篇7:<b class='flag-5'>Linux</b><b class='flag-5'>內(nèi)核</b>目錄<b class='flag-5'>結(jié)構(gòu)</b>詳解

    Linux內(nèi)核的鏈表數(shù)據(jù)結(jié)構(gòu)

    Linux內(nèi)核實(shí)現(xiàn)了自己的鏈表數(shù)據(jù)結(jié)構(gòu),它的設(shè)計(jì)與傳統(tǒng)的方式不同,非常巧妙也很通用。
    的頭像 發(fā)表于 03-24 11:34 ?1075次閱讀
    <b class='flag-5'>Linux</b><b class='flag-5'>內(nèi)核</b>的鏈表數(shù)據(jù)<b class='flag-5'>結(jié)構(gòu)</b>

    Linux內(nèi)核如何使用結(jié)構(gòu)體和函數(shù)指針?

    我將結(jié)合具體的Linux內(nèi)核驅(qū)動框架代碼來展示Linux內(nèi)核如何使用結(jié)構(gòu)體和函數(shù)指針。
    的頭像 發(fā)表于 09-06 14:17 ?1391次閱讀
    <b class='flag-5'>Linux</b><b class='flag-5'>內(nèi)核</b>如何使用<b class='flag-5'>結(jié)構(gòu)</b>體和函數(shù)指針?

    Linux內(nèi)核中使用的數(shù)據(jù)結(jié)構(gòu)

    Linux內(nèi)核代碼中廣泛使用了數(shù)據(jù)結(jié)構(gòu)和算法,其中最常用的兩個是鏈表和紅黑樹。 鏈表 Linux內(nèi)核代碼大量使用了鏈表這種數(shù)據(jù)
    的頭像 發(fā)表于 11-09 14:24 ?772次閱讀
    <b class='flag-5'>Linux</b><b class='flag-5'>內(nèi)核</b>中使用的數(shù)據(jù)<b class='flag-5'>結(jié)構(gòu)</b>