linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* Can't set the schedual parameter of threads in linux
@ 2004-03-11  1:06 yang
  2004-03-11 11:56 ` Jaap-Jan Boor
  0 siblings, 1 reply; 7+ messages in thread
From: yang @ 2004-03-11  1:06 UTC (permalink / raw)
  To: linuxppc-embedded


Hello,
    I encounter a problem when I transplant application.
    There is no effect to the pthread when I call pthread_setschedparam() function in test program,  and it's policy and priority are stilll zero, not what I expected, after call pthread_getschedparam(). The codes  is as the follow:

#include <sched.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <linux/ipc.h>
#include <linux/msg.h>
#include <errno.h>
#include <stddef.h>
#include <string.h>

void * func()
{
        while (1);
    return;
}

int main()
{
    pthread_attr_t tattr;
    pthread_t tid;
    int policy;
    int ret;
    int newprio = 20;
    struct sched_param param;

    ret = pthread_attr_init (&tattr);
    if (ret != 0)
    {
        printf("Error in init: %s\n", strerror(errno));
    }

    ret = pthread_attr_getschedparam (&tattr, &param);
    if (ret != 0)
    {
        printf("Error in get after init: %s\n", strerror(errno));
    }
    ret = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
   if (ret != 0)
    {
        printf("Error in setdea: %s\n", strerror(errno));
    }
    ret = pthread_attr_setschedpolicy(&tattr, SCHED_RR);
    if (ret != 0)
    {
        printf("Error in setpolicy: %s\n", strerror(errno));
    }

    param.sched_priority = newprio;
    ret = pthread_attr_setschedparam (&tattr, &param);
    if (ret != 0)
    {
        printf("Error in set: %s\n", strerror(errno));
    }

    ret = pthread_create (&tid, &tattr, (int*) func, NULL);
    if (ret != 0)
    {
        printf("Error in create: %s\n", strerror(errno));
    }

    param.sched_priority = -1;
    ret = pthread_getschedparam (tid, &policy, &param);
    if (ret != 0)
    {
        printf("Error in get after create: %d %s\n", ret, strerror(errno));
    }

    printf("policy: %d\tpriority: %d\n", policy, param.sched_priority);

    return 0;

}

    The output is :
    policy: 0    priority: 0

    Would you like to tell me how to set the policy and priority to pthreads in Red Hat.? Thank you very much!
    Best regards,
                                     yang


** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 7+ messages in thread
* RE: Can't set the schedual parameter of threads in linux
@ 2004-03-11 15:22 Jean-Denis Boyer
  2004-03-11 15:37 ` Jaap-Jan Boor
  0 siblings, 1 reply; 7+ messages in thread
From: Jean-Denis Boyer @ 2004-03-11 15:22 UTC (permalink / raw)
  To: yang; +Cc: linuxppc-embedded


Your program logic is absolutely correct.
I ran it in my embedded PPC environment (as root) and got the following results:

policy: 2       priority: 20

The problem is elsewhere...

--------------------------------------------
 Jean-Denis Boyer, Eng.
 M5T Centre d'Excellence en Télécoms Inc.
 4283 Garlock Street
 Sherbrooke (Québec)
 J1L 2C8  CANADA
 (819)829-3972 x241
--------------------------------------------
> -----Original Message-----
> From: owner-linuxppc-embedded@lists.linuxppc.org
> [mailto:owner-linuxppc-embedded@lists.linuxppc.org]On Behalf Of yang
> Sent: 10 mars, 2004 20:07
> To: linuxppc-embedded@lists.linuxppc.org
> Subject: Can't set the schedual parameter of threads in linux
>
>
>
> Hello,
>     I encounter a problem when I transplant application.
>     There is no effect to the pthread when I call
> pthread_setschedparam() function in test program,  and it's
> policy and priority are stilll zero, not what I expected,
> after call pthread_getschedparam(). The codes  is as the follow:
>
> #include <sched.h>
> #include <pthread.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <sys/types.h>
> #include <linux/ipc.h>
> #include <linux/msg.h>
> #include <errno.h>
> #include <stddef.h>
> #include <string.h>
>
> void * func()
> {
>         while (1);
>     return;
> }
>
> int main()
> {
>     pthread_attr_t tattr;
>     pthread_t tid;
>     int policy;
>     int ret;
>     int newprio = 20;
>     struct sched_param param;
>
>     ret = pthread_attr_init (&tattr);
>     if (ret != 0)
>     {
>         printf("Error in init: %s\n", strerror(errno));
>     }
>
>     ret = pthread_attr_getschedparam (&tattr, &param);
>     if (ret != 0)
>     {
>         printf("Error in get after init: %s\n", strerror(errno));
>     }
>     ret = pthread_attr_setdetachstate(&tattr,
> PTHREAD_CREATE_DETACHED);
>    if (ret != 0)
>     {
>         printf("Error in setdea: %s\n", strerror(errno));
>     }
>     ret = pthread_attr_setschedpolicy(&tattr, SCHED_RR);
>     if (ret != 0)
>     {
>         printf("Error in setpolicy: %s\n", strerror(errno));
>     }
>
>     param.sched_priority = newprio;
>     ret = pthread_attr_setschedparam (&tattr, &param);
>     if (ret != 0)
>     {
>         printf("Error in set: %s\n", strerror(errno));
>     }
>
>     ret = pthread_create (&tid, &tattr, (int*) func, NULL);
>     if (ret != 0)
>     {
>         printf("Error in create: %s\n", strerror(errno));
>     }
>
>     param.sched_priority = -1;
>     ret = pthread_getschedparam (tid, &policy, &param);
>     if (ret != 0)
>     {
>         printf("Error in get after create: %d %s\n", ret,
> strerror(errno));
>     }
>
>     printf("policy: %d\tpriority: %d\n", policy,
> param.sched_priority);
>
>     return 0;
>
> }
>
>     The output is :
>     policy: 0    priority: 0
>
>     Would you like to tell me how to set the policy and
> priority to pthreads in Red Hat.? Thank you very much!
>     Best regards,
>                                      yang
>
>


** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 7+ messages in thread
* RE: Can't set the schedual parameter of threads in linux
@ 2004-03-11 19:39 erik.teose
  0 siblings, 0 replies; 7+ messages in thread
From: erik.teose @ 2004-03-11 19:39 UTC (permalink / raw)
  To: jjboor, jdboyer; +Cc: wchyang_hn, linuxppc-embedded


>> Your program logic is absolutely correct.
>> I ran it in my embedded PPC environment (as root) and got
>the following results:
>>
>> policy: 2       priority: 20
>>
>> The problem is elsewhere...
>
>RedHat 9 uses nptl, that is a difference.

And a big difference it is. Here's some bits of an email
conversation I recently had on this issue:

  >>RH9 introduces 'nptl', (locally known as 'non-portable threads
  >>library'), which is strictly SCHED_OTHER.  Any
  >>RTOS code which relies on prioritized scheduling to work reliably
  >>(including some of the v2pthreads emulation layer) will be broken with
  >>'nptl'....
  >>
  >Isn't 'nptl' also 'standard' in the new 2.6 kernel? Is it strictly
  >SCHED_OTHER in 2.6 also? Isn't that a severe blow to 'real-time'
  >embedded Linux? I don't understand...
  >
  Both statements are regrettably true. The developer(s) of 'nptl'
  regard regard real-time scheduling as 'nonsense' (that's what Ulrich
  Drepper called it!) and have no intentions of supporting it.
  Furthermore, their development priority is on scheduling efficiency
  rather than priority, and they believe it's okay to 'water down' the
  expectations of the applications programmer in order to boost
  performance.  Consequently I intend to personally take a look at their
  code to see what can be done to make it more desirable for the real-time
  applications community.  Drepper and crew don't see the shortcomings in
  their approach, so we in the real-time community will have to make any
  corrections ourselves.

So there we have it. The new 'nptl' threading library does not support
real-time scheduling. Comments?

Erik Teose
erik.teose@tek.com

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-03-11 19:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-11  1:06 Can't set the schedual parameter of threads in linux yang
2004-03-11 11:56 ` Jaap-Jan Boor
     [not found]   ` <001601c4076a$465d6470$5e1312ac@yang>
2004-03-11 15:04     ` Jaap-Jan Boor
2004-03-11 15:10       ` Mark Hatle
  -- strict thread matches above, loose matches on Subject: below --
2004-03-11 15:22 Jean-Denis Boyer
2004-03-11 15:37 ` Jaap-Jan Boor
2004-03-11 19:39 erik.teose

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).