To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 2517
2516  |  2518
Subject: 
Accurate msleep and timeslicing - was Re: sys_timer
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Fri, 3 May 2002 11:43:07 GMT
Viewed: 
2372 times
  
"Michael Obenland" <obenland@t-online.de> wrote in message
news:GvJ5vD.7MC@lugnet.com...
<snip>
this only seems to update by 20 ms at a time.

That is right.

That doesn't really make sense though...

It does, actually. The timer itself counts the millisec. But if you do a
wait_event() call, your running program gives up its time slice, the OS
waits for the event and then continues your task with the next task • switch.
And the granularity for a task switch is 20ms ( or whatever you want it to
be. Look in include/sys/tm.h and try what happens with a TM_DEFAULT_SLICE
of 10 or 30.)

I made some modifications to the tm_sleep_wakeup that allows high priority
tasks to wake up at exactly the time specified for msleep (which uses
wait_event on tm_sleep_wakeup).  The modification works well for
applications where driving or turning a specific amount of time is required.
However, I think this modification could be applied anywhere you need a high
priority task to return more quickly from a wait_event...

You would likely want to write your own 'wakeup' function, but could modify
the kernel function as well.

Here is the modified tm_sleep_wakeup - explaination follows:

-----------------------------------------
static wakeup_t tm_sleep_wakeup(wakeup_t data) {
time_t remaining = ((time_t)data) - sys_time;

if (((time_t)data)<=sys_time)
{
  tm_timeslice = TM_DEFAULT_SLICE;
  return -1;
}

if (remaining < tm_timeslice)
  tm_timeslice = remaining;

return 0;
}

-----------------------------------------

If the condition to wake up is true, set the tm_timeslice = TM_DEFAULT_SLICE
to return to normal time slicing.  Otherwise, set tm_timeslice = X; where X
is the time before the next check of this event handler.

WARNING:  This method can have drastic effects on the application/OS.
Setting this to 0 would block all tasks until the event handler returns
true.  Setting it to a low number (1 - 5 perhaps) could cause a lot of
overhead... slowing other tasks down.

It works well for the tm_sleep_wakeup because the amount of time remaining
is known... and the timeslice is only reduced when necessary.

// Joe



Message is in Reply To:
  Re: sys_timer
 
(...) Yes. (...) That is right. (...) It does, actually. The timer itself counts the millisec. But if you do a wait_event() call, your running program gives up its time slice, the OS waits for the event and then continues your task with the next (...) (23 years ago, 3-May-02, to lugnet.robotics.rcx.legos)

4 Messages in This Thread:


Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR