From: Oleg Nesterov <oleg@tv-sign.ru>
To: linux-kernel@vger.kernel.org, Linus Torvalds <torvalds@osdl.org>,
Ingo Molnar <mingo@elte.hu>,
Christoph Lameter <christoph@lameter.com>,
"Chen, Kenneth W" <kenneth.w.chen@intel.com>,
Andrew Morton <akpm@osdl.org>
Subject: Re: [RFC][PATCH] timers fixes/improvements
Date: Fri, 01 Apr 2005 15:59:46 +0400 [thread overview]
Message-ID: <424D37B2.2CE24C67@tv-sign.ru> (raw)
In-Reply-To: 424D373F.1BCBF2AC@tv-sign.ru
Here it is code snippets for easier review.
typedef struct timer_base_s {
spinlock_t lock;
struct timer_list *running_timer;
} timer_base_t;
struct tvec_t_base_s {
timer_base_t t_base;
...
} tvec_bases[];
struct timer_list {
...
timer_base_t *_base;
};
int timer_pending(struct timer_list * timer)
{
return timer->entry.next != NULL;
}
void init_timer(struct timer_list *timer)
{
timer->entry.next = NULL;
timer->_base = &per_cpu(tvec_bases).t_base;
}
timer_base_t *lock_timer_base(struct timer_list *timer, unsigned long *flags)
{
for (;;) {
timer_base_t *base = timer->_base;
if (base != NULL) {
spin_lock_irqsave(&base->lock, *flags);
if (base == timer->_base)
return base;
spin_unlock_irqrestore(&base->lock, *flags);
}
}
}
int __mod_timer(struct timer_list *timer, unsigned long expires)
{
timer_base_t *base;
tvec_base_t *new_base;
int ret = -1;
do {
base = lock_timer_base(timer, &flags);
new_base = &__get_cpu_var(tvec_bases);
/* Ensure the timer is serialized. */
if (base != &new_base->t_base
&& base->running_timer == timer)
goto unlock;
ret = 0;
if (timer_pending(timer)) {
__list_del(timer->entry);
ret = 1;
}
if (base != &new_base->t_base) {
timer->_base = NULL;
spin_unlock(&base->lock);
base = &new_base->t_base;
spin_lock(&base->lock);
timer->_base = base;
}
timer->expires = expires;
internal_add_timer(new_base, timer);
unlock:
spin_unlock_irqrestore(&base->lock, flags);
} while (ret < 0);
return ret;
}
void detach_timer(struct timer_list *timer)
{
__list_del(timer->entry);
entry->next = NULL;
}
int del_timer(struct timer_list *timer)
{
int ret = 0;
if (timer_pending(timer)) {
timer_base_t *base = lock_timer_base(timer);
if (timer_pending(timer)) {
detach_timer(timer);
ret = 1;
}
spin_unlock_irqrestore(&base->lock, flags);
}
return ret;
}
int del_timer_sync(struct timer_list *timer)
{
int ret = -1;
do {
timer_base_t *base = lock_timer_base(timer);
if (base->running_timer == timer)
goto unlock;
ret = 0;
if (timer_pending(timer)) {
detach_timer(timer);
ret = 1;
}
unlock:
spin_unlock_irqrestore(&base->lock, flags);
} while (ret < 0);
return ret;
}
void __run_timers(tvec_base_t *base)
{
spin_lock_irq(&base->t_base.lock);
for_each_expired_timer(timer) {
base->t_base.running_timer = timer;
detach_timer(timer);
spin_unlock(&base->t_base.lock);
timer->function(data);
spin_lock(&base->t_base.lock);
}
}
next prev parent reply other threads:[~2005-04-01 11:54 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-04-01 11:57 [RFC][PATCH] timers fixes/improvements Oleg Nesterov
2005-04-01 11:59 ` Oleg Nesterov [this message]
2005-04-01 13:07 ` Ingo Molnar
2005-04-01 13:52 ` Oleg Nesterov
2005-04-01 12:58 ` Ingo Molnar
2005-04-01 16:08 ` Linus Torvalds
2005-04-01 18:32 ` Andrew Morton
2005-04-01 18:41 ` Christoph Lameter
2005-04-01 18:44 ` Chen, Kenneth W
2005-04-02 9:22 ` Oleg Nesterov
2005-05-09 20:35 ` Christoph Lameter
2005-05-09 21:42 ` Andrew Morton
2005-05-09 21:51 ` Christoph Lameter
2005-05-10 10:23 ` Oleg Nesterov
2005-05-10 19:15 ` Christoph Lameter
2005-05-10 21:48 ` George Anzinger
2005-05-11 10:18 ` Oleg Nesterov
2005-05-11 15:12 ` Christoph Lameter
2005-05-13 22:36 ` Greg KH
[not found] ` <20050510.125301.59655362.davem@davemloft.net>
2005-05-11 15:06 ` Oleg Nesterov
2005-05-12 23:36 ` Ganesh Venkatesan
2005-05-09 23:10 ` Christoph Lameter
2005-04-02 10:07 ` Andrew Morton
2005-04-02 11:02 ` Oleg Nesterov
2005-04-02 14:58 ` Ingo Molnar
-- strict thread matches above, loose matches on Subject: below --
2005-05-17 15:38 Sy, Dely L
2005-05-17 15:50 ` Greg KH
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=424D37B2.2CE24C67@tv-sign.ru \
--to=oleg@tv-sign.ru \
--cc=akpm@osdl.org \
--cc=christoph@lameter.com \
--cc=kenneth.w.chen@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=torvalds@osdl.org \
/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