lkml.org 
[lkml]   [2008]   [Nov]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
SubjectRe: [PATCH] cpumask: introduce new API, without changing anything
Date
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;




\
 
 \ /
  Last update: 2008-11-07 12:35    [W:0.208 / U:0.164 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site