heap: Rename memory "tags" to "types" to avoid confusion w/ old tag allocator API

This commit is contained in:
Angus Gratton
2017-07-04 12:46:39 +08:00
committed by Angus Gratton
parent ee28fafcdf
commit ad60c30de0
5 changed files with 75 additions and 69 deletions
+3 -3
View File
@@ -62,7 +62,7 @@ inline static uint32_t get_all_caps(const heap_t *heap)
return 0;
}
uint32_t all_caps = 0;
for (int prio = 0; prio < SOC_HEAP_TAG_NO_PRIOS; prio++) {
for (int prio = 0; prio < SOC_MEMORY_TYPE_NO_PRIOS; prio++) {
all_caps |= heap->caps[prio];
}
return all_caps;
@@ -87,7 +87,7 @@ IRAM_ATTR void *heap_caps_malloc( size_t size, uint32_t caps )
//If any, EXEC memory should be 32-bit aligned, so round up to the next multiple of 4.
size = (size + 3) & (~3);
}
for (int prio = 0; prio < SOC_HEAP_TAG_NO_PRIOS; prio++) {
for (int prio = 0; prio < SOC_MEMORY_TYPE_NO_PRIOS; prio++) {
//Iterate over heaps and check capabilities at this priority
for (int heap_idx = 0; heap_idx < num_registered_heaps; heap_idx++) {
heap_t *heap = &registered_heaps[heap_idx];
@@ -96,7 +96,7 @@ IRAM_ATTR void *heap_caps_malloc( size_t size, uint32_t caps )
//doesn't cover, see if they're available in other prios.
remCaps = caps & (~heap->caps[prio]); //Remaining caps to be fulfilled
int j = prio + 1;
while (remCaps != 0 && j < SOC_HEAP_TAG_NO_PRIOS) {
while (remCaps != 0 && j < SOC_MEMORY_TYPE_NO_PRIOS) {
remCaps = remCaps & (~heap->caps[j]);
j++;
}
+12 -12
View File
@@ -57,7 +57,7 @@ static void disable_mem_region(soc_memory_region_t *regions, intptr_t from, intp
intptr_t regEnd = region->start + region->size;
if (regStart >= from && regEnd <= to) {
//Entire region falls in the range. Disable entirely.
regions[i].tag = -1;
regions[i].type = -1;
} else if (regStart >= from && regEnd > to && regStart < to) {
//Start of the region falls in the range. Modify address/len.
intptr_t overlap = to - regStart;
@@ -72,7 +72,7 @@ static void disable_mem_region(soc_memory_region_t *regions, intptr_t from, intp
} else if (regStart < from && regEnd > to) {
//Range punches a hole in the region! We do not support this.
ESP_EARLY_LOGE(TAG, "region %d: hole punching is not supported!", i);
regions->tag = -1; //Just disable memory region. That'll teach them!
regions->type = -1; //Just disable memory region. That'll teach them!
}
}
}
@@ -108,13 +108,13 @@ void heap_caps_init()
}
//The heap allocator will treat every region given to it as separate. In order to get bigger ranges of contiguous memory,
//it's useful to coalesce adjacent regions that have the same tag.
//it's useful to coalesce adjacent regions that have the same type.
for (int i = 1; i < soc_memory_region_count; i++) {
soc_memory_region_t *a = &regions[i - 1];
soc_memory_region_t *b = &regions[i];
if (b->start == a->start + a->size && b->tag == a->tag ) {
a->tag = -1;
if (b->start == a->start + a->size && b->type == a->type ) {
a->type = -1;
b->start = a->start;
b->size += a->size;
}
@@ -123,7 +123,7 @@ void heap_caps_init()
/* Count the heaps left after merging */
num_registered_heaps = 0;
for (int i = 0; i < soc_memory_region_count; i++) {
if (regions[i].tag != -1) {
if (regions[i].type != -1) {
num_registered_heaps++;
}
}
@@ -139,24 +139,24 @@ void heap_caps_init()
ESP_EARLY_LOGI(TAG, "Initializing. RAM available for dynamic allocation:");
for (int i = 0; i < soc_memory_region_count; i++) {
soc_memory_region_t *region = &regions[i];
const soc_memory_tag_desc_t *tag = &soc_memory_tags[region->tag];
const soc_memory_type_desc_t *type = &soc_memory_types[region->type];
heap_t *heap = &temp_heaps[heap_idx];
if (region->tag == -1) {
if (region->type == -1) {
continue;
}
heap_idx++;
assert(heap_idx <= num_registered_heaps);
heap->tag = region->tag;
heap->type = region->type;
heap->start = region->start;
heap->end = region->start + region->size;
memcpy(heap->caps, tag->caps, sizeof(heap->caps));
memcpy(heap->caps, type->caps, sizeof(heap->caps));
vPortCPUInitializeMutex(&heap->heap_mux);
ESP_EARLY_LOGI(TAG, "At %08X len %08X (%d KiB): %s",
region->start, region->size, region->size / 1024, tag->name);
region->start, region->size, region->size / 1024, type->name);
if (tag->startup_stack) {
if (type->startup_stack) {
/* Will be registered when OS scheduler starts */
heap->heap = NULL;
} else {
+2 -2
View File
@@ -25,8 +25,8 @@
/* Type for describing each registered heap */
typedef struct {
size_t tag;
uint32_t caps[SOC_HEAP_TAG_NO_PRIOS]; ///< Capabilities for this tag (as a prioritised set). Copied from soc_memory_tags so it's in RAM not flash.
size_t type;
uint32_t caps[SOC_MEMORY_TYPE_NO_PRIOS]; ///< Capabilities for the type of memory in this healp (as a prioritised set). Copied from soc_memory_types so it's in RAM not flash.
intptr_t start;
intptr_t end;
portMUX_TYPE heap_mux;