Changing Priority of Resource Manager

Hi,

I have developed a Resource Manager. By default it runs at priority 9. I want to increase the priority from 9 to 11.

Is there any way to provide this priority information in the resmgr_attr_t structure, while attaching this. If not, what could be alternate way to increase the priority!!

Thanks in advance,

Best regards,
Dheeraj

Oh oh, this looks like a case of RTFM.

By default, processes/threads priority will float to that of the event that it received. If it receives a pulse of priority 20, the thread that received the pulse will be given priority 20. So in your case if you say that the resmgr is of priority 9, it`s because it received a message/pulse which is of priority 9…

You can change that by changing the priority of the pulse or raising the priority of the process that send the message.

Mario, I think that’s the important half of the story. Here’s the other half. Just like any other process/thread, when your Resource Manager starts, it is running at some priority. There are two ways to change this. From the shell you can use the “nice” command. Once a process is started, it can (to some degree) change its own priority. I think it is setprio() or set_prio() that does this. There is another related routine that will change both its priority and scheduling algorithm, but the name eludes me right now.

Most of the time changing the priority of a resmgr is totaly useless. It’s the priority of the pulses that makes the difference or of the client that sends message to it. For example build a dummy resmgr, from the shell do echo dummy >/dev/dummy. Then slay -P50 resmgr. This will raise the priority to 50, but the do a echo dummy >/dev/dummy again and watch the priority go down to 10 shell (10).

These are present for compatibility with QNX4. sched_setparam is the POSIX way of setting priority and sched_setscheduler().

Yup. Since the resmgr is always blocked (unless it gets a pulse or message) its fixed priority is valuless (since it is never ready at that priority).

The only time were it could make sense is if a work thread is do to some “off-line” processing. Even then, since the off-line processing is usually done following a request from a client, then it’s logical for the processing to be performed at the priority of the requestee (is that a word).

In the case of a thread that handles some hardware, then what ever event that wakes up the thread must be setup at high priority, not the thread itself.

However a thread that waits on a interrupt event, then I think in that case the thread should/could set itself up at high priority.

Many thanks for the information.

But unfortunately, for me nothing is working… (:frowning:
I used “nice” in the script to increase the priority but failed to get the result. The same with the “setpriority” function call inside the resource manager module.

Let me explain the scenario,
I have a SINGLE Threaded resource manager, which spawns multiple threads to receive the data from H/w. This mechanism is semaphore based, means the ISR releases the semaphores and the receiving thread of the Resouce Manager blocks on this semaphore. On successful reception of the packet, the notification is sent to the application to issue the read command to get the packet.
The read and write functionality is the part of the main Resource manager process.

Now the problem is that I can increase the priority of these threads, but unable to increase the peiority of this Resource Manager process. And this is what I want to increase.

I used the following function to increase the priority of the resource manager task,

/* set its priority to 11 */
if(-1 == setpriority(PRIO_PGRP,0,11))
{
    REPORT_ERROR("Could not set the priority to 11, [Error - %s]\n",strerror(errno));
}

But after loading the image, pidin shows the same old priority as 9.

Any idea / pointer how to do this!!

Many thanks in advance,

setpriority? Never heard of this function.

At any rate the answer to your question is in the posts above. I’m not sure how else I could explain it ;)

But if you are really intend on running your process at fix priority (this is usually bad and probably mean you misunderstood the concept of priority inheritance ) you could setup the resmgr channel to _NTO_CHF_FIXED_PRIORITY.

Dheeraj,

Are you sure you understand what pidin is actually showing you?

Based on your description of your manager you have the following:

main thread - blocked waiting for a semaphore from the h/w threads
h/w threads - blocked waiting for h/w data.

So when you run pidin I expect that regardless of the priority that is reported all your threads are showing a state of RECEIVE or CONDVAR or REPLY or some other blocked state. In other words, none of them are currently running. That’s normal and in that case it matters not at all what priority is shown because they are blocked and not getting CPU cycles.

The chances of you running pidin in the few microseconds that your driver is actually processing data is remote (unless there is a LOT of data being spewed in which case your CPU is likely VERY busy).

If you don’t believe your running at priority 11 then just add a line like:

printf (“My Priority is %d\n”, getprio());

when the driver code is actually doing work and see what it prints out. My guess is it will print out 11 assuming you used setprio() and not setpriority() ;)

Tim

Also, If your resource manager is set to a higher priority than you run pidin at, you can never see your resource manager unblockedd and actually running with pidin, unless you have an SMP machine. Why is this? Well if the resource manager is ready, it gets all cycles until it is done.

I think I got the answer… :smiley:
Just one doubt, if the application will issue read / write commands to the Resource manager, at which priority these function will be served!! At the priority of the application or at the priority of the resource manager!!
What I understood that the read / write calls of the resource manager will be called by the kernal after mapping the FD passed into these POSIX calles.

many thanks for help…

At the priority of the application.

The read write calls of the resource manager are NOT called by the kernel though. You application send a message (containned within open(), read(), write(), close(), etc) to the resource manager directly. The kernel is only involved in the message passing itself, it doesn’t know nor care that it’s a resource manager or not. The kernel cannot called resource manager fonction, this is not Linux.

Many thanks. I got it. :smiley:

Hi,
For any process, is it possible to specify the priority at which the main thread starts when the process is invoked from the build file startup script?
Thanks,
Jeansha

Jeansha,

Yes, you can use the ‘nice’ command or the ‘on’ command.

But why not just use the setpriority command at the start of your process to get to the desired priority. That’s how most processes set the priority of their main thread.

Tim

Note that in most cases process priority is irrelavant, as the process will float to priority of the message/event it receives.

Tim,
In case of setprio, wouldn’t there be a time gap for which the main thread is executing at default priority?The thread could be preempted in that gap.
Thanks,
Jeansha

Jeansha,

That is quite true, but think about the implications.   The process is just starting up, and hasn't called setprio yet.   If the system isn't cpu bound by a higher priority threads, then setprio is called an all is well.   If the system is indefinitely cpu bound by a higher priority thread, then I think it is safe to say that there is something seriously wrong with the system.

Mitchell