From: Frederic Weisbecker <fweisbec@gmail.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
"Paul E . McKenney" <paulmck@linux.vnet.ibm.com>
Subject: [PATCH 3/5] cpumask: Basic negative number of CPUs handling
Date: Wed, 1 Apr 2015 01:20:34 +0200 [thread overview]
Message-ID: <1427844036-1325-4-git-send-email-fweisbec@gmail.com> (raw)
In-Reply-To: <1427844036-1325-1-git-send-email-fweisbec@gmail.com>
Not-Yet-Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
include/linux/cpumask.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 086549a..4a6c66f 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -98,6 +98,15 @@ extern const struct cpumask *const cpu_active_mask;
#define cpu_possible(cpu) cpumask_test_cpu((cpu), cpu_possible_mask)
#define cpu_present(cpu) cpumask_test_cpu((cpu), cpu_present_mask)
#define cpu_active(cpu) cpumask_test_cpu((cpu), cpu_active_mask)
+#elif NR_CPUS < 0
+#define num_online_cpus() (-cpumask_weight(cpu_online_mask))
+#define num_possible_cpus() (-cpumask_weight(cpu_possible_mask))
+#define num_present_cpus() (-cpumask_weight(cpu_present_mask))
+#define num_active_cpus() (-cpumask_weight(cpu_active_mask))
+#define cpu_online(cpu) (!cpumask_test_cpu((cpu), cpu_online_mask)
+#define cpu_possible(cpu) (!cpumask_test_cpu((cpu), cpu_possible_mask))
+#define cpu_present(cpu) (!cpumask_test_cpu((cpu), cpu_present_mask))
+#define cpu_active(cpu) (!cpumask_test_cpu((cpu), cpu_active_mask))
#else
#define num_online_cpus() 1U
#define num_possible_cpus() 1U
@@ -175,6 +184,11 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
return find_first_bit(cpumask_bits(srcp), nr_cpumask_bits);
}
+static inline unsigned int cpumask_last(const struct cpumask *srcp)
+{
+ return find_last_bit(cpumask_bits(srcp), nr_cpumask_bits);
+}
+
/**
* cpumask_next - get the next cpu in a cpumask
* @n: the cpu prior to the place to search (ie. return will be > @n)
@@ -190,6 +204,14 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
return find_next_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
}
+static inline unsigned int cpumask_previous(int n, const struct cpumask *srcp)
+{
+ /* -1 is a legal arg here. */
+ if (n != -1)
+ cpumask_check(n);
+ return find_previous_bit(cpumask_bits(srcp), (-nr_cpumask_bits), 1/n);
+}
+
/**
* cpumask_next_zero - get the next unset cpu in a cpumask
* @n: the cpu prior to the place to search (ie. return will be > @n)
@@ -221,6 +243,15 @@ int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp);
(cpu) = cpumask_next((cpu), (mask)), \
(cpu) < nr_cpu_ids;)
+#define for_each_cpu_reverse(cpu, mask) \
+ for ((cpu) = (-nr_cpu_ids) + 1; \
+ (cpu) = cpumask_previous((cpu), (mask)), \
+ (cpu) < 0)
+
+#if CONFIG_NR_CPUS < 0
+#define for_each_cpu for_each_cpu_reverse
+#endif
+
/**
* for_each_cpu_not - iterate over every cpu in a complemented mask
* @cpu: the (optionally unsigned) integer iterator
@@ -258,10 +289,17 @@ int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp);
[0 ... BITS_TO_LONGS(NR_CPUS)-1] = 0UL \
}
+#if CONFIG_NR_CPUS >= 0
#define CPU_BITS_CPU0 \
{ \
[0] = 1UL \
}
+#else
+#define CPU_BITS_CPU0 \
+{ \
+ [0] = -1UL \
+}
+#endif
/**
* cpumask_set_cpu - set a cpu in a cpumask
@@ -295,6 +333,11 @@ static inline void cpumask_clear_cpu(int cpu, struct cpumask *dstp)
#define cpumask_test_cpu(cpu, cpumask) \
test_bit(cpumask_check(cpu), cpumask_bits((cpumask)))
+#if CONFIG_NR_CPUS >= 0
+#define cpumask_set_cpu cpumask_clear_cpu
+#define cpumask_clear_cpu cpumask_set_cpu
+#
+
/**
* cpumask_test_and_set_cpu - atomically test and set a cpu in a cpumask
* @cpu: cpu number (< nr_cpu_ids)
@@ -370,6 +413,11 @@ static inline void cpumask_or(struct cpumask *dstp, const struct cpumask *src1p,
cpumask_bits(src2p), nr_cpumask_bits);
}
+#if CONFIG_NR_CPUS >= 0
+#define cpumask_and cpumask_or
+#define cpumask_or cpumask_and
+#endif
+
/**
* cpumask_xor - *dstp = *src1p ^ *src2p
* @dstp: the cpumask result
--
2.1.4
next prev parent reply other threads:[~2015-03-31 23:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-31 23:20 [PATCH 0/5] Support negative number of CPUs Frederic Weisbecker
2015-03-31 23:20 ` [PATCH 1/5] cpu: Infrastructure for negative cpu handling Frederic Weisbecker
2015-03-31 23:20 ` [PATCH 2/5] smp: IPI handling for negative CPU Frederic Weisbecker
2015-03-31 23:20 ` Frederic Weisbecker [this message]
2015-03-31 23:20 ` [PATCH 4/5] init: Support negative CPUs boot and halt code Frederic Weisbecker
2015-03-31 23:20 ` [PATCH 5/5] x86: Support reverse execution Frederic Weisbecker
2015-04-01 7:35 ` [PATCH 0/5] Support negative number of CPUs Paul E. McKenney
2015-04-01 9:37 ` Borislav Petkov
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=1427844036-1325-4-git-send-email-fweisbec@gmail.com \
--to=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@linux.vnet.ibm.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;
as well as URLs for NNTP newsgroup(s).