linux-newbie.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: anish singh <anish198519851985@gmail.com>
To: Arun KS <getarunks@gmail.com>
Cc: Rajat Jain <rajatjain@juniper.net>,
	"linux-newbie@vger.kernel.org" <linux-newbie@vger.kernel.org>,
	"kernelnewbies@kernelnewbies.org"
	<kernelnewbies@kernelnewbies.org>
Subject: Re: Ordering / preemption of work in a workqueue preempt?
Date: Mon, 18 Nov 2013 23:39:05 -0800	[thread overview]
Message-ID: <CAK7N6vov2dKhK3hfn6wPHc+ELQavjho_ypALVts4Ajs=J0U1WA@mail.gmail.com> (raw)
In-Reply-To: <CABOM9ZrSiwM0K73RGshOC67sedvcV=4ny-YRHNmU3fLKhak3_w@mail.gmail.com>

On Mon, Nov 18, 2013 at 10:20 PM, Arun KS <getarunks@gmail.com> wrote:
> Hi Rajat,
>
> On Fri, Nov 15, 2013 at 8:46 PM, Rajat Jain <rajatjain@juniper.net> wrote:
>> Hi,
>>
>> I have a single work queue, on which I have scheduled a worker function [using queue_work(wq, fn)] in interrupt context.
>>
>> I get the interrupt twice before the work queue gets a chance to run, and hence the same function will get queued twice (with different private context - arguments etc) which is fine and expected.
>
> You got it wrong here.
>
> bool queue_work_on(int cpu, struct workqueue_struct *wq,
>                    struct work_struct *work)
> {
>         bool ret = false;
>         unsigned long flags;
>
>         local_irq_save(flags);
>
>         if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) {
>                 __queue_work(cpu, wq, work);
>                 ret = true;
>         }
>
>         local_irq_restore(flags);
>         return ret;
> }
> EXPORT_SYMBOL(queue_work_on);
>
> If you look at function queue_work_on, the function returns
> immediately if WORK_STRUCT_PENDING_BIT was already set.
> So in effect your second call to queue_work will just return.
Best thing to do is just disable interrupt as soon as you receive
first interrupt
and re-enable it when you think you can handle it.I hope you are not writing
network driver where this sequence would cause unacceptable delays.
>
> HTH
>
> Thanks,
> Arun
>
>
>>
>> Questions:
>>
>> 1) Is it possible that the instance that was queued by 2nd interrupt, can get to run BEFORE the instance that was queued by 1st interrupt? In other words, is reordering possible?
>>
>> 2) Is it possible that one running instance of the function, can get preempted by second instance of the same work queue? I read through http://lwn.net/Articles/511421/ and it talks about same work queue cannot run on different CPU, but I have doubt about single CPU. If If I am writing a worker function, does my code have to be ready that it can be preempted by another instance of the same function?
>>
>> Please note that I understand that my worker function can preempted by other processes, my doubts are related to the same workqueue.
>>
>> Thanks,
>>
>> Rajat
>>
>>
>> _______________________________________________
>> Kernelnewbies mailing list
>> Kernelnewbies@kernelnewbies.org
>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
--
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

      reply	other threads:[~2013-11-19  7:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-15 15:16 Ordering / preemption of work in a workqueue preempt? Rajat Jain
2013-11-16  1:01 ` Rajat Sharma
2013-11-16  5:11   ` anish singh
2013-11-17  4:10   ` anish singh
2013-11-19  6:20 ` Arun KS
2013-11-19  7:39   ` anish singh [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAK7N6vov2dKhK3hfn6wPHc+ELQavjho_ypALVts4Ajs=J0U1WA@mail.gmail.com' \
    --to=anish198519851985@gmail.com \
    --cc=getarunks@gmail.com \
    --cc=kernelnewbies@kernelnewbies.org \
    --cc=linux-newbie@vger.kernel.org \
    --cc=rajatjain@juniper.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).