Does Trigger() cause rescheduling?

Hi Gurus,

Almost a philosophical question. Is Trigger() really a non-blocking call, or
just a ‘blocking and instantly unblocking’ one?

A typical scenario. There are two processes (A and B) at the same priority,
FIFO scheduling, both READY. A higher-priority process (C) is runniung. Then
the following happens:

  1. C goes blocked, A gets the CPU.
  2. In the middle of its timeslice, A calls Trigger().

Will A be still running after this? Assuming that Trigger() is ‘a kind of
Send() which returns immediately’, calling it should cause rescheduling
anyway, so after A calls Trigger(), B will instantly get the CPU.

Am I right?

P.S. “This question is based on a real story.” :slight_smile:

Thanks,

  • Nick

Nikolai Gorbunov <n.gorbunov@swd.ru> wrote:

Hi Gurus,

Almost a philosophical question. Is Trigger() really a non-blocking call, or
just a ‘blocking and instantly unblocking’ one?

Um…define instantly unblocking? Yes, it makes a kernel call, no
your process doesn’t leave the READY state.

A typical scenario. There are two processes (A and B) at the same priority,
FIFO scheduling, both READY. A higher-priority process (C) is runniung. Then
the following happens:

  1. C goes blocked, A gets the CPU.
  2. In the middle of its timeslice, A calls Trigger().

Will A be still running after this? Assuming that Trigger() is ‘a kind of
Send() which returns immediately’, calling it should cause rescheduling
anyway, so after A calls Trigger(), B will instantly get the CPU.

Am I right?

A should continue running after the Trigger().

P.S. “This question is based on a real story.” > :slight_smile:

My small test bears this out.

I set up a program that creates two proxies. Setup two fifo processes
that loop and occasionally Trigger their proxy – one is given proxya
the other proxyb.

When I run them, I see a few “proxy a”, then when I run the 2nd program,
I see one “proxy b”, the Trigger() before it drops its priority just
to make sure it got the right proxy, then I never see another Trigger from
proxy b – only proxy a.

So, this bears out that Trigger() doesn’t block, even instantly, the
calling process.

(Note: if running on a fast machine, may want to grow the length of the
delay loops, this was run on a 133Mhz Pentium.)

-David

recv.c:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/kernel.h>
#include <sys/proxy.h>
#include <sys/sched.h>

void main()
{
int proxya, proxyb, pid;


proxya = qnx_proxy_attach( 0, 0, 0, -1 );
proxyb = qnx_proxy_attach( 0, 0, 0, -1 );
printf(“proxya: %d, proxyb: %d\n”, proxya, proxyb );

while(1) {
pid = Receive(0, NULL, 0 );
if (pid == proxya) printf(“proxy from a\n”);
if (pid == proxyb) printf(“proxy from b\n”);
}
}

trigger.c:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/kernel.h>
#include <sys/proxy.h>
#include <sys/sched.h>

void main(int argc, char **argv)
{
int proxy;
struct sched_param param;
int i;

proxy = atoi( argv[1] );
Trigger(proxy );
param.sched_priority = 5;
sched_setscheduler( 0, SCHED_FIFO, &param );
//setprio( 0, 5 );

while(1) {
for(i=0; i<10000000; i++ );
Trigger(proxy);
}
printf(“i is %d\n”, i );
}

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Thanks a lot David :slight_smile:

“David Gibbs” <dagibbs@qnx.com> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
news:aabr9p$iut$1@nntp.qnx.com

Nikolai Gorbunov <> n.gorbunov@swd.ru> > wrote:
Hi Gurus,

Almost a philosophical question. Is Trigger() really a non-blocking
call, or
just a ‘blocking and instantly unblocking’ one?

Um…define instantly unblocking? Yes, it makes a kernel call, no
your process doesn’t leave the READY state.

A typical scenario. There are two processes (A and B) at the same
priority,
FIFO scheduling, both READY. A higher-priority process (C) is runniung.
Then
the following happens:

  1. C goes blocked, A gets the CPU.
  2. In the middle of its timeslice, A calls Trigger().

Will A be still running after this? Assuming that Trigger() is ‘a kind
of
Send() which returns immediately’, calling it should cause rescheduling
anyway, so after A calls Trigger(), B will instantly get the CPU.

Am I right?

A should continue running after the Trigger().

P.S. “This question is based on a real story.” > :slight_smile:

My small test bears this out.

I set up a program that creates two proxies. Setup two fifo processes
that loop and occasionally Trigger their proxy – one is given proxya
the other proxyb.

When I run them, I see a few “proxy a”, then when I run the 2nd program,
I see one “proxy b”, the Trigger() before it drops its priority just
to make sure it got the right proxy, then I never see another Trigger from
proxy b – only proxy a.

So, this bears out that Trigger() doesn’t block, even instantly, the
calling process.

(Note: if running on a fast machine, may want to grow the length of the
delay loops, this was run on a 133Mhz Pentium.)

-David

recv.c:

#include <stdio.h
#include <stdlib.h
#include <unistd.h
#include <sys/kernel.h
#include <sys/proxy.h
#include <sys/sched.h

void main()
{
int proxya, proxyb, pid;


proxya = qnx_proxy_attach( 0, 0, 0, -1 );
proxyb = qnx_proxy_attach( 0, 0, 0, -1 );
printf(“proxya: %d, proxyb: %d\n”, proxya, proxyb );

while(1) {
pid = Receive(0, NULL, 0 );
if (pid == proxya) printf(“proxy from a\n”);
if (pid == proxyb) printf(“proxy from b\n”);
}
}

trigger.c:

#include <stdio.h
#include <stdlib.h
#include <unistd.h
#include <sys/kernel.h
#include <sys/proxy.h
#include <sys/sched.h

void main(int argc, char **argv)
{
int proxy;
struct sched_param param;
int i;

proxy = atoi( argv[1] );
Trigger(proxy );
param.sched_priority = 5;
sched_setscheduler( 0, SCHED_FIFO, &param );
//setprio( 0, 5 );

while(1) {
for(i=0; i<10000000; i++ );
Trigger(proxy);
}
printf(“i is %d\n”, i );
}

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Nikolai Gorbunov <n.gorbunov@swd.ru> wrote:

Thanks a lot David > :slight_smile:

As further evidence, after running since Friday, the “sin ti” output:

SID PID PROGRAM PRI START TIME UTIME STIME CUTIME CSTIME
15 13795 //61/home/dagibbs/c 10o Apr 26 11:24 104 46.207 0.000 0.000
10 17468 //61/home/dagibbs/a 5f Apr 26 11:24 247373 57.976 0.000 0.000
10 29154 //61/home/dagibbs/d 5f Apr 26 11:25 0.000 0.010 0.000 0.000

Where, a is the one calling Trigger(), c is getting the proxies, and
d is never getting scheduled since a’s calling Trigger() doesn’t drop
it from the head of the queue at priority 5.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.