Skip to contentSkip to conversation

cacheinfo support to read no. of L2 cache ways enabled

PATCH In review Yash Shah 3 participants 6 messages Feb 20, 2020 – May 20, 2020

Subsystems (2)
lore
Share & tools
lore

Yash Shah

author
#0 lore raw

v5 cover cacheinfo support to read no. of L2 cache ways enabled

The patchset includes 2 patches. Patch 1 implements cache_get_priv_group which make use of a generic ops structure to return a private attribute group for custom cacheinfo. Patch 2 implements a private attribute named "number_of_ways_enabled" in the cacheinfo framework. Reading this attribute returns the number of L2 cache ways enabled at runtime,

This patchset is based on Linux v5.6-rc2 and tested on HiFive Unleashed board.

v5:
- Since WayEnable is 8bits, mask out and return only the last 8 bit in l2_largest_wayenabled()
- Rebased on Linux v5.6-rc2

v4:
- Rename "sifive_l2_largest_wayenabled" to "l2_largest_wayenabled" and make it a static function

v3:
- As per Anup Patel's suggestion[0], implement a new approach which uses generic ops structure. Hence addition of patch 1 to this series and corresponding changes to patch 2.
- Dropped "riscv: dts: Add DT support for SiFive L2 cache controller" patch since it is already merged
- Rebased on Linux v5.5-rc6

Changes in v2:
- Rebase the series on v5.5-rc3
- Remove the reserved-memory node from DT

[0]: https://lore.kernel.org/linux-riscv/CAAhSdy0CXde5s_ya=4YvmA4UQ5f5gLU-Z_FaOr8LPni+s_615Q@mail.gmail.com/

Yash Shah (2):
riscv: cacheinfo: Implement cache_get_priv_group with a generic ops
structure
riscv: Add support to determine no. of L2 cache way enabled

 arch/riscv/include/asm/cacheinfo.h   | 15 ++++++++++++++
 arch/riscv/kernel/cacheinfo.c        | 17 ++++++++++++++++
 drivers/soc/sifive/sifive_l2_cache.c | 38 ++++++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+)
 create mode 100644 arch/riscv/include/asm/cacheinfo.h
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v5 1/2 riscv: cacheinfo: Implement cache_get_priv_group with a generic ops structure

Implement cache_get_priv_group() that will make use of a generic ops structure to return a private attribute group for custom cache info.

Using riscv_set_cacheinfo_ops() users can hook their own custom function to return the private attribute group for cacheinfo. In future we can add more ops to this generic ops structure for SOC specific cacheinfo.

---
 arch/riscv/include/asm/cacheinfo.h | 15 +++++++++++++++
 arch/riscv/kernel/cacheinfo.c      | 17 +++++++++++++++++
 2 files changed, 32 insertions(+)
 create mode 100644 arch/riscv/include/asm/cacheinfo.h
arch/riscv/include/asm/cacheinfo.h new file +15 -0
new file mode 100644
index 0000000..5d9662e
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef _ASM_RISCV_CACHEINFO_H
+#define _ASM_RISCV_CACHEINFO_H
+
+#include <linux/cacheinfo.h>
+
+struct riscv_cacheinfo_ops {
+	const struct attribute_group * (*get_priv_group)(struct cacheinfo
+							*this_leaf);
+};
+
+void riscv_set_cacheinfo_ops(struct riscv_cacheinfo_ops *ops);
+
+#endif /* _ASM_RISCV_CACHEINFO_H */
arch/riscv/kernel/cacheinfo.c +17 -0
index 4c90c07..bd0f122 100644
@@ -7,6 +7,23 @@
 #include <linux/cpu.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
+#include <asm/cacheinfo.h>
+
+static struct riscv_cacheinfo_ops *rv_cache_ops;
+
+void riscv_set_cacheinfo_ops(struct riscv_cacheinfo_ops *ops)
+{
+	rv_cache_ops = ops;
+}
+EXPORT_SYMBOL_GPL(riscv_set_cacheinfo_ops);
+
+const struct attribute_group *
+cache_get_priv_group(struct cacheinfo *this_leaf)
+{
+	if (rv_cache_ops && rv_cache_ops->get_priv_group)
+		return rv_cache_ops->get_priv_group(this_leaf);
+	return NULL;
+}
 
 static void ci_leaf_init(struct cacheinfo *this_leaf,
 			 struct device_node *node,
Signature · 1 line
2.7.4
author
#2 lore raw

PATCH v5 2/2 riscv: Add support to determine no. of L2 cache way enabled

In reply to Yash Shah

In order to determine the number of L2 cache ways enabled at runtime, implement a private attribute ("number_of_ways_enabled"). Reading this attribute returns the number of enabled L2 cache ways at runtime.

Using riscv_set_cacheinfo_ops() hook a custom function, that returns this private attribute, to the generic ops structure which is used by cache_get_priv_group() in cacheinfo framework.

---
 drivers/soc/sifive/sifive_l2_cache.c | 38 ++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
drivers/soc/sifive/sifive_l2_cache.c +38 -0
index a506939..d5f2665 100644
@@ -9,6 +9,8 @@
 #include <linux/interrupt.h>
 #include <linux/of_irq.h>
 #include <linux/of_address.h>
+#include <linux/device.h>
+#include <asm/cacheinfo.h>
 #include <soc/sifive/sifive_l2_cache.h>
 
 #define SIFIVE_L2_DIRECCFIX_LOW 0x100
@@ -31,6 +33,7 @@
 
 static void __iomem *l2_base;
 static int g_irq[SIFIVE_L2_MAX_ECCINTR];
+static struct riscv_cacheinfo_ops l2_cache_ops;
 
 enum {
 	DIR_CORR = 0,
@@ -107,6 +110,38 @@ int unregister_sifive_l2_error_notifier(struct notifier_block *nb)
 }
 EXPORT_SYMBOL_GPL(unregister_sifive_l2_error_notifier);
 
+static int l2_largest_wayenabled(void)
+{
+	return readl(l2_base + SIFIVE_L2_WAYENABLE) & 0xFF;
+}
+
+static ssize_t number_of_ways_enabled_show(struct device *dev,
+					   struct device_attribute *attr,
+					   char *buf)
+{
+	return sprintf(buf, "%u\n", l2_largest_wayenabled());
+}
+
+static DEVICE_ATTR_RO(number_of_ways_enabled);
+
+static struct attribute *priv_attrs[] = {
+	&dev_attr_number_of_ways_enabled.attr,
+	NULL,
+};
+
+static const struct attribute_group priv_attr_group = {
+	.attrs = priv_attrs,
+};
+
+const struct attribute_group *l2_get_priv_group(struct cacheinfo *this_leaf)
+{
+	/* We want to use private group for L2 cache only */
+	if (this_leaf->level == 2)
+		return &priv_attr_group;
+	else
+		return NULL;
+}
+
 static irqreturn_t l2_int_handler(int irq, void *device)
 {
 	unsigned int add_h, add_l;
@@ -170,6 +205,9 @@ static int __init sifive_l2_init(void)
 
 	l2_config_read();
 
+	l2_cache_ops.get_priv_group = l2_get_priv_group;
+	riscv_set_cacheinfo_ops(&l2_cache_ops);
+
 #ifdef CONFIG_DEBUG_FS
 	setup_sifive_debug();
 #endif
Signature · 1 line
2.7.4
author
#3 lore raw
In reply to Yash Shah

Any comments or updates on this series?

- Yash

Quoted 61 lines

-----Original Message-----
From: Yash Shah <[email protected]>
Sent: 20 February 2020 10:45
To: [email protected]; Paul Walmsley ( Sifive) <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Sachin Ghadi <[email protected]>; Yash Shah <[email protected]>
Subject: [PATCH v5 0/2] cacheinfo support to read no. of L2 cache ways enabled

The patchset includes 2 patches. Patch 1 implements cache_get_priv_group which make use of a generic ops structure to return a private attribute group for custom cacheinfo. Patch 2 implements a private attribute named "number_of_ways_enabled" in the cacheinfo framework. Reading this attribute returns the number of L2 cache ways enabled at runtime,

This patchset is based on Linux v5.6-rc2 and tested on HiFive Unleashed board.

v5:
- Since WayEnable is 8bits, mask out and return only the last 8 bit in l2_largest_wayenabled()
- Rebased on Linux v5.6-rc2

v4:
- Rename "sifive_l2_largest_wayenabled" to "l2_largest_wayenabled" and make it a static function

v3:
- As per Anup Patel's suggestion[0], implement a new approach which uses generic ops structure. Hence addition of patch 1 to this series and corresponding changes to patch 2.
- Dropped "riscv: dts: Add DT support for SiFive L2 cache controller" patch since it is already merged
- Rebased on Linux v5.5-rc6

Changes in v2:
- Rebase the series on v5.5-rc3
- Remove the reserved-memory node from DT

[0]: https://lore.kernel.org/linux-
riscv/CAAhSdy0CXde5s_ya=4YvmA4UQ5f5gLU-
[email protected]/

Yash Shah (2):
riscv: cacheinfo: Implement cache_get_priv_group with a generic ops
structure
riscv: Add support to determine no. of L2 cache way enabled

 arch/riscv/include/asm/cacheinfo.h   | 15 ++++++++++++++
 arch/riscv/kernel/cacheinfo.c        | 17 ++++++++++++++++
 drivers/soc/sifive/sifive_l2_cache.c | 38
++++++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+)
 create mode 100644 arch/riscv/include/asm/cacheinfo.h

--
2.7.4

#4 lore raw

Ping.

I think this one got lost in time. I don't see it in v5.6 or v5.7.

david

Quoted 68 lines · Yash Shah

Any comments or updates on this series?

- Yash

Quoted 61 lines

-----Original Message-----
From: Yash Shah <[email protected]>
Sent: 20 February 2020 10:45
To: [email protected]; Paul Walmsley ( Sifive) <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Sachin Ghadi <[email protected]>; Yash Shah <[email protected]>
Subject: [PATCH v5 0/2] cacheinfo support to read no. of L2 cache ways enabled

The patchset includes 2 patches. Patch 1 implements cache_get_priv_group which make use of a generic ops structure to return a private attribute group for custom cacheinfo. Patch 2 implements a private attribute named "number_of_ways_enabled" in the cacheinfo framework. Reading this attribute returns the number of L2 cache ways enabled at runtime,

This patchset is based on Linux v5.6-rc2 and tested on HiFive Unleashed board.

v5:
- Since WayEnable is 8bits, mask out and return only the last 8 bit in l2_largest_wayenabled()
- Rebased on Linux v5.6-rc2

v4:
- Rename "sifive_l2_largest_wayenabled" to "l2_largest_wayenabled" and make it a static function

v3:
- As per Anup Patel's suggestion[0], implement a new approach which uses generic ops structure. Hence addition of patch 1 to this series and corresponding changes to patch 2.
- Dropped "riscv: dts: Add DT support for SiFive L2 cache controller" patch since it is already merged
- Rebased on Linux v5.5-rc6

Changes in v2:
- Rebase the series on v5.5-rc3
- Remove the reserved-memory node from DT

[0]: https://lore.kernel.org/linux-
riscv/CAAhSdy0CXde5s_ya=4YvmA4UQ5f5gLU-
[email protected]/

Yash Shah (2):
riscv: cacheinfo: Implement cache_get_priv_group with a generic ops
structure
riscv: Add support to determine no. of L2 cache way enabled

 arch/riscv/include/asm/cacheinfo.h   | 15 ++++++++++++++
 arch/riscv/kernel/cacheinfo.c        | 17 ++++++++++++++++
 drivers/soc/sifive/sifive_l2_cache.c | 38
++++++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+)
 create mode 100644 arch/riscv/include/asm/cacheinfo.h

--
2.7.4

maintainer
#5 lore raw
In reply to Yash Shah
Quoted 37 lines · On Wed, 19 Feb 2020 21:15:17 PST (-0800), [email protected] wrote:

The patchset includes 2 patches. Patch 1 implements cache_get_priv_group which make use of a generic ops structure to return a private attribute group for custom cacheinfo. Patch 2 implements a private attribute named "number_of_ways_enabled" in the cacheinfo framework. Reading this attribute returns the number of L2 cache ways enabled at runtime,

This patchset is based on Linux v5.6-rc2 and tested on HiFive Unleashed board.

v5:
- Since WayEnable is 8bits, mask out and return only the last 8 bit in l2_largest_wayenabled()
- Rebased on Linux v5.6-rc2

v4:
- Rename "sifive_l2_largest_wayenabled" to "l2_largest_wayenabled" and make it a static function

v3:
- As per Anup Patel's suggestion[0], implement a new approach which uses generic ops structure. Hence addition of patch 1 to this series and corresponding changes to patch 2.
- Dropped "riscv: dts: Add DT support for SiFive L2 cache controller" patch since it is already merged
- Rebased on Linux v5.5-rc6

Changes in v2:
- Rebase the series on v5.5-rc3
- Remove the reserved-memory node from DT

[0]: https://lore.kernel.org/linux-riscv/CAAhSdy0CXde5s_ya=4YvmA4UQ5f5gLU-Z_FaOr8LPni+s_615Q@mail.gmail.com/

Yash Shah (2):
riscv: cacheinfo: Implement cache_get_priv_group with a generic ops
structure
riscv: Add support to determine no. of L2 cache way enabled

Quoted 5 lines
 arch/riscv/include/asm/cacheinfo.h   | 15 ++++++++++++++
 arch/riscv/kernel/cacheinfo.c        | 17 ++++++++++++++++
 drivers/soc/sifive/sifive_l2_cache.c | 38 ++++++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+)
 create mode 100644 arch/riscv/include/asm/cacheinfo.h

I must have lost track of this one, it's on for-next now. Thanks to David for reminding me.