<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 29, 2016 at 5:32 PM, Muni Sekhar <span dir="ltr">&lt;<a href="mailto:munisekharrms@gmail.com" target="_blank">munisekharrms@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi All,<br>
<br>
I have a doubt regarding the workqueue scheduling.<br>
<br>
I am using the workqueue for processing the Rx Interrupt data. I am<br>
calling schedule_work() on receiving the Rx interrupt from hardware.<br>
<br>
I calculated the time between calling the schedule_work() and<br>
workqueue task actually getting executed, Here I see many cases of<br>
less than 100 us(It is fairly good).<br>
<br>
But sometimes I see 10’s of ms and a lot in the 100’s of ms. I have<br>
seen over 0.5 secs too. I would like to know why does sometimes kernel<br>
takes longer time(in milli seconds) to schedule it? Is there any way<br>
to reduce this time gap?<br>
<br>
<br>
My code:<br>
<br>
static void my_workqueuetask(struct work_struct *work)<br>
{<br>
    printk(&quot;In %s() \n&quot;,__func__);<br>
<br>
    mutex_lock(&amp;bh_mutex);<br>
<br>
    //Do something here<br>
<br>
    mutex_unlock(&amp;bh_mutex);<br>
}<br>
<br>
<br>
static irqreturn_t my_irq_handler(int irq, void *dev)<br>
{<br>
        ……;<br>
<br>
        if(Rx Interrupt)<br>
             schedule_work(&amp;rx_work);<br>
<br>
return IRQ_HANDLED;<br>
}<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Thanks,<br>
Sekhar<br>
</font></span><br clear="all"></blockquote></div><br></div><div class="gmail_extra">Hi Sekhar<br><br></div><div class="gmail_extra">In general, in non real time kernel, there is no way you can make sure your work will be scheduled after N seconds.<br><br></div><div class="gmail_extra">Have you done simple statistic calculation how much % it is slower than 100 us, and how much % it is faster than 100 us? <br><br></div><div class="gmail_extra">IMHO, if slower % is lower than 1% of overall sample, I think it is still acceptable, but this is up to your judgement<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">BTW, like other said too, that mutex_lock, have you also measured how long, by average, the lock is taken?<br></div><div class="gmail_extra"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">regards,<br><br>Mulyadi Santosa<br>Freelance Linux trainer and consultant<br><br>blog: <a href="http://the-hydra.blogspot.com" target="_blank">the-hydra.blogspot.com</a><br>training: <a href="http://mulyaditraining.blogspot.com" target="_blank">mulyaditraining.blogspot.com</a></div>
</div></div>