From: Andrew Morton <akpm@osdl.org>
To: David Howells <dhowells@redhat.com>
Cc: torvalds@osdl.org, davem@davemloft.com, wli@holomorphy.com,
matthew@wil.cx, linux-kernel@vger.kernel.org,
linux-arch@vger.kernel.org
Subject: Re: [PATCH 3/3] WorkStruct: Use direct assignment rather than cmpxchg()
Date: Thu, 7 Dec 2006 08:54:09 -0800 [thread overview]
Message-ID: <20061207085409.228016a2.akpm@osdl.org> (raw)
In-Reply-To: <20061207153143.28408.7274.stgit@warthog.cambridge.redhat.com>
On Thu, 07 Dec 2006 15:31:43 +0000
David Howells <dhowells@redhat.com> wrote:
> Use direct assignment rather than cmpxchg() as the latter is unavailable and
> unimplementable on some platforms and is actually unnecessary.
>
> The use of cmpxchg() was to guard against two possibilities, neither of which
> can actually occur:
>
> (1) The pending flag may have been unset or may be cleared. However, given
> where it's called, the pending flag is _always_ set. I don't think it
> can be unset whilst we're in set_wq_data().
>
> Once the work is enqueued to be actually run, the only way off the queue
> is for it to be actually run.
>
> If it's a delayed work item, then the bit can't be cleared by the timer
> because we haven't started the timer yet. Also, the pending bit can't be
> cleared by cancelling the delayed work _until_ the work item has had its
> timer started.
>
> (2) The workqueue pointer might change. This can only happen in two cases:
>
> (a) The work item has just been queued to actually run, and so we're
> protected by the appropriate workqueue spinlock.
>
> (b) A delayed work item is being queued, and so the timer hasn't been
> started yet, and so no one else knows about the work item or can
> access it (the pending bit protects us).
>
> Besides, set_wq_data() _sets_ the workqueue pointer unconditionally, so
> it can be assigned instead.
>
> So, replacing the set_wq_data() with a straight assignment would be okay in
> most cases. The problem is where we end up tangling with test_and_set_bit()
> emulated using spinlocks, and even then it's not a problem _provided_
> test_and_set_bit() doesn't attempt to modify the word if the bit was set.
>
> If that's a problem, then a bitops-proofed assignment will be required -
> equivalent to atomic_set() vs other atomic_xxx() ops.
>
I don't understand, as usual.
afacit in all (but one) cases we do
if (!test_and_set_bit(WORK_STRUCT_PENDING, &work->management)) {
...
set_wq_data(work, wq);
...
<now do stuff which makes it possible for run_workqueue()
to get a look at the new work>
}
cancel_delayed_work() looks OK too.
The possible exception is schedule_on_each_cpu() which is being lazy, but
looks fixable.
So... afaict in all the places where there can be a concurrent
set_wq_data() and test_and_set_bit(), WORK_STRUCT_PENDING is reliably set,
and we can assume (and ensure) that a failing test_and_set_bit() will not
write to the affected word at all.
What am I missing?
next prev parent reply other threads:[~2006-12-07 16:55 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-07 15:31 [PATCH 1/3] WorkStruct: Fix up some PA-RISC work items David Howells
2006-12-07 15:31 ` [PATCH 2/3] WorkStruct: Add assign_bits() to give an atomic-bitops safe assignment David Howells
2006-12-07 15:31 ` [PATCH 3/3] WorkStruct: Use direct assignment rather than cmpxchg() David Howells
2006-12-07 16:54 ` Andrew Morton [this message]
2006-12-07 20:06 ` David Howells
2006-12-07 21:06 ` Andrew Morton
2006-12-07 21:06 ` James Bottomley
2006-12-07 21:16 ` David Howells
2006-12-07 22:11 ` David Miller
2006-12-07 23:42 ` Russell King
2006-12-07 23:58 ` David Howells
2006-12-08 11:14 ` Russell King
2006-12-08 13:57 ` David Howells
2006-12-08 3:42 ` [PATCH 1/3] WorkStruct: Fix up some PA-RISC work items Kyle McMartin
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=20061207085409.228016a2.akpm@osdl.org \
--to=akpm@osdl.org \
--cc=davem@davemloft.com \
--cc=dhowells@redhat.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matthew@wil.cx \
--cc=torvalds@osdl.org \
--cc=wli@holomorphy.com \
/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