From patchwork Mon Nov 15 16:57:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Elisei X-Patchwork-Id: 12692641 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 623C9C433FE for ; Mon, 15 Nov 2021 16:59:03 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F078A61BE5 for ; Mon, 15 Nov 2021 16:59:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org F078A61BE5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ja3RJ4o7SpxtBJOYYz9XnXvlkqNqWGCu4SsgykTdZGs=; b=Ejy0jvM0ydwZP3 lgN3ahdOVXDb/uLW280l9FgVxwcs0SSDGz7ODZgMrUcAXu79APfaZMDwwHRCISRO58ZCR13FPq6qO 2RHXDLWzO53q6rLy3EzaVaLk17b8MAroY01pyJtI+TvPlyvrCfNREp610Ncbu+AGj7tUkcLgRCQ3r DLTRDosWkXQLqS+AX4BuNXj8kLsTOLapAhbTv7mo6S0Zq6gjXH4CHw8wmsyvSNzR7Yl86G6HBlTNu P/o2xP2G67fsfwomsfbRh7H2nLjd84krXx0erkW9nyYUGNfeGRZ9cLUZvuilWrL6dJwuagsXEgOys ELQsy7i3rB4zDjwyC2+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mmfIZ-00GRZ0-DE; Mon, 15 Nov 2021 16:57:39 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mmfGb-00GQcN-2T for linux-arm-kernel@lists.infradead.org; Mon, 15 Nov 2021 16:55:38 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 115041FB; Mon, 15 Nov 2021 08:55:36 -0800 (PST) Received: from monolith.localdoman (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 92CF53F766; Mon, 15 Nov 2021 08:55:34 -0800 (PST) From: Alexandru Elisei To: will@kernel.org, julien.thierry.kdev@gmail.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, maz@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, mark.rutland@arm.com Subject: [PATCH kvmtool 6/9] util: Add basic cpumask functions Date: Mon, 15 Nov 2021 16:57:02 +0000 Message-Id: <20211115165705.195736-7-alexandru.elisei@arm.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211115165705.195736-1-alexandru.elisei@arm.com> References: <20211115165705.195736-1-alexandru.elisei@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211115_085537_233191_39B1E795 X-CRM114-Status: GOOD ( 14.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a handful of basic cpumask functions, some of which will be used when dealing with different PMUs on heterogeneous systems. Signed-off-by: Alexandru Elisei --- arm/aarch32/include/asm/kernel.h | 8 ++++++++ arm/aarch64/include/asm/kernel.h | 8 ++++++++ include/linux/bitmap.h | 20 +++++++++++++++++++ include/linux/cpumask.h | 33 ++++++++++++++++++++++++++++++++ include/linux/kernel.h | 2 ++ mips/include/asm/kernel.h | 8 ++++++++ powerpc/include/asm/kernel.h | 8 ++++++++ x86/include/asm/kernel.h | 8 ++++++++ 8 files changed, 95 insertions(+) create mode 100644 arm/aarch32/include/asm/kernel.h create mode 100644 arm/aarch64/include/asm/kernel.h create mode 100644 include/linux/bitmap.h create mode 100644 include/linux/cpumask.h create mode 100644 mips/include/asm/kernel.h create mode 100644 powerpc/include/asm/kernel.h create mode 100644 x86/include/asm/kernel.h diff --git a/arm/aarch32/include/asm/kernel.h b/arm/aarch32/include/asm/kernel.h new file mode 100644 index 000000000000..61296094deb1 --- /dev/null +++ b/arm/aarch32/include/asm/kernel.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __ASM_KERNEL_H +#define __ASM_KERNEL_H + +#define NR_CPUS 32 + +#endif /* __ASM_KERNEL_H */ diff --git a/arm/aarch64/include/asm/kernel.h b/arm/aarch64/include/asm/kernel.h new file mode 100644 index 000000000000..4ab195fcb89d --- /dev/null +++ b/arm/aarch64/include/asm/kernel.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __ASM_KERNEL_H +#define __ASM_KERNEL_H + +#define NR_CPUS 512 + +#endif /* __ASM_KERNEL_H */ diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h new file mode 100644 index 000000000000..33b24520a576 --- /dev/null +++ b/include/linux/bitmap.h @@ -0,0 +1,20 @@ +#ifndef KVM__BITMAP_H +#define KVM__BITMAP_H + +#include + +#include + +#define DECLARE_BITMAP(name,bits) \ + unsigned long name[BITS_TO_LONGS(bits)] + +#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) +#define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1))) + +static inline void bitmap_zero(unsigned long *dst, unsigned int nbits) +{ + unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); + memset(dst, 0, len); +} + +#endif /* KVM__BITMAP_H */ diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h new file mode 100644 index 000000000000..36959885aeff --- /dev/null +++ b/include/linux/cpumask.h @@ -0,0 +1,33 @@ +#ifndef KVM__CPUMASK_H +#define KVM__CPUMASK_H + +#include + +#include +#include + +typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t; + +#define cpumask_bits(maskp) ((maskp)->bits) + +static inline void cpumask_set_cpu(int cpu, cpumask_t *dstp) +{ + set_bit(cpu, cpumask_bits(dstp)); +} + +static inline void cpumask_clear_cpu(int cpu, cpumask_t *dstp) +{ + clear_bit(cpu, cpumask_bits(dstp)); +} + +static inline int cpumask_test_cpu(int cpu, const cpumask_t *cpumask) +{ + return test_bit(cpu, cpumask_bits((cpumask))); +} + +static inline void cpumask_clear(cpumask_t *dstp) +{ + bitmap_zero(cpumask_bits(dstp), NR_CPUS); +} + +#endif /* KVM__CPUMASK_H */ diff --git a/include/linux/kernel.h b/include/linux/kernel.h index f2bff5f12b61..f3240e09a321 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -2,6 +2,8 @@ #ifndef KVM__LINUX_KERNEL_H_ #define KVM__LINUX_KERNEL_H_ +#include + #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) diff --git a/mips/include/asm/kernel.h b/mips/include/asm/kernel.h new file mode 100644 index 000000000000..cbceffd02acd --- /dev/null +++ b/mips/include/asm/kernel.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __ASM_KERNEL_H +#define __ASM_KERNEL_H + +#define NR_CPUS 256 + +#endif /* __ASM_KERNEL_H */ diff --git a/powerpc/include/asm/kernel.h b/powerpc/include/asm/kernel.h new file mode 100644 index 000000000000..7b4fe88efd65 --- /dev/null +++ b/powerpc/include/asm/kernel.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __ASM_KERNEL_H +#define __ASM_KERNEL_H + +#define NR_CPUS 2048 + +#endif /* __ASM_KERNEL_H */ diff --git a/x86/include/asm/kernel.h b/x86/include/asm/kernel.h new file mode 100644 index 000000000000..87fad2a0300a --- /dev/null +++ b/x86/include/asm/kernel.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _ASM_KERNEL_H +#define _ASM_KERNEL_H + +#define NR_CPUS 8196 + +#endif /* _ASM_KERNEL_H */