Nnamdi Kohn <nnamdi.kohn@tu-bs.de> wrote:
Hello David, thanks for the help so far.
- the first time I start my programs everything runs fine and I can
exchange messages as usual between the threads (the priorities of my
servers
change according to the client priorities - inheritance ). But the
second
time I start the programs: QNX hangs. Is it possible that the setprio()
function is not supported for newer QNX versions anymore? How do I
correctly
handle the task of setting my own thread priority?
setprio() is supported.
When you say “QNX hangs” what do you mean? Are you running in text mode
or Photon? Or, are you running on a target with some sort of embedded
image? If in text mode, do you see a kernel dump? If you have a keyboard
attached, and you hit the caps lock or num lock key, does the light on the
keyboard toggle?
QNX hangs means that I can not even move the mouse anymore. I’m running
Photon and the processes I start in a terminal window. Pressing the NUM LOCK
key in the “hang” toggles the keyboard led, but CAPS LOCK changes nothing.
So I reboot the system.
That NUM_LOCK toggles the keyboard led suggests that the system is still
operating. Also your later description of priorities bouncing around
also suggests that you are not hanging the system – you are just
pre-empting the user interface, including the updates for moving the
mouse pointer around. If you take a look at the output from ‘pidin’,
you will notice that most of the Photon components run in the priority
range of 10-15, if anything runs higher than that, nothing will get updated
on the screen.
But I also recognized an other oddity. Let me describe it:
At first I start a server “process1” (I set the priority to 12r and then
create a second thread at 8r - this works fine). Process1 does a
MsgReceive().
Which thread in Process1? Once you have more than one thread in a
process you can no longer usefully say that the process does something,
you must talk about what each thread does.
Then I start a second “process2” (just one threaded) and set
its priority to 10r (which it would be anyway if I did nothing). Now
process2 does a MsgSend() to process1. This causes thread1 of Process1 to
jump to priority 10r and handle the request. After leaving process2 (with
CTRL-C) process1 suddenly jumps to priority 20r.
Ctrl-C causes a signal to be delivered to process2. This carries no
priority information. The death, though, of process2 may pass some
information to process1 – how did you create the channel for process1
and if done with ChannelCreate() what channel flags did you pass?
When I start process2 again with the same priority as before (10r), the
whole computer becomes incredibly slow (might be connected to the mutexes
and condvars I use within process2) but communication with process1 works
fine as before.
If process2 is single-threaded, why does it have mutexes and condvars?
Again, the “becomes incredibly slow” sure sounds like you have something
chewing up a lot of the CPU time – something is probably spinning at
priority 10 (since the UI is slow, but still acting).
Is the CPU monitor visible on your shelf? Is it pegged at this point?
Now I leave process2 (CTRL-C) and start it again at priority level of e.g.
14r. Now it does not even start but QNX hangs as described above. I don’t
even know if it has to do with priorities or rather with the mutexes or
condvars that mysteriously slow down the whole system after a second start.
How could I go on checking for the source of the error?
Well, do the testing in console, rather than GUI mode, and have high-priority
shell open to do pidin(s) to check what is happening, and what state various
threads are in – anything READY or RUNNING all the time is highly
likely to be the cause of this, or should I say, the highest priority
usually READY thread is the likely cause of this.
Use qconn and the system information perspective in the IDE accross a
network, with qconn running at a high priority (say 60) to watch the
system and do similar data collection to the above.
Install the instrumented kernel, use tracelogger to collect system events,
and use the System Profiling perspective of the IDE to analyse what is
going on.
Run your code under the profiler in the IDE and see where you are chewing
up huge amounts of CPU.
Examine your code, and look for places where you loop, or might chew up
large amounts of CPU.
-David
QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.