schedule to highest priorty process

fve
 
Avatar
 
Subject:

schedule to highest priorty process

 · 
Posted: 04.07.2014 - 09:45  ·  #1
Hi,

I'm having the following problem:

my program consists out of 5# processes and 1 task:

ticktime = 8ms

task is called every 2 ticks

the task does some processing on adc samples. if a predefined threshold is found, i want to schedule directly to one of the processes( this process generates a telegram and sends it out to a plc).

my problem: i know that the priority of the processes equals the amount processisng time the schedular gives to the process.
On the other hand i read in the manual that i can call the schedule function to schedule to the task with the highes priority:
The process/task is suspended here and the control is passed to the scheduler. The scheduler now looks for the next process with the highest priority, and this process gets activated.

So to test it out, i created a new process, gave it the highest priority:


process testprocess($20, $20 : iData; 15,suspended);
begin
waitsema(testsema);
Serout4($10);
schedule;
end testprocess;


when reaching the threshold in the task, i increment the semaphore, and call the schedule function.

I would suspect that the schedular schedules directly to the testprocess, since it has the highest priority and is waiting on a semaphore (no process time spend yet).

But i notice other processes are being called before going to my testprocess..

Can you tell me something more about the way the scheudar works?
Or is there a better way to make sure the schedular schedules to the process i want (without suspending all the other processes :p)

Regards,
Flor
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1409
Registered: 03 / 2005
Subject:

Re: schedule to highest priorty process

 · 
Posted: 04.07.2014 - 14:44  ·  #2
The scheduler acts as a round robin. Processes can be suspended but the order in which they are executed does not change. So to do what you want you would probably need to suspend all, resume this one, then resume all, perhaps like this (unless someone else knows different...)
Code

// in the task
  SuspendAll( processes );
  Resume( testProcess );

...

process testprocess($20, $20 : iData; 15,suspended); 
begin 
//waitsema(testsema); 
Serout4($10); 
ResumeAll(processes);
//schedule;
suspend( testprocess );  // sleeps until woken up by the task 
end testprocess; 


You don't need to suspend the process, but given what you are doing it might be more efficient than using a semaphore. It puts less burden on the scheduler.
Gunter
Administrator
Avatar
Gender:
Location: Frankfurt Main / Germany
Posts: 1697
Registered: 02 / 2003
Subject:

Re: schedule to highest priorty process

 · 
Posted: 05.07.2014 - 07:49  ·  #3
Hi all,

shouldn't Lock (TestProcess) in the Task and
Unlock (TestProcess) in the process itself be
an easy way to archieve this?

I never tried these commands,

Gunter
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: schedule to highest priorty process

 · 
Posted: 05.07.2014 - 16:33  ·  #4
@Gunter,

al "lock" doesn't change the priority or which process comes as next.
Lock only takes place if the locked process gains the control, and this is uncertain.
Merlin's suggestion seems the only way to do it.

rolf
fve
 
Avatar
 
Subject:

Re: schedule to highest priorty process

 · 
Posted: 07.07.2014 - 09:35  ·  #5
Hi all,

I'll try it the way Merlin suggests.
I wasn't sure suspending all other processes was the right way to go.

Thanks for the help.

Regards,
Flor
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 15 · Cache Hits: 14   93   107 · Page-Gen-Time: 0.028586s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI