Linux设备驱动程序3Ed文件IO&如何使用解释性UML图影响计划 [英] Linux Device Drivers 3Ed File IO & How to Influence Scheduling with Explanatory UML Diagrams

查看:65
本文介绍了Linux设备驱动程序3Ed文件IO&如何使用解释性UML图影响计划的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用了UMLet来绘制一些UML图,这些图描述了由Corbet,Rubini,Kroah-Hartman撰写的Linux Device Drivers 3Ed(LDD3)每一章中的各种实体关系.可以在以下位置找到最新版本的图表:

I've used UMLet to draw some UML diagrams describing various entity relationships for each of the chapters of Linux Device Drivers 3Ed (LDD3), by Corbet, Rubini, Kroah-Hartman. The latest version of the diagrams can be found here:

Linux设备驱动程序3Ed UML图

我想请您帮助了解一个调度问题,该问题由上述链接的非阻塞文件IO序列图"中的文档以及P156-158的LDD3中的文档提供支持,尤其是来自scull_getwritespace()(另请参见P156,但是此代码已更新为使用互斥锁而不是信号灯):

I would like to ask help understanding a scheduling problem which is supported by documentation in the Non-Blocking File IO Sequence Diagram(s) at the above link, and in LDD3 on P156-158, and in particular this code snippet from scull_getwritespace() (also see P156, but this code has been updated to use mutex rather than a semaphore):

/* Wait for space for writing; caller must hold device semaphore.  On
 * error the semaphore will be released before returning. */
static int scull_getwritespace(struct scull_pipe *dev, struct file *filp)
{
	while (spacefree(dev) == 0) { /* full */
		DEFINE_WAIT(wait);
		
		mutex_unlock(&dev->mutex);
		if (filp->f_flags & O_NONBLOCK)
			return -EAGAIN;
		PDEBUG("\"%s\" writing: going to sleep\n",current->comm);
		prepare_to_wait(&dev->outq, &wait, TASK_INTERRUPTIBLE);
		if (spacefree(dev) == 0)
			schedule();
		finish_wait(&dev->outq, &wait);
		if (signal_pending(current))
			return -ERESTARTSYS; /* signal: tell the fs layer to handle it */
		if (mutex_lock_interruptible(&dev->mutex))
			return -ERESTARTSYS;
	}
	return 0;
}	

尤其是:

if(spacefree(dev) == 0)
  schedule();

感兴趣的情况是这样的:

The case of interest is this:

  1. spacefree(dev)== 0为真,并且写入过程将调用schedule().
  2. 在调用schedule()之前,读取过程会发出已经消耗掉所有缓冲区数据的wake_up_interruptible(& dev-> outq),因此应唤醒写过程,以便可以产生更多数据.这会将写过程状态设置回TASK_RUNNING.
  3. 写入过程调用schedule()并可能进入睡眠状态.

进行上述操作是为了避免出现比赛情况.

The above is done to avoid race conditions.

这是我的问题:

  1. 是否可以修改内核的代码/操作,以便我可以保证schedule()不会进入睡眠状态,而是立即从调用中返回?我不足够详尽地了解schedule()来回答这个问题,我们将不胜感激.我认为答案是否定的,因为调度程序可以选择接下来要发生的事情,并且可能会有软件中断,tasklet或要处理的信号.
  2. 是否可以修改代码,以保证在重新进入读取过程之前可以运行写入过程?同样,我认为答案可能不是,但是线程优先级排序可能存在一些可能性.

我发现linux内核实体的图形表示形式对于理解内核中的模式非常有帮助,这极大地提高了我的编码效率,但是手工生成它们非常繁琐.为了节省时间,是否有人针对LDD3做过类似的事情?

I find the pictorial representations of the linux kernel entities very helpful in understanding the patterns in the kernel which greatly improves my coding productivity, but they are very tedious to generate by hand. In the interests of saving time has anybody else done something similar with specific reference to LDD3?

谢谢.

推荐答案

不确定是否有机会研究内核映射 http://www.makelinux.net/kernel_map/

Not sure if you have had a chance to took into kernel map http://www.makelinux.net/kernel_map/

这篇关于Linux设备驱动程序3Ed文件IO&如何使用解释性UML图影响计划的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆