From: Andrew Jones <andrew.jones@linux.dev>
To: kvm-riscv@lists.infradead.org
Cc: atishp@rivosinc.com, cleger@rivosinc.com, jamestiotio@gmail.com
Subject: [kvm-unit-tests PATCH v2 07/11] lib/cpumask: Add some operators
Date: Thu, 27 Feb 2025 15:19:31 +0100 [thread overview]
Message-ID: <20250227141946.91604-20-andrew.jones@linux.dev> (raw)
In-Reply-To: <20250227141946.91604-13-andrew.jones@linux.dev>
We have a need for cpumask_andnot(). Add that and a few friends.
Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
---
lib/cpumask.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/lib/cpumask.h b/lib/cpumask.h
index b4cd83a66a56..3f03d3370f85 100644
--- a/lib/cpumask.h
+++ b/lib/cpumask.h
@@ -72,6 +72,62 @@ static inline bool cpumask_subset(const struct cpumask *src1, const struct cpuma
return !lastmask || !((cpumask_bits(src1)[i] & ~cpumask_bits(src2)[i]) & lastmask);
}
+/* false if dst is empty */
+static inline bool cpumask_and(cpumask_t *dst, const cpumask_t *src1, const cpumask_t *src2)
+{
+ unsigned long lastmask = BIT_MASK(nr_cpus) - 1;
+ unsigned long ret = 0;
+ int i;
+
+ for (i = 0; i < BIT_WORD(nr_cpus); ++i) {
+ cpumask_bits(dst)[i] = cpumask_bits(src1)[i] & cpumask_bits(src2)[i];
+ ret |= cpumask_bits(dst)[i];
+ }
+
+ cpumask_bits(dst)[i] = (cpumask_bits(src1)[i] & cpumask_bits(src2)[i]) & lastmask;
+
+ return ret | cpumask_bits(dst)[i];
+}
+
+static inline void cpumask_or(cpumask_t *dst, const cpumask_t *src1, const cpumask_t *src2)
+{
+ unsigned long lastmask = BIT_MASK(nr_cpus) - 1;
+ int i;
+
+ for (i = 0; i < BIT_WORD(nr_cpus); ++i)
+ cpumask_bits(dst)[i] = cpumask_bits(src1)[i] | cpumask_bits(src2)[i];
+
+ cpumask_bits(dst)[i] = (cpumask_bits(src1)[i] | cpumask_bits(src2)[i]) & lastmask;
+}
+
+static inline void cpumask_xor(cpumask_t *dst, const cpumask_t *src1, const cpumask_t *src2)
+{
+ unsigned long lastmask = BIT_MASK(nr_cpus) - 1;
+ int i;
+
+ for (i = 0; i < BIT_WORD(nr_cpus); ++i)
+ cpumask_bits(dst)[i] = cpumask_bits(src1)[i] ^ cpumask_bits(src2)[i];
+
+ cpumask_bits(dst)[i] = (cpumask_bits(src1)[i] ^ cpumask_bits(src2)[i]) & lastmask;
+}
+
+/* false if dst is empty */
+static inline bool cpumask_andnot(cpumask_t *dst, const cpumask_t *src1, const cpumask_t *src2)
+{
+ unsigned long lastmask = BIT_MASK(nr_cpus) - 1;
+ unsigned long ret = 0;
+ int i;
+
+ for (i = 0; i < BIT_WORD(nr_cpus); ++i) {
+ cpumask_bits(dst)[i] = cpumask_bits(src1)[i] & ~cpumask_bits(src2)[i];
+ ret |= cpumask_bits(dst)[i];
+ }
+
+ cpumask_bits(dst)[i] = (cpumask_bits(src1)[i] & ~cpumask_bits(src2)[i]) & lastmask;
+
+ return ret | cpumask_bits(dst)[i];
+}
+
static inline bool cpumask_equal(const struct cpumask *src1, const struct cpumask *src2)
{
unsigned long lastmask = BIT_MASK(nr_cpus) - 1;
--
2.48.1
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
next prev parent reply other threads:[~2025-02-27 14:43 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-27 14:19 [kvm-unit-tests PATCH v2 00/11] riscv: sbi: Test improvements and a couple new Andrew Jones
2025-02-27 14:19 ` [kvm-unit-tests PATCH v2 01/11] riscv: sbi: Drop fwft upper bits test Andrew Jones
2025-02-27 14:21 ` Clément Léger
2025-02-27 14:19 ` [kvm-unit-tests PATCH v2 02/11] riscv: sbi: Add fwft pte_hw_ad_updating test Andrew Jones
2025-02-27 14:30 ` Clément Léger
2025-02-27 14:19 ` [kvm-unit-tests PATCH v2 03/11] riscv: sbi: Ensure we have IPIs enabled for HSM suspend tests Andrew Jones
2025-02-27 14:19 ` [kvm-unit-tests PATCH v2 04/11] riscv: sbi: Ensure SUSP test gets an interrupt Andrew Jones
2025-02-27 14:19 ` [kvm-unit-tests PATCH v2 05/11] riscv: sbi: Improve susp expected error output Andrew Jones
2025-02-27 14:38 ` Clément Léger
2025-02-27 14:19 ` [kvm-unit-tests PATCH v2 06/11] riscv: sbi: Improve interrupt handling cleanup Andrew Jones
2025-02-27 14:19 ` Andrew Jones [this message]
2025-02-27 14:22 ` [kvm-unit-tests PATCH v2 08/11] riscv: sbi: HSM suspend may not be supported Andrew Jones
2025-02-27 14:22 ` [kvm-unit-tests PATCH v2 09/11] riscv: sbi: Probe/skip SUSP Andrew Jones
2025-02-27 14:22 ` [kvm-unit-tests PATCH v2 10/11] riscv: sbi: susp: Check upper bits of sleep_type are ignored Andrew Jones
2025-02-27 14:22 ` [kvm-unit-tests PATCH v2 11/11] riscv: sbi: Add bad fid tests Andrew Jones
2025-02-27 14:33 ` Clément Léger
2025-03-04 9:31 ` [kvm-unit-tests PATCH v2 00/11] riscv: sbi: Test improvements and a couple new Andrew Jones
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=20250227141946.91604-20-andrew.jones@linux.dev \
--to=andrew.jones@linux.dev \
--cc=atishp@rivosinc.com \
--cc=cleger@rivosinc.com \
--cc=jamestiotio@gmail.com \
--cc=kvm-riscv@lists.infradead.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.