From: Oleg Nesterov <oleg@tv-sign.ru>
To: Krishna Kumar <krkumar2@in.ibm.com>
Cc: linux-kernel@vger.kernel.org, Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH 1/2]: workqueue: Implement the kernel API
Date: Mon, 22 Sep 2008 18:10:51 +0400 [thread overview]
Message-ID: <20080922141051.GA252@tv-sign.ru> (raw)
In-Reply-To: <20080922040417.10477.35834.sendpatchset@localhost.localdomain>
On 09/22, Krishna Kumar wrote:
>
> Implement two API's for quickly updating delayed works:
> void schedule_update_delayed_work(struct delayed_work *dwork,
> unsigned long delay);
> void queue_update_delayed_work(struct workqueue_struct *wq,
> struct delayed_work *dwork,
> unsigned long delay);
>
> These API's are useful to update an existing work entry more efficiently (but
> can be used to queue a new work entry too) when the operation is done very
> frequently. The rationale is to save time of first cancelling work/timer and
> adding work/timer when the same work is added many times in quick succession.
I agree, this looks like a useful helper. But, afaics, it is not as quick
as it could, please see below.
> + * Passing delay=0 will result in immediate queueing of the entry, whether
> + * queue'd earlier or otherwise.
The comment doesn't match the code ;)
> + * Always succeeds.
minor, but perhaps it would be nice to change this helper to return 0/1 to
indicate was the work pending or not. like __mod_timer().
> +void queue_update_delayed_work(struct workqueue_struct *wq,
> + struct delayed_work *dwork, unsigned long delay)
> +{
> + struct work_struct *work = &dwork->work;
> +
> + if (likely(test_and_set_bit(WORK_STRUCT_PENDING,
> + work_data_bits(work)))) {
> + struct timer_list *timer = &dwork->timer;
> +
> + /*
> + * Already present in workqueue. Check if the timer expiry is
> + * the same. Also, optimize in case requests are within one
> + * jiffy beyond the set expiry.
> + */
> + if (time_in_range(jiffies + delay, timer->expires,
> + timer->expires + 1))
> + return;
Not that I argue, but do we really need to optimize this very unlikely case?
> + __cancel_work_timer_internal(work, timer);
__cancel_work_timer_internal() is slow, mostly due to
wait_on_work()->for_each_cpu_mask_nr(). And please note we don't really
need wait_on_work() once del_timer() || try_to_grab_pending() succeeds.
Can't we take another approach? First, let's add the new helper:
int __update_timer(struct timer_list *timer, unsigned long expires)
{
struct tvec_base *base;
unsigned long flags;
int ret = 0;
base = lock_timer_base(timer, &flags);
if (timer_pending(timer)) {
detach_timer(timer, 0);
timer->expires = expires;
internal_add_timer(base, timer);
ret = 1;
}
spin_unlock_irqrestore(&base->lock, flags);
return ret;
}
Now, something like
int update_delayed_work(...)
{
ret = 0;
for (;;) {
if (queue_delayed_work(...))
break;
ret = 1;
if (__update_timer(...))
break;
cancel_work_sync(...);
}
return ret;
}
This way the fast path is really fast, and the patch becomes simpler.
What do you think? We can optimize the code (the usage of cancel_work_sync)
further, but perhaps this is enough.
Oleg.
next prev parent reply other threads:[~2008-09-22 14:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-22 4:04 [PATCH 0/2] workqueue: Two API's to update delayed works quickly Krishna Kumar
2008-09-22 4:04 ` [PATCH 1/2]: workqueue: Implement the kernel API Krishna Kumar
2008-09-22 14:10 ` Oleg Nesterov [this message]
2008-09-23 5:20 ` Krishna Kumar2
2008-09-22 4:04 ` [PATCH 2/2]: workqueue: Modify some users to use the new API Krishna Kumar
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=20080922141051.GA252@tv-sign.ru \
--to=oleg@tv-sign.ru \
--cc=krkumar2@in.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
/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