Scheduling

Hello,

As I know thread in QNX can have priority and scheduling algorithms attached
to them. But what about processes? I know they can have priority. Does it
use the same scheduling algorithms as threads? Can I use the same
priority/shceduling models for processes?
Thanks.

Best regards,
Darius

Darius wrote:

Hello,

As I know thread in QNX can have priority and scheduling algorithms attached
to them. But what about processes? I know they can have priority. Does it
use the same scheduling algorithms as threads? Can I use the same
priority/shceduling models for processes?
Thanks.

I think you’ll find that a process is an environment that contains at
least one thread, it doesn’t execute any code itself, that thread is the
one that’s executing main(). So you are really asking: Can the initial
thread’s algorithm be adjusted?

I guess the answer will be yes but someone else will have to give the
definitive answer.

Hello,

I think you’ll find that a process is an environment that contains at
least one thread, it doesn’t execute any code itself, that thread is the
one that’s executing main(). So you are really asking: Can the initial
thread’s algorithm be adjusted?

Yes, of course. Threads are scheduled along all processes. I forgot.
So then I have one more question. What is function “nice” for? Why should I
need to change process priority if all threads have their priority and they
are scheduled in global? I can understand nice function if threads are
scheduled in process context, but in that case I just lost. Thanks in
advande for explaining.

Best regards,
Darius

“Darius” <alpha_byte@SAFe-mail.net> wrote in message
news:cgb0bv$543$1@inn.qnx.com

Hello,

I think you’ll find that a process is an environment that contains at
least one thread, it doesn’t execute any code itself, that thread is the
one that’s executing main(). So you are really asking: Can the initial
thread’s algorithm be adjusted?

Yes, of course. Threads are scheduled along all processes. I forgot.
So then I have one more question. What is function “nice” for? Why should
I
need to change process priority if all threads have their priority and
they
are scheduled in global? I can understand nice function if threads are
scheduled in process context, but in that case I just lost. Thanks in
advande for explaining.

Nice is typicaly use for processes that have only one thread.

Usually the first thread will start the other threads. Since priority and
scheduling are inherited, using nice end ups also affecting the non primary
thread.



Best regards,
Darius

Hello,

Nice is typicaly use for processes that have only one thread.

Usually the first thread will start the other threads. Since priority and
scheduling are inherited, using nice end ups also affecting the non
primary
thread.

I think I don’t understant something. If I have two processes with one
thread and these threads have opriority 9 and 10, so these threads will be
scheduled across all two processes, so why do I need priority for process if
thread already have its priority assigned?
Hope you’ll understand my question, becouse my english is not very good.

Best regards,
Darius

“Darius” <alpha_byte@safe-mail.net> wrote in message
news:cgbtj9$o84$1@inn.qnx.com

Hello,

Nice is typicaly use for processes that have only one thread.

Usually the first thread will start the other threads. Since priority
and
scheduling are inherited, using nice end ups also affecting the non
primary
thread.

I think I don’t understant something. If I have two processes with one
thread and these threads have opriority 9 and 10, so these threads will be
scheduled across all two processes, so why do I need priority for process
if
thread already have its priority assigned?

Because the process and the thread are the same entity, it the same thing.
In fact process don’t have priority, threads do.

Think as process as container for threads.


Hope you’ll understand my question, becouse my english is not very good.

Best regards,
Darius

In a program with one thread, IF that thread sets it’s own priority then
that will be the priority that it runs at. If it doesn’t set it’s own
priority, and many simple utilities don’t, then it will inherity the
priority of the process/thread that loaded it.

For instance, the shell usually runs at priority 10. So anything that
it runs, that doesn’t set it’s own priority, will also run at priority 10.
If the shell were running at priority 15, then everything that it starts
will also run at 15, unless they set their own priority.

I hope that helps.


Mario Charest <nowheretobefound@8thdimension.com> wrote:

MC > “Darius” <alpha_byte@safe-mail.net> wrote in message
MC > news:cgbtj9$o84$1@inn.qnx.com

Hello,

Nice is typicaly use for processes that have only one thread.

Usually the first thread will start the other threads. Since priority
and
scheduling are inherited, using nice end ups also affecting the non
primary
thread.

I think I don’t understant something. If I have two processes with one
thread and these threads have opriority 9 and 10, so these threads will be
scheduled across all two processes, so why do I need priority for process
if
thread already have its priority assigned?

MC > Because the process and the thread are the same entity, it the same thing.
MC > In fact process don’t have priority, threads do.

MC > Think as process as container for threads.

Hope you’ll understand my question, becouse my english is not very good.

Best regards,
Darius

Hello,

For instance, the shell usually runs at priority 10. So anything that
it runs, that doesn’t set it’s own priority, will also run at priority 10.
If the shell were running at priority 15, then everything that it starts
will also run at 15, unless they set their own priority.

I hope that helps.

Thanks. Now the picture is more clear. And if process have two threads -
main and other and other thread sets its own priority, but main does not.
What would happen if program will be started from schell? Main will have
priority 10 and other thread its own custom?

Best regards,
Darius

Darius <alpha_byte@safe-mail.net> wrote:

Hello,

As I know thread in QNX can have priority and scheduling algorithms attached
to them.

Yes, and threads are scheduled on a system-wide basis.

But what about processes? I know they can have priority.

Technically, a process doesn’t have a priority. (1)

BUT.

There is a lot of carry-over from the process as the smallest unit
of execution/scheduling Unix tradition in both POSIX and QNX. There
are a bunch of utilities (e.g. nice, renice) and library routines
(getprio(), setprio()) that modify priority and/or scheduling algorithm
for a process.

If a process has only one thread, that QNX process can be thought of,
and treated as, an old-style-process with priority & scheduling
algorithm.

If a process has more than one thread, then applying the PROCESS
oriented functions/utilities for modifying that process’s priority
or scheduling will result in undefined behaviour. (POSIX does not
expect or require this to do anything sensible.) It is a bad thing
to do. (In fact, under QNX, it will apply the prio/shed changes to
thread 1 in the process, if it exists. If it doesn’t it will probably
apply the change to the lowest numbered thread. I’ve tested the first
behaviour, not the second. But, the behaviour is not a documented
behaviour – you should not depend on it, or expect it to continue that
way.)


Does it
use the same scheduling algorithms as threads? Can I use the same
priority/shceduling models for processes?

Properly a process doesn’t have either of these. (Properly a process
is a holder of resources such as memory, timers, or open files and one
or more threads.)

In the single thread process case, you can think of thread priority/sched
algorithm and process priority/sched algorithm as being interchangeable.
But, you can ONLY do this in the case of the single-threaded process.

(1) There is, in fact, a priority value stored in the process entry – though
there is no scheduling algorithm stored. This “process” priority is used
to schedule a thread that receives a pulse where the pulse priority has a
value of -1 (PULSE_PRIO_INHERIT in <sys/neutrino.h> I think).

-David

Please follow-up to newsgroup, rather than personal email.
David Gibbs
QNX Training Services
dagibbs@qnx.com

Darius <alpha_byte@safe-mail.net> wrote:

Hello,

I think you’ll find that a process is an environment that contains at
least one thread, it doesn’t execute any code itself, that thread is the
one that’s executing main(). So you are really asking: Can the initial
thread’s algorithm be adjusted?

Yes, of course. Threads are scheduled along all processes. I forgot.
So then I have one more question. What is function “nice” for? Why should I
need to change process priority if all threads have their priority and they
are scheduled in global? I can understand nice function if threads are
scheduled in process context, but in that case I just lost. Thanks in
advande for explaining.

nice (renice, etc) come from Unix history. In the one thread in a process
case, they change the priority of that thread, and effectively of hte
process – though this is slightly sloppy thinking and use of terminology.
(Basically, they’re there for backwards compatability.)

-David

Please follow-up to newsgroup, rather than personal email.
David Gibbs
QNX Training Services
dagibbs@qnx.com

Darius <alpha_byte@safe-mail.net> wrote:

Hello,

For instance, the shell usually runs at priority 10. So anything that
it runs, that doesn’t set it’s own priority, will also run at priority 10.
If the shell were running at priority 15, then everything that it starts
will also run at 15, unless they set their own priority.

I hope that helps.

Thanks. Now the picture is more clear. And if process have two threads -
main and other and other thread sets its own priority, but main does not.
What would happen if program will be started from schell? Main will have
priority 10 and other thread its own custom?

The first thread (main thread) will have the priority of the shell
(or other program that started it), unless that priority has been
changed by a library call, or by receiving a message, or by anything
else that could change its priority.

If the main thread programmatically creates a thread, that new thread
will inherit the priority of the main thread when the main thread called
the thread creation function (pthread_create()) unless the main thread
explicitly creates the new thread with a different priority by passing
an attribute structure to the pthread_create() call to do this.

The new thread could, after creation, independently change its priority,
or have it changed by external events (main thread, receving a message,
receving a pulse, mutex contention, etc.).

-David

Please follow-up to newsgroup, rather than personal email.
David Gibbs
QNX Training Services
dagibbs@qnx.com

Hello,

The new thread could, after creation, independently change its priority,
or have it changed by external events (main thread, receving a message,
receving a pulse, mutex contention, etc.).

Now its clear. If I have two threads in a process with their own
programmicaly created priorities, so what affect nice command to the
process. Will it change manual created thread’s priorities?

Best regards,
Darius

Now its clear. If I have two threads in a process with their own
programmicaly created priorities, so what affect nice command to the
process. Will it change manual created thread’s priorities?

Sorry, do not answer this, I wrote it not having read David’s next reply,
where this situation is explained. Thanks.

Best regards,
Darius