Skip to contentSkip to conversation

Problems with pthread on ARM/PXA270

DISCUSSION Juergen Schindele 7 participants 16 messages Sep 16, 2009 – Sep 24, 2009

lore
Share & tools
lore
#0 lore raw

Hello all,
we tried to implement a thread based software on our PXA270 based platform but we had trouble with pthreads. So i modyfied a tiny progam to test. This little progam creates 10 threads and each thread does print something (an index an a pointer to itself).

On my PC with Suse 11.0 Linux (kernel 2.6.27) this works fine as supposed to. Each thread has his turn and print his own values.

But on our pxa270 platform the thread switch does not (or really rarely) happen and only one thread is printing always the same values. So i suppose thread switching is not working!

Any hints or experiences are welcome !!!

we use codesourcery compiler
arm-none-linux-gnueabi-gcc (CodeSourcery Sourcery G++ Lite 2007q1-10) 4.2.0 20070413 (prerelease) Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

and here the C-code compiled with "arm-none-linux-gnueabi-gcc -o test test.c -lpthread"

#include <errno.h>
#include <error.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <time.h>

#define NUM_THREADS 10
#define NUM_ITERS 50
#define TIMEOUT_NS 100000000L

static void *thread (void *);
static int argument[NUM_THREADS];
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_attr_t defaultattr;

static void * print_thread (void *arg)

{
    int i;
    int number = *((int*)arg);

    for (;;) {
        pthread_t self = pthread_self ();
        printf ("Thread %d is [%d]\n", number, self);
    }
}

int main (void)

{
    pthread_t th;
    int i, retvalue;

    struct sched_param param;
    pthread_attr_init(&defaultattr);

    pthread_attr_setschedpolicy(&defaultattr, SCHED_RR);

    param.sched_priority = 10;
    if ((retvalue = pthread_attr_setschedparam(&defaultattr, &param))!=0) {
        printf ("ERROR\n");
        exit (0);
    }

    for (i = 0; i < NUM_THREADS; i++)
    {
        argument[i] = i;
        if (pthread_create (&th, &defaultattr, print_thread, &argument[i]) != 0)
            error (EXIT_FAILURE, 0, "cannot create thread");
        printf ("Thread [%d]\n", i);
    }

    while (1) {
        ;
    }

    /* notreached */
    return 0;
}

--------------------------------------------------------------
J?rgen Schindele
Software-Entwicklung

NENTEC Netzwerktechnologie GmbH
Greschbachstr. 12
76229 Karlsruhe
Deutschland

Telefon: +49 721 94249-51
Telefax: +49 721 94249-10
E-Mail:  [email protected]
WEB:     www.nentec.de

Gesch?ftsf?hrung: Klaus Becker, Roland Knapp
Sitz der Gesellschaft: Karlsruhe
Handelsregister: Amtsgericht Mannheim HRB 107658
--------------------------------------------------------------

#1 lore raw

Don't remember we had such problems before. What kind of system and libraries are you using?

Quoted 104 lines · Juergen Schindele

Hello all,
we tried to implement a thread based software on our PXA270 based platform but we had trouble with pthreads. So i modyfied a tiny progam to test. This little progam creates 10 threads and each thread does print something (an index an a pointer to itself).

On my PC with Suse 11.0 Linux (kernel 2.6.27) this works fine as supposed to. Each thread has his turn and print his own values.

But on our pxa270 platform the thread switch does not (or really rarely) happen and only one thread is printing always the same values. So i suppose thread switching is not working!

Any hints or experiences are welcome !!!

we use codesourcery compiler
arm-none-linux-gnueabi-gcc (CodeSourcery Sourcery G++ Lite 2007q1-10) 4.2.0 20070413 (prerelease) Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. ?There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

and here the C-code compiled with ?"arm-none-linux-gnueabi-gcc -o test test.c -lpthread"

#include <errno.h>
#include <error.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <time.h>

#define NUM_THREADS 10
#define NUM_ITERS ? 50
#define TIMEOUT_NS ?100000000L

static void *thread (void *);
static int argument[NUM_THREADS];
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_attr_t defaultattr;

static void * print_thread (void *arg)
{
? ?int i;
? ?int number = *((int*)arg);

? ?for (;;) {
? ? ? ?pthread_t self = pthread_self ();
? ? ? ?printf ("Thread %d is [%d]\n", number, self); ? ?}
}

int main (void)
{
? ?pthread_t th;
? ?int i, retvalue;

? ?struct sched_param param;
? ?pthread_attr_init(&defaultattr);

? ?pthread_attr_setschedpolicy(&defaultattr, SCHED_RR);

? ?param.sched_priority = 10;
? ?if ((retvalue = pthread_attr_setschedparam(&defaultattr, &param))!=0) { ? ? ? ?printf ("ERROR\n");
? ? ? ?exit (0);
? ?}

? ?for (i = 0; i < NUM_THREADS; i++)
? ?{
? ? ? ?argument[i] = i;
? ? ? ?if (pthread_create (&th, &defaultattr, print_thread, &argument[i]) != 0) ? ? ? ? ? ?error (EXIT_FAILURE, 0, "cannot create thread");
? ? ? ?printf ("Thread [%d]\n", i);
? ?}

? ?while (1) {
? ? ? ?;
? ?}

? ?/* notreached */
? ?return 0;
}

--------------------------------------------------------------
J?rgen Schindele
Software-Entwicklung

NENTEC Netzwerktechnologie GmbH
Greschbachstr. 12
76229 Karlsruhe
Deutschland
Telefon: +49 721 94249-51
Telefax: +49 721 94249-10
E-Mail: ?schindele at nentec.de
WEB: ? ? www.nentec.de

Gesch?ftsf?hrung: Klaus Becker, Roland Knapp
Sitz der Gesellschaft: Karlsruhe
Handelsregister: Amtsgericht Mannheim HRB 107658
--------------------------------------------------------------

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#8 lore raw
In reply to Juergen Schindele
Quoted 5 lines · Juergen Schindele

Hello all,
we tried to implement a thread based software on our PXA270 based platform but we had trouble with pthreads. So i modyfied a tiny progam to test. This little progam creates 10 threads and each thread does print something (an index an a pointer to itself).

Quoted 8 lines

On my PC with Suse 11.0 Linux (kernel 2.6.27) this works fine as supposed to. Each thread has his turn and print his own values.

But on our pxa270 platform the thread switch does not (or really rarely) happen and only one thread is printing always the same values. So i suppose thread switching is not working!

Any hints or experiences are welcome !!!

It's just a wild guess, but check your sched_clock implementation. I fixed a similar problem in QEMU last week; the kernel used to function OK with sched_clock always returning zero, but some time between 2.6.25 and 2.6.28 became dependent on it.

Signature · 2 lines
Daniel Jacobowitz
CodeSourcery
#2 lore raw
In reply to Eric Miao

Am Mittwoch, 16. September 2009 schrieb Eric Miao:

Quoted 2 lines

Don't remember we had such problems before. What kind of system and libraries are you using?

thanks for your reply.
System is custom PXA270 platform.
with codesourcery compiler (see below)
and glibc 2.5 with pthread.
I dont know what more information to give ?

Quoted 109 lines · Juergen Schindele
Quoted 104 lines

Hello all,
we tried to implement a thread based software on our PXA270 based platform but we had trouble with pthreads. So i modyfied a tiny progam to test. This little progam creates 10 threads and each thread does print something (an index an a pointer to itself).

On my PC with Suse 11.0 Linux (kernel 2.6.27) this works fine as supposed to. Each thread has his turn and print his own values.

But on our pxa270 platform the thread switch does not (or really rarely) happen and only one thread is printing always the same values. So i suppose thread switching is not working!

Any hints or experiences are welcome !!!

we use codesourcery compiler
arm-none-linux-gnueabi-gcc (CodeSourcery Sourcery G++ Lite 2007q1-10) 4.2.0 20070413 (prerelease) Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. ?There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

and here the C-code compiled with ?"arm-none-linux-gnueabi-gcc -o test test.c -lpthread"

#include <errno.h>
#include <error.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <time.h>

#define NUM_THREADS 10
#define NUM_ITERS ? 50
#define TIMEOUT_NS ?100000000L

static void *thread (void *);
static int argument[NUM_THREADS];
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_attr_t defaultattr;

static void * print_thread (void *arg)
{
? ?int i;
? ?int number = *((int*)arg);

? ?for (;;) {
? ? ? ?pthread_t self = pthread_self ();
? ? ? ?printf ("Thread %d is [%d]\n", number, self); ? ?}
}

int main (void)
{
? ?pthread_t th;
? ?int i, retvalue;

? ?struct sched_param param;
? ?pthread_attr_init(&defaultattr);

? ?pthread_attr_setschedpolicy(&defaultattr, SCHED_RR);

? ?param.sched_priority = 10;
? ?if ((retvalue = pthread_attr_setschedparam(&defaultattr, &param))!=0) { ? ? ? ?printf ("ERROR\n");
? ? ? ?exit (0);
? ?}

? ?for (i = 0; i < NUM_THREADS; i++)
? ?{
? ? ? ?argument[i] = i;
? ? ? ?if (pthread_create (&th, &defaultattr, print_thread, &argument[i]) != 0) ? ? ? ? ? ?error (EXIT_FAILURE, 0, "cannot create thread");
? ? ? ?printf ("Thread [%d]\n", i);
? ?}

? ?while (1) {
? ? ? ?;
? ?}

? ?/* notreached */
? ?return 0;
}

--------------------------------------------------------------
J?rgen Schindele
Software-Entwicklung

NENTEC Netzwerktechnologie GmbH
Greschbachstr. 12
76229 Karlsruhe
Deutschland
Telefon: +49 721 94249-51
Telefax: +49 721 94249-10
E-Mail: ?schindele at nentec.de
WEB: ? ? www.nentec.de

Gesch?ftsf?hrung: Klaus Becker, Roland Knapp
Sitz der Gesellschaft: Karlsruhe
Handelsregister: Amtsgericht Mannheim HRB 107658
--------------------------------------------------------------

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Signature · 27 lines
--------------------------------------------------------------
J?rgen Schindele  
Software-Entwicklung

NENTEC Netzwerktechnologie GmbH
Greschbachstr. 12
76229 Karlsruhe
Deutschland
Telefon: +49 721 94249-51
Telefax: +49 721 94249-10
E-Mail:  schindele at nentec.de
WEB:     www.nentec.de
 
Gesch?ftsf?hrung: Klaus Becker, Roland Knapp
Sitz der Gesellschaft: Karlsruhe
Handelsregister: Amtsgericht Mannheim HRB 107658
 
Diese E-Mail enth?lt vertrauliche oder rechtlich gesch?tzte Informationen.
Wenn Sie nicht der vorgesehene Empf?nger sind, informieren Sie bitte sofort
den Absender und l?schen Sie diese E-Mail. Das unbefugte Kopieren dieser E-Mail
oder die unbefugte Weitergabe der enthaltenen Informationen ist nicht gestattet.
 
The information contained in this message is confidential or protected by law.
If you are not the intended recipient, please contact the sender and delete this
message. Any unauthorised copying of this message or unauthorised distribution of
the information contained herein is prohibited.
--------------------------------------------------------------
#3 lore raw
Quoted 8 lines · Juergen Schindele

Am Mittwoch, 16. September 2009 schrieb Eric Miao:

Quoted 2 lines

Don't remember we had such problems before. What kind of system and libraries are you using?

thanks for your reply.
System is custom PXA270 platform. with codesourcery compiler (see below) and glibc 2.5 with pthread.
I dont know what more information to give ?

Like which kernel version, where do you get the glibc-2.5 and pthread binary, or you compiled it from scratch, and with which compiler of which version?

#11 lore raw
In reply to Juergen Schindele
Quoted 3 lines · Juergen Schindele

But on our pxa270 platform the thread switch does not (or really rarely) happen and only one thread is printing always the same values. So i suppose thread switching is not working!

What time quantum does sched_rr_get_interval() return? SCHED_RR is only expected to switch that often.

-- Jamie

#12 lore raw
In reply to Juergen Schindele

Hi,

Quoted 4 lines · Juergen Schindele

we tried to implement a thread based software on our PXA270 based platform but we had trouble with pthreads. So i modyfied a tiny progam to test. This little progam creates 10 threads and each thread does print something (an index an a pointer to itself).

Quoted 8 lines

On my PC with Suse 11.0 Linux (kernel 2.6.27) this works fine as supposed to. Each thread has his turn and print his own values.

But on our pxa270 platform the thread switch does not (or really rarely) happen and only one thread is printing always the same values. So i suppose thread switching is not working!

Any hints or experiences are welcome !!!

I'm not a very thread aware programmer so please don't shoot me, but I was wondering, why would a thread give up control after printing its values? Your program has them doing a tight loop with no sleep, or yield.

I added a usleep(1) just after the printf("Thread...."), and the results on my Linux Ubuntu-Desktop 2.6.24-24-generic #1 SMP Tue Aug 18 17:04:53 UTC 2009 i686 GNU/Linux are much better, but still not one message per thread. I changed the usleep to a sched_yield() and got still better results, but still not what I'd expect from RR.

So what does it look like on your Suse box? Do you get one message per thread in turn? I.e.
Thread 0 is [...]
Thread 1 is [...]
Thread 2 is [...]
Thread 3 is [...]
etc.?

Or do you get, say, 100 messages from thread 0, then 100 from thread 1, etc.?

Are you running with superuser privileges? My manpage tells me that SCHED_RR is only available if run with superuser privileges.

Out of curiosity, I got rid of the printf in the thread, and added a global array of ints, as in int counter[NUM_THREADS]; Then made the threads increment their counter each loop, and got the main while loop to print the counter values.

Without a sched_yield() or usleep() in the thread loop, the values increase at a phenomenal rate. With a sched_yield() the values increase at about 1/100th the speed.

I once had some interesting problems running a program with just two threads, one doing I/O to an ISA bus, the other handling a socket interface, on a dual core machine. To get more predictable performance, I ended up building a single threaded program and using select for the whole lot, thereby implementing my own scheduling policy, effectively.

In any case, I think there's more going on with threads than meets the eye. IMHO, they're evil, and should be left for Bill's programmers, who are sadly bound to using them due to the lack of better ways on that platform ;-)

Regards,
James.

#4 lore raw
In reply to Eric Miao

Am Mittwoch, 16. September 2009 schrieb Eric Miao:

Quoted 11 lines · Juergen Schindele
Quoted 8 lines

Am Mittwoch, 16. September 2009 schrieb Eric Miao:

Quoted 2 lines

Don't remember we had such problems before. What kind of system and libraries are you using?

thanks for your reply.
System is custom PXA270 platform. with codesourcery compiler (see below) and glibc 2.5 with pthread.
I dont know what more information to give ?

Like which kernel version, where do you get the glibc-2.5 and pthread binary,

Sorry forgot that completely !
Kernel version tested is 2.6.16 and 2.6.20 (sorry no newer version available yet) Compiler , GlibC, pthread all come from Codesourcery precompiled in a package
"CodeSourcery Sourcery G++ Lite 2007q1-10" downloadable for free.
Compiler version is as mentioned before :
arm-none-linux-gnueabi-gcc (CodeSourcery Sourcery G++ Lite 2007q1-10) 4.2.0 20070413 (prerelease)

--------------------------------------------------------------
J?rgen Schindele
Software-Entwicklung

NENTEC Netzwerktechnologie GmbH
Greschbachstr. 12
76229 Karlsruhe
Deutschland

Telefon: +49 721 94249-51
Telefax: +49 721 94249-10
E-Mail:  schindele at nentec.de
WEB:     www.nentec.de

Gesch?ftsf?hrung: Klaus Becker, Roland Knapp
Sitz der Gesellschaft: Karlsruhe
Handelsregister: Amtsgericht Mannheim HRB 107658
--------------------------------------------------------------

#5 lore raw

Greetings All,
I will quickly add the following to this thread, as it seems related.
Platform:
Custom ARM9 SoC using Montavista Linux Release 3.1, a 2.4.21 Linux Kernel. Montavista tool chain and libraries.

Problem:
When we try and execute a pthread_create, "when loaded as a .so", the thread will be created, but will not "return" to the main thread for further processing, we basically get "stuck" in this new thread. In the "real" case, this is an ISR thread, would hang on waiting for an interrupt. For testing, I use Sleep and prints to document program flow.
However, IF I use the "exact same code" and build the program as an application, it works just fine dandy. . . The thread gets spawned, prints it's initial hello, then goes into the while (1) sleep/print incrementing value loop. The thread returns to the "Main" and we spawn 2 more threads and they work just fine (based upon interleaving printouts)

NOTE:
For our "normal" development we use an external host processor (PowerPC based) to control the SoC and the ability to create threads from a .so has worked in this setup (using same MVL 3.1 kernel/toolchain) for the past 4+ years on 10's of platforms. So we suspected some issue/problem with the MVL setup

Now, we are migrating to a new ARM11 based SoC and I am in the process of re-testing this functionality. This new platform will be based upon 2.6.28 kernel release and CodeSourcery G++ Lite 2008q3-72 tools/libraries. I'm in the process of setting this up on an ARM RealView EB.

Details to follow.

Regards,
Stephen Beckwith

-----Original Message-----
From: [email protected] [mailto:linux-arm-kernel-bounces at lists.infradead.org] On Behalf Of Juergen Schindele
Sent: Thursday, September 17, 2009 3:36 AM
To: linux-arm-kernel at lists.infradead.org
Cc: Eric Miao
Subject: Re: Problems with pthread on ARM/PXA270

Am Mittwoch, 16. September 2009 schrieb Eric Miao:

Quoted 11 lines · Juergen Schindele
Quoted 8 lines

Am Mittwoch, 16. September 2009 schrieb Eric Miao:

Quoted 2 lines

Don't remember we had such problems before. What kind of system and libraries are you using?

thanks for your reply.
System is custom PXA270 platform. with codesourcery compiler (see below) and glibc 2.5 with pthread.
I dont know what more information to give ?

Like which kernel version, where do you get the glibc-2.5 and pthread binary,

Sorry forgot that completely !
Kernel version tested is 2.6.16 and 2.6.20 (sorry no newer version available yet) Compiler , GlibC, pthread all come from Codesourcery precompiled in a package
"CodeSourcery Sourcery G++ Lite 2007q1-10" downloadable for free.
Compiler version is as mentioned before :
arm-none-linux-gnueabi-gcc (CodeSourcery Sourcery G++ Lite 2007q1-10) 4.2.0 20070413 (prerelease)

--------------------------------------------------------------
J?rgen Schindele
Software-Entwicklung

NENTEC Netzwerktechnologie GmbH
Greschbachstr. 12
76229 Karlsruhe
Deutschland

Telefon: +49 721 94249-51
Telefax: +49 721 94249-10
E-Mail:  schindele at nentec.de
WEB:     www.nentec.de

Gesch?ftsf?hrung: Klaus Becker, Roland Knapp
Sitz der Gesellschaft: Karlsruhe
Handelsregister: Amtsgericht Mannheim HRB 107658
--------------------------------------------------------------

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#6 lore raw

Am Donnerstag, 17. September 2009 schrieb Beckwith, Stephen (Stephen):

Quoted 4 lines

Greetings All,
I will quickly add the following to this thread, as it seems related.
Platform:
Custom ARM9 SoC using Montavista Linux Release 3.1, a 2.4.21 Linux Kernel. Montavista tool chain and libraries.

Stephen thanks for your comment.
I tested with Montavista toolchain and 2.6.12 kernel too but without success. Perhaps this is arm/arch implementation dependant ???

Quoted 3 lines

Problem:
When we try and execute a pthread_create, "when loaded as a .so", the thread will be created, but will not "return" to the main thread for further processing, we basically get "stuck" in this new thread. In the "real" case, this is an ISR thread, would hang on waiting for an interrupt. For testing, I use Sleep and prints to document program flow.

As you see the example i sent in first mail i build a simple application, so it should work. Can you please test this little prog on your environment/platform ?

Quoted 1 line

However, IF I use the "exact same code" and build the program as an application, it works just fine dandy. . . The thread gets spawned, prints it's initial hello, then goes into the while (1) sleep/print incrementing value loop. The thread returns to the "Main" and we spawn 2 more threads and they work just fine (based upon interleaving printouts)

This seems to be dependant of memory location or what ? What parameters do you use for creating your threads ?

Quoted 65 lines

NOTE:
For our "normal" development we use an external host processor (PowerPC based) to control the SoC and the ability to create threads from a .so has worked in this setup (using same MVL 3.1 kernel/toolchain) for the past 4+ years on 10's of platforms. So we suspected some issue/problem with the MVL setup

Now, we are migrating to a new ARM11 based SoC and I am in the process of re-testing this functionality. This new platform will be based upon 2.6.28 kernel release and CodeSourcery G++ Lite 2008q3-72 tools/libraries. I'm in the process of setting this up on an ARM RealView EB.

Details to follow.

Regards,
Stephen Beckwith

-----Original Message-----
From: linux-arm-kernel-bounces at lists.infradead.org [mailto:linux-arm-kernel-bounces at lists.infradead.org] On Behalf Of Juergen Schindele
Sent: Thursday, September 17, 2009 3:36 AM
To: linux-arm-kernel at lists.infradead.org
Cc: Eric Miao
Subject: Re: Problems with pthread on ARM/PXA270

Am Mittwoch, 16. September 2009 schrieb Eric Miao:

Quoted 11 lines · Juergen Schindele
Quoted 8 lines

Am Mittwoch, 16. September 2009 schrieb Eric Miao:

Quoted 2 lines

Don't remember we had such problems before. What kind of system and libraries are you using?

thanks for your reply.
System is custom PXA270 platform. with codesourcery compiler (see below) and glibc 2.5 with pthread.
I dont know what more information to give ?

Like which kernel version, where do you get the glibc-2.5 and pthread binary,

Sorry forgot that completely !
Kernel version tested is 2.6.16 and 2.6.20 (sorry no newer version available yet) Compiler , GlibC, pthread all come from Codesourcery precompiled in a package
"CodeSourcery Sourcery G++ Lite 2007q1-10" downloadable for free.
Compiler version is as mentioned before :
arm-none-linux-gnueabi-gcc (CodeSourcery Sourcery G++ Lite 2007q1-10) 4.2.0 20070413 (prerelease)

--------------------------------------------------------------
J?rgen Schindele
Software-Entwicklung

NENTEC Netzwerktechnologie GmbH
Greschbachstr. 12
76229 Karlsruhe
Deutschland

Telefon: +49 721 94249-51
Telefax: +49 721 94249-10
E-Mail:  schindele at nentec.de
WEB:     www.nentec.de

Gesch?ftsf?hrung: Klaus Becker, Roland Knapp
Sitz der Gesellschaft: Karlsruhe
Handelsregister: Amtsgericht Mannheim HRB 107658
--------------------------------------------------------------

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Signature · 27 lines
--------------------------------------------------------------
J?rgen Schindele  
Software-Entwicklung

NENTEC Netzwerktechnologie GmbH
Greschbachstr. 12
76229 Karlsruhe
Deutschland
Telefon: +49 721 94249-51
Telefax: +49 721 94249-10
E-Mail:  schindele at nentec.de
WEB:     www.nentec.de
 
Gesch?ftsf?hrung: Klaus Becker, Roland Knapp
Sitz der Gesellschaft: Karlsruhe
Handelsregister: Amtsgericht Mannheim HRB 107658
 
Diese E-Mail enth?lt vertrauliche oder rechtlich gesch?tzte Informationen.
Wenn Sie nicht der vorgesehene Empf?nger sind, informieren Sie bitte sofort
den Absender und l?schen Sie diese E-Mail. Das unbefugte Kopieren dieser E-Mail
oder die unbefugte Weitergabe der enthaltenen Informationen ist nicht gestattet.
 
The information contained in this message is confidential or protected by law.
If you are not the intended recipient, please contact the sender and delete this
message. Any unauthorised copying of this message or unauthorised distribution of
the information contained herein is prohibited.
--------------------------------------------------------------
#13 lore raw
In reply to James
Quoted 2 lines · James

Are you running with superuser privileges? My manpage tells me that SCHED_RR is only available if run with superuser privileges.

Note that pthread_attr_setschedpolicy has a return value that tells you if the function was successful.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                              | Uwe Kleine-K?nig            |
Industrial Linux Solutions                    | http://www.pengutronix.de/  |
#9 lore raw
In reply to Daniel Jacobowitz

Am Mittwoch, 16. September 2009 schrieb Daniel Jacobowitz:

Quoted 13 lines · Juergen Schindele
Quoted 12 lines

Hello all,
we tried to implement a thread based software on our PXA270 based platform but we had trouble with pthreads. So i modyfied a tiny progam to test. This little progam creates 10 threads and each thread does print something (an index an a pointer to itself).

On my PC with Suse 11.0 Linux (kernel 2.6.27) this works fine as supposed to. Each thread has his turn and print his own values.

But on our pxa270 platform the thread switch does not (or really rarely) happen and only one thread is printing always the same values. So i suppose thread switching is not working!

Quoted 7 lines
Quoted 1 line

Any hints or experiences are welcome !!!

It's just a wild guess, but check your sched_clock implementation. I fixed a similar problem in QEMU last week; the kernel used to function OK with sched_clock always returning zero, but some time between 2.6.25 and 2.6.28 became dependent on it.

sched_clock is apparently not implemented the same way in all kernel versions. What about thread implementation in codesourcery compiler ? Are they "linux-threads" or "Native Posix thread library" or is it possible that there are important bugfixes til the version i use ???

Is my example app. correct in programming or am i doing bloody beginners mistake there ??

Thanks for your help
--------------------------------------------------------------
J?rgen Schindele
Software-Entwicklung

NENTEC Netzwerktechnologie GmbH
Greschbachstr. 12
76229 Karlsruhe
Deutschland

Telefon: +49 721 94249-51
Telefax: +49 721 94249-10
E-Mail:  schindele at nentec.de
WEB:     www.nentec.de

Gesch?ftsf?hrung: Klaus Becker, Roland Knapp
Sitz der Gesellschaft: Karlsruhe
Handelsregister: Amtsgericht Mannheim HRB 107658

Diese E-Mail enth?lt vertrauliche oder rechtlich gesch?tzte Informationen. Wenn Sie nicht der vorgesehene Empf?nger sind, informieren Sie bitte sofort den Absender und l?schen Sie diese E-Mail. Das unbefugte Kopieren dieser E-Mail oder die unbefugte Weitergabe der enthaltenen Informationen ist nicht gestattet.

The information contained in this message is confidential or protected by law. If you are not the intended recipient, please contact the sender and delete this message. Any unauthorised copying of this message or unauthorised distribution of the information contained herein is prohibited.
--------------------------------------------------------------

#14 lore raw
In reply to Uwe Kleine-König
Quoted 5 lines · Uwe Kleine-K?nig
Quoted 2 lines · James

Are you running with superuser privileges? My manpage tells me that SCHED_RR is only available if run with superuser privileges.

Note that pthread_attr_setschedpolicy has a return value that tells you if the function was successful.

And that SCHED_RR has a time quantum returned by sched_rr_get_interval which is not guaranteed to be small. However, if it is a small time and it's not switching that's a bug in either libc or the kernel.

Note that printf() does locking which may complicate things. Try opening separate outputs for each thread, or using write().

-- Jamie

#10 lore raw
In reply to Juergen Schindele
Quoted 4 lines · Juergen Schindele

sched_clock is apparently not implemented the same way in all kernel versions. What about thread implementation in codesourcery compiler ? Are they "linux-threads" or "Native Posix thread library" or is it possible that there are important bugfixes til the version i use ???

NPTL in any recent version. I don't remember for the ancient version you said you were using; consider an update.

Signature · 2 lines
Daniel Jacobowitz
CodeSourcery
#7 lore raw
In reply to Beckwith, Stephen (Stephen)

Greetings All,
As noted below, we experienced a problem on Linux 2.4.x kernels for ARM when running pthreads. Thanks to Daniel @ CodeSourcery for assistance in getting my .so to link properly with my application.

My results are:  I do NOT see the same problem as seen on the Linux 2.4.x kernel.  When creating pthreads when calling a .so, they get created correctly and return to the "main" to continue execution.  
The test platform is:  ARM Realview EB with ARM11MPCore CoreTile using the "stock" ARM released 2.6.28 SMP built kernel.

We use real-time threads with FIFO ordering and set the priority as we define in our application so that everything works correctly.

Regards,
Stephen Beckwith

-----Original Message-----
From: [email protected] [mailto:linux-arm-kernel-bounces at lists.infradead.org] On Behalf Of Beckwith, Stephen (Stephen)
Sent: Thursday, September 17, 2009 8:47 AM
To: schindele at nentec.de; linux-arm-kernel at lists.infradead.org
Cc: Eric Miao
Subject: RE: Problems with pthread on ARM/PXA270

Greetings All,
I will quickly add the following to this thread, as it seems related.
Platform:
Custom ARM9 SoC using Montavista Linux Release 3.1, a 2.4.21 Linux Kernel. Montavista tool chain and libraries.

Problem:
When we try and execute a pthread_create, "when loaded as a .so", the thread will be created, but will not "return" to the main thread for further processing, we basically get "stuck" in this new thread. In the "real" case, this is an ISR thread, would hang on waiting for an interrupt. For testing, I use Sleep and prints to document program flow.
However, IF I use the "exact same code" and build the program as an application, it works just fine dandy. . . The thread gets spawned, prints it's initial hello, then goes into the while (1) sleep/print incrementing value loop. The thread returns to the "Main" and we spawn 2 more threads and they work just fine (based upon interleaving printouts)

NOTE:
For our "normal" development we use an external host processor (PowerPC based) to control the SoC and the ability to create threads from a .so has worked in this setup (using same MVL 3.1 kernel/toolchain) for the past 4+ years on 10's of platforms. So we suspected some issue/problem with the MVL setup

Now, we are migrating to a new ARM11 based SoC and I am in the process of re-testing this functionality. This new platform will be based upon 2.6.28 kernel release and CodeSourcery G++ Lite 2008q3-72 tools/libraries. I'm in the process of setting this up on an ARM RealView EB.

Details to follow.

Regards,
Stephen Beckwith

-----Original Message-----
From: [email protected] [mailto:linux-arm-kernel-bounces at lists.infradead.org] On Behalf Of Juergen Schindele
Sent: Thursday, September 17, 2009 3:36 AM
To: linux-arm-kernel at lists.infradead.org
Cc: Eric Miao
Subject: Re: Problems with pthread on ARM/PXA270

Am Mittwoch, 16. September 2009 schrieb Eric Miao:

Quoted 11 lines · Juergen Schindele
Quoted 8 lines

Am Mittwoch, 16. September 2009 schrieb Eric Miao:

Quoted 2 lines

Don't remember we had such problems before. What kind of system and libraries are you using?

thanks for your reply.
System is custom PXA270 platform. with codesourcery compiler (see below) and glibc 2.5 with pthread.
I dont know what more information to give ?

Like which kernel version, where do you get the glibc-2.5 and pthread binary,

Sorry forgot that completely !
Kernel version tested is 2.6.16 and 2.6.20 (sorry no newer version available yet) Compiler , GlibC, pthread all come from Codesourcery precompiled in a package
"CodeSourcery Sourcery G++ Lite 2007q1-10" downloadable for free.
Compiler version is as mentioned before :
arm-none-linux-gnueabi-gcc (CodeSourcery Sourcery G++ Lite 2007q1-10) 4.2.0 20070413 (prerelease)

--------------------------------------------------------------
J?rgen Schindele
Software-Entwicklung

NENTEC Netzwerktechnologie GmbH
Greschbachstr. 12
76229 Karlsruhe
Deutschland

Telefon: +49 721 94249-51
Telefax: +49 721 94249-10
E-Mail:  schindele at nentec.de
WEB:     www.nentec.de

Gesch?ftsf?hrung: Klaus Becker, Roland Knapp
Sitz der Gesellschaft: Karlsruhe
Handelsregister: Amtsgericht Mannheim HRB 107658
--------------------------------------------------------------

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#15 lore raw
In reply to Juergen Schindele

Am Mittwoch, 16. September 2009 schrieb Juergen Schindele:
Hey all,
i've done some tests on different platforms

running OK on x86 openSuse 11.0
- SCHED_OTHER OK
- SCHED_RR OK

on pxa270 (xscale) platform
compiler gcc 4.2.0
with glibc 2.5 (NPTL) from CodeSourcery
Sourcery G++ Lite 2007q1-10
on Kernel 2.6.20
- SCHED_OTHER works fine
- SCHED_RR does not work at all

on the same pxa270 (xscale) platform
compiler gcc 4.3.3
and glibc 2.8 (NPTL) from CodeSourcery Sourcery G++ Lite 2009q1-203
Kernel 2.6.20
- SCHED_OTHER only one thread is running all the time other threads are blocked.
- SCHED_RR does not work at all

on ixp425 (xscale) platform
compiler 3.3.2
with glibc 2.2.5 (not NPTL)
from uclinux
kernel 2.6.16
- SCHED_OTHER
First no thread are running. 30 minutes after starting the test all threads are started and running. It's unbeleivable !!.
-SCHED_RR does not work at all

Why is SCHED_RR only running on x86 platform ???
Where is the difference in handling between SCHED_RR ans SCHED_OTHER ? Any comments or helps ????

Quoted 105 lines

Hello all,
we tried to implement a thread based software on our PXA270 based platform but we had trouble with pthreads. So i modyfied a tiny progam to test. This little progam creates 10 threads and each thread does print something (an index an a pointer to itself).

On my PC with Suse 11.0 Linux (kernel 2.6.27) this works fine as supposed to. Each thread has his turn and print his own values.

But on our pxa270 platform the thread switch does not (or really rarely) happen and only one thread is printing always the same values. So i suppose thread switching is not working!

Any hints or experiences are welcome !!!

we use codesourcery compiler
arm-none-linux-gnueabi-gcc (CodeSourcery Sourcery G++ Lite 2007q1-10) 4.2.0 20070413 (prerelease) Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

and here the C-code compiled with "arm-none-linux-gnueabi-gcc -o test test.c -lpthread"

#include <errno.h>
#include <error.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <time.h>

#define NUM_THREADS 10
#define NUM_ITERS 50
#define TIMEOUT_NS 100000000L

static void *thread (void *);
static int argument[NUM_THREADS];
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_attr_t defaultattr;

static void * print_thread (void *arg)

{
    int i;
    int number = *((int*)arg);

    for (;;) {
        pthread_t self = pthread_self ();
        printf ("Thread %d is [%d]\n", number, self);
    }
}

int main (void)

{
    pthread_t th;
    int i, retvalue;

    struct sched_param param;
    pthread_attr_init(&defaultattr);

    pthread_attr_setschedpolicy(&defaultattr, SCHED_RR);

    param.sched_priority = 10;
    if ((retvalue = pthread_attr_setschedparam(&defaultattr, &param))!=0) {
        printf ("ERROR\n");
        exit (0);
    }

    for (i = 0; i < NUM_THREADS; i++)
    {
        argument[i] = i;
        if (pthread_create (&th, &defaultattr, print_thread, &argument[i]) != 0)
            error (EXIT_FAILURE, 0, "cannot create thread");
        printf ("Thread [%d]\n", i);
    }

    while (1) {
        ;
    }

    /* notreached */
    return 0;
}

--------------------------------------------------------------
J?rgen Schindele
Software-Entwicklung

NENTEC Netzwerktechnologie GmbH
Greschbachstr. 12
76229 Karlsruhe
Deutschland

Telefon: +49 721 94249-51
Telefax: +49 721 94249-10
E-Mail:  schindele at nentec.de
WEB:     www.nentec.de

Gesch?ftsf?hrung: Klaus Becker, Roland Knapp
Sitz der Gesellschaft: Karlsruhe
Handelsregister: Amtsgericht Mannheim HRB 107658
--------------------------------------------------------------

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Signature · 17 lines
--------------------------------------------------------------
J?rgen Schindele  
Software-Entwicklung

NENTEC Netzwerktechnologie GmbH
Greschbachstr. 12
76229 Karlsruhe
Deutschland
Telefon: +49 721 94249-51
Telefax: +49 721 94249-10
E-Mail:  schindele at nentec.de
WEB:     www.nentec.de
 
Gesch?ftsf?hrung: Klaus Becker, Roland Knapp
Sitz der Gesellschaft: Karlsruhe
Handelsregister: Amtsgericht Mannheim HRB 107658
--------------------------------------------------------------