18 内核开发-内核重点数据结构学习

server/2024/9/25 4:59:38/

课程简介:
Linux内核开发入门是一门旨在帮助学习者从最基本的知识开始学习Linux内核开发的入门课程。该课程旨在为对Linux内核开发感兴趣的初学者提供一个扎实的基础,让他们能够理解和参与到Linux内核的开发过程中。

课程特点:
1. 入门级别:该课程专注于为初学者提供Linux内核开发的入门知识。无论你是否具有编程或操作系统的背景,该课程都将从最基本的概念和技术开始,逐步引导学习者深入了解Linux内核开发的核心原理。

2. 系统化学习:课程内容经过系统化的安排,涵盖了Linux内核的基础知识、内核模块编程、设备驱动程序开发等关键主题。学习者将逐步了解Linux内核的结构、功能和工作原理,并学习如何编写和调试内核模块和设备驱动程序。

3. 实践导向:该课程强调实践,通过丰富的实例和编程练习,帮助学习者将理论知识应用到实际的Linux内核开发中。学习者将有机会编写简单的内核模块和设备驱动程序,并通过实际的测试和调试来加深对Linux内核开发的理解。

4. 配套资源:为了帮助学习者更好地掌握课程内容,该课程提供了丰富的配套资源,包括教学文档、示例代码、实验指导和参考资料等。学习者可以根据自己的学习进度和需求,灵活地利用这些资源进行学习和实践。

无论你是计算机科学专业的学生、软件工程师还是对Linux内核开发感兴趣的爱好者,Linux内核开发入门课程都将为你提供一个扎实的学习平台,帮助你掌握Linux内核开发的基础知识,为进一步深入研究和应用Linux内核打下坚实的基础。

这一讲,主要分享内核中的重点数据结构,并且以脑图的形式进行整理,后面如果有其他内核数据结构,会一同整理到这里。主要介绍内核中使用的4大数据结构:链表,队列,映射,二叉树。

以下是脑图主要内容。

需要脑图文件的可以私信或者评论留言,可以免费同步给你。文章后再贴下 list.h kfifo.h 相关文件定义

LXR linux/include/linux/klist.h 

  1/*2 *      klist.h - Some generic list helpers, extending struct list_head a bit.3 *4 *      Implementations are found in lib/klist.c5 *6 *7 *      Copyright (C) 2005 Patrick Mochel8 *9 *      This file is rleased under the GPL v2.10 */1112#ifndef _LINUX_KLIST_H13#define _LINUX_KLIST_H1415#include <linux/spinlock.h>16#include <linux/completion.h>17#include <linux/kref.h>18#include <linux/list.h>1920struct klist_node;21struct klist {22        spinlock_t              k_lock;23        struct list_head        k_list;24        void                    (*get)(struct klist_node *);25        void                    (*put)(struct klist_node *);26};272829extern void klist_init(struct klist * k, void (*get)(struct klist_node *),30                       void (*put)(struct klist_node *));3132struct klist_node {33        struct klist            * n_klist;34        struct list_head        n_node;35        struct kref             n_ref;36        struct completion       n_removed;37};3839extern void klist_add_tail(struct klist_node * n, struct klist * k);40extern void klist_add_head(struct klist_node * n, struct klist * k);4142extern void klist_del(struct klist_node * n);43extern void klist_remove(struct klist_node * n);4445extern int klist_node_attached(struct klist_node * n);464748struct klist_iter {49        struct klist            * i_klist;50        struct list_head        * i_head;51        struct klist_node       * i_cur;52};535455extern void klist_iter_init(struct klist * k, struct klist_iter * i);56extern void klist_iter_init_node(struct klist * k, struct klist_iter * i, 57                                 struct klist_node * n);58extern void klist_iter_exit(struct klist_iter * i);59extern struct klist_node * klist_next(struct klist_iter * i);6061#endif62

The original LXR software by the LXR community, this experimental version by lxr@linux.no.

LXR linux/include/linux/kfifo.h 

  1/*2 * A simple kernel FIFO implementation.3 *4 * Copyright (C) 2004 Stelian Pop <stelian@popies.net>5 *6 * This program is free software; you can redistribute it and/or modify7 * it under the terms of the GNU General Public License as published by8 * the Free Software Foundation; either version 2 of the License, or9 * (at your option) any later version.10 *11 * This program is distributed in the hope that it will be useful,12 * but WITHOUT ANY WARRANTY; without even the implied warranty of13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the14 * GNU General Public License for more details.15 *16 * You should have received a copy of the GNU General Public License17 * along with this program; if not, write to the Free Software18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.19 *20 */21#ifndef _LINUX_KFIFO_H22#define _LINUX_KFIFO_H2324#ifdef __KERNEL__2526#include <linux/kernel.h>27#include <linux/spinlock.h>2829struct kfifo {30        unsigned char *buffer;  /* the buffer holding the data */31        unsigned int size;      /* the size of the allocated buffer */32        unsigned int in;        /* data is added at offset (in % size) */33        unsigned int out;       /* data is extracted from off. (out % size) */34        spinlock_t *lock;       /* protects concurrent modifications */35};3637extern struct kfifo *kfifo_init(unsigned char *buffer, unsigned int size,38                                gfp_t gfp_mask, spinlock_t *lock);39extern struct kfifo *kfifo_alloc(unsigned int size, gfp_t gfp_mask,40                                 spinlock_t *lock);41extern void kfifo_free(struct kfifo *fifo);42extern unsigned int __kfifo_put(struct kfifo *fifo,43                                unsigned char *buffer, unsigned int len);44extern unsigned int __kfifo_get(struct kfifo *fifo,45                                unsigned char *buffer, unsigned int len);4647/**48 * __kfifo_reset - removes the entire FIFO contents, no locking version49 * @fifo: the fifo to be emptied.50 */51static inline void __kfifo_reset(struct kfifo *fifo)52{53        fifo->in = fifo->out = 0;54}5556/**57 * kfifo_reset - removes the entire FIFO contents58 * @fifo: the fifo to be emptied.59 */60static inline void kfifo_reset(struct kfifo *fifo)61{62        unsigned long flags;6364        spin_lock_irqsave(fifo->lock, flags);6566        __kfifo_reset(fifo);6768        spin_unlock_irqrestore(fifo->lock, flags);69}7071/**72 * kfifo_put - puts some data into the FIFO73 * @fifo: the fifo to be used.74 * @buffer: the data to be added.75 * @len: the length of the data to be added.76 *77 * This function copies at most 'len' bytes from the 'buffer' into78 * the FIFO depending on the free space, and returns the number of79 * bytes copied.80 */81static inline unsigned int kfifo_put(struct kfifo *fifo,82                                     unsigned char *buffer, unsigned int len)83{84        unsigned long flags;85        unsigned int ret;8687        spin_lock_irqsave(fifo->lock, flags);8889        ret = __kfifo_put(fifo, buffer, len);9091        spin_unlock_irqrestore(fifo->lock, flags);9293        return ret;94}9596/**97 * kfifo_get - gets some data from the FIFO98 * @fifo: the fifo to be used.99 * @buffer: where the data must be copied.100 * @len: the size of the destination buffer.101 *102 * This function copies at most 'len' bytes from the FIFO into the103 * 'buffer' and returns the number of copied bytes.104 */105static inline unsigned int kfifo_get(struct kfifo *fifo,106                                     unsigned char *buffer, unsigned int len)107{108        unsigned long flags;109        unsigned int ret;110111        spin_lock_irqsave(fifo->lock, flags);112113        ret = __kfifo_get(fifo, buffer, len);114115        /*116         * optimization: if the FIFO is empty, set the indices to 0117         * so we don't wrap the next time118         */119        if (fifo->in == fifo->out)120                fifo->in = fifo->out = 0;121122        spin_unlock_irqrestore(fifo->lock, flags);123124        return ret;125}126127/**128 * __kfifo_len - returns the number of bytes available in the FIFO, no locking version129 * @fifo: the fifo to be used.130 */131static inline unsigned int __kfifo_len(struct kfifo *fifo)132{133        return fifo->in - fifo->out;134}135136/**137 * kfifo_len - returns the number of bytes available in the FIFO138 * @fifo: the fifo to be used.139 */140static inline unsigned int kfifo_len(struct kfifo *fifo)141{142        unsigned long flags;143        unsigned int ret;144145        spin_lock_irqsave(fifo->lock, flags);146147        ret = __kfifo_len(fifo);148149        spin_unlock_irqrestore(fifo->lock, flags);150151        return ret;152}153154#else155#warning "don't include kernel headers in userspace"156#endif /* __KERNEL__ */157#endif158

http://www.ppmy.cn/server/32612.html

相关文章

FloodFill-----洪水灌溉算法(DFS例题详解)

目录 一.图像渲染&#xff1a; 代码详解&#xff1a; 二.岛屿数量&#xff1a; 代码详解&#xff1a; 三.岛屿的最大面积&#xff1a; 代码详解&#xff1a; 四.被围绕的区域&#xff1a; 代码详解&#xff1a; 五.太平洋大西洋水流问题&#xff1a; 代码详解&#x…

用户中心(下)

文章目录 计划登录逻辑接口简单说明cookie和session写代码流程后端逻辑层控制层测试用户管理接口 前端简化代码对接后端代理 计划 开发完成后端登录功能 &#xff08;单机登录 > 后续改造为分布式 / 第三方登录&#xff09;✔开发后端用户的管理接口 &#xff08;用户的查询…

什么是binutils-arm-linux-gnueabi

2024年5月3日&#xff0c;周五晚上 binutils-arm-linux-gnueabi 是针对 ARM 架构的 Linux 系统开发的 GNU Binutils 工具链。Binutils 是一组用于汇编、链接和转换目标文件的工具&#xff0c;包括 as (汇编器)、ld (链接器)、objcopy (目标文件转换工具) 等。 binutils-arm-li…

Redis__三大日志

文章目录 &#x1f60a; 作者&#xff1a;Lion J &#x1f496; 主页&#xff1a; https://blog.csdn.net/weixin_69252724 &#x1f389; 主题&#xff1a;Redis__三大日志 ⏱️ 创作时间&#xff1a;2024年04月30日 ———————————————— 对于MySQL来说, 有…

Android使用kts发布aar到JitPack仓库

Android使用kts发布aar到JitPack 之前做过sdk开发&#xff0c;需要将仓库上传到maven、JitPack或JCenter,但是JCenter已停止维护&#xff0c;本文是讲解上传到JitPack的方式,使用KTS语法&#xff0c;记录使用过程中遇到的一些坑.相信Groovy的方式是大家经常使用的&#xff0c;…

第三节课,功能2:开发后端用户的管理接口5min(用户的查询/状态更改)【4】【9开始--本人】

一、代码任务 【录个屏】 二、写代码 2.1 代码文件位置 2.2 代码如下&#xff1a; 2.3 官方文档&#xff1a; 网址&#xff1a; 逻辑删除 | MyBatis-Plus (baomidou.com) 三、代码有bug&#xff0c;没有鉴权&#xff0c;表里添加一个字段。role 管理员 3.1 判断操作的人&am…

链舞算法谱---链表经典题剖析

前言&#xff1a;探究链表算法的奥秘&#xff0c;解锁编程新世界&#xff01; 欢迎来到我的链表算法博客&#xff0c;这将是您深入了解链表算法&#xff0c;提升编程技能的绝佳机会。链表作为数据结构的重要成员之一&#xff0c;其动态性和灵活性在实现某些功能上发挥不可替代的…

【Linux】进程exec函数族以及守护进程

一.exec函数族 1.exec函数族的应用 在shell下敲shell的命令都是在创建shell的子进程。而我们之前学的创建父进程和子进程代码内容以及通过pid与0的关系来让父子进程执行不同的代码内容都是在一个代码文件里面&#xff0c;而shell是如何做到不在一个文件里面写代码使之成为子进…