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

课程简介:
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.c
  5 *
  6 *
  7 *      Copyright (C) 2005 Patrick Mochel
  8 *
  9 *      This file is rleased under the GPL v2.
  10 */
  11
  12#ifndef _LINUX_KLIST_H
  13#define _LINUX_KLIST_H
  14
  15#include <linux/spinlock.h>
  16#include <linux/completion.h>
  17#include <linux/kref.h>
  18#include <linux/list.h>
  19
  20struct 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};
  27
  28
  29extern void klist_init(struct klist * k, void (*get)(struct klist_node *),
  30                       void (*put)(struct klist_node *));
  31
  32struct klist_node {
  33        struct klist            * n_klist;
  34        struct list_head        n_node;
  35        struct kref             n_ref;
  36        struct completion       n_removed;
  37};
  38
  39extern void klist_add_tail(struct klist_node * n, struct klist * k);
  40extern void klist_add_head(struct klist_node * n, struct klist * k);
  41
  42extern void klist_del(struct klist_node * n);
  43extern void klist_remove(struct klist_node * n);
  44
  45extern int klist_node_attached(struct klist_node * n);
  46
  47
  48struct klist_iter {
  49        struct klist            * i_klist;
  50        struct list_head        * i_head;
  51        struct klist_node       * i_cur;
  52};
  53
  54
  55extern 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);
  60
  61#endif
  62

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 modify
  7 * it under the terms of the GNU General Public License as published by
  8 * the Free Software Foundation; either version 2 of the License, or
  9 * (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 of
  13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14 * GNU General Public License for more details.
  15 *
  16 * You should have received a copy of the GNU General Public License
  17 * along with this program; if not, write to the Free Software
  18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19 *
  20 */
  21#ifndef _LINUX_KFIFO_H
  22#define _LINUX_KFIFO_H
  23
  24#ifdef __KERNEL__
  25
  26#include <linux/kernel.h>
  27#include <linux/spinlock.h>
  28
  29struct 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};
  36
  37extern 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);
  46
  47/**
  48 * __kfifo_reset - removes the entire FIFO contents, no locking version
  49 * @fifo: the fifo to be emptied.
  50 */
  51static inline void __kfifo_reset(struct kfifo *fifo)
  52{
  53        fifo->in = fifo->out = 0;
  54}
  55
  56/**
  57 * kfifo_reset - removes the entire FIFO contents
  58 * @fifo: the fifo to be emptied.
  59 */
  60static inline void kfifo_reset(struct kfifo *fifo)
  61{
  62        unsigned long flags;
  63
  64        spin_lock_irqsave(fifo->lock, flags);
  65
  66        __kfifo_reset(fifo);
  67
  68        spin_unlock_irqrestore(fifo->lock, flags);
  69}
  70
  71/**
  72 * kfifo_put - puts some data into the FIFO
  73 * @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' into
  78 * the FIFO depending on the free space, and returns the number of
  79 * 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;
  86
  87        spin_lock_irqsave(fifo->lock, flags);
  88
  89        ret = __kfifo_put(fifo, buffer, len);
  90
  91        spin_unlock_irqrestore(fifo->lock, flags);
  92
  93        return ret;
  94}
  95
  96/**
  97 * kfifo_get - gets some data from the FIFO
  98 * @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 the
 103 * '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;
 110
 111        spin_lock_irqsave(fifo->lock, flags);
 112
 113        ret = __kfifo_get(fifo, buffer, len);
 114
 115        /*
 116         * optimization: if the FIFO is empty, set the indices to 0
 117         * so we don't wrap the next time
 118         */
 119        if (fifo->in == fifo->out)
 120                fifo->in = fifo->out = 0;
 121
 122        spin_unlock_irqrestore(fifo->lock, flags);
 123
 124        return ret;
 125}
 126
 127/**
 128 * __kfifo_len - returns the number of bytes available in the FIFO, no locking version
 129 * @fifo: the fifo to be used.
 130 */
 131static inline unsigned int __kfifo_len(struct kfifo *fifo)
 132{
 133        return fifo->in - fifo->out;
 134}
 135
 136/**
 137 * kfifo_len - returns the number of bytes available in the FIFO
 138 * @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;
 144
 145        spin_lock_irqsave(fifo->lock, flags);
 146
 147        ret = __kfifo_len(fifo);
 148
 149        spin_unlock_irqrestore(fifo->lock, flags);
 150
 151        return ret;
 152}
 153
 154#else
 155#warning "don't include kernel headers in userspace"
 156#endif /* __KERNEL__ */
 157#endif
 158

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/592697.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

9.4.k8s的控制器资源(job控制器,cronjob控制器)

目录 一、job控制器 二、cronjob控制器 一、job控制器 job控制器就是一次性任务的pod控制器&#xff0c;pod完成作业后不会重启&#xff0c;其重启策略是&#xff1a;Never&#xff1b; 简单案例 启动一个pod&#xff0c;执行完成一个事件&#xff0c;然后pod关闭&#xff1b;…

破解keil uvision4 4.12时遇到:*** TOOLS.INI: TOOLCHAIN NOT INSTALLED **

1 使用管理员权限打开keil和注册机。 2 将注册机中的target改为ARM。

免费开源,无需 GPU,本地化部署大语言模型的对话系统

免费开源&#xff0c;无需 GPU&#xff0c;本地化部署大语言模型的对话系统 分类 编程技术 项目名: FreeAskInternet -- 本地化部署大语言模型的对话系统 Github 开源地址&#xff1a; https://github.com/nashsu/FreeAskInternet FreeAskInternet 是一个免费开源的工具&am…

ZOC8 for Mac v8.08.1激活版:卓越性能的SSH客户端

在远程连接和管理的世界中&#xff0c;ZOC8 for Mac以其卓越的性能和丰富的功能&#xff0c;成为了众多专业人士的首选SSH客户端。它支持SSH1、SSH2、Telnet、Rlogin、Serial等多种协议&#xff0c;让您轻松连接到远程服务器。ZOC8拥有简洁直观的界面和强大的功能设置&#xff…

STM32 F103C8T6学习笔记16:1.3寸OLED的驱动显示日历

今天尝试使用STM32 F103C8T6驱动显示 1.3寸的OLED&#xff0c;显示数字、字符串、汉字、图片等 本质与0.96寸的OLED是完全相同的原理&#xff1a; 而且经过我的研究发现: 1.3寸大小的OLED并未比0.96寸的有更多的显示像素点数来显示&#xff0c;也是128*64的像素点数显示: 也…

【设计模式】函数式编程范式工厂模式(Factory Method Pattern)

目录标题 定义函数式接口函数式接口实现类工厂类封装实际应用总结 定义函数式接口 ISellIPad.java /*** 定义一个函数式接口* param <T>*/ FunctionalInterface public interface ISellIPad<T> {T getSellIPadInfo();}函数式接口实现类 HuaWeiSellIPad.java pu…

头歌实践教学平台:三维图形观察OpenGL1.0

第1关&#xff1a;模型变换 一.任务描述 根据提示&#xff0c;在右侧修改代码&#xff0c;并自己绘制出图形。平台会对你编写的代码进行测试。 1.本关任务 学习了解三维图形几何变换原理。 理解掌握OpenGL三维图形几何变换的方法。 理解掌握OpenGL程序的模型视图变换。 掌握…

【机器视觉】C# .NET 8 部署yolov9 onnx对象检测

这段代码展示了一个使用YOLOv9进行对象检测的简单测试框架。代码主体以及其功能分为以下几个关键部分&#xff1a; 创建测试图片数组 _testImages&#xff0c;它包含了图片文件名和对应的标签。使用 buildTests 方法来从给定的文件名中加载图片并调整尺寸&#xff0c;准备测试数…

【每日力扣】141. 环形链表与142. 环形链表 II

&#x1f525; 个人主页: 黑洞晓威 &#x1f600;你不必等到非常厉害&#xff0c;才敢开始&#xff0c;你需要开始&#xff0c;才会变的非常厉害 141. 环形链表 给你一个链表的头节点 head &#xff0c;判断链表中是否有环。 如果链表中有某个节点&#xff0c;可以通过连续跟…

利用策略模式+模板方法实现项目中运维功能

前段时间项目中有个需求&#xff1a;实现某业务的运维功能&#xff0c;主要是对10张数据库表的增删改查&#xff0c;没有复杂的业务逻辑&#xff0c;只是满足运维人员的基本需要&#xff0c;方便他们快速分析定位问题。这里简单记录分享下实现方案&#xff0c;仅供参考。 一、…

学习Rust的第27天:Rust中的pwd

过去几天我们一直在重新创建 GNU 核心实用程序的基本功能&#xff0c;而今天&#xff0c;我们将做一些有点太简单的事情&#xff0c; pwd 这个实用程序是用于打印Linux终端中的工作目录。 Understanding the utility 了解实用程序 Running the pwd command, we get an output l…

SpringBoot使用AOP注解记录操作日志

一、前言 日志&#xff1a;指系统所指定对象的某些操作和其操作结果按时间有序的集合。 操作日志&#xff1a;主要是对某个对象进行新增操作或者修改操作后记录下这个新增或者修改&#xff0c;操作日志要求可读性比较强。比如张三在某个时间下了订单买了某个商品&#xff01; …

linux实验(数据库备份)

以下所有操作皆以机房电脑上的虚拟机为基础环境 下载链接&#xff1a;Linux课程机房虚拟机# 切换到root用户 su - root安装数据库mysql 5.7 rpm -ivh https://mirrors4.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64/mysql-community-common-5.7.29-1.el7.x…

Llama改进之——SwiGLU激活函数

引言 今天介绍LLAMA模型引入的关于激活函数的改进——SwiGLU1&#xff0c;该激活函数取得了不错的效果&#xff0c;得到了广泛地应用。 SwiGLU是GLU的一种变体&#xff0c;其中包含了GLU和Swish激活函数。 GLU GLU(Gated Linear Units,门控线性单元)2引入了两个不同的线性层…

Linux(openEuler、CentOS8)常用的IP修改方式(文本配置工具nmtui+配置文件+nmcli命令)

----本实验环境为openEuler系统<以server方式安装>&#xff08;CentOS类似&#xff0c;可参考本文&#xff09;---- 一、知识点 &#xff08;一&#xff09;文本配置工具nmtui(openEuler已预装) nmtui&#xff08;NetworkManager Text User Interface&#xff09;是一…

ZooKeeper以及DolphinScheduler的用法

目录 一、ZooKeeper的介绍 数据模型 ​编辑 操作使用 ①登录客户端 ​编辑 ②可以查看下面节点有哪些 ③创建新的节点&#xff0c;并指定数据 ④查看节点内的数据 ⑤、删除节点及数据 特殊点&#xff1a; 运行机制&#xff1a; 二、DolphinScheduler的介绍 架构&#…

计算机毕业设计Python+Spark知识图谱高考志愿推荐系统 高考数据分析 高考可视化 高考大数据 大数据毕业设计

毕业设计&#xff08;论文&#xff09;任务书 毕业设计&#xff08;论文&#xff09;题目&#xff1a; 基于大数据的高考志愿推荐系统 设计&#xff08;论文&#xff09;的主要内容与要求&#xff1a; 主要内容&#xff1a; 高…

贝叶斯回归

1. 贝叶斯推断的定义 简单来说&#xff0c;贝叶斯推断 (Bayesian inference) 就是结合“经验 (先验)”和“实践 (样本)”&#xff0c;得出“结论 (后 验)”。 2. 什么是先验&#xff1f; 贝叶斯推断把模型参数看作随机变量。在得到样本之前&#xff0c;根据主观经验和既有知…

巧记英语单词

页面 在输入框中填写英语单词的谐音 这样的话就进行了一次英语单词的记忆练习。 页面代码 <% layout(/layouts/default.html, {title: 英语单词管理, libs: [dataGrid]}){ %> <div class"main-content"><div class"box box-main">&l…

anaconda、cuda、tensorflow、pycharm环境安装

anaconda、cuda、tensorflow、pycharm环境安装 anaconda安装 anaconda官方下载地址 本文使用的是基于python3.9的anaconda 接下来跟着步骤安装&#xff1a; 检验conda是否成功安装 安装CUDA和cuDNN 提醒&#xff0c;CUDA和cuDNN两者必须版本对应&#xff0c;否者将会出错…