Can't build libpthread for M3

Andrii bearrailgun at gmail.com
Thu Oct 30 12:01:29 UTC 2014


After some tests it seems that linuxthreads doesn't work stable (on 0.9.33.2
release + 2 patches from emcraft)
2 simple threads work well, but when I try to create more complicated app
with few more (4 for example)
I have constant crashes during malloc of mem for a new thread' stack.
Seems like it crashes here:
pthread_allocate_stack()->malloc()->__heap_free()->__heap_add_free_area()

Here is the example of log:
00032 : __pthread_initialize_manager: send REQ_DEBUG to manager thread
00032 : pthread_create: write REQ_CREATE to manager thread
00033 : __pthread_manager: before poll
00033 : __pthread_manager: after poll
00033 : __pthread_manager: before read
00033 : __pthread_manager: after read, n=28
00033 : __pthread_manager: got REQ_CREATE
00033 : pthread_allocate_stack: BEGIN
00033 : pthread_allocate_stack: HAVE NO MMU
00032 : pthread_create: before suspend(self)
00033 : pthread_allocate_stack: SETTING STACK SIZE
00033 : pthread_allocate_stack: BEFORE MALLOC. SIZE: 16384
malloc: 16384 bytes
   before __heap_alloc: heap @0xa000dff4:
      0xa000dff4:  0xa000d148 - 0xa000e000  (3768)      P=0x0, N=0xa0054464
      0xa0054464:  0xa0054370 - 0xa0054470  (256)       P=0xa000dff4, N=0x0
   after __heap_alloc: heap @0xa000dff4:
      0xa000dff4:  0xa000d148 - 0xa000e000  (3768)      P=0x0, N=0xa0054464
      0xa0054464:  0xa0054370 - 0xa0054470  (256)       P=0xa000dff4, N=0x0
   adding system memory to heap: 0xa0088000 - 0xa008d000 (20480 bytes)
      before __heap_free: heap @0xa000dff4:
         0xa000dff4:  0xa000d148 - 0xa000e000  (3768)   P=0x0, N=0xa0054464
         0xa0054464:  0xa0054370 - 0xa0054470  (256)    P=0xa000dff4, N=0x0
      __heap_free debug1: heap @0xa000dff4:
         0xa000dff4:  0xa000d148 - 0xa000e000  (3768)   P=0x0, N=0xa0054464
         0xa0054464:  0xa0054370 - 0xa0054470  (256)    P=0xa000dff4, N=0x0
      __heap_free debug4: heap @0xa000dff4:
         0xa000dff4:  0xa000d148 - 0xa000e000  (3768)   P=0x0, N=0xa0054464
         0xa0054464:  0xa0054370 - 0xa0054470  (256)    P=0xa000dff4, N=0x0
      __heap_add_free_area debug1: heap @0xa000dff4:
         0xa000dff4:  0xa000d148 - 0xa000e000  (3768)   P=0x0, N=0xa0054464
         0xa0054464:  0xa0054370 - 0xa0054470  (256)    P=0xa000dff4, N=0x0
[   66.630000]
[   66.630000] zpm_thread: unhandled MPU fault (0x08) at 0x00000000
[pc=0xa004545a,sp=0xa001df18]
[   66.630000]

Seems like magic.
I tested malloc allocations with allocating like 100 chunks for 16-20Kb and
everything works well.
I also compared malloc from 0.9.33.2 with latest one from git and found no
any significant changes,
so I don't think there is a malloc bug.
It doesn't look like stack overflow either because main app has 32Kb and
every thread has 16Kb stack.
Maybe something is still wrong exactly with cloning and stack allocation
for thread?
Also I have an idea that maybe locks doesn't work well... Is it still
contiguous with ldrex/strex? But this is less
possible as I have only one hardware cpu thread on M3 ;)

Regards.









On Fri, Oct 24, 2014 at 1:50 AM, Andrii <bearrailgun at gmail.com> wrote:

> I tried to build a very simple app which just calls pthread_create() and
> prints debugs. And I could say it works.
> 0.9.33.2 release + 2 patches from emcraft and 1 more fix for compilation.
> So If someone needs uclibc with threads
> for M3 - it could be downloaded here:
> https://github.com/repu1sion/uclibc
> (not an advertisement - just hope it will solve someone's problem).
> It was built with
> make ARCH_CFLAGS= 'CPU_CFLAGS=-mthumb -march=armv7 -mfix-cortex-m3-ldrd'
> as Sergei said but I think its not about flags but about complicated app I
> tried to run before and some issues with
> mem allocations (not stack size. stack size was changed
> with arm-uclinuxeabi-flthdr to 32Kb and was enough when running without
> threads)
>
> /opt # ./zpm_thread
> 00033 : pthread_initialize: initial thread stack bounds: bos=0x1,
> tos=0xffffffff
> app started. v1
> 00033 : __pthread_initialize_manager: manager stack: size=8160,
> bos=0xa0018008, tos=0xa0019fe8
> 00033 : __pthread_initialize_manager: send REQ_DEBUG to manager thread
> 00034 : __pthread_manager: before poll
> 00033 : pthread_create: write REQ_CREATE to manager thread
> 00034 : __pthread_manager: after poll
> 00034 : __pthread_manager: before read
> 00034 : __pthread_manager: after read, n=28
> 00034 : __pthread_manager: got REQ_CREATE
> 00033 : pthread_create: before suspend(self)
> 00034 : pthread_allocate_stack: malloced chunk: base=0xa0278008,
> size=0x4000
> 00034 : pthread_allocate_stack: thread stack: bos=0xa0278008,
> tos=0xa027bea8
> 00034 : pthread_allocate_stack: initial stack: bos=0xa0019fe8,
> tos=0xa0278008
> 00034 : pthread_handle_create: cloning new_thread = 0xa027bea8
> 00034 : pthread_handle_create: new thread pid = 35
> 00035 : pthread_start_thread:
> new thread created
> thread
> 00034 : __pthread_manager: restarting 0xa004ddd0
> 00033 : pthread_create: after suspend(self)
> app
> 00034 : __pthread_manager: before poll
> thread
> app
>
> Thanks for the help!
>
>
> On Thu, Oct 23, 2014 at 6:25 PM, Bernhard Reutner-Fischer <
> rep.dot.nop at gmail.com> wrote:
>
>> On 22 October 2014 12:11:26 CEST, Sergei Poselenov <
>> sposelenov at emcraft.com> wrote:
>> >Hello,
>> >
>>
>> >Uclibc (still) lacks pthreads support on Cortex-M3.
>> >
>> >I'm attaching two patches:
>> > - implement testandset() for Cortex-M3.
>> > - Fix a bug in implementation of clone() for Cortex-M3.
>>
>> Can you please send the two patches with appropriate signed-off-by lines?
>>
>> TIA,
>>
>>
>


More information about the uClibc mailing list