Skip to contentSkip to conversation

Timer patch for 2.6

uml-devel Pete Zaitcev 2 participants 2 messages Apr 2, 2004

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

Guys,

this is a relatively straightforward port of the IBM on-demand-timer patch which they developed for s390.

I was unable to verify that it actually works in UML. My UML seems to be hosed by a recent Fedora update, known good setups fail to work, too. So, I am posting this mainly for review. I am terribly confused by the way timers work in UML. In particular, it appears that every process has to set up a timer. So... what are the implications for implementation of stop_hz_timer()? I reckon that we don't care about timers of processes which are not runnable anyway, and so I did not attempt to do anything about timers of them. I only start and stop interval timer of the current thread (which runs the idle loop). This is the sort of thing which bothers me about this.

If Jeff wants to apply this to his 2.6 tree and throw it onto developers to test, it would be fine, but personally I'd like someone to read this first. Like I said, I am completely lost in arch/um/.

-- Pete

arch/um/include/time_user.h +6 -2
diff -ur -X dontdiff linux-2.6.4-uml-1/arch/um/include/time_user.h linux-2.6.4-uml-1-t1/arch/um/include/time_user.h
@@ -6,11 +6,15 @@
 #ifndef __TIME_USER_H__
 #define __TIME_USER_H__
 
-extern void timer(void);
+/* struct timeval has the same layout in user and kernel */
+extern void timer(struct timeval *tv);
+
 extern void switch_timers(int to_real);
 extern void set_interval(int timer_type);
-extern void idle_sleep(int secs);
+extern void idle_sleep(void);
 extern void enable_timer(void);
+extern void enable_hz_timer(int delta_usec);
+extern void disable_hz_timer(struct timeval *delta);
 extern unsigned long time_lock(void);
 extern void time_unlock(unsigned long);
 
arch/um/Kconfig +9 -0
diff -ur -X dontdiff linux-2.6.4-uml-1/arch/um/Kconfig linux-2.6.4-uml-1-t1/arch/um/Kconfig
@@ -219,6 +219,15 @@
 	up for the time spent at the breakpoint.  This could result in a 
 	noticable lag.  If this is a problem, then disable this option.
 
+config NO_IDLE_HZ
+	bool "Stop periodic timer when idle"
+	default n
+
+config NO_IDLE_HZ_INIT
+	bool "Idle HZ timer on by default"
+	depends on NO_IDLE_HZ
+	default y
+
 endmenu
 
 source "init/Kconfig"
arch/um/kernel/irq.c +4 -0
diff -ur -X dontdiff linux-2.6.4-uml-1/arch/um/kernel/irq.c linux-2.6.4-uml-1-t1/arch/um/kernel/irq.c
@@ -278,6 +278,10 @@
 	unsigned int status;
 
 	irq_enter();
+#ifdef CONFIG_NO_IDLE_HZ
+	if (!timer_ticking)		/* SMP implications... XXX */
+		start_hz_timer();
+#endif
 	kstat_this_cpu.irqs[irq]++;
 	spin_lock(&desc->lock);
 	desc->handler->ack(irq);
arch/um/kernel/process_kern.c +3 -2
diff -ur -X dontdiff linux-2.6.4-uml-1/arch/um/kernel/process_kern.c linux-2.6.4-uml-1-t1/arch/um/kernel/process_kern.c
@@ -209,8 +209,9 @@
 		irq_stat[smp_processor_id()].idle_timestamp = jiffies;
 		if(need_resched())
 			schedule();
-		
-		idle_sleep(10);
+
+		stop_hz_timer();
+		idle_sleep();
 	}
 }
 
arch/um/kernel/time.c +30 -11

63 lines not on this page · raw message

arch/um/kernel/time_kern.c +134 -1

162 lines not on this page · raw message

include/asm-um/system-generic.h +10 -0
diff -ur -X dontdiff linux-2.6.4-uml-1/include/asm-um/system-generic.h linux-2.6.4-uml-1-t1/include/asm-um/system-generic.h
@@ -45,3 +45,13 @@
 #define switch_to(prev, next, last) prev = _switch_to(prev, next, last)
 
 #endif
+
+#ifdef CONFIG_NO_IDLE_HZ
+extern void stop_hz_timer(void);
+extern void start_hz_timer(void);
+extern int timer_ticking;
+#else
+#define stop_hz_timer()		/* */
+#define start_hz_timer()	/* */
+#define timer_ticking   (0)
+#endif
include/linux/sched.h +6 -0
diff -ur -X dontdiff linux-2.6.4-uml-1/include/linux/sched.h linux-2.6.4-uml-1-t1/include/linux/sched.h
@@ -166,6 +166,9 @@
 extern void cpu_init (void);
 extern void trap_init(void);
 extern void update_process_times(int user);
+#ifdef CONFIG_NO_IDLE_HZ
+extern void update_process_times_us(int user, int system);
+#endif
 extern void update_one_process(struct task_struct *p, unsigned long user,
 			       unsigned long system, int cpu);
 extern void scheduler_tick(int user_tick, int system);
@@ -598,6 +601,9 @@
 extern unsigned long itimer_ticks;
 extern unsigned long itimer_next;
 extern void do_timer(struct pt_regs *);
+#ifdef CONFIG_NO_IDLE_HZ
+extern void do_timer_ticks(int ticks);
+#endif
 
 extern int FASTCALL(wake_up_state(struct task_struct * tsk, unsigned int state));
 extern int FASTCALL(wake_up_process(struct task_struct * tsk));
include/linux/sysctl.h +1 -0
diff -ur -X dontdiff linux-2.6.4-uml-1/include/linux/sysctl.h linux-2.6.4-uml-1-t1/include/linux/sysctl.h
@@ -131,6 +131,7 @@
 	KERN_PRINTK_RATELIMIT_BURST=61,	/* int: tune printk ratelimiting */
 	KERN_PTY=62,		/* dir: pty driver */
 	KERN_NGROUPS_MAX=63,	/* int: NGROUPS_MAX */
+	KERN_S390_HZ_TIMER=64,	/* int: hz timer on or off (not just s390) */
 };
 
 
include/linux/timer.h +4 -0
diff -ur -X dontdiff linux-2.6.4-uml-1/include/linux/timer.h linux-2.6.4-uml-1-t1/include/linux/timer.h
@@ -94,4 +94,8 @@
 extern void run_local_timers(void);
 extern void it_real_fn(unsigned long);
 
+#ifdef CONFIG_NO_IDLE_HZ
+extern unsigned long next_timer_event(void **);
+#endif
+
 #endif
kernel/sysctl.c +13 -0
diff -ur -X dontdiff linux-2.6.4-uml-1/kernel/sysctl.c linux-2.6.4-uml-1-t1/kernel/sysctl.c
@@ -106,6 +106,9 @@
 #endif
 extern int sysctl_userprocess_debug;
 #endif
+#ifdef CONFIG_NO_IDLE_HZ	/* Not just s390 anymore */
+extern int sysctl_hz_timer;
+#endif
 
 #if defined(CONFIG_PPC32) && defined(CONFIG_6xx)
 extern unsigned long powersave_nap;
@@ -846,6 +849,16 @@
 		.mode		= 0644,
 		.proc_handler	= &proc_dointvec,
 	},
+#ifdef CONFIG_NO_IDLE_HZ
+	{
+		.ctl_name	= KERN_S390_HZ_TIMER,
+		.procname	= "hz_timer",
+		.data		= &sysctl_hz_timer,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= &proc_dointvec,
+	},
+#endif
 	{ .ctl_name = 0 }
 };
 
kernel/timer.c +165 -2

197 lines not on this page · raw message

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#1 lore raw
Quoted 5 lines · Pete Zaitcev

I was unable to verify that it actually works in UML. My UML seems to be hosed by a recent Fedora update, known good setups fail to work, too. So, I am posting this mainly for review. I am terribly confused by the way timers work in UML. In particular, it appears that every process has to set up a timer.

In tt mode, each UML process gets a host process, the kernel is mapped into each process, and it runs in each process. That means that the kernel switches host processes every time there's a context switch. So, every process needs its own timer.

For this, what needs to happen is that, on every context switch, the timer has to be reset to fire at the appropriate time. The switch will happen some time in the middle of the interval, so the remaining time needs to be calculated, and the timer for the new process set accordingly. The timer of the outgoing process can just be disabled.

Things are somewhat more sane in skas mode. There are two processes - kernel and user, and both need a timer. However, there's a complication. The kernel process needs to be able to manipulate the user process' timer, which would appear to call for another ptrace op or something.

I haven't taken a good look at the patch yet.

Thanks for doing this...

Jeff

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel