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
xtensa/esp32: When PSRAM is enabled allow drivers and tasks to allocate memory from a separate internal memory #1958
Conversation
allocated in an internal heap. Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
… from DRAM when the given buffer is from PSRAM. Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
memory region is available. Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
warning that's not relevant anymore. Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
@@ -73,6 +73,18 @@ | |||
#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) | |||
#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) | |||
|
|||
#ifdef CONFIG_XTENSA_USE_SEPERATE_IMEM |
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.
I see these macros are used in some places, and they are defined in multi *.c
files, so maybe we can move these into a new file like xtensa_mm.h
,and let these *.c
include xtensa_mm.h
.
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.
These macros come from config.h (which is generated based on the .config file created by Kconfig tools)
*.c files include the config.h and use the macros.
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.
Ah I see what macros you are talking about, Github confused me.
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.
@donghengqaz done. PTAL.
arch/xtensa/src/esp32/esp32_spi.c
Outdated
if (esp32_ptr_extram(txbuffer)) | ||
{ | ||
tp = up_imm_malloc(bytes); | ||
if (tp == NULL) |
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.
Because the esp32_spi_dma_exchange
can't return error code tell callers that the function failed, so maybe we add an assert
function here ?
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.
something like the following?
if (esp32_ptr_extram(txbuffer))
{
tp = up_imm_malloc(bytes);
- if (tp == NULL)
- {
- return;
- }
+ DEBUGASSERT(tp != NULL);
}
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.
Done.
arch/xtensa/src/esp32/esp32_spi.c
Outdated
rp = up_imm_malloc(bytes); | ||
if (rp == NULL) | ||
{ | ||
goto error_with_tp; |
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.
Same as above.
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.
Done.
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
code, assert the return of the imm_malloc function. Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
to be 4 bytes. Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
range 0x2000 0x28000 | ||
default 0x28000 | ||
|
||
config XTENSA_IMEM_PROCFS |
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.
i feel it's more convenient for users to have this info in /proc/meminfo than the dedicated file. how do you think?
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.
I was concerned that this change would be too "invasive" in procfsmeminfo. This feature is "too" Xtensa/ESP32 specific.
arch/xtensa/Kconfig
Outdated
@@ -81,6 +81,21 @@ config XTENSA_CP_INITSET | |||
is provided by CONFIG_XTENSA_CP_INITSET. Each bit corresponds to one | |||
coprocessor with the same bit layout as for the CPENABLE register. | |||
|
|||
config XTENSA_USE_SEPERATE_IMEM | |||
bool "Use a seperate heap for internal memory" |
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.
i guess the description should at least explain:
- what's internal memory
- what uses the memory if this config is enabled
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.
I'll add a help section.
arch/xtensa/src/esp32/esp32_spi.c
Outdated
if (esp32_ptr_extram(txbuffer)) | ||
{ | ||
tp = up_imm_malloc(bytes); | ||
DEBUGASSERT(tp != NULL); |
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.
don't you need memcpy here?
(i don't understand what this function is doing. just a wild guess.)
arch/xtensa/src/esp32/esp32_spi.c
Outdated
if (esp32_ptr_extram(rxbuffer)) | ||
{ | ||
memcpy(rxbuffer, rp, bytes); | ||
up_imm_free(rp); |
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.
tp and rp are modified above. (tp += n)
i guess you should free the original pointer.
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.
Indeed. Thanks, done.
arch/xtensa/src/esp32/esp32_spi.c
Outdated
#ifdef CONFIG_XTENSA_USE_SEPERATE_IMEM | ||
if (esp32_ptr_extram(txbuffer)) | ||
{ | ||
up_imm_free(tp); |
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.
ditto
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.
Done
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
bool up_imm_heapmember(FAR void *mem); | ||
int up_imm_mallinfo(FAR struct mallinfo *info); | ||
#endif | ||
|
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.
The naming up_imm_* does not follow the NuttX naming conventions. These should all be xtensa_imm_* . See https://cwiki.apache.org/confluence/display/NUTTX/Naming+of+Architecture%2C+MCU%2C+and+Board+Interfaces
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.
The prefix up_ is reserved only for MCU interfaces called directly by the OS and prototyped in included/nuttx/*.h (usually arch.h)
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.
Originally I had in mind that maybe other architectures would need the same functionality and that prototypes would go to one of the locations you mentioned.
But I didn't follow with that and forgot to rename the functions. Thanks for the reminder. Fixed!
@@ -77,8 +77,13 @@ | |||
void up_allocate_heap(FAR void **heap_start, size_t *heap_size) | |||
{ | |||
board_autoled_on(LED_HEAPALLOCATE); | |||
#ifdef CONFIG_XTENSA_USE_SEPERATE_IMEM |
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.
A small typo: SEPERATE -> SEPARATE
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.
Done
@@ -73,6 +73,18 @@ | |||
#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) | |||
#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) | |||
|
|||
#ifdef CONFIG_XTENSA_USE_SEPERATE_IMEM |
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.
SEPERATE -> SEPARATE
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.
Done
arch/xtensa/Kconfig
Outdated
@@ -81,6 +81,16 @@ config XTENSA_CP_INITSET | |||
is provided by CONFIG_XTENSA_CP_INITSET. Each bit corresponds to one | |||
coprocessor with the same bit layout as for the CPENABLE register. | |||
|
|||
config XTENSA_USE_SEPERATE_IMEM |
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.
A small typo: SEPERATE -> SEPARATE
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.
Done.
arch/xtensa/Kconfig
Outdated
config XTENSA_IMEM_PROCFS | ||
bool "Internal memory PROCFS support" | ||
default n | ||
depends on XTENSA_USE_SEPERATE_IMEM && !DISABLE_MOUNTPOINT && FS_PROCFS && FS_PROCFS_REGISTER |
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.
please align "depends on" below "default n"
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.
I think this is just a Github glitch. You can see the file here: https://github.com/apache/incubator-nuttx/blob/7b1234bb38379c5ce28c3ffefa82c4f6b4b42e0d/arch/xtensa/Kconfig
7b1234b
to
8eb6b04
Compare
be prefixed by xtensa_ instead of up_. Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
Summary
When external RAM and external FLASH are used together we have to make sure that:
const
variables aren't in .ro.data.Impact
Impacts ESP32 when both PSRAM and SPIFLASH are enabled.
Testing
esp32-core:spiflash with PSRAM enabled and disabled.