Sleeping in a driver

Richard B. Johnson (root@chaos.analogic.com)
Fri, 5 Nov 1999 15:26:47 -0500 (EST)


Hello Driver Wizzards,

I am looking at ways that certain drivers have problems giving up
the CPU when waiting for an event to occur. In particular, there
are problems with SCSI and other hardware where the respective
drivers tend to wait forever for an event to occur. The code seems
good, the code in all cases I've checked has methods of timing out.

However, I think there may be a problem in the kernel, preventing
drivers from every getting control again.

Here is one way I found to give up the CPU while waiting for an event
to occur. It works, however the CPU time shown by `top` nears 100% during
the spin-wait. If a add "current->state = TASK_INTERRUPTIBLE", the task
remains in 'end' forever.

current->policy |= SCHED_YIELD;
timeout = jiffies + TIMEOUT;
while(timeout > jiffies)
{
if(this == that)
break;
schedule();
}

Here is another way found in kernel drivers. Unfortunately this only
works sometimes. About 1-2 percent of the time, the task remains forever
in 'reschedule`.

current->state = TASK_INTERRUPTIBLE;
timeout = jiffies + TIMEOUT;
while(timeout > jiffies)
{
if(this == that)
break;
schedule_timeout(1);
}

In both cases, there seems to be something missing that prevents them
from working correctly. Does anybody really know what needs to be done
to make a driver sleep while waiting for an event? If so, I can add
the required stuff to a bunch of drivers so they don't hang, or if
this information gets published I'm sure there will be a lot of drivers
fixed by their normal maintainers.

Cheers,
Dick Johnson

Penguin : Linux version 2.3.13 on an i686 machine (400.59 BogoMips).
Warning : It's hard to remain at the trailing edge of technology.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/