Skip to contentSkip to conversation

2.5.69 process.c: cpu_idle() cleanup

Linux-ia64 David Mosberger 2 participants 6 messages May 12, 2003 – May 13, 2003

lore
Share & tools
lore
#0 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Jes Sorensen

Jes> Hi David. Looking at the 2.5.69 cpu_idle() code and noticing Jes> that it has some SGI specific hooks in it. However I can see Jes> other platforms having leds or lcds or something else they want Jes> to flash or play little jingles when the box is idle.

Jes> As such I suggest we make these hooks that any platform can Jes> register. Adding the extra code to the idle loop doesn't seem Jes> all that expensive ;-)

Is this a real need or is this just something hypothetical? If the latter, I'd rather leave what's there now.

	--david
#1 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"David" = David Mosberger <[email protected]> writes:

David> Is this a real need or is this just something hypothetical? If David> the latter, I'd rather leave what's there now.

Hi David,

The problem with the current code is that it doesn't work for generic kernels and for the SN2 we really like to have this feature in place. The PROM allows you to go in and look at the led status even if the kernel has hung.

The other reason was that I was trying to get rid of SN specific features from generic files and having a more generic API for this seemed useful to me.

So to answer your question, yes I think there is a real use for this.

Cheers,
Jes

#2 lore raw
In reply to David Mosberger
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines · Jes Sorensen

"David" = David Mosberger <[email protected]> writes:

David> Is this a real need or is this just something hypothetical? David> If the latter, I'd rather leave what's there now.

Jes> The problem with the current code is that it doesn't work for Jes> generic kernels and for the SN2 we really like to have this Jes> feature in place. The PROM allows you to go in and look at the Jes> led status even if the kernel has hung.

Jes> The other reason was that I was trying to get rid of SN Jes> specific features from generic files and having a more generic Jes> API for this seemed useful to me.

Jes> So to answer your question, yes I think there is a real use for Jes> this.

OK, I can probably live with that argument. However, let's make it a platform vector then (which I was opposed to back when) and make it a single function (e.g., "mark_idle"), which takes an "idleness" argument.

	--david
#3 lore raw
In reply to David Mosberger
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"David" = David Mosberger <[email protected]> writes:

David> OK, I can probably live with that argument. However, let's David> make it a platform vector then (which I was opposed to back David> when) and make it a single function (e.g., "mark_idle"), which David> takes an "idleness" argument.

Hi David,

It was actually a deliberate decision of mine to not make it a machine vector, because this was meant to be an optional feature. With a machine vector one always ends up calling a dummy function on platforms that do not wish to do anything here.

I'll be happy to change it over to a machine vector if you still prefer, let me know.

Cheers,
Jes

#4 lore raw
In reply to David Mosberger
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Jes Sorensen

Jes> It was actually a deliberate decision of mine to not make it a machine Jes> vector, because this was meant to be an optional feature. With a Jes> machine vector one always ends up calling a dummy function on Jes> platforms that do not wish to do anything here.

Jes> I'll be happy to change it over to a machine vector if you still Jes> prefer, let me know.

It doesn't make a huge difference either way. But I definitely want there to be only a single function/callback. In fact, if you load the function pointer into a local variable, the load (and NULL check) can be amortized across both calls and we can rest assured that we squeze every single cycle out of the idle loop! ;-)

(Actually, on the more serious side, we don't want to waste CPU cycles outright in the idle loop either, as that could negatively affect power consumption---not that it makes a huge difference on current generation CPUs.)

	--david
#5 lore raw
In reply to David Mosberger
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"David" = David Mosberger <[email protected]> writes:

David> It doesn't make a huge difference either way. But I definitely David> want there to be only a single function/callback. In fact, if David> you load the function pointer into a local variable, the load David> (and NULL check) can be amortized across both calls and we can David> rest assured that we squeze every single cycle out of the idle David> loop! ;-)

Here you go!

A top tuned idle loop, just as you all dreamed of last Christmas and were really disappointed when your dream didn't come true! This time it did, so start dancing around the Christmas tree!

This one goes on top of the gettimeoffset() patch as well.

Cheers,
Jes

arch/ia64/kernel/process.c +9 -10
diff -urN -X /home/jes/exclude-linux linux-2.5.69-030509-timer/arch/ia64/kernel/process.c linux-2.5.69-030509/arch/ia64/kernel/process.c
@@ -33,16 +33,15 @@
 #include <asm/unwind.h>
 #include <asm/user.h>
 
-#ifdef CONFIG_IA64_SGI_SN
-#include <asm/sn/idle.h>
-#endif
-
 #ifdef CONFIG_PERFMON
 # include <asm/perfmon.h>
 #endif
 
 #include "sigframe.h"
 
+void (*ia64_mark_idle)(int);
+
+
 void
 ia64_do_show_stack (struct unw_frame_info *info, void *arg)
 {
@@ -175,6 +174,8 @@
 void __attribute__((noreturn))
 cpu_idle (void *unused)
 {
+	register void (*__mark_idle)(int) = ia64_mark_idle;
+
 	/* endless idle loop with no priority at all */
 	while (1) {
 		void (*idle)(void) = pm_idle;
@@ -187,15 +188,13 @@
 #endif
 
 		while (!need_resched()) {
-#ifdef CONFIG_IA64_SGI_SN
-			snidle();
-#endif
+			if (__mark_idle)
+				(*__mark_idle)(1);
 			(*idle)();
 		}
 
-#ifdef CONFIG_IA64_SGI_SN
-		snidleoff();
-#endif
+		if (__mark_idle)
+			(*__mark_idle)(0);
 
 #ifdef CONFIG_SMP
 		normal_xtp();
arch/ia64/sn/kernel/idle.c +36 -0
diff -urN -X /home/jes/exclude-linux linux-2.5.69-030509-timer/arch/ia64/sn/kernel/idle.c linux-2.5.69-030509/arch/ia64/sn/kernel/idle.c
@@ -0,0 +1,36 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (c) 2001-2003 Silicon Graphics, Inc.  All rights reserved.
+ */
+
+#include <linux/config.h>
+#include <asm/sn/leds.h>
+#include <asm/sn/simulator.h>
+
+void snidle(int state) {
+	if (state) {
+		if (pda.idle_flag = 0) {
+			/* 
+			 * Turn the activity LED off.
+			 */
+			set_led_bits(0, LED_CPU_ACTIVITY);
+		}
+
+#ifdef CONFIG_IA64_SGI_SN_SIM
+		if (IS_RUNNING_ON_SIMULATOR())
+			SIMULATOR_SLEEP();
+#endif
+
+		pda.idle_flag = 1;
+	} else {
+		/* 
+		 * Turn the activity LED on.
+		 */
+		set_led_bits(LED_CPU_ACTIVITY, LED_CPU_ACTIVITY);
+
+		pda.idle_flag = 0;
+	}
+}
arch/ia64/sn/kernel/setup.c +5 -1
diff -urN -X /home/jes/exclude-linux linux-2.5.69-030509-timer/arch/ia64/sn/kernel/setup.c linux-2.5.69-030509/arch/ia64/sn/kernel/setup.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1999,2001-2002 Silicon Graphics, Inc. All rights reserved.
+ * Copyright (C) 1999,2001-2003 Silicon Graphics, Inc. All rights reserved.
  * 
  * This program is free software; you can redistribute it and/or modify it 
  * under the terms of version 2 of the GNU General Public License 
@@ -79,6 +79,8 @@
 extern void bte_init_node (nodepda_t *, cnodeid_t);
 extern void bte_init_cpu (void);
 extern void sn_timer_init (void);
+extern void (*ia64_mark_idle)(int);
+extern void snidle(int);
 
 unsigned long sn_rtc_cycles_per_second;   
 
@@ -304,6 +306,8 @@
 	current->thread.flags |= IA64_THREAD_FPEMU_NOPRINT;
 
 	sn_timer_init();
+
+	ia64_mark_idle = &snidle;
 }
 
 /**
include/asm-ia64/sn/idle.h +0 -57

57 lines not on this page · raw message