From: Rusty Russell <rusty@rustcorp.com.au>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@elte.hu>,
Linus Torvalds <torvalds@linux-foundation.org>,
Stephen Rothwell <sfr@canb.auug.org.au>,
Thomas Gleixner <tglx@linutronix.de>,
"H. Peter Anvin" <hpa@zytor.com>, Mike Travis <travis@sgi.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] cpumask: introduce new API, without changing anything
Date: Fri, 7 Nov 2008 22:32:02 +1100 [thread overview]
Message-ID: <200811072232.03323.rusty@rustcorp.com.au> (raw)
In-Reply-To: <20081107005229.53d6f2e3.akpm@linux-foundation.org>
On Friday 07 November 2008 19:52:29 Andrew Morton wrote:
> So I can happily compile and run
>
> cpumask_first("hello, world");
>
> with CONFIG_SMP=n?
Good point. It was based on the existing "first_cpu", but it's not a practice
we should encourage.
Hmm, the implementation of these UP versions is wrong in corner cases, too.
Obviously it doesn't currently matter the way they are used, but a nasty trap
for the future.
Here's the addition, I've queued it for linux-next (which will next come out
after the weekend).
diff -u b/include/linux/cpumask.h b/include/linux/cpumask.h
--- b/include/linux/cpumask.h Fri Nov 07 00:15:12 2008 +1100
+++ b/include/linux/cpumask.h Fri Nov 07 22:28:33 2008 +1100
@@ -564,12 +564,36 @@
}
#if NR_CPUS == 1
-/* Uniprocesor. */
-#define cpumask_first(src) ({ (void)(src); 0; })
-#define cpumask_next(n, src) ({ (void)(src); 1; })
-#define cpumask_next_zero(n, src) ({ (void)(src); 1; })
-#define cpumask_next_and(n, srcp, andp) ({ (void)(srcp), (void)(andp); 1; })
-#define cpumask_any_but(mask, cpu) ({ (void)(mask); (void)(cpu); 0; })
+/* Uniprocessor. Assume all masks are "1". */
+static inline unsigned int cpumask_first(const struct cpumask *srcp)
+{
+ return 0;
+}
+
+/* Valid inputs for n are -1 and 0. */
+static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
+{
+ return n+1;
+}
+
+static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
+{
+ return n+1;
+}
+
+static inline unsigned int cpumask_next_and(int n,
+ const struct cpumask *srcp,
+ const struct cpumask *andp)
+{
+ return n+1;
+}
+
+/* cpu must be a valid cpu, ie 0, so there's no other choice. */
+static inline unsigned int cpumask_any_but(const struct cpumask *mask,
+ unsigned int cpu)
+{
+ return 1;
+}
#define for_each_cpu(cpu, mask) \
for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
diff -u b/lib/cpumask.c b/lib/cpumask.c
--- b/lib/cpumask.c Fri Nov 07 00:15:12 2008 +1100
+++ b/lib/cpumask.c Fri Nov 07 22:28:33 2008 +1100
@@ -67,6 +67,7 @@
{
unsigned int i;
+ cpumask_check(cpu);
for_each_cpu(i, mask)
if (i != cpu)
break;
next prev parent reply other threads:[~2008-11-07 11:32 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20081029152849.3883d072.sfr@canb.auug.org.au>
[not found] ` <200811021229.16061.rusty@rustcorp.com.au>
[not found] ` <alpine.LFD.2.00.0811011834360.3483@nehalem.linux-foundation.org>
2008-11-06 22:49 ` [PATCH] cpumask: introduce new API, without changing anything Rusty Russell
2008-11-07 8:40 ` Ingo Molnar
2008-11-07 8:52 ` Andrew Morton
2008-11-07 8:57 ` Ingo Molnar
2008-11-07 11:32 ` Rusty Russell [this message]
2008-11-07 9:11 ` Stephen Rothwell
2008-11-07 9:39 ` Ingo Molnar
2008-11-07 12:24 ` Ingo Molnar
2008-11-07 18:17 ` Mike Travis
2008-11-08 9:24 ` Rusty Russell
2008-11-08 12:28 ` Ingo Molnar
2008-11-10 18:16 ` Mike Travis
2008-11-09 20:01 ` Linus Torvalds
2008-11-09 20:16 ` Ingo Molnar
2008-11-09 21:37 ` Ingo Molnar
2008-11-09 21:46 ` Rusty Russell
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=200811072232.03323.rusty@rustcorp.com.au \
--to=rusty@rustcorp.com.au \
--cc=akpm@linux-foundation.org \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=sfr@canb.auug.org.au \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=travis@sgi.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