LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Embedded & Single-board computer (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/)
-   -   no difference seen even after setting application thread priority in linux environmen (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/no-difference-seen-even-after-setting-application-thread-priority-in-linux-environmen-845294/)

rahimlnx 11-19-2010 07:09 AM

no difference seen even after setting application thread priority in linux environmen
 
Hi,

Can any one help in resolving the below problem.

Actually i am trying to set different priorities for two application threads.With root privilages i could set the thread priority using pthread_setschedparam()(Returning the expected as successfull) in linux environment.But i don't see any difference in the output(thread's) i.e.thread with high priority and thread with low priority are exiting at the same time. Actually thread with high priority should get called more number of times and it should exit first.

Below is the process i followed to set the thread priority.


pthread_attr_t attr;
pthread_t threadId;
int threadStatus;
struct sched_param param;
int policy;

threadStatus = pthread_attr_init(&attr);
threadStatus = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
threadStatus = pthread_attr_setstacksize(&attr,0x10000);
param.sched_priority = threadPriority;

ret = pthread_attr_setinheritsched (&attr, PTHREAD_EXPLICIT_SCHED);

/* cleanup any zombie threads that are holding resources */
waitpid(0, &status, WNOHANG | __WCLONE);

threadStatus = pthread_create(&threadId, &attr, pThreadFuncAddress, pParameter);

ret= pthread_setschedparam(threadId,SCHED_RR,&param);


Please comment..

ozanbaba 11-20-2010 04:06 PM

you can't rise the thread prority. It's for stoping DOS attacts. I lack detailed information right now. Try greping pthread documetion and linux/Documetation.

rahimlnx 11-21-2010 06:19 AM

No difference seen even after setting application thread priority in linux environment
 
Quote:

Originally Posted by ozanbaba (Post 4165640)
you can't rise the thread prority. It's for stoping DOS attacts. I lack detailed information right now. Try greping pthread documetion and linux/Documetation.

From the linux pthread documentation i came to know that we can raise the thread priority(between 0-99) with root privilages, same i am doing but expected result was not seen.I am working on Linux kernel 2.6.9.

I have referred below link

http://www.kernel.org/doc/man-pages/...edparam.3.html


Please comment on this.

Syed.

ozanbaba 11-21-2010 08:06 AM

I think I have a idea but I need to know which scheduling you use. Right now, Defualt linux scheduling mechanism follows dynamic scheduling. For that, you may not really see scheduling differences between differently priority threads.

stress_junkie 11-21-2010 08:15 AM

If the machine isn't busy then priority won't affect execution time. Scheduling makes a difference when resources are overtaxed. On a multiple core/CPU machine the resources (CPU mainly in this case) will be available for both threads when they request CPU so they will both execute at full speed.

Now if you had two cores and three very busy threads then there would be contention for the CPU resources. Busy threads would be doing something like
Code:

dd if=/dev/urandom of=/dev/null <whatever>
Most practical threads have some i/o wait. Other threads can execute during the time when a high priority thread is waiting for i/o.

These kinds of factors affect the amount of CPU requested by a high priority thread.


All times are GMT -5. The time now is 12:10 AM.