Re: question about thread scheduling



On 17 Mar, 11:12, "Zhiqiang Li" <zhiqiang...@xxxxxxxxxx> wrote:
Hi Remi,
thanks for your advice.
Let me tell you what I exactly want to do:

In essential, it is a control problem, and I must send a voltage to the
moter every 4ms(this can be configured to another value in other cases), and
this voltage is calculated through a process model, which is based on neural
network. During the 4ms, I must use the CUP resource as much as possible,
since algorithms on neural networks are always computational intensive, and
I have to stop my calculation before is reach the 4ms deadline, so I am
afraid that I can not use any sleep function to kill the precious CPU time:)

Um, sounds like you've not grasped all of the fundamentals of
multitasking (or I have totally misunderstood what you're trying to
do). If you have enough cycles to make a 4ms deadline it should be
trivial to achieve what you need using a couple of threads and
Sleep(...). If the NN run in a different thread as the control loop
you simply schedule the control loop with a higher priority than the
NN loop. If they run in the same thread, you could just create a pace-
thread that signals an event every 4 ms (using Sleep(...)) that the
control/NN thread wait for. When trigged, the ctrl thread run to
completion and go back to waiting for the event again.

Henrik Viklund
http://www.addlogic.se


I am using CE 6.0 on a CEPC, and I have modifid the value of
g_dwBSPMsPerIntr to 4, so that it will generate an timer interrupt every
4ms. I found that if I want to let the scheduler run also every 4ms, I have
to modify the code inside "PeRPISR", so that it will generated a
SYSINTR_RESCHED every 4ms.

I am now study this source code, and trying to modify it to meet my
requirement.

best wishes
Zhiqiang
"Remi de Gravelaine" <gravelaine at aton dash sys dot fr> schrieb im
Newsbeitragnews:OHk45G9ZHHA.4520@xxxxxxxxxxxxxxxxxxxxxxx



Zhiqiang,

You should try to tell us *exactly* what you want to do.
You should also avoid multiplying the discussion threads if you want
people to take care of you from the beginning.
If I understood what you want to do, you have implemented a polling loop
to do some job (what kind of job?) every 4ms.
You have put this loop in a high-priority thread started by the XXX_Init
function of a stream driver.
You are using CE 6.0 on a CEPC.

The loop should thus look like:

while (!g_bSuicide)
{
Sleep(3);
<do some job>
}

There is no reason that such a loop exits except when g_bSuicide is set to
TRUE (something that can be done in XXX_Deinit) or the <do some job> code
executes a break of goto intruction.

Now, why Sleep(3) instead of Sleep(4)? Because Sleep(3) will sleep for *at
least* 3 ms and because Sleep is synchonized on timer ticks, that fire
every ms (producing the SYSINTR_RESCHED you are focusing on.) So, Sleep(3)
returns from sleeping right after the third tick and a new 1ms slice
begins. You <do some job> during a portion of this slice and reenter
Sleep(3). Sleep(3) puts your thread to sleep for 3 timer ticks and that
means the time remaining in the current tick + 3 ms.

HTH
Remi- Dölj citerad text -

- Visa citerad text -


.



Relevant Pages

  • Re: Digitally Controlled Power Supply with Digital POT, Keeping the Digipot from being fried
    ... At the voltage which I ... to provide digital power control. ... digital potentiometer from Xicor/Intersil (10K Ohm, ... the equivalent "fully protected MOSFET ...
    (sci.electronics.design)
  • Re: Slope Compensation and Vodka
    ... > | IIRC its associated with the sampled-data nature of the overall ... > | loop, which the standard linear analysis conveniently ignores. ... the real circuit for a control loop analysis, ... It all seems to boil down to the "choice" of modulator transfer ...
    (sci.electronics.design)
  • Re: Exploring the FOPDT Model With a Parameter Sensitivity Study
    ... primary focus is on PID control and related architectures. ... PID loops and from 50 to over 1000 measurements. ... A control person seeking to tune a loop 'might' ... And I know my posts on this newsgroup announcing the publication of the ...
    (sci.engr.control)
  • Re: Industrial duty dimmer
    ... >> I tried to run one of these things off of a regular $5 dimmer and it ... > control of multi-horsepower AC motors. ... > the asymmetry of the DIAC triggering voltage. ... > line voltage on the pot would be out. ...
    (sci.electronics.design)
  • Re: The Cascade Control Architecture - controlguru post
    ... performance are cascade control and feed forward with feedback trim. ... literally nest a secondary control loop inside a primary loop as ... you _cannot_ improve the disturbance ...
    (sci.engr.control)