From ebce385d616d20bb3cd39668fd348eff4a18017a Mon Sep 17 00:00:00 2001 From: Tomasz Kulasek Date: Mon, 4 Feb 2019 12:07:39 +0100 Subject: [PATCH] lib/util/cpuset: add negate and xor Change-Id: I8d2fc9d0fcc6cb8b088c307d1520f0b1051c3ef6 Signed-off-by: Tomasz Kulasek Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/443518 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Shuhei Matsumoto --- include/spdk/cpuset.h | 15 +++++++++++++++ lib/util/cpuset.c | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/spdk/cpuset.h b/include/spdk/cpuset.h index d59305714..153fe0fae 100644 --- a/include/spdk/cpuset.h +++ b/include/spdk/cpuset.h @@ -100,6 +100,21 @@ void spdk_cpuset_and(struct spdk_cpuset *dst, const struct spdk_cpuset *src); */ void spdk_cpuset_or(struct spdk_cpuset *dst, const struct spdk_cpuset *src); +/** + * Perform XOR operation on two CPU sets. The result is stored in dst. + * + * \param dst First argument of operation. This value also stores the result of operation. + * \param src Second argument of operation. + */ +void spdk_cpuset_xor(struct spdk_cpuset *dst, const struct spdk_cpuset *src); + +/** + * Negate all CPUs in CPU set. + * + * \param set CPU set to be negated. This value also stores the result of operation. + */ +void spdk_cpuset_negate(struct spdk_cpuset *set); + /** * Clear all CPUs in CPU set. * diff --git a/lib/util/cpuset.c b/lib/util/cpuset.c index de9fbfb63..a1a8dd2e7 100644 --- a/lib/util/cpuset.c +++ b/lib/util/cpuset.c @@ -67,6 +67,16 @@ spdk_cpuset_copy(struct spdk_cpuset *set1, const struct spdk_cpuset *set2) memcpy(&set1->cpus, &set2->cpus, sizeof(set2->cpus)); } +void +spdk_cpuset_negate(struct spdk_cpuset *set) +{ + unsigned int i; + assert(set != NULL); + for (i = 0; i < sizeof(set->cpus); i++) { + set->cpus[i] = ~set->cpus[i]; + } +} + void spdk_cpuset_and(struct spdk_cpuset *set1, const struct spdk_cpuset *set2) { @@ -89,6 +99,17 @@ spdk_cpuset_or(struct spdk_cpuset *set1, const struct spdk_cpuset *set2) } } +void +spdk_cpuset_xor(struct spdk_cpuset *set1, const struct spdk_cpuset *set2) +{ + unsigned int i; + assert(set1 != NULL); + assert(set2 != NULL); + for (i = 0; i < sizeof(set2->cpus); i++) { + set1->cpus[i] ^= set2->cpus[i]; + } +} + void spdk_cpuset_zero(struct spdk_cpuset *set) {