1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
Commit Graph

8 Commits

Author SHA1 Message Date
Leandro Lanzieri
81cb769cad
makefiles: avoid building archives when compiling 2020-09-04 15:01:10 +02:00
Juan Carrano
cc907fa54e pkg/tlsf: Fix the way system functions are overriden.
The correct way to overrride the malloc family of functions in newlib-nano is
to provide the *_r (reentrant) variants. Newlib implements the "normal"
functions on top of these (see the newlib source code). Also, internally it calls
the *_r functions when allocating buffers.

If only the "normal" non-reentrant functions are provided this will mean that
some of the code will still use the vanilla newlib allocator. Furthermore, if
one uses the whole heap as a pool for TLSF then the system may in the best case
crash as there is no enough memory for its internall allocations or in the worst
case function eratically (this depends on how the heap reserved, there is an
upcomming series of commits in that direction).

This commit splits the handling between newlib and native. It also prepares the
ground for future work on the pool initialization.

Right now I could only test this in ARM and native and I cannot ensure it will
work on other platforms. Replacing the system's memory allocator is not something
that can be taken lightly and will inevitably require diving into the depths of
the libc. Therefore I would say that using TLSF as a system wide allocator is ATM
supported officially only on those plaftorms.

Testing:

Aside from reading the newlib sources, you can see the issue in a live system
using the debugger.

Compile any example (with or without tlsf-malloc), grab a debugger and place
a breakpoint in sbrk and _sbrk_r. Doing a backtrace will reveal it gets called
by _malloc_r.
2019-09-17 21:18:50 +02:00
Juan Carrano
cf686bde2d pkg/tlsf: Refactor the TLSF package and bring back original TLSF api.
- Cleanup package makefile.
- Download directly from git.
- Remove giant patch.
- Implement malloc function as a contrib package.
- Update ccn example.
- Update ps command.
2018-05-18 15:41:07 +02:00
8d88781e05 make: pkg: make use of PKGDIRBASE 2017-03-10 14:18:44 +01:00
b3c5446209 pkg: tlsf: build in board directory 2016-03-25 14:28:04 +01:00
c63a924778 pkg: adapt to RIOTPKG 2016-03-05 03:05:32 +01:00
Oleg Hahm
3b5f1f949f pkg tlsf: use pkg directory for sources
The TLSF package was the only one using the $(BINDIR) instead of a subdirectory of pkg/. This commit changes this.
2016-01-31 14:33:08 +01:00
René Kijewski
88e8915dfe Add TLSF (two level segregated fit) PKG
This is my second take on #669, because I was asked to separate it from #764.

This change adds a malloc implementation as a PKG, which uses *TLSF* (two
level segregated fit).

The patch file removes the 64bit capatibilities, debug functions, and the
option to have multiple "control blocks" (a control block holds multiple
memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`.

The implemention does not support 16bit platforms, yet, but probably only some
constants would need fixing. I limited the maximum size of a memory pool to
2**30 bytes = 1GB.

This PKG is not meant to be used by applicitions directly, but by the boards.
The board's initialition code needs to call
`int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it
has. If the board in using newlib, then this call needs to happen before the
first call to `puts`, `printf`, and friends, because newlib allocates the
control data IO streams (stdin, stdout, stderr) on the heap. Adding a small
(e.g. 1kB) pool before proper board initialization would be a possible solution.

Please read the additional information in the website of the implementator,
http://tlsf.baisoku.org/:

> TLSF (two level segregated fit) is a relatively new memory
allocator designed for embedded systems. It boasts constant
time O(1) malloc/free response time and a 4-byte block
overhead. Though it typically is slightly slower than other
allocators such as dlmalloc, it has no worst-case behavior.

> The original implementation, which comes alongside the white
paper, is distributed under the GNU GPL/LGPL. The code found
here is an original implementation, released into the public
domain, therefore is not subject to any licensing restrictions.

> Features:
 -  O(1) cost for malloc, free, realloc, memalign
 -  Extremely low overhead per allocation (4 bytes)
 -  Low overhead per pool (~3kB)
 -  Low fragmentation
 -  Compiles to only a few kB of code and data

> Caveats:
 -  Currently, assumes architecture can make 4-byte aligned accesses
 -  Not designed to be thread safe; the user must provide this

> Known Issues:
Due to the internal block structure size and the implementation
details of tlsf_memalign, there is worst-case behavior when requesting
small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign
will generally increase fragmentation, but this particular case will leave
lots of unusable "holes" in the heap. The solution would be to internally
align all blocks to 8 bytes, but this will require significantl changes
to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00