Linux 3Ed Device Drivers IO File and How to Influence Scheduling Using UML Explanatory Diagrams

I have used UMLet to draw some UML diagrams describing different entity relationships for each of the Linux 3Ed (LDD3), Corbet, Rubini, Kroah-Hartman device driver chapters. The latest version of the charts can be found here:

Linux 3Ed UML Diagrams Device Drivers

I would like to ask for help in understanding the scheduling problem which is supported by the documentation in the non-blocking I / O sequence diagram (s) in the link above, as well as in LDD3 on the P156-158 and in particular this piece of code from scull_getwritespace ( ) (see also P156, but this code has been updated to use a mutex, not 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 */
		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)
		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;

Run codeHide result

and in particular:

if(spacefree(dev) == 0)

Run codeHide result

Interesting case:

  • spacefree (dev) == 0 is true and the recording process is about to call schedule ().
  • before calling schedule (), the read process calls wake_up_interruptible (& dev-> outq), which consumes all the data in the buffer, so the write process needs to be woken up so it can create more data. This sets the state of the write process back to TASK_RUNNING.
  • the write process calls the schedule () and potentially goes to sleep.

The above is done to avoid race conditions.

Here are my questions:

  • Is it possible to modify the kernel code / operation so that I can ensure that schedule () does not hibernate but returns immediately from the call? I don't understand graph () in enough detail to answer this question and any help would be appreciated. I think the answer is no, because the scheduler chooses what comes next and there may be software interrupts, tasks, or signals to handle.
  • Is it possible to change the code so that I can ensure that the write process is done before the read process is re-entered? Again, I think the answer might not be like that, but maybe there are some possibilities with thread priority.

I find that graphical representations of Linux kernel objects are very helpful in understanding patterns in the kernel, which greatly improves my coding performance, but they are very tedious to generate manually. In the interest of saving time, has anyone else done something similar with a specific reference to LDD3?



source to share

1 answer

Not sure if you had the opportunity to take a kernel map



All Articles