Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sun 23 Nov 2014, 17:39
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Idea for a system timer API to replace polling in programs.
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 2 [24 Posts]   Goto page: 1, 2 Next
Author Message
sunburnt


Joined: 08 Jun 2005
Posts: 5042
Location: Arizona, U.S.A.

PostPosted: Tue 17 Dec 2013, 13:55    Post subject:  Idea for a system timer API to replace polling in programs.  

# Code discussion: amigo commented on how bad polling is, I know this all too well. Cron?

I`m thinking system timers ( .5, 1, 2 , 5, etc...) that each run app lists that are "env" variables.
This way there`s only one timer running for each time interval. Not one running in each app.

# An API utility would be needed to add, modify, and delete apps in the env variables.
.
Back to top
View user's profile Send private message 
Flash
Official Dog Handler


Joined: 04 May 2005
Posts: 11157
Location: Arizona USA

PostPosted: Tue 17 Dec 2013, 16:36    Post subject:  

How does Puppy know when a keyboard key is pressed? Surely polling would be too slow. Keyboards have an internal controller chip, but how does it tell the computer that a key was pressed? Is there an interrupt dedicated to the keyboard?
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5042
Location: Arizona, U.S.A.

PostPosted: Tue 17 Dec 2013, 19:01    Post subject:  

Hi Flash; Apparently the keyboard is polled at maybe 200 to 1000 times a second.
This seems way too fast, human beings are no way near that fast.
And kinda disappointing also, you`d think better use would be made of hardware interrupts.
Back to top
View user's profile Send private message 
Flash
Official Dog Handler


Joined: 04 May 2005
Posts: 11157
Location: Arizona USA

PostPosted: Tue 17 Dec 2013, 21:45    Post subject:  

Nobody can type that fast, for sure. Probably the reason the keyboard is polled so often has to do with latency or delay. When you hit a key, you expect the response on the screen to be instantaneous. A millisecond is the same as instantaneous to our limited brains.

Is the polling done by the computer's motherboard or by the keyboard's built-in controller?
Back to top
View user's profile Send private message 
Moose On The Loose


Joined: 24 Feb 2011
Posts: 534

PostPosted: Tue 17 Dec 2013, 21:47    Post subject:  

sunburnt wrote:
Hi Flash; Apparently the keyboard is polled at maybe 200 to 1000 times a second.
This seems way too fast, human beings are no way near that fast.
And kinda disappointing also, you`d think better use would be made of hardware interrupts.


IIRC:
IRQ-1 was used in early PCs before the USB keyboard came on the scene.
When IRQ-1 happened, the BIOS did some stuff and then some Rube Goldberg things happened letting the code check a circular buffer for keys.

There was a bizarre bit of code on early laptops that each time you pressed a key restarted a down counter that timed how long until the thing went into power saving mode.
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5042
Location: Arizona, U.S.A.

PostPosted: Tue 17 Dec 2013, 22:41    Post subject:  

Ahhh yes... The haphazard evolution of the PC. How sad that there was no real planning.

The keybd. offers output to the PC`s port, the O.S. ( Linux ) decides when to look at it.
Back to top
View user's profile Send private message 
Flash
Official Dog Handler


Joined: 04 May 2005
Posts: 11157
Location: Arizona USA

PostPosted: Wed 18 Dec 2013, 01:01    Post subject:  

The reason I brought up the keyboard at all is that how it works might have some application to this particular topic. The OS must respond with very little delay when a keyboard key is pressed, and it must not miss any keystrokes. How do it do it?
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5042
Location: Arizona, U.S.A.

PostPosted: Wed 18 Dec 2013, 01:39    Post subject:  

I`m not sure, but I`d think the keybd. has a fifo buffer to hold the key strokes.
When the O.S. gets around to looking at the buffer, it empties it all.
Back to top
View user's profile Send private message 
amigo

Joined: 02 Apr 2007
Posts: 2276

PostPosted: Wed 18 Dec 2013, 02:29    Post subject:  

Right you are -there's a buffer. As for the Interrupts, they can follow very quickly -the kernel is always ready for an interrupt and they can happen, potentially, many thousands of times per second.

cron is the answer -except that the bottom time-limit is 1 minute. Of course, there are other methods too. If the desired action involves kernel 'events', then a udev rule can be used to trigger an action only when the event occurs. Most of the time when a polling-loop has been considered as the answer, it is because the underlying idea has not been properly sorted.

Exactly what are you trying to do?
Back to top
View user's profile Send private message 
greengeek

Joined: 20 Jul 2010
Posts: 2668
Location: New Zealand

PostPosted: Wed 18 Dec 2013, 02:35    Post subject:  

I guess both the keyboard and mouse would have to have a pretty high priority as far as the OS 'looking' at their output - although, having said that, I do find there are plenty of times where flash objects running / loading in my browser seem to prevent the OS from looking at either mouse or keyboard at all...
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4376

PostPosted: Wed 18 Dec 2013, 03:26    Post subject:  

are you looking to come up with something that handles hibernation and suspend well?
If so, your huckleberry is /sys/class/rtc/rtc0/wakealarm or possibly
/sys/devices/virtual/misc/rtc/power/wakeup
(you can use the date command to write the wakeup time to it as shown here)
and you can use init facilities to run stuff on thaw/resume

As for events here is some applicable example code:
http://www.xmailserver.org/eventfd-bench.c
http://www.xmailserver.org/timerfd-test.c
http://www.xmailserver.org/signafd-test.c
more here:http://kernelnewbies.org/Linux_2_6_22#head-0357b2415f5d3116bf2b03de07224d16912acec2

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5042
Location: Arizona, U.S.A.

PostPosted: Wed 18 Dec 2013, 16:24    Post subject:  

Hi guys; The spark here was my Separate Desktop Wallpapers app using polling.
I also have my usb-auto app that auto mounts / unmount usb devices that`s polled.

I`d mentioned before about having a set of system timers instead of using "sleep 1".

I did not know that cron only had a resolution of 1 minute. So it`s no help here.

Out of curiosity... amigo; You`re saying the keybd. is hardware interrupted.? Mouse too.?

# My suggestion of an API system timer:
Using "sleep" is asynchronous, so accurate to the second timing isn`t needed here.
I was thinking "sleep 0.1" and have a counter to provide the other time intervals.
However, this may be more cpu intensive than just having multiple sleeps running.
As I said the timer events would look at env variables for lists of apps to run.
env variables: $SLEEP01, $SLEEP02, $SLEEP05, $SLEEP1, etc...
So writing apps as daemons ( like my Wallpapers app.) with a sleep-loop isn`t needed.
The app is called and it does whatever the daemon usually did during each timed loop.

# Calling the apps is a sys. load, so 1 second and under may not be a good idea.
If the app runs with a polled loop, then there`s no sys. load of firing up another shell.

# Wacha think guys.? Is this just another dumb idea, or does it have merit.?
.
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4376

PostPosted: Thu 19 Dec 2013, 02:54    Post subject:  

Take a look in may simple icon tray code. It uses a gtk wrapper around inotify to handle file events without polling (my earlier code used inotify directly, but I wanted portability to windows). The most recent version also handles the desktop background. It is really simple to update any image, for bg, just cat the new image over the default.
you could do something like this:
Code:
sdesk -b /usr/share/backgrounds/default.jpg &
while :; do
for x in $HOME/backgrounds/*;do
sleep 30
cat $x >/usr/share/backgrounds/default.jpg
done
done
The trayicons and tooltips work the same way.
_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
amigo

Joined: 02 Apr 2007
Posts: 2276

PostPosted: Thu 19 Dec 2013, 03:06    Post subject:  

udev is a great way to handle auto-mounting of USB devices. The kernel event triggers udev into action and you can create udev rules to call an external program for each event.

I see no point at all in having a loop which does something for desktop backgrounds. These should simply be set and then forgotten until the next time you want to change. BTW, controlling the background (root window) image is the rightful domain of the Window Manager. Some of them allow for using different images for each virtual desktop -some of them do not. rox and some other desktop-related programs impinge on this control. In your case, both JWM and rox are trying to control it, while you are trying to impose your own will... If you want to control it, then you need to disable both jwm and rox from doing so.
Back to top
View user's profile Send private message 
jamesbond

Joined: 26 Feb 2007
Posts: 2230
Location: The Blue Marble

PostPosted: Thu 19 Dec 2013, 05:19    Post subject:  

amigo wrote:
udev is a great way to handle auto-mounting of USB devices. The kernel event triggers udev into action and you can create udev rules to call an external program for each event.

+1

_________________
Fatdog64, Slacko and Puppeee user. Puppy user since 2.13.
Contributed Fatdog64 packages thread
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 2 [24 Posts]   Goto page: 1, 2 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0797s ][ Queries: 11 (0.0044s) ][ GZIP on ]