mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andi Kleen <andi@firstfloor.org>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: Andi Kleen <andi@firstfloor.org>,
	mingo@elte.hu, linux-kernel@vger.kernel.org,
	peterz@infradead.org
Subject: Re: [PATCH] [4/4] SCHED: Use a lookup array in sd_level_to_string
Date: Wed, 12 Nov 2008 16:28:28 +0100	[thread overview]
Message-ID: <20081112152828.GM3810@one.firstfloor.org> (raw)
In-Reply-To: <20081112144709.GB2672@cmpxchg.org>

On Wed, Nov 12, 2008 at 03:47:09PM +0100, Johannes Weiner wrote:
> > +#define T(x) [SD_LV_ ## x ] = #T
> 
> Shouldn't                         ^ that be x?

Yes good point. Thanks. Revised patch appended.

-Andi

---

SCHED: Use a lookup array in sd_level_to_string v2

Generates better/shorter code. Doesn't matter much because it's only
a SCHED_DEBUG function. 

v2: Fix stupid typo thanks to Johannes Weiner

Signed-off-by: Andi Kleen <ak@linux.intel.com>

---
 kernel/sched.c |   29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)

Index: linux-2.6.28-rc4-test/kernel/sched.c
===================================================================
--- linux-2.6.28-rc4-test.orig/kernel/sched.c	2008-11-12 16:35:02.000000000 +0100
+++ linux-2.6.28-rc4-test/kernel/sched.c	2008-11-12 16:35:48.000000000 +0100
@@ -6629,24 +6629,17 @@
 
 static inline const char *sd_level_to_string(enum sched_domain_level lvl)
 {
-	switch (lvl) {
-	case SD_LV_NONE:
-			return "NONE";
-	case SD_LV_SIBLING:
-			return "SIBLING";
-	case SD_LV_MC:
-			return "MC";
-	case SD_LV_CPU:
-			return "CPU";
-	case SD_LV_NODE:
-			return "NODE";
-	case SD_LV_ALLNODES:
-			return "ALLNODES";
-	case SD_LV_MAX:
-			return "MAX";
-
-	}
-	return "MAX";
+	static const char *lva[] = {
+#define T(x) [SD_LV_ ## x ] = #x
+		T(NONE),
+		T(SIBLING),
+		T(MC),
+		T(CPU),
+		T(NODE),
+		T(ALLNODES),
+#undef T
+	};
+	return (unsigned)lvl < ARRAY_SIZE(lva) ? lva[lvl] : "MAX";
 }
 
 static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level,

  reply	other threads:[~2008-11-12 15:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-12 12:45 [PATCH] [0/4] SCHED: Trivial scheduler fixes Andi Kleen
2008-11-12 12:45 ` [PATCH] [1/4] SCHED: cache task_hot result Andi Kleen
2008-11-12 12:45 ` [PATCH] [2/4] SCHED: Mark all frequently used sysctls __read_mostly Andi Kleen
2008-11-12 12:45 ` [PATCH] [3/4] SCHED: don't inline idle_balance into schedule() Andi Kleen
2008-11-12 12:45 ` [PATCH] [4/4] SCHED: Use a lookup array in sd_level_to_string Andi Kleen
2008-11-12 14:47   ` Johannes Weiner
2008-11-12 15:28     ` Andi Kleen [this message]
2008-11-12 18:43     ` Ingo Molnar

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=20081112152828.GM3810@one.firstfloor.org \
    --to=andi@firstfloor.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.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

all inboxes | Powered by JetHome®