-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pkg/tlsf: Early initialization of memory pool. #12032
Open
jcarrano
wants to merge
2
commits into
RIOT-OS:master
Choose a base branch
from
jcarrano:tlsf-early-init
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+207
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
UNDEF += $(BINDIR)/tlsf-malloc/tlsf-malloc.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
DEVELHELP ?= 1 | ||
|
||
include ../Makefile.tests_common | ||
|
||
# The bug is not fixed yet, so blacklist this test. | ||
TEST_ON_CI_BLACKLIST += all | ||
TEST_ON_CI_WHITELIST += native samr21-xpro | ||
|
||
USEMODULE += tlsf-malloc | ||
|
||
CFLAGS += -DDEBUG_ASSERT_VERBOSE -DTLSF_NATIVE_HEAPSIZE=0x4000 | ||
|
||
include $(RIOTBASE)/Makefile.include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (C) 2019 Freie Universität Berlin | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup examples | ||
* @{ | ||
* | ||
* @file | ||
* @brief TLSF initialization tests. | ||
* | ||
* @author Juan I Carrano <[email protected]> | ||
* | ||
* Verify that TLSF is correctly and automatically initialized when used as | ||
* the default global allocator. Failure to do so will result in segfaults / | ||
* hardfaults, even if the application does not use malloc (this is because | ||
* the C library does buffer allocations internally). | ||
* | ||
* This is currently failing as the initialization is not being done. | ||
* | ||
* @} | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <assert.h> | ||
|
||
#include "tlsf.h" | ||
#include "tlsf-malloc.h" | ||
|
||
extern char _eheap[]; | ||
|
||
#define BLOCKSIZE 42 | ||
|
||
static void walker(void* ptr, size_t size, int used, void* _accumulator) | ||
{ | ||
size_t *accumulator = _accumulator; | ||
*accumulator += size; | ||
printf("\t%p %s size: %u\n", ptr, used ? "used" : "free", (unsigned int)size); | ||
} | ||
|
||
int main(void) | ||
{ | ||
size_t accumulator = 0; | ||
void *some_block; | ||
size_t requested_size = 0; | ||
|
||
printf("Using TLSF-malloc, global pool at %p\n", (void*)_tlsf_get_global_control()); | ||
|
||
#ifndef BOARD_NATIVE | ||
requested_size = _eheap - (char*)_tlsf_get_global_control(); | ||
#else | ||
requested_size = TLSF_NATIVE_HEAPSIZE; | ||
#endif | ||
|
||
/* increase the chances of a crash */ | ||
some_block = calloc(1, BLOCKSIZE); | ||
|
||
assert(some_block != NULL); | ||
|
||
puts("TLSF heap report:"); | ||
|
||
tlsf_walk_pool(tlsf_get_pool(_tlsf_get_global_control()), walker, &accumulator); | ||
|
||
printf("According to TLSF heap has %u bytes\n", accumulator); | ||
printf("The size should be %u bytes.\n", requested_size); | ||
|
||
printf("Overhead: %d bytes\n", requested_size-accumulator); | ||
|
||
free(some_block); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (C) 2019 Freie Universität Berlin | ||
# | ||
# This file is subject to the terms and conditions of the GNU Lesser | ||
# General Public License v2.1. See the file LICENSE in the top level | ||
# directory for more details. | ||
|
||
# Tell the lua interpreter running in riot to load some modules and print | ||
# the value of a variable inside that module. | ||
|
||
import os | ||
import sys | ||
|
||
|
||
def test(child): | ||
# this is the worst test ever. | ||
child.expect('Overhead: (-?[0-9]+) bytes') | ||
|
||
assert(int(child.match[1]) >= 0) | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.path.append(os.path.join(os.environ['RIOTTOOLS'], 'testrunner')) | ||
from testrunner import run | ||
sys.exit(run(test)) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x & ~0x3