Nordic - nRF9160 (nRF Zephyr SDK) - Is __heapstats() Supported? When will it be supported if not?

Hello,

Are there plans to support the ARM function __heapstats() for the nRF9160 (under Zephyr)?

I see since 1.9.x sys_heap_runtime_stats_get() is supported - but when I try to compile under 1.9.1 it says I'm trying to redefine the function and/or 


struct sys_heap_runtime_stats stat; -> sizeof stat Is undefined or unknown.

Are there working examples of either of these two functions someplace for the nRF9160 under Zephyr?

I have the following in my source:

#include <sys/sys_heap.h>


#define CONFIG_SYS_HEAP_RUNTIME_STATS

I see also from the pull request logs for Zephyr on github this was done (adding the sys_heap stats) in the Fall of 2021.

Thanks,
John W.

Parents Reply
  • Amanda,

    At least that's a real example that you've found - 

    sys_heap_runtime_stats_get(&nrf_modem_lib_shmem_heap.heap, &stats->shmem.heap);

    And that's great if it's the nrf_model_lib_shmem_heap I'm wanting to monitor - but to be useful in this app I need a way to get a handle to the remaining available memory that's in the 1/2 of the 9160's M33 memory space - what's left of the 0x40000 / 2 -> 0x20000 -> 128KB - what's the handle to that?  

    Once I know that - then sys_heap_runtime_stats_get() will be useful.

    Maybe there's an additional config option for this - I've searched 'heap' in the available options - it doesn't jump out at me if it's there.

    If I'm understanding this correctly - there's modem heap, Zephyr heap, and application heap - and I don't know the handle to the application heap.

    Thanks,
    John

     

Children
  • Amanda,

    I see this in heap.c - I'll focus on this:

    void *sys_heap_alloc(struct sys_heap *heap, size_t bytes)
    {
    struct z_heap *h = heap->heap;

    if (bytes == 0U || size_too_big(h, bytes)) {
    return NULL;
    }

    chunksz_t chunk_sz = bytes_to_chunksz(h, bytes);
    chunkid_t c = alloc_chunk(h, chunk_sz);
    if (c == 0U) {
    return NULL;
    }

    /* Split off remainder if any */
    if (chunk_size(h, c) > chunk_sz) {
    split_chunks(h, c, c + chunk_sz);
    free_list_add(h, c + chunk_sz);
    }

    set_chunk_used(h, c, true);
    #ifdef CONFIG_SYS_HEAP_RUNTIME_STATS
    h->allocated_bytes += chunksz_to_bytes(h, chunk_size(h, c));
    #endif
    return chunk_mem(h, c);
    }

    Regards,
    John

  • Hi John, 

    Not sure if this is something of use to you but I will put it here for others facing this issue in the future. 

    I have had luck with the following:

    proj.conf:

    CONFIG_SYS_HEAP_RUNTIME_STATS=y

    c function:

    #include <zephyr/sys/sys_heap.h>

    // Debug Variables
    extern struct k_heap _system_heap;
    struct sys_memory_stats stats;
    void rtos_hal_print_heap_info(void
    {
        sys_heap_runtime_stats_get(&_system_heap.heap, &stats);

        printk("\n");
        printk("INFO: Allocated Heap = %zu\n", stats.allocated_bytes);
        printk("INFO: Free Heap = %zu\n", stats.free_bytes);
        printk("INFO: Max Allocated Heap = %zu\n", stats.max_allocated_bytes);
        printk("\n");

        return;
    }
    Kind Regards, 
    Jaden 
Related