public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: A better interface, perhaps: a timed signal flag
@ 2006-07-29  6:56 linux
  0 siblings, 0 replies; 14+ messages in thread
From: linux @ 2006-07-29  6:56 UTC (permalink / raw)
  To: linux-kernel, tytso; +Cc: linux

> If we had such an interface, then the application would look like
> this:
> 
>	volatile int	flag = 0;
>
>	register_timout(&time_val, &flag);
>	while (work to do) {
>		do_a_bit_of_work();
>		if (flag)
>			break;
>	}
>
> Finally, a note about tickless designs.  Very often such applications
> don't need a constantly ticking design.  For example, the X server
> only needs to have the memory location incremented while it is
> processing events; if the laptop is idle, there's no reason to have
> the RTC generating interrupts and incrementing memory locations.
> Similarly, the Metronome garbage collector would only need to poll to
> see if the timeout has expired while the garbage collector is running,
> which is _not_ all of the time.  
> 
> Yes, you could use ioctl's to start and stop the RTC interrupt
> handler, but that's just ugly, and points out that maybe the interface
> should not be one of programming the RTC interrupt frequency directly,
> but rather one of "increment this flag after X units of
> (CPU/wallclock) time, and I don't care how it is implemented at the
> hardware level."

Actually, unless you want the kernel to have to poll the timeout_flag
periodically, it's more like:

	volatile bool	timeout_flag = false, armed_flag = false;

	register_timout(&time_val, &flag);
	while (work to do) {
		if (!armed_flag) {
			rearm_timeout();
			armed_flag = true;
		}
		do_a_bit_of_work();
		if (timeout_flag) {
			armed_flag = false;
			timeout_flag = false;
			break;
		}
	}

Personally, I use setitimer() for this.  You can maintain the flags in
software, and be slightly lazy about disarming it.  If you get a signal
while you shouldn't be armed, *then* disarm the timer in the kernel.
Likewise, when rearming, set the user-disarmed flag and chec if kernel-level
rearming is required.

volatile bool timeout_flag = false, armed_flag = false, sys_armed_flag = false;

void
sigalrm(int sig)
{
	(void)sig;
	if (!armed_flag) {
		static const struct itimerval it_zero = {{0,0},{0,0}};
		if (sys_armed_flag)
			warn_unexpected_sigalrm();
		setitimer(ITIMER_REAL, &it_zero, 0);
		
	} else if (timeout_flag)
		warn_gc_is_slow();
	else
		timeout_flag = true;
}

void
arm_timer()
{
	static const struct itimerval it_interval = { time_val, time_val };

	armed_flag = true;
	if (!sys_armed_flag) {
		setitimer(ITIMER_REAL, &it_interval, 0);
		sys_armed_flag = true;
	}
}

main_loop()
{
	signal(SIGALRM, sigalrm);

	while (work to do) {
		arm_timer();
		do_a_bit_of_work();
		if (timeout_flag) {
			gc();
			armed_flag = false;
			timeout_flag = false;
		}
	}
}

... where only do_a_bit_of_work can prompt the need for more gc() calls.
This really tries to minimize the number of system calls.

^ permalink raw reply	[flat|nested] 14+ messages in thread
* RE: A better interface, perhaps: a timed signal flag
@ 2006-07-26 15:15 Brown, Len
  0 siblings, 0 replies; 14+ messages in thread
From: Brown, Len @ 2006-07-26 15:15 UTC (permalink / raw)
  To: Theodore Tso, Neil Horman
  Cc: H. Peter Anvin, Segher Boessenkool, Dave Airlie, linux-kernel,
	a.zummo, jg

>if the application doesn't need to
>know exactly how many microseconds have gone by, but just whether or
>not 150us has ellapsed, why calculate the necessary time?  (Especially
>if it requires using some ACPI interface...)

Yes, ACPI is involved in the boot-time enumeration of various timers
and counters.  But at run-time; the use of any and all of them
(including the PM_TIMER supplied by ACPI hardware itself) could/should
appear generic to kernel users, who should not have to directly call
any routine with an "acpi" in it.

I believe that this is true today, and can/should stay true.

-Len

^ permalink raw reply	[flat|nested] 14+ messages in thread
* Re: [PATCH] RTC: Add mmap method to rtc character driver
@ 2006-07-25 19:47 Neil Horman
  2006-07-25 20:04 ` Dave Airlie
  0 siblings, 1 reply; 14+ messages in thread
From: Neil Horman @ 2006-07-25 19:47 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: H. Peter Anvin, linux-kernel, a.zummo, jg

On Tue, Jul 25, 2006 at 09:31:32PM +0200, Segher Boessenkool wrote:
> >>Not really.  This introduces a potentially very difficult support
> >>user-visible interface.  Consider a tickless kernel -- you might  
> >>end up
> >>taking tick interrupts ONLY to update this page, since you don't have
> >>any way of knowing when userspace wants to look at it.
> >>
> >Well, you do actually know when they want to look at it.  The rtc  
> >driver only
> >unmasks its interrupt when a user space process has opened the  
> >device and sent
> >it a RTC_UIE ON or RTC_PIE_ON (or other shuch ioctl).  So if you  
> >open /dev/rtc,
> >and memory map the page, but never enable a timer method, then  
> >every read of the
> >page returns zero.  The only overhead this patch is currently  
> >adding, execution
> >time-wise is the extra time it takes to write to a the shared page  
> >variable.  If
> >the timer tick interrupt is executing, its because someone is  
> >reading tick data,
> >or plans to very soon.
> 
> But userland cannot know if there is a more efficient option to
> use than this /dev/rtc way, without using VDSO/vsyscall.
> 
Sure, but detecting if /dev/rtc via mmap is faster than gettimeofday is an
orthogonal issue to having the choice in the first place.  I say let the X guys
write code to determine at run time what is more efficient to get their job
done.  I really just wanted to give them the ability to avoid making a million
kernel traps a second for those arches where a userspace gettimeofday is not
yet implemented, or cannot be implemented.  It won't cost anything to add this
feature, and if the Xorg people can write code to use gettimeofday if its faster
than mmaped /dev/rtc (or even configured to do so at compile-time).  This patch
doesn't create any interrupts that wouldn't be generated already anyway by any
user using /dev/rtc, and even if X doesn't already use /dev/rtc, the added
interrupts are in trade for an equally fewer number of kernel traps, which I
think has to be a net savings.

I'm not saying we shouldn't implement a vsyscall on more platforms to provide a
speedup for this problem (in fact I'm interested to learn how, since I hadn't
previously considered that as a possibility), but I think offering the choice is
a smart thing to do until the latter solution gets propogated to other
arches/platforms besides x86_64

Regards
Neil

 
> 
> Segher

-- 
/***************************************************
 *Neil Horman
 *Software Engineer
 *gpg keyid: 1024D / 0x92A74FA1 - http://pgp.mit.edu
 ***************************************************/

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2006-07-29 18:29 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <fa.xkoDc6Uvpcp6dnG8+9iwy53PPeo@ifi.uio.no>
     [not found] ` <fa.7gpoVg9wmtQ0g4u4T8FaCZGXup0@ifi.uio.no>
2006-07-29 18:29   ` A better interface, perhaps: a timed signal flag Robert Hancock
2006-07-29  6:56 linux
  -- strict thread matches above, loose matches on Subject: below --
2006-07-26 15:15 Brown, Len
2006-07-25 19:47 [PATCH] RTC: Add mmap method to rtc character driver Neil Horman
2006-07-25 20:04 ` Dave Airlie
2006-07-25 20:24   ` H. Peter Anvin
2006-07-25 20:47     ` Neil Horman
2006-07-25 20:50       ` H. Peter Anvin
2006-07-25 22:25         ` Neil Horman
2006-07-25 23:29           ` Segher Boessenkool
2006-07-25 23:56             ` Neil Horman
2006-07-26  0:02               ` H. Peter Anvin
2006-07-26  0:20                 ` Neil Horman
2006-07-26 14:45                   ` A better interface, perhaps: a timed signal flag Theodore Tso
2006-07-28 13:33                     ` Steven Rostedt
2006-07-28 14:52                       ` Theodore Tso
2006-07-28 15:05                         ` Steven Rostedt
2006-07-28 16:41                         ` Alan Cox
2006-07-28 16:44                           ` Steven Rostedt
2006-07-28 20:01                             ` Alan Cox
2006-07-28 20:12                               ` Steven Rostedt
2006-07-28 20:36                                 ` Alan Cox
2006-07-28 20:31                                   ` Steven Rostedt
2006-07-28 17:11                     ` H. Peter Anvin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox