All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anton Blanchard <anton-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
To: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: jk-mnsaURCQ41sdnm+yROfE0A@public.gmane.org
Subject: [PATCH] dtc: Sort unit addresses by number
Date: Tue, 21 Jan 2014 13:49:35 +1100	[thread overview]
Message-ID: <20140121134935.1f9cebcc@kryten> (raw)


The sort option in dtc treats unit addresses as strings. This causes
cpu nodes to end up out of order:

# dtc -s -I fs -O dts /proc/device-tree | grep PowerPC,POWER7

		PowerPC,POWER7@30 {
		PowerPC,POWER7@68 {
		PowerPC,POWER7@70 {
		PowerPC,POWER7@828 {
		PowerPC,POWER7@860 {
		PowerPC,POWER7@868 {
		PowerPC,POWER7@8a0 {
		PowerPC,POWER7@8b0 {
		PowerPC,POWER7@8f0 {
		PowerPC,POWER7@a0 {
		PowerPC,POWER7@a8 {
		PowerPC,POWER7@e0 {

If we use this device tree for a kexec boot we end up with a confusing
layout of logical CPUs:

node 0 cpus: 0-23 72-95
node 0 size: 32633 MB

node 1 cpus: 24-71
node 1 size: 32631 MB

The reason for this is that we allocate logical CPU ids as we walk
through the device tree.

In cmp_subnode, if both nodes have a hex unit address and the
basenames match, then compare by number.

This fixes the issue:

# dtc -s -I fs -O dts /proc/device-tree | grep PowerPC,POWER7
		PowerPC,POWER7@30 {
		PowerPC,POWER7@68 {
		PowerPC,POWER7@70 {
		PowerPC,POWER7@a0 {
		PowerPC,POWER7@a8 {
		PowerPC,POWER7@e0 {
		PowerPC,POWER7@828 {
		PowerPC,POWER7@860 {
		PowerPC,POWER7@868 {
		PowerPC,POWER7@8a0 {
		PowerPC,POWER7@8b0 {
		PowerPC,POWER7@8f0 {

And the CPU layout is as expected:

node 0 cpus: 0-47
node 0 size: 32633 MB

node 1 cpus: 48-95
node 1 size: 32631 MB

Signed-off-by: Anton Blanchard <anton-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
--

Index: b/livetree.c
===================================================================
--- a/livetree.c
+++ b/livetree.c
@@ -656,12 +656,38 @@ static void sort_properties(struct node
 	free(tbl);
 }
 
+static bool is_hex(const char *str)
+{
+	while (*str) {
+		if (!isxdigit(*str++))
+			return false;
+	}
+
+	return true;
+}
+
 static int cmp_subnode(const void *ax, const void *bx)
 {
-	const struct node *a, *b;
+	struct node *a, *b;
+	const char *a_unit, *b_unit;
+
+	a = *((struct node * const *)ax);
+	b = *((struct node * const *)bx);
+
+	a_unit = get_unitname(a);
+	b_unit = get_unitname(b);
+
+	/* Sort hex unit addresses by number */
+	if (a_unit && b_unit && (a->basenamelen == b->basenamelen) &&
+	    !strncmp(a->name, b->name, a->basenamelen) &&
+	    is_hex(a_unit) && is_hex(b_unit)) {
+		unsigned long long a_num, b_num;
+
+		a_num = strtoull(a_unit, NULL, 16);
+		b_num = strtoull(b_unit, NULL, 16);
 
-	a = *((const struct node * const *)ax);
-	b = *((const struct node * const *)bx);
+		return (a_num > b_num) - (a_num < b_num);
+	}
 
 	return strcmp(a->name, b->name);
 }
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

             reply	other threads:[~2014-01-21  2:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-21  2:49 Anton Blanchard [this message]
2014-01-21 10:02 ` [PATCH] dtc: Sort unit addresses by number Mark Rutland
     [not found]   ` <20140121100221.GJ28747-NuALmloUBlrZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>
2014-01-24 12:21     ` Anton Blanchard

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=20140121134935.1f9cebcc@kryten \
    --to=anton-eunubhrolfbytjvyw6ydsg@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=jk-mnsaURCQ41sdnm+yROfE0A@public.gmane.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.