kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* Query on workqueue
@ 2015-01-13 13:51 Victor Ascroft
  2015-01-13 15:31 ` Dave Tian
  2015-01-13 17:21 ` Richard Maciel Costa
  0 siblings, 2 replies; 3+ messages in thread
From: Victor Ascroft @ 2015-01-13 13:51 UTC (permalink / raw)
  To: kernelnewbies

Hello,

Is it ok to use wait_for_completion in a workqueue? 

static void my_work(struct work_struct *work)
{

	while (true)
	{
		wait_for_completion(completion);
		
		// Do something here

		reinit_completion(completion);
		enable_irq(irq);
	}
}

static irqreturn_t my_irq_handler(int irq, void *dev)
{
	disable_irq(irq);

	complete(completion);

	return IRQ_HANDLED;
}

Something like the above is what I have. Is it a correct way to 
do things or complete idiotic brainfart. Workqueues can sleep so
I thought of the above code, but, was not sure.

And I am not using _interruptible or _interruptible_timeout because
I absolutely want it to wait for the IRQ. Now as such though this 
works I get stack traces with hung task complaining and I have
to set /proc/sys/kernel/hung_task_timeout_secs to 0. And were the IRQ
not generated I do get NMI watchdog hang.

I will accept I have only little knowledge of these things.

Regards,
Victor.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Query on workqueue
  2015-01-13 13:51 Query on workqueue Victor Ascroft
@ 2015-01-13 15:31 ` Dave Tian
  2015-01-13 17:21 ` Richard Maciel Costa
  1 sibling, 0 replies; 3+ messages in thread
From: Dave Tian @ 2015-01-13 15:31 UTC (permalink / raw)
  To: kernelnewbies

If you have to wait for the IRQ to be finished, do NOT use work queue, which belongs to bottom half. Just write your own IRQ handler, do sth there and register your handler.

-daveti


> On Jan 13, 2015, at 8:51 AM, Victor Ascroft <victorascroft@gmail.com> wrote:
> 
> Hello,
> 
> Is it ok to use wait_for_completion in a workqueue? 
> 
> static void my_work(struct work_struct *work)
> {
> 
> 	while (true)
> 	{
> 		wait_for_completion(completion);
> 		
> 		// Do something here
> 
> 		reinit_completion(completion);
> 		enable_irq(irq);
> 	}
> }
> 
> static irqreturn_t my_irq_handler(int irq, void *dev)
> {
> 	disable_irq(irq);
> 
> 	complete(completion);
> 
> 	return IRQ_HANDLED;
> }
> 
> Something like the above is what I have. Is it a correct way to 
> do things or complete idiotic brainfart. Workqueues can sleep so
> I thought of the above code, but, was not sure.
> 
> And I am not using _interruptible or _interruptible_timeout because
> I absolutely want it to wait for the IRQ. Now as such though this 
> works I get stack traces with hung task complaining and I have
> to set /proc/sys/kernel/hung_task_timeout_secs to 0. And were the IRQ
> not generated I do get NMI watchdog hang.
> 
> I will accept I have only little knowledge of these things.
> 
> Regards,
> Victor.
> 
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Query on workqueue
  2015-01-13 13:51 Query on workqueue Victor Ascroft
  2015-01-13 15:31 ` Dave Tian
@ 2015-01-13 17:21 ` Richard Maciel Costa
  1 sibling, 0 replies; 3+ messages in thread
From: Richard Maciel Costa @ 2015-01-13 17:21 UTC (permalink / raw)
  To: kernelnewbies

Hi Victor,

I don't think it's a good idea to block an entire IRQ line for so much time
(i.e. until a work queue runs), unless you're sure you're the sole user of
it.

How about you try a more traditional approach and make the IRQ handler
schedule a work queue after it completes?

Or, if you need to run as fast as possible, why don't you create a tasklet?
Remember that you can't sleep in this case.

- Richard

2015-01-13 11:51 GMT-02:00 Victor Ascroft <victorascroft@gmail.com>:

> Hello,
>
> Is it ok to use wait_for_completion in a workqueue?
>
> static void my_work(struct work_struct *work)
> {
>
>         while (true)
>         {
>                 wait_for_completion(completion);
>
>                 // Do something here
>
>                 reinit_completion(completion);
>                 enable_irq(irq);
>         }
> }
>
> static irqreturn_t my_irq_handler(int irq, void *dev)
> {
>         disable_irq(irq);
>
>         complete(completion);
>
>         return IRQ_HANDLED;
> }
>
> Something like the above is what I have. Is it a correct way to
> do things or complete idiotic brainfart. Workqueues can sleep so
> I thought of the above code, but, was not sure.
>
> And I am not using _interruptible or _interruptible_timeout because
> I absolutely want it to wait for the IRQ. Now as such though this
> works I get stack traces with hung task complaining and I have
> to set /proc/sys/kernel/hung_task_timeout_secs to 0. And were the IRQ
> not generated I do get NMI watchdog hang.
>
> I will accept I have only little knowledge of these things.
>
> Regards,
> Victor.
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150113/7d9f9e92/attachment.html 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-01-13 17:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-13 13:51 Query on workqueue Victor Ascroft
2015-01-13 15:31 ` Dave Tian
2015-01-13 17:21 ` Richard Maciel Costa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).