public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Tony Luck <tony.luck@intel.com>
To: Fenghua Yu <fenghua.yu@intel.com>,
	Reinette Chatre <reinette.chatre@intel.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Shaopeng Tan <tan.shaopeng@fujitsu.com>,
	Jamie Iles <quic_jiles@quicinc.com>,
	James Morse <james.morse@arm.com>,
	Babu Moger <babu.moger@amd.com>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
	Tony Luck <tony.luck@intel.com>
Subject: [RFC PATCH 7/7] x86/resctrl: Example resctrl driver
Date: Thu, 20 Apr 2023 15:06:36 -0700	[thread overview]
Message-ID: <20230420220636.53527-8-tony.luck@intel.com> (raw)
In-Reply-To: <20230420220636.53527-1-tony.luck@intel.com>

Simply add two files to each ctrlmon directory that show the closid and
rmid respectively.

Signed-off-by: Tony Luck <tony.luck@intel.com>
---
 .../cpu/resctrl/drivers/resctrl_example.c     | 77 +++++++++++++++++++
 arch/x86/Kconfig                              | 11 +++
 arch/x86/kernel/cpu/resctrl/Makefile          |  1 +
 arch/x86/kernel/cpu/resctrl/drivers/Makefile  |  1 +
 4 files changed, 90 insertions(+)
 create mode 100644 arch/x86/kernel/cpu/resctrl/drivers/resctrl_example.c
 create mode 100644 arch/x86/kernel/cpu/resctrl/drivers/Makefile

diff --git a/arch/x86/kernel/cpu/resctrl/drivers/resctrl_example.c b/arch/x86/kernel/cpu/resctrl/drivers/resctrl_example.c
new file mode 100644
index 000000000000..24998e0dc3c2
--- /dev/null
+++ b/arch/x86/kernel/cpu/resctrl/drivers/resctrl_example.c
@@ -0,0 +1,77 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright(c) 2023 Intel Corporation. */
+
+/*
+ *  Example resctrl driver
+ */
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/acpi.h>
+#include <linux/seq_file.h>
+#include <linux/slab.h>
+#include <linux/resctrl.h>
+
+#undef pr_fmt
+#define pr_fmt(fmt) "exampleresctrl: " fmt
+
+static int closid_show(struct seq_file *sf, void *arg)
+{
+	struct kernfs_open_file *of = sf->private;
+	unsigned long priv = (unsigned long)of->kn->priv;
+	u32 closid = priv >> 16;
+
+	seq_printf(sf, "%d\n", closid);
+
+	return 0;
+}
+
+static int rmid_show(struct seq_file *sf, void *arg)
+{
+	struct kernfs_open_file *of = sf->private;
+	unsigned long priv = (unsigned long)of->kn->priv;
+	u32 rmid = priv & 0xffff;
+
+	seq_printf(sf, "%d\n", rmid);
+
+	return 0;
+}
+
+static struct kernfs_ops closid_ops = {
+	.seq_show	= closid_show,
+};
+
+static struct kernfs_ops rmid_ops = {
+	.seq_show	= rmid_show,
+};
+
+static struct resctrl_fileinfo files[] = {
+	{
+		.name = "closid", .ops = &closid_ops
+	},
+	{
+		.name = "rmid", .ops = &rmid_ops
+	},
+	{
+	}
+};
+
+static struct resctrl_driver ops = {
+	.ctrlfiles	= files,
+};
+
+static int __init init_example(void)
+{
+	resctrl_register_driver(&ops);
+
+	return 0;
+}
+
+static void __exit cleanup_example(void)
+{
+	resctrl_unregister_driver(&ops);
+}
+
+module_init(init_example);
+module_exit(cleanup_example);
+
+MODULE_LICENSE("GPL");
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index a825bf031f49..7f2faec17365 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -500,6 +500,17 @@ config X86_CPU_RESCTRL
 
 	  Say N if unsure.
 
+config X86_CPU_RESCTRL_DRIVERS
+	bool "resctrl driver"
+
+config X86_CPU_RESCTRL_EXAMPLE_DRIVER
+	tristate "example x86 resctrl driver"
+	depends on X86_CPU_RESCTRL
+	select X86_CPU_RESCTRL_DRIVERS
+	help
+	  Example driver to show one possible use case for
+	  resctrl driver registration.
+
 if X86_32
 config X86_BIGSMP
 	bool "Support for big SMP systems with more than 8 CPUs"
diff --git a/arch/x86/kernel/cpu/resctrl/Makefile b/arch/x86/kernel/cpu/resctrl/Makefile
index 4a06c37b9cf1..7db4d729afbc 100644
--- a/arch/x86/kernel/cpu/resctrl/Makefile
+++ b/arch/x86/kernel/cpu/resctrl/Makefile
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_X86_CPU_RESCTRL)	+= core.o rdtgroup.o monitor.o
 obj-$(CONFIG_X86_CPU_RESCTRL)	+= ctrlmondata.o pseudo_lock.o
+obj-$(CONFIG_X86_CPU_RESCTRL_DRIVERS) += drivers/
 CFLAGS_pseudo_lock.o = -I$(src)
diff --git a/arch/x86/kernel/cpu/resctrl/drivers/Makefile b/arch/x86/kernel/cpu/resctrl/drivers/Makefile
new file mode 100644
index 000000000000..27db936eb947
--- /dev/null
+++ b/arch/x86/kernel/cpu/resctrl/drivers/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_X86_CPU_RESCTRL_EXAMPLE_DRIVER) += resctrl_example.o
-- 
2.39.2


  parent reply	other threads:[~2023-04-20 22:07 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-20 22:06 [RFC PATCH 0/7] Add driver registration i/f to resctrl Tony Luck
2023-04-20 22:06 ` [RFC PATCH 1/7] x86/resctrl: Add register/unregister functions for driver to hook into resctrl Tony Luck
2023-05-05 23:17   ` Reinette Chatre
2023-04-20 22:06 ` [RFC PATCH 2/7] x86/resctrl: Add an interface to add/remove a new info/directory Tony Luck
2023-04-20 22:06 ` [RFC PATCH 3/7] x86/resctrl: Add driver callback when directories are removed Tony Luck
2023-05-05 23:19   ` Reinette Chatre
2023-04-20 22:06 ` [RFC PATCH 4/7] x86/resctrl: Add capability to driver registration to create control files Tony Luck
2023-05-05 23:20   ` Reinette Chatre
2023-04-20 22:06 ` [RFC PATCH 5/7] x86/resctrl: Enhance driver registration to hook into schemata files Tony Luck
2023-05-05 23:20   ` Reinette Chatre
2023-04-20 22:06 ` [RFC PATCH 6/7] x86/resctrl: Allow a device to override an existing schemata entry Tony Luck
2023-05-05 23:20   ` Reinette Chatre
2023-04-20 22:06 ` Tony Luck [this message]
2023-05-05 23:17 ` [RFC PATCH 0/7] Add driver registration i/f to resctrl Reinette Chatre
2023-05-08 18:32   ` Luck, Tony
2023-05-09 21:34     ` Reinette Chatre
2023-05-09 23:35       ` Luck, Tony
2023-05-10  0:07         ` Reinette Chatre
2023-05-10  0:52           ` Luck, Tony
2023-05-11 20:35         ` Luck, Tony
2023-05-12 16:57           ` Reinette Chatre
2023-05-12 20:35             ` Luck, Tony
2023-05-12 21:08               ` Reinette Chatre

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=20230420220636.53527-8-tony.luck@intel.com \
    --to=tony.luck@intel.com \
    --cc=babu.moger@amd.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=fenghua.yu@intel.com \
    --cc=hpa@zytor.com \
    --cc=james.morse@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=quic_jiles@quicinc.com \
    --cc=reinette.chatre@intel.com \
    --cc=tan.shaopeng@fujitsu.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox