4

Can I set up the priority of a workqueue?

I am modifying the SPI kernel module "spidev" so it can communicate faster with my hardware. The external hardware is a CAN controller with a very small buffer, so I must read any incoming data quickly to avoid loosing data. I have configured a GPIO interrupt to inform me of the new data, but I cannot read the SPI hardware in the interrupt handler. My interrupt handler basically sets up a workqueue that will read the SPI data. It works fine when there is only one active process in the kernel. As soon as I open any other process (even the process viewer top) at the same time, I start loosing data in bunches, i.e., I might receive 1000 packects of data with no problems and then loose 15 packets in a row and so on. I suspect that the cause of my problem is that when the other process (top, in this case) has control over the cpu the interrupt handler runs, but the work in the workqueue doesn't until the scheduler is called again. I tried to increase the priority of my process with no success.

I wonder if there is a way to tell the kernel to execute the work in workqueue immediatelly after the interrupt handling function. Suggestions are welcome.

Eduardo
  • 93
  • 2
  • 6

1 Answers1

1

As an alternative you could consider using a tasklet, which will tell the kernel execute more immediate, but be aware you are unable to sleep in tasklets

A good ibm article on deffering work in the kernel

http://www.ibm.com/developerworks/linux/library/l-tasklets/

http://www.makelinux.net/ldd3/chp-7-sect-5

A tasklet is run at the next timer tick as long as the CPU is busy running a process, but it is run immediately when the CPU is otherwise idle. The kernel provides a set of ksoftirqd kernel threads, one per CPU, just to run "soft interrupt" handlers, such as the tasklet_action function. Thus, the final three runs of the tasklet take place in the context of the ksoftirqd kernel thread associated to CPU 0. The jitasklethi implementation uses a high-priority tasklet, explained in an upcoming list of functions.

user2342491
  • 96
  • 1
  • 3