Using kernel threads inside a block device driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

i am trying to implement a small block device driver. It is a simple
driver that uses as a support medium a file (this means that everything
that is read/written in the device will be eventually read/written in the
support file).
Because i need to use the file and the specific system calls (open, read,
write, close, lseek) i am using a kernel thread for each device to handle
the requests. That means that the request routine specific to every block
device driver will only remove the current request from the request queue
and let the kernel thread do all the work.
This is where the troubles begin. As i need to synchronize between the
request routine and the kernel thread a am using a list (queue) of
requests and a semaphore. As soon as the request routine extract a new
request it puts it inside the queue and call up (&dev->sem) on the
semaphore associated with that specific device.
But the kernel thread NEVER wakes up. I use an ioctl command to disconnect
the support file from the current driver, and that's when i terminate the
thread using kill_proc. After the thread receives the signal, it wakes up
from the down_interruptible (&dev->sem) semaphore.
To make matters worse, i am inspecting the semaphore (using trylock) and
it turns out that i can use down on the semaphore the exact number of
times that the request routine called up (although the thread never woke
up before)

Why does this happen? Should i use daemonize inside the kernel thread (i
am currently not using it)? Also, the request routine is created (at
module initialization) with an associated spinlock. Is it because of this
spinlock that the request routine never gets preempted, thus not allowing
the kernel thread to do its chore?

Thanks,
Razvan


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux