Skip to contentSkip to conversation

add of_find_next_cache_node()

PATCH In review Nathan Lynch 3 participants 11 messages Dec 11, 2008 – Dec 16, 2008 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 add of_find_next_cache_node()

We have more than one piece of code that looks up cache nodes manually using the "l2-cache" property. Add a common helper routine which does this and handles ePAPR's "next-level-cache" property as well as powermac.

---
 arch/powerpc/include/asm/prom.h |    3 +++
 arch/powerpc/kernel/prom.c      |   31 +++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 0 deletions(-)
arch/powerpc/include/asm/prom.h +3 -0
index eb3bd2e..6ff0418 100644
@@ -253,6 +253,9 @@ extern void kdump_move_device_tree(void);
 /* CPU OF node matching */
 struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);
 
+/* cache lookup */
+struct device_node *of_find_next_cache_node(struct device_node *np);
+
 /* Get the MAC address */
 extern const void *of_get_mac_address(struct device_node *np);
 
arch/powerpc/kernel/prom.c +31 -0
index 3a2dc7e..d8266dd 100644
@@ -1271,6 +1271,37 @@ struct device_node *of_find_node_by_phandle(phandle handle)
 EXPORT_SYMBOL(of_find_node_by_phandle);
 
 /**
+ *	of_find_next_cache_node - Find a node's subsidiary cache
+ *	@np:	node of type "cpu" or "cache"
+ *
+ *	Returns a node pointer with refcount incremented, use
+ *	of_node_put() on it when done.  Caller should hold a reference
+ *	to np.
+ */
+struct device_node *of_find_next_cache_node(struct device_node *np)
+{
+	struct device_node *child;
+	const phandle *handle;
+
+	handle = of_get_property(np, "l2-cache", NULL);
+	if (!handle)
+		handle = of_get_property(np, "next-level-cache", NULL);
+
+	if (handle)
+		return of_find_node_by_phandle(*handle);
+
+	/* OF on pmac has nodes instead of properties named "l2-cache"
+	 * beneath CPU nodes.
+	 */
+	if (!strcmp(np->type, "cpu"))
+		for_each_child_of_node(np, child)
+			if (!strcmp(child->type, "cache"))
+				return child;
+
+	return NULL;
+}
+
+/**
  *	of_find_all_nodes - Get next node in global list
  *	@prev:	Previous node or NULL to start iteration
  *		of_node_put() will be called on it
Signature · 1 line
1.5.5
#1 lore raw

PATCH 2/3 convert cpu_to_l2cache() to of_find_next_cache_node()

The smp code uses cache information to populate cpu_core_map; change it to use common code for cache lookup.

---
 arch/powerpc/kernel/smp.c |   10 +---------
 1 files changed, 1 insertions(+), 9 deletions(-)
arch/powerpc/kernel/smp.c +1 -9
index ff9f701..450865b 100644
@@ -408,8 +408,6 @@ out:
 static struct device_node *cpu_to_l2cache(int cpu)
 {
 	struct device_node *np;
-	const phandle *php;
-	phandle ph;
 
 	if (!cpu_present(cpu))
 		return NULL;
@@ -418,13 +416,7 @@ static struct device_node *cpu_to_l2cache(int cpu)
 	if (np == NULL)
 		return NULL;
 
-	php = of_get_property(np, "l2-cache", NULL);
-	if (php == NULL)
-		return NULL;
-	ph = *php;
-	of_node_put(np);
-
-	return of_find_node_by_phandle(ph);
+	return of_find_next_cache_node(np);
 }
 
 /* Activate a secondary processor. */
Signature · 1 line
1.5.5
#2 lore raw

Re: [PATCH 2/3] convert cpu_to_l2cache() to of_find_next_cache_node()

Hi Nathan,

Quoted 4 lines · On Wed, 10 Dec 2008 18:46:05 -0600 Nathan Lynch <[email protected]> wrote:
arch/powerpc/kernel/smp.c +0 -0
@@ -418,13 +416,7 @@ static struct device_node *cpu_to_l2cache(int cpu)
 	if (np == NULL)
 		return NULL;

arch/powerpc/kernel/smp.c static struct device_node *cpu_to_l2cache(int cpu) · line 420

Quoted 10 lines
arch/powerpc/kernel/smp.c +1 -7
 
-	php = of_get_property(np, "l2-cache", NULL);
-	if (php == NULL)
-		return NULL;
-	ph = *php;
-	of_node_put(np);
-
-	return of_find_node_by_phandle(ph);
+	return of_find_next_cache_node(np);
 }

This leaks a reference on np ...

Signature · 3 lines
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/
#3 lore raw

Re: [PATCH 2/3] convert cpu_to_l2cache() to of_find_next_cache_node()

Quoted 6 lines · Stephen Rothwell
Quoted 5 lines · On Wed, 10 Dec 2008 18:46:05 -0600 Nathan Lynch <[email protected]> wrote:
arch/powerpc/kernel/smp.c +0 -0
@@ -418,13 +416,7 @@ static struct device_node *cpu_to_l2cache(int cpu)
 	if (np == NULL)
 		return NULL;
 
Quoted 11 lines

arch/powerpc/kernel/smp.c static struct device_node *cpu_to_l2cache(int cpu) · line 420

Quoted 9 lines
arch/powerpc/kernel/smp.c +1 -7
-	php = of_get_property(np, "l2-cache", NULL);
-	if (php == NULL)
-		return NULL;
-	ph = *php;
-	of_node_put(np);
-
-	return of_find_node_by_phandle(ph);
+	return of_find_next_cache_node(np);
 }

This leaks a reference on np ...

Thanks, will fix.

#4 lore raw

PATCH v2 2/3 convert cpu_to_l2cache() to of_find_next_cache_node()

In reply to Nathan Lynch

The smp code uses cache information to populate cpu_core_map; change it to use common code for cache lookup.

---
 arch/powerpc/kernel/smp.c |   11 ++++-------
 1 files changed, 4 insertions(+), 7 deletions(-)

v2: Fix refcount imbalance, thanks to sfr.

arch/powerpc/kernel/smp.c +4 -7
index ff9f701..a112ba9 100644
@@ -408,8 +408,7 @@ out:
 static struct device_node *cpu_to_l2cache(int cpu)
 {
 	struct device_node *np;
-	const phandle *php;
-	phandle ph;
+	struct device_node *cache;
 
 	if (!cpu_present(cpu))
 		return NULL;
@@ -418,13 +417,11 @@ static struct device_node *cpu_to_l2cache(int cpu)
 	if (np == NULL)
 		return NULL;
 
-	php = of_get_property(np, "l2-cache", NULL);
-	if (php == NULL)
-		return NULL;
-	ph = *php;
+	cache = of_find_next_cache_node(np);
+
 	of_node_put(np);
 
-	return of_find_node_by_phandle(ph);
+	return cache;
 }
 
 /* Activate a secondary processor. */
Signature · 1 line
1.5.5
#5 lore raw

PATCH 3/3 convert sysfs cache code to of_find_next_cache_node()

In reply to Nathan Lynch

Using the common code means that more complete cache information will provided in sysfs on platforms that don't use the l2-cache property convention.

---
 arch/powerpc/kernel/sysfs.c |    7 +------
 1 files changed, 1 insertions(+), 6 deletions(-)
arch/powerpc/kernel/sysfs.c +1 -6
index 20885a3..0c64f10 100644
@@ -566,7 +566,6 @@ static bool cache_is_unified(struct device_node *np)
 
 static struct cache_desc * __cpuinit create_cache_index_info(struct device_node *np, struct kobject *parent, int index, int level)
 {
-	const phandle *next_cache_phandle;
 	struct device_node *next_cache;
 	struct cache_desc *new, **end;
 
@@ -591,11 +590,7 @@ static struct cache_desc * __cpuinit create_cache_index_info(struct device_node
 	while (*end)
 		end = &(*end)->next;
 
-	next_cache_phandle = of_get_property(np, "l2-cache", NULL);
-	if (!next_cache_phandle)
-		goto out;
-
-	next_cache = of_find_node_by_phandle(*next_cache_phandle);
+	next_cache = of_find_next_cache_node(np);
 	if (!next_cache)
 		goto out;
 
Signature · 1 line
1.5.5
#6 lore raw
In reply to Nathan Lynch

arch/powerpc/kernel/prom.c struct device_node *of_find_node_by_phandle(phandle handle) · line 1300

Quoted 8 lines · Nathan Lynch
arch/powerpc/kernel/prom.c +8 -0
+       /* OF on pmac has nodes instead of properties named "l2-cache"
+        * beneath CPU nodes.
+        */
+       if (!strcmp(np->type, "cpu"))
+               for_each_child_of_node(np, child)
+                       if (!strcmp(child->type, "cache"))
+                               return child;
+

pmac has both actually. And the property points to the node. It's a problem for /proc/device-tree so we rename them iirc, but only in /proc, ie, they should still be intact in the tree I think.

Cheers,
Ben.

#7 lore raw
Quoted 10 lines · Benjamin Herrenschmidt

arch/powerpc/kernel/prom.c struct device_node *of_find_node_by_phandle(phandle handle) · line 1300

Quoted 8 lines · Nathan Lynch
arch/powerpc/kernel/prom.c +8 -0
+       /* OF on pmac has nodes instead of properties named "l2-cache"
+        * beneath CPU nodes.
+        */
+       if (!strcmp(np->type, "cpu"))
+               for_each_child_of_node(np, child)
+                       if (!strcmp(child->type, "cache"))
+                               return child;
+
Quoted 3 lines

pmac has both actually. And the property points to the node. It's a problem for /proc/device-tree so we rename them iirc, but only in /proc, ie, they should still be intact in the tree I think.

Okay, I'll check on this.

#8 lore raw
In reply to Benjamin Herrenschmidt
Quoted 10 lines · Benjamin Herrenschmidt

arch/powerpc/kernel/prom.c struct device_node *of_find_node_by_phandle(phandle handle) · line 1300

Quoted 8 lines · Nathan Lynch
arch/powerpc/kernel/prom.c +8 -0
+       /* OF on pmac has nodes instead of properties named "l2-cache"
+        * beneath CPU nodes.
+        */
+       if (!strcmp(np->type, "cpu"))
+               for_each_child_of_node(np, child)
+                       if (!strcmp(child->type, "cache"))
+                               return child;
+
Quoted 3 lines

pmac has both actually. And the property points to the node. It's a problem for /proc/device-tree so we rename them iirc, but only in /proc, ie, they should still be intact in the tree I think.

I see the 'l2-cache' property (renamed to 'l2-cache#1' in /proc) on a G4 iBook, but it is not present on the two G5 models I've checked.

#9 lore raw
Quoted 11 lines · Nathan Lynch
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 8 lines · Nathan Lynch
arch/powerpc/kernel/prom.c +8 -0
+       /* OF on pmac has nodes instead of properties named "l2-cache"
+        * beneath CPU nodes.
+        */
+       if (!strcmp(np->type, "cpu"))
+               for_each_child_of_node(np, child)
+                       if (!strcmp(child->type, "cache"))
+                               return child;
+
Quoted 6 lines
Quoted 3 lines

pmac has both actually. And the property points to the node. It's a problem for /proc/device-tree so we rename them iirc, but only in /proc, ie, they should still be intact in the tree I think.

I see the 'l2-cache' property (renamed to 'l2-cache#1' in /proc) on a G4 iBook, but it is not present on the two G5 models I've checked.

Ah crap.

Oh well, keep your fallback then.

Don't 970MP have a shared L2 tho ? That will make it look like it's not, I suppose there isn't much we can do about it tho...

Cheers,
Ben.

#10 lore raw
Quoted 2 lines · Benjamin Herrenschmidt

Don't 970MP have a shared L2 tho ?

The 970MP UM describes 1MB L2 per core, and the device tree on the quad G5 reflects that... might be interesting to know what it looks like on IBM JS21 for comparison's sake, but I think we're okay.