From: Mike Travis <travis@sgi.com>
To: Ingo Molnar <mingo@elte.hu>, Andrew Morton <akpm@linux-foundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
"H. Peter Anvin" <hpa@zytor.com>, Jack Steiner <steiner@sgi.com>,
Jes Sorensen <jes@sgi.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/3] cpumask: add for_each_online_cpu_mask_nr function
Date: Tue, 09 Sep 2008 08:50:14 -0700 [thread overview]
Message-ID: <20080909155013.735125000@polaris-admin.engr.sgi.com> (raw)
In-Reply-To: <20080909155013.455071000@polaris-admin.engr.sgi.com>
[-- Attachment #1: for_each_online_cpu_mask_nr --]
[-- Type: text/plain, Size: 4351 bytes --]
* Add for_each_online_cpu_mask_nr() function to eliminate need for
a common use of a temporary cpumask_t variable. When the following
procedure is being used:
funcproto(cpumask_t *mask, ...)
{
cpumask_t temp;
cpus_and(temp, *mask, cpu_online_map);
for_each_cpu_mask_nr(cpu, temp)
...
If then becomes:
funcproto(cpumask_t *mask, ...)
{
for_each_online_cpu_mask_nr(cpu, *mask)
...
* Note the generic __next_cpu_and (and __next_cpu_and_nr) functions
allowing AND'ing with any cpumask_t variable, not just the cpu_online_map.
Applies to linux-2.6.tip/master.
Signed-off-by: Mike Travis <travis@sgi.com>
---
include/linux/cpumask.h | 26 +++++++++++++++++++++++---
lib/cpumask.c | 26 ++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 3 deletions(-)
--- linux-2.6.tip.orig/include/linux/cpumask.h
+++ linux-2.6.tip/include/linux/cpumask.h
@@ -404,23 +404,32 @@ static inline void __cpus_fold(cpumask_t
#define first_cpu(src) ({ (void)(src); 0; })
#define next_cpu(n, src) ({ (void)(src); 1; })
#define any_online_cpu(mask) 0
-#define for_each_cpu_mask(cpu, mask) \
+
+#define for_each_cpu_mask(cpu, mask) \
for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
+#define for_each_online_cpu_mask(cpu, mask) \
+ for_each_cpu_mask(cpu, mask)
#else /* NR_CPUS > 1 */
extern int nr_cpu_ids;
int __first_cpu(const cpumask_t *srcp);
int __next_cpu(int n, const cpumask_t *srcp);
+int __next_cpu_and(int n, const cpumask_t *srcp, const cpumask_t *andp);
int __any_online_cpu(const cpumask_t *mask);
#define first_cpu(src) __first_cpu(&(src))
#define next_cpu(n, src) __next_cpu((n), &(src))
#define any_online_cpu(mask) __any_online_cpu(&(mask))
+
#define for_each_cpu_mask(cpu, mask) \
for ((cpu) = -1; \
(cpu) = next_cpu((cpu), (mask)), \
(cpu) < NR_CPUS; )
+#define for_each_online_cpu_mask(cpu, mask) \
+ for ((cpu) = -1; \
+ (cpu) = __next_cpu_and((cpu), &(mask), &(cpu_online_map)), \
+ (cpu) < NR_CPUS; )
#endif
#if NR_CPUS <= 64
@@ -428,17 +437,28 @@ int __any_online_cpu(const cpumask_t *ma
#define next_cpu_nr(n, src) next_cpu(n, src)
#define cpus_weight_nr(cpumask) cpus_weight(cpumask)
#define for_each_cpu_mask_nr(cpu, mask) for_each_cpu_mask(cpu, mask)
+#define for_each_online_cpu_mask_nr(cpu, mask) \
+ for_each_online_cpu_mask(cpu, mask)
#else /* NR_CPUS > 64 */
int __next_cpu_nr(int n, const cpumask_t *srcp);
-#define next_cpu_nr(n, src) __next_cpu_nr((n), &(src))
-#define cpus_weight_nr(cpumask) __cpus_weight(&(cpumask), nr_cpu_ids)
+int __next_cpu_and_nr(int n, const cpumask_t *srcp, const cpumask_t *andp);
+
+#define next_cpu_nr(n, src) __next_cpu_nr((n), &(src))
+#define next_cpu_and_nr(n, src, and) __next_cpu_and_nr((n), &(src), &(and))
+#define cpus_weight_nr(cpumask) __cpus_weight(&(cpumask), nr_cpu_ids)
+
#define for_each_cpu_mask_nr(cpu, mask) \
for ((cpu) = -1; \
(cpu) = next_cpu_nr((cpu), (mask)), \
(cpu) < nr_cpu_ids; )
+#define for_each_online_cpu_mask_nr(cpu, mask) \
+ for ((cpu) = -1; \
+ (cpu) = next_cpu_and_nr((cpu), (mask), (cpu_online_map)), \
+ (cpu) < nr_cpu_ids; )
+
#endif /* NR_CPUS > 64 */
/*
--- linux-2.6.tip.orig/lib/cpumask.c
+++ linux-2.6.tip/lib/cpumask.c
@@ -14,6 +14,19 @@ int __next_cpu(int n, const cpumask_t *s
return min_t(int, NR_CPUS, find_next_bit(srcp->bits, NR_CPUS, n+1));
}
EXPORT_SYMBOL(__next_cpu);
+int __next_cpu_and(int n, const cpumask_t *srcp, const cpumask_t *andp)
+{
+ int cpu;
+
+ for (cpu = n + 1; cpu < NR_CPUS; cpu++) {
+ cpu = find_next_bit(srcp->bits, NR_CPUS, cpu);
+
+ if (cpu < NR_CPUS && cpu_isset(cpu, *andp))
+ return cpu;
+ }
+ return NR_CPUS;
+}
+EXPORT_SYMBOL(__next_cpu_and);
#if NR_CPUS > 64
int __next_cpu_nr(int n, const cpumask_t *srcp)
@@ -22,6 +35,19 @@ int __next_cpu_nr(int n, const cpumask_t
find_next_bit(srcp->bits, nr_cpu_ids, n+1));
}
EXPORT_SYMBOL(__next_cpu_nr);
+int __next_cpu_and_nr(int n, const cpumask_t *srcp, const cpumask_t *andp)
+{
+ int cpu;
+
+ for (cpu = n + 1; cpu < nr_cpu_ids; cpu++) {
+ cpu = find_next_bit(srcp->bits, nr_cpu_ids, cpu);
+
+ if (cpu < nr_cpu_ids && cpu_isset(cpu, *andp))
+ return cpu;
+ }
+ return nr_cpu_ids;
+}
+EXPORT_SYMBOL(__next_cpu_and_nr);
#endif
int __any_online_cpu(const cpumask_t *mask)
--
next prev parent reply other threads:[~2008-09-09 15:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-09 15:50 [PATCH 0/3] x86: remove extraneous stack cpumask variables Mike Travis
2008-09-09 15:50 ` Mike Travis [this message]
2008-09-12 4:33 ` [PATCH 1/3] cpumask: add for_each_online_cpu_mask_nr function Rusty Russell
2008-09-12 14:17 ` Mike Travis
2008-09-09 15:50 ` [PATCH 2/3] x86: modify send_IPI_mask interface to accept cpumask_t pointers Mike Travis
2008-09-09 15:50 ` [PATCH 3/3] sched: Optimize cpumask temp stack usage in kernel/sched.c Mike Travis
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=20080909155013.735125000@polaris-admin.engr.sgi.com \
--to=travis@sgi.com \
--cc=akpm@linux-foundation.org \
--cc=hpa@zytor.com \
--cc=jes@sgi.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=steiner@sgi.com \
--cc=tglx@linutronix.de \
/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
all inboxes | Powered by JetHome®