From: Oleg Nesterov <oleg@tv-sign.ru>
To: Ingo Molnar <mingo@elte.hu>
Cc: linux-kernel@vger.kernel.org, Linus Torvalds <torvalds@osdl.org>,
Andrew Morton <akpm@osdl.org>,
Arjan van de Ven <arjanv@infradead.org>,
Steven Rostedt <rostedt@goodmis.org>,
Alan Cox <alan@lxorguk.ukuu.org.uk>,
Christoph Hellwig <hch@infradead.org>, Andi Kleen <ak@suse.de>,
David Howells <dhowells@redhat.com>,
Alexander Viro <viro@ftp.linux.org.uk>, Paul Jackson <pj@sgi.com>
Subject: Re: [patch 05/15] Generic Mutex Subsystem, mutex-core.patch
Date: Wed, 21 Dec 2005 19:21:21 +0300 [thread overview]
Message-ID: <43A98101.364DB5CF@tv-sign.ru> (raw)
In-Reply-To: 20051219013718.GA28038@elte.hu
Ingo Molnar wrote:
>
> mutex implementation, core files: just the basic subsystem, no users of it.
Ingo, could you explain to me ...
> +__mutex_lock_common(struct mutex *lock, struct mutex_waiter *waiter,
> + struct thread_info *ti, struct task_struct *task,
> + unsigned long *flags, unsigned long task_state __IP_DECL__)
> +{
> + unsigned int old_val;
> +
> + debug_lock_irqsave(&debug_lock, *flags, ti);
> + DEBUG_WARN_ON(lock->magic != lock);
> +
> + spin_lock(&lock->wait_lock);
> + __add_waiter(lock, waiter, ti, task __IP__);
> + set_task_state(task, task_state);
I can't understand why __mutex_lock_common() does xchg() after
adding the waiter to the ->wait_list. We are holding ->wait_lock,
we can't race with __mutex_unlock_nonatomic() - it calls wake_up()
and sets ->count under this spinlock.
So, I think it can be simplified:
int __mutex_lock_common(lock, waiter)
{
lock(&lock->wait_lock);
ret = 1;
if (xchg(&lock->count, -1) == 1)
goto out;
__add_waiter(lock, waiter);
task->state = state;
ret = 0;
out:
unlock(&lock->wait_lock);
return ret;
}
No?
> +__mutex_wakeup_waiter(struct mutex *lock __IP_DECL__)
> +{
> + struct mutex_waiter *waiter;
> ...
> + if (!waiter->woken) {
> + waiter->woken = 1;
> + wake_up_process(waiter->ti->task);
> + }
Is it optimization? If yes - why? From mutex.h:
- only one task can hold the mutex at a time
- only the owner can unlock the mutex
So, how can this help?
> +start_mutex_timer(struct timer_list *timer, unsigned long time,
> + unsigned long *expire)
> +{
> + *expire = time + jiffies;
> + init_timer(timer);
> + timer->expires = *expire;
> + timer->data = (unsigned long)current;
> + timer->function = process_timeout;
> + add_timer(timer);
> +}
How about
setup_timer(&timer, process_timeout, (unsigned long)current);
__mod_timer(&timer, *expire);
?
> +stop_mutex_timer(struct timer_list *timer, unsigned long time,
> + unsigned long expire)
> +{
> + int ret;
> +
> + ret = (int)(expire - jiffies);
> + if (!timer_pending(timer)) {
> + del_singleshot_timer_sync(timer);
> + ret = -ETIMEDOUT;
> + }
Did you mean
if (!timer_pending(timer))
ret = -ETIMEDOUT;
del_singleshot_timer_sync(timer);
?
> +__mutex_lock_interruptible(struct mutex *lock, unsigned long time __IP_DECL__)
> +{
> + struct thread_info *ti = current_thread_info();
> + struct task_struct *task = ti->task;
> + unsigned long expire = 0, flags;
> + struct mutex_waiter waiter;
> + struct timer_list timer;
> + int ret;
> +
> +repeat:
> + if (__mutex_lock_common(lock, &waiter, ti, task, &flags,
> + TASK_INTERRUPTIBLE __IP__))
> + return 0;
I think this is wrong. We may have pending timer here if we were woken
by signal.
Oleg.
next prev parent reply other threads:[~2005-12-21 15:05 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-19 1:37 [patch 05/15] Generic Mutex Subsystem, mutex-core.patch Ingo Molnar
2005-12-19 3:56 ` Steven Rostedt
2005-12-19 4:15 ` Steven Rostedt
2005-12-19 4:21 ` Steven Rostedt
2005-12-19 4:43 ` Steven Rostedt
2005-12-19 5:00 ` Steven Rostedt
2005-12-19 5:09 ` Steven Rostedt
2005-12-19 16:51 ` Ingo Molnar
2005-12-19 5:12 ` Steven Rostedt
2005-12-19 16:43 ` Ingo Molnar
2005-12-19 5:16 ` Steven Rostedt
2005-12-21 16:21 ` Oleg Nesterov [this message]
2005-12-21 15:57 ` Ingo Molnar
2005-12-21 17:51 ` Oleg Nesterov
2005-12-21 18:26 ` Ingo Molnar
2005-12-21 15:59 ` Ingo Molnar
2005-12-21 16:02 ` Ingo Molnar
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=43A98101.364DB5CF@tv-sign.ru \
--to=oleg@tv-sign.ru \
--cc=ak@suse.de \
--cc=akpm@osdl.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=arjanv@infradead.org \
--cc=dhowells@redhat.com \
--cc=hch@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=pj@sgi.com \
--cc=rostedt@goodmis.org \
--cc=torvalds@osdl.org \
--cc=viro@ftp.linux.org.uk \
/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