From: Mike Travis <travis@sgi.com>
To: Ingo Molnar <mingo@elte.hu>, Andrew Morton <akpm@linux-foundation.org>
Cc: davej@codemonkey.org.uk, David Miller <davem@davemloft.net>,
Eric Dumazet <dada1@cosmosbay.com>,
"Eric W. Biederman" <ebiederm@xmission.com>,
Jack Steiner <steiner@sgi.com>,
Jeremy Fitzhardinge <jeremy@goop.org>, Jes Sorensen <jes@sgi.com>,
"H. Peter Anvin" <hpa@zytor.com>,
Thomas Gleixner <tglx@linutronix.de>,
linux-kernel@vger.kernel.org
Subject: [RFC 02/13] cpumask: add for_each_online_cpu_mask_nr function
Date: Sat, 06 Sep 2008 16:50:38 -0700 [thread overview]
Message-ID: <20080906235037.207282000@polaris-admin.engr.sgi.com> (raw)
In-Reply-To: 20080906235036.891970000@polaris-admin.engr.sgi.com
[-- Attachment #1: for_each_online_cpu_mask_nr --]
[-- Type: text/plain, Size: 4303 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:
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-06 23:51 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-06 23:50 [RFC 00/13] smp: reduce stack requirements for genapic send_IPI_mask functions Mike Travis
2008-09-06 23:50 ` [RFC 01/13] smp: modify send_IPI_mask interface to accept cpumask_t pointers Mike Travis
2008-09-06 23:50 ` Mike Travis [this message]
2008-09-06 23:50 ` [RFC 03/13] xen: use new for_each_online_cpu_mask_nr function Mike Travis
2008-09-06 23:50 ` [RFC 04/13] cpumask: add cpumask_ptr operations Mike Travis
2008-09-06 23:50 ` [RFC 05/13] cpumask: add get_cpumask_var debug operations Mike Travis
2008-09-06 23:50 ` [RFC 06/13] genapic: use get_cpumask_var operations for allbutself cpumask_ts Mike Travis
2008-09-06 23:50 ` [RFC 07/13] sched: Reduce stack size requirements in kernel/sched.c Mike Travis
2008-09-07 10:24 ` Peter Zijlstra
2008-09-07 11:00 ` Andrew Morton
2008-09-07 13:05 ` Peter Zijlstra
2008-09-08 14:56 ` Mike Travis
2008-09-07 20:28 ` Peter Zijlstra
2008-09-08 14:54 ` Mike Travis
2008-09-08 15:05 ` Peter Zijlstra
2008-09-08 18:38 ` Ingo Molnar
2008-09-10 22:47 ` [RFC] CPUMASK: proposal for replacing cpumask_t Mike Travis
2008-09-10 22:53 ` Andi Kleen
2008-09-10 23:33 ` Mike Travis
2008-09-11 5:21 ` Andi Kleen
2008-09-11 9:00 ` Peter Zijlstra
2008-09-11 15:04 ` Mike Travis
2008-09-12 4:55 ` Rusty Russell
2008-09-12 14:28 ` Mike Travis
2008-09-12 22:02 ` Rusty Russell
2008-09-12 22:50 ` Mike Travis
2008-09-12 22:58 ` H. Peter Anvin
2008-09-06 23:50 ` [RFC 08/13] cpufreq: Reduce stack size requirements in acpi-cpufreq.c Mike Travis
2008-09-06 23:50 ` [RFC 09/13] genapic: reduce stack pressuge in io_apic.c step 1 temp cpumask_ts Mike Travis
2008-09-08 11:01 ` Andi Kleen
2008-09-08 16:03 ` Mike Travis
2008-09-06 23:50 ` [RFC 10/13] genapic: reduce stack pressuge in io_apic.c step 2 internal abi Mike Travis
2008-09-06 23:50 ` [RFC 11/13] genapic: reduce stack pressuge in io_apic.c step 3 target_cpus Mike Travis
2008-09-07 7:55 ` Bert Wesarg
2008-09-07 9:13 ` Ingo Molnar
2008-09-08 15:01 ` Mike Travis
2008-09-08 15:29 ` Mike Travis
2008-09-06 23:50 ` [RFC 12/13] genapic: reduce stack pressuge in io_apic.c step 4 vector allocation Mike Travis
2008-09-06 23:50 ` [RFC 13/13] genapic: reduce stack pressuge in io_apic.c step 5 cpu_mask_to_apicid Mike Travis
2008-09-07 7:36 ` [RFC 00/13] smp: reduce stack requirements for genapic send_IPI_mask functions Ingo Molnar
2008-09-08 15:17 ` 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=20080906235037.207282000@polaris-admin.engr.sgi.com \
--to=travis@sgi.com \
--cc=akpm@linux-foundation.org \
--cc=dada1@cosmosbay.com \
--cc=davej@codemonkey.org.uk \
--cc=davem@davemloft.net \
--cc=ebiederm@xmission.com \
--cc=hpa@zytor.com \
--cc=jeremy@goop.org \
--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;
as well as URLs for NNTP newsgroup(s).