Is it planned to enable the optional locks again in nano-mallocr.c in upstream newlib?

Asked by Tamas Kleiber

Hello,

 I have just realized that nano-mallocr.c in the latest Newlib master branch under git still disables the optional locks by commenting out the API calls:

/* Disable MALLOC_LOCK so far. So it won't be thread safe */
#define MALLOC_LOCK /*__malloc_lock(reent_ptr) */
#define MALLOC_UNLOCK /*__malloc_unlock(reent_ptr) */

Is it planned to enable back the original optional locking mechanisms that could be overridden by the end users via linker substitutions at least in the back ported nano-mallocr.c version?

Thanks in advance for your kind response.

Best regards,
 Tamas

_

Question information

Language:
English Edit question
Status:
Answered
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Terry Guo (terry.guo) said :
#1

Newlib nano is mainly built for small code size purpose. Do you evaluate the code size impact if we enable those functions?

Revision history for this message
Tamas Kleiber (kleiber-tamas) said :
#2

On my platform (Cortex-M3) __malloc_lock and __malloc_unlock takes up 136 bytes compiled with -O0.

The locks are accessed by these modules: lib_a-mlock.o lib_a-nano-freer.o lib_a-nano-mallinfor.o lib_a-nano-mallocr.o only.

Calling to the lock functions passing a reent structure pointer as argument 0 in r0 takes up minimal space as the callers of the lock functions already had the same reent structure passed to them as argument 0 in r0 so the compiler does not load them again.

So in most of the times calling to the locks are assembled as a single bl <address> jump that consumes 4 bytes of flash / call.

In a linked test application with malloc and free calls __malloc_lock() and __malloc_unlock() are called only 9 times.

So my locks related overhead is less than 200 bytes of flash/rom. My lock implementation requires no additional RAM thanks to my RTOS.

Now if I would be required to use the base malloc_r from newlib instead of nano-malloc_r I would lose tons of additional resources (+3kB of ROM and +1kB of RAM).

As mainline newlib enables multi threaded configurations used together with nano-mallocr.c in my opinion the locks should not be disabled as this way the end result is not really thread safe, even though end users may assume so.

Revision history for this message
Joey Ye (jinyun-ye) said :
#3

Tamas, as newlib-nano is fully upstreamed to newlib mainline now, it is
welcome to post patch to newlib community for change like this. We will be
happy to review patches regarding newlib-nano.

Thanks,
Joey

On Mon, Dec 8, 2014 at 7:46 PM, Tamas Kleiber <
<email address hidden>> wrote:

> Question #258710 on GCC ARM Embedded changed:
> https://answers.launchpad.net/gcc-arm-embedded/+question/258710
>
> Tamas Kleiber posted a new comment:
> On my platform (Cortex-M3) __malloc_lock and __malloc_unlock takes up
> 136 bytes compiled with -O0.
>
> The locks are accessed by these modules: lib_a-mlock.o lib_a-nano-
> freer.o lib_a-nano-mallinfor.o lib_a-nano-mallocr.o only.
>
> Calling to the lock functions passing a reent structure pointer as
> argument 0 in r0 takes up minimal space as the callers of the lock
> functions already had the same reent structure passed to them as
> argument 0 in r0 so the compiler does not load them again.
>
> So in most of the times calling to the locks are assembled as a single
> bl <address> jump that consumes 4 bytes of flash / call.
>
> In a linked test application with malloc and free calls __malloc_lock()
> and __malloc_unlock() are called only 9 times.
>
> So my locks related overhead is less than 200 bytes of flash/rom. My
> lock implementation requires no additional RAM thanks to my RTOS.
>
> Now if I would be required to use the base malloc_r from newlib instead
> of nano-malloc_r I would lose tons of additional resources (+3kB of ROM
> and +1kB of RAM).
>
> As mainline newlib enables multi threaded configurations used together
> with nano-mallocr.c in my opinion the locks should not be disabled as
> this way the end result is not really thread safe, even though end users
> may assume so.
>
> --
> You received this question notification because you are an answer
> contact for GCC ARM Embedded.
>

Can you help with this problem?

Provide an answer of your own, or ask Tamas Kleiber for more information if necessary.

To post a message you must log in.