块设备驱动要点
块设备驱动
块设备驱动比字符设备驱动要复杂许多,它在I/O操作上表现出极大的不同,缓冲,I/O调度和<
请求队列等是块设备驱动的主要概念。
块设备I/O的主要操作特点:
-
块设备只能以块为单位进行I/O,字符设备则以字节为单位。大多数设备是字符设备,因为它
们不需要缓冲而且不以固定块大小进行操作。 -
块设备对于I/O请求有对应的缓冲,因此它们可以选择以什么顺序进行响应,字符设备无需缓
冲且被直接读写。对于存储设备而言调整读写顺序的作用巨大,因为读写连续的山区比
分离的扇区更快。 -
字符设备只能顺序读写,而块设备可以随机访问。虽然块设备可以随机访问,但是对于磁盘
这类机械设备而言,顺序的组织设备的访问可以提高性能。注意,对SD卡和RAMDISK等块
设备而言,不春在机械上的原因,所以没有必要这样调整。
Linux块设备的驱动结构
-
struct block_device_operations,块设备的操作集合,类似于file_operations
-
struct gendisk,通用磁盘结构体,用于代表一个独立磁盘设备或者分区。gendisk 中包含1
个kobject成员,因此,它是一个可被引用计数的结构体。通过get_disk()和put_dis
k()函数可用来操作引用计数,这个工作一般不需要驱动亲自做。通常对 del_gendisk
()的调用会去掉gendisk的最终引用计数,但是这一点并不是一定的。因此,在del_ge
ndisk()被调用后,这个结构体可能继续存在。
这个结构体将块设备和设备驱动模型联系起来,实现驱动模型中的计数和继承等功能。
-
struct request,用于描述一次I\O请求。 它的主要成员包括:bio链表和请求链表。
-
struct request_queue,用于描述请求队列中请求的限制和设定,并记录用于生成请求的函
数。最为重要的用它配合I\O调度算法来给请求排序。 -
struct bio,用于描述块设备传输的最小单元,它主要描述了单次传输的开始扇区和传输的大
小。
块设备的初始化过程
- register_blkdev,分配块设备需要的设备号。
- blk_init_queue,分配请求队列
- alloc_disk,分配gendisk
- add_disk,将gendisk加入设备模型
块设备请求
块设备的请求是驱动的核心。
Wed, 11 May 2022 20:16:45 +0800
Whats up very cool web site!! Man .. Beautiful .. Superb .. I will bookmark your web site and take the feeds additionally…I am happy to find a lot of useful information here in the put up, we want develop extra techniques on this regard, thank you for sharing. How to Start a Payment Processing Company
=================================
Sometimes, blogging is a bit tiresome specially if you need to update more topics.”:’:’ How to Start a Merchant Service Business
Tue, 30 Aug 2022 00:37:35 +0800
I’m impressed aided by the surpassing not to mention preachy advertising for which you embellish in such bit timing. 補光燈
============
This is often as a result exquisite and even very creative. Freezing take pleasure in that tones and even whomever makes the application with the -mail can be beaming. 雲台
================
The online world is usually bogged decrease having untrue information sites without the need of authentic meaning even so the write-up seemed to be excellent in addition to worthwhile this understand. Appreciate it intended for giving that by himself. 電腦回收
===================
Your overall tunes may be remarkable. You've got numerous quite accomplished musicians. My spouse and i want anyone the top involving good results. Macbook回收
Sun, 14 Jan 2024 19:11:20 +0800
awesome article. Thank you for sharing the post with your tribe