schedule to highest priorty process

fve
 
Avatar
 
Betreff:

schedule to highest priorty process

 · 
Gepostet: 04.07.2014 - 09:45 Uhr  ·  #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
Geschlecht:
Alter: 26
Beiträge: 1480
Dabei seit: 03 / 2005
Betreff:

Re: schedule to highest priorty process

 · 
Gepostet: 04.07.2014 - 14:44 Uhr  ·  #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
Geschlecht:
Herkunft: Frankfurt Main / Germany
Beiträge: 1697
Dabei seit: 02 / 2003
Betreff:

Re: schedule to highest priorty process

 · 
Gepostet: 05.07.2014 - 07:49 Uhr  ·  #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
Geschlecht:
Herkunft: Germany
Alter: 26
Homepage: e-lab.de
Beiträge: 5558
Dabei seit: 03 / 2002
Betreff:

Re: schedule to highest priorty process

 · 
Gepostet: 05.07.2014 - 16:33 Uhr  ·  #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
 
Betreff:

Re: schedule to highest priorty process

 · 
Gepostet: 07.07.2014 - 09:35 Uhr  ·  #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
Gewählte Zitate für Mehrfachzitierung:   0

Registrierte in diesem Topic

Aktuell kein registrierter in diesem Bereich

Die Statistik zeigt, wer in den letzten 5 Minuten online war. Erneuerung alle 90 Sekunden.
MySQL Queries: 15 · Cache Hits: 14   93   107 · Page-Gen-Time: 0.036225s · Speichernutzung: 2 MB · GZIP: ein · Viewport: SMXL-HiDPI