Skip to content
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

DRAM: fast_get() cache-handling improvements #9817

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions zephyr/lib/fast-get.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <sof/lib/fast-get.h>
#include <rtos/alloc.h>
#include <rtos/cache.h>
#include <rtos/spinlock.h>
#include <rtos/symbol.h>
#include <ipc/topology.h>
Expand Down Expand Up @@ -37,33 +38,27 @@ LOG_MODULE_REGISTER(fast_get, CONFIG_SOF_LOG_LEVEL);
static int fast_get_realloc(struct sof_fast_get_data *data)
{
struct sof_fast_get_entry *entries;

if (!data->num_entries) {
/*
* Allocate 8 entries for the beginning. Currently we only use
* 2 entries at most, so this should provide a reasonable first
* allocation.
*/
const unsigned int n_entries = 8;

data->entries = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM,
n_entries * sizeof(*entries));
if (!data->entries)
return -ENOMEM;
data->num_entries = n_entries;
return 0;
}

entries = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM,
2 * data->num_entries * sizeof(*entries));
/*
* Allocate 8 entries for the beginning. Currently we only use 2 entries
* at most, so this should provide a reasonable first allocation.
*/
const unsigned int init_n_entries = 8;
unsigned int n_entries = data->num_entries ? data->num_entries * 2 : init_n_entries;

entries = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM,
n_entries * sizeof(*entries));
if (!entries)
return -ENOMEM;

memcpy_s(entries, 2 * data->num_entries * sizeof(*entries), data->entries,
data->num_entries * sizeof(*entries));
rfree(data->entries);
if (data->num_entries) {
memcpy_s(entries, n_entries * sizeof(*entries), data->entries,
data->num_entries * sizeof(*entries));
rfree(data->entries);
}

data->entries = entries;
data->num_entries = 2 * data->num_entries;
data->num_entries = n_entries;

return 0;
}

Expand Down Expand Up @@ -113,6 +108,11 @@ const void *fast_get(const void *dram_ptr, size_t size)

ret = entry->sram_ptr;
entry->refcount++;
/*
* The data is constant, so it's safe to use cached access to
* it, but initially we have to invalidate cached
*/
dcache_invalidate_region((__sparse_force void __sparse_cache *)ret, size);
goto out;
}

Expand Down Expand Up @@ -159,10 +159,10 @@ void fast_put(const void *sram_ptr)
goto out;
}
entry->refcount--;
if (entry->refcount > 0)
goto out;
rfree(entry->sram_ptr);
memset(entry, 0, sizeof(*entry));
if (!entry->refcount) {
rfree(entry->sram_ptr);
memset(entry, 0, sizeof(*entry));
}
out:
tr_dbg(fast_get, "put %p, DRAM %p size %u refcnt %u", sram_ptr, entry ? entry->dram_ptr : 0,
entry ? entry->size : 0, entry ? entry->refcount : 0);
Expand Down
Loading