字符设备驱动增强操作:scullpipe与poll/select机制详解
1. scullpipe设备简介
/dev/scullpipe设备默认有四个,是scull模块的一部分,用于展示阻塞I/O的实现方式。在常规驱动里,读调用中被阻塞的进程会在数据到达时被唤醒,通常由硬件发送中断信号,驱动在处理中断时唤醒等待进程。但scull驱动的工作方式不同,它无需特定硬件或中断处理程序,通过另一个进程生成数据并唤醒读取进程,读取进程也可唤醒睡眠的写入进程,这种实现方式类似于FIFO(命名管道)文件系统节点。
2. scullpipe设备结构
设备驱动使用的设备结构嵌入了两个等待队列和一个缓冲区,缓冲区大小可在编译时、加载时或运行时进行配置。其定义如下:
typedef struct Scull_Pipe {
wait_queue_head_t inq, outq;
/* read and write queues */
char *buffer, *end;
/* begin of buf, end of buf */
int buffersize;
/* used in pointer arithmetic */
char *rp, *wp;
/* where to read, where to write */
int nreaders, nwriters;
/* number of openings for r/w */
struct fasync_struct *async_queue; /* asynchronous
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



