Hello, Hackers!
I trying to porting a library from Linux to L4Re and I got a issue with libpthread on ARM device (beagleboard clone). If I create a detached thread use pthread_detach() or pthread attributes then error is occured. Error does not occur on x86, tested in qemu. I wrote a simple programm for test.
Is problem in L4Re? Or should I make any steps before use pthread?
Thank you!
Code:
#include <stdio.h> #include <string.h> #include <pthread.h>
void *thread(void* arg) { int res; int num = (int)arg; printf("Start thread %d\n", num); res = pthread_detach(pthread_self()); printf("Detach thread %d (%d)\n", num, res); usleep(5000*num); printf("End thread %d\n", num); return 0; }
int main(int argc, char* argv[]) { pthread_t t1, t2; printf("Test pthread\n"); while(1) { printf("new loop...\n"); pthread_create(&t1, NULL, thread, (void*)1); pthread_create(&t2, NULL, thread, (void*)2); usleep(100000); } return 0; }
Log:
Starting kernel ...
L4 Bootstrapper Build: #101 Срд Сен 14 16:32:30 MSD 2011, 4.4.1 Scanning up to 128 MB RAM Memory size is 128MB (80000000 - 88000000) RAM: 0000000080000000 - 0000000087ffffff: 131072kB Total RAM: 128MB mod04: 810c5000-810e7ec0: pthread_test mod03: 810aa000-810c439c: l4re mod02: 8106f000-810a9b50: moe mod01: 81065000-8106e70c: sigma0 mod00: 81015000-81064f74: fiasco Moving 5 modules to 81100000 with offset eb000 moving module 05 { 810c5000-810e7ec0 } -> { 811b0000-811d2ec0 } moving module 04 { 810aa000-810c439c } -> { 81195000-811af39c } moving module 03 { 8106f000-810a9b50 } -> { 8115a000-81194b50 } moving module 02 { 81065000-8106e70c } -> { 81150000-8115970c } moving module 01 { 81015000-81064f74 } -> { 81100000-8114ff74 } Scanning fiasco Scanning sigma0 Scanning moe --init=rom/pthread_test Relocated mbi to [0x8100f000-0x8100f0e4] Loading fiasco Loading sigma0 Loading moe find kernel info page... found kernel info page at 0x80002000 Regions of list regions [ 80001000, 800019ff] { a00} Kern fiasco [ 80002000, 80061fff] { 60000} Kern fiasco [ 80090000, 800969bf] { 69c0} Sigma0 sigma0 [ 80098000, 8009e17b] { 617c} Sigma0 sigma0 [ 80140000, 8017618b] { 3618c} Root moe [ 80178000, 8018ed0f] { 16d10} Root moe [ 81000000, 810143eb] { 143ec} Boot bootstrap [ 8100f000, 8100f1e1] { 1e2} Root Multiboot info [ 81195000, 811d2ebf] { 3dec0} Root Modules Memory API Version: (87) experimental Sigma0 config ip:800900e0 sp:81013704 Roottask config ip:801401c0 sp:00000000 Starting kernel fiasco at 80001000 Hello from Startup::stage2 Initialize page table Vmem_alloc::init() Cache config: ON ID_PFR0: 00001031 ID_PFR1: 00000011 ID_DFR0: 00010400 ID_AFR0: 00000000 ID_MMFR0: 31100003 ID_MMFR1: 20000000 ID_MMFR2: 01202000 ID_MMFR3: 00000011 FPU0: Arch: VFPv3(3), Part: VFPv3(30), r: 1, v: c, i: 41, t: hard, p: dbl/sngl Welcome to Fiasco.OC (arm)! L4/Fiasco.OC arm microkernel (C) 1998-2011 TU Dresden
Rev: rUNKNOWN compiled with gcc 4.4.1 for Beagleboard []
Build: #1 Чтв Сен 8 11:49:39 MSD 2011
Calibrating timer loop... done. SIGMA0: Hello! KIP @ 80002000 allocated 4KB for maintenance structures SIGMA0: Dump of all resource maps RAM:------------------------ [0:80000000;80000fff] [0:80062000;8008ffff] [0:80097000;80097fff] [0:8009f000;8013ffff] [4:80140000;80176fff] [0:80177000;80177fff] [4:80178000;8018efff] [0:8018f000;8100efff] [4:8100f000;8100ffff] [0:81010000;81194fff] [4:81195000;811d2fff] [0:811d3000;86ffffff] IOMEM:---------------------- [0:0;7fffffff] [0:88000000;ffffffff] MOE: Hello world MOE: found 113680 KByte free memory MOE: found RAM from 80000000 to 87000000 MOE: allocated 112 KByte for the page array @0x80062000 MOE: virtual user address space [0-bfffffff] MOE: rom name space cap -> [C:501000] BOOTFS: [81195000-811af39c] [C:503000] l4re BOOTFS: [811b0000-811d2ec0] [C:504000] pthread_test MOE: cmdline: moe --init=rom/pthread_test MOE: Starting: rom/pthread_test MOE: loading 'rom/pthread_test' Test pthread new loop... Start thread 1 Detach thread 1 (0) Start thread 2 Detach thread 2 (0) End thread 1 L4Re[rm]: unhandled read page fault @300d3c pc=1003b54 L4Re: unhandled exception: pc=0x1003b54 End thread 2 new loop...
modules.list:
modaddr 0x01100000 entry pthread_test roottask moe --init=rom/pthread_test module l4re module pthread_test
On Wed Sep 14, 2011 at 17:33:26 +0400, Ivan Loskutov wrote:
I trying to porting a library from Linux to L4Re and I got a issue with libpthread on ARM device (beagleboard clone). If I create a detached thread use pthread_detach() or pthread attributes then error is occured. Error does not occur on x86, tested in qemu. I wrote a simple programm for test.
Is problem in L4Re? Or should I make any steps before use pthread?
Please apply this patch, fixes it for me. http://os.inf.tu-dresden.de/download/tmp/u.patch
Adam
Hi, Adam
On Thu, Sep 15, 2011 at 8:40 PM, Adam Lackorzynski < adam@os.inf.tu-dresden.de> wrote:
Please apply this patch, fixes it for me. http://os.inf.tu-dresden.de/download/tmp/u.patch
Thanks for patch. It fixed issue for my test program. Also error does not occur if thread created with attribute PTHREAD_CREATE_DETACHED. But if thread detached in main then i have same error.
Code: #include <stdio.h> #include <string.h> #include <pthread.h>
void *thread(void* arg) { int num = (int)arg; printf("Start thread %d\n", num); usleep(5000*num); printf("End thread %d\n", num); return 0; }
int main(int argc, char* argv[]) { pthread_t t1, t2; int res; printf("Test pthread\n"); while(1) { printf("new loop...\n"); pthread_create(&t1, NULL, thread, (void*)1); res = pthread_detach(&t1); printf("Detach thread 1 (%d)\n", res); pthread_create(&t2, NULL, thread, (void*)2); res = pthread_detach(&t2); printf("Detach thread 2 (%d)\n", res); usleep(100000); } return 0; }
Log: Starting kernel ...
L4 Bootstrapper Build: #8 Птн Сен 16 12:21:37 MSD 2011, 4.4.1 Scanning up to 128 MB RAM Memory size is 128MB (80000000 - 88000000) RAM: 0000000080000000 - 0000000087ffffff: 131072kB Total RAM: 128MB mod04: 810c5000-810e7938: pthread_test mod03: 810aa000-810c439c: l4re mod02: 8106f000-810a9b50: moe mod01: 81065000-8106e70c: sigma0 mod00: 81015000-81064f74: fiasco Moving 5 modules to 81100000 with offset eb000 moving module 05 { 810c5000-810e7938 } -> { 811b0000-811d2938 } moving module 04 { 810aa000-810c439c } -> { 81195000-811af39c } moving module 03 { 8106f000-810a9b50 } -> { 8115a000-81194b50 } moving module 02 { 81065000-8106e70c } -> { 81150000-8115970c } moving module 01 { 81015000-81064f74 } -> { 81100000-8114ff74 } Scanning fiasco Scanning sigma0 Scanning moe --init=rom/pthread_test Relocated mbi to [0x8100f000-0x8100f0e4] Loading fiasco Loading sigma0 Loading moe find kernel info page... found kernel info page at 0x80002000 Regions of list regions [ 80001000, 800019ff] { a00} Kern fiasco [ 80002000, 80061fff] { 60000} Kern fiasco [ 80090000, 800969bf] { 69c0} Sigma0 sigma0 [ 80098000, 8009e17b] { 617c} Sigma0 sigma0 [ 80140000, 801761f3] { 361f4} Root moe [ 80178000, 8018ed0f] { 16d10} Root moe [ 81000000, 810143eb] { 143ec} Boot bootstrap [ 8100f000, 8100f1e1] { 1e2} Root Multiboot info [ 81195000, 811d2937] { 3d938} Root Modules Memory API Version: (87) experimental Sigma0 config ip:800900e0 sp:81013704 Roottask config ip:801401c0 sp:00000000 Starting kernel fiasco at 80001000 Hello from Startup::stage2 Initialize page table Vmem_alloc::init() Cache config: ON ID_PFR0: 00001031 ID_PFR1: 00000011 ID_DFR0: 00010400 ID_AFR0: 00000000 ID_MMFR0: 31100003 ID_MMFR1: 20000000 ID_MMFR2: 01202000 ID_MMFR3: 00000011 FPU0: Arch: VFPv3(3), Part: VFPv3(30), r: 1, v: c, i: 41, t: hard, p: dbl/sngl Welcome to Fiasco.OC (arm)! L4/Fiasco.OC arm microkernel (C) 1998-2011 TU Dresden
Rev: rUNKNOWN compiled with gcc 4.4.1 for Beagleboard []
Build: #1 Птн Сен 16 11:07:29 MSD 2011
Calibrating timer loop... done. SIGMA0: Hello! KIP @ 80002000 allocated 4KB for maintenance structures SIGMA0: Dump of all resource maps RAM:------------------------ [0:80000000;80000fff] [0:80062000;8008ffff] [0:80097000;80097fff] [0:8009f000;8013ffff] [4:80140000;80176fff] [0:80177000;80177fff] [4:80178000;8018efff] [0:8018f000;8100efff] [4:8100f000;8100ffff] [0:81010000;81194fff] [4:81195000;811d2fff] [0:811d3000;86ffffff] IOMEM:---------------------- [0:0;7fffffff] [0:88000000;ffffffff] MOE: Hello world MOE: found 113680 KByte free memory MOE: found RAM from 80000000 to 87000000 MOE: allocated 112 KByte for the page array @0x80062000 MOE: virtual user address space [0-bfffffff] MOE: rom name space cap -> [C:501000] BOOTFS: [81195000-811af39c] [C:503000] l4re BOOTFS: [811b0000-811d2938] [C:504000] pthread_test MOE: cmdline: moe --init=rom/pthread_test MOE: Starting: rom/pthread_test MOE: loading 'rom/pthread_test' Test pthread new loop... L4Re[rm]: unhandled read page fault @800080d4 pc=10048fc L4Re: unhandled exception: pc=0x10048fc Start thread 1 End thread 1
Hi,
On Fri Sep 16, 2011 at 12:40:09 +0400, Ivan Loskutov wrote:
On Thu, Sep 15, 2011 at 8:40 PM, Adam Lackorzynski < Thanks for patch. It fixed issue for my test program. Also error does not occur if thread created with attribute PTHREAD_CREATE_DETACHED. But if thread detached in main then i have same error.
Code: printf("new loop...\n"); pthread_create(&t1, NULL, thread, (void*)1); res = pthread_detach(&t1); printf("Detach thread 1 (%d)\n", res); pthread_create(&t2, NULL, thread, (void*)2); res = pthread_detach(&t2);
pthread_detach does not take a pointer of pthread_t, just pthread_t.
Adam
On Fri, Sep 16, 2011 at 9:19 PM, Adam Lackorzynski < adam@os.inf.tu-dresden.de> wrote:
Code: printf("new loop...\n"); pthread_create(&t1, NULL, thread, (void*)1); res = pthread_detach(&t1); printf("Detach thread 1 (%d)\n", res); pthread_create(&t2, NULL, thread, (void*)2); res = pthread_detach(&t2);
pthread_detach does not take a pointer of pthread_t, just pthread_t.
Sorry. It's my mistake :)
l4-hackers@os.inf.tu-dresden.de