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

logging: uart_backend: add uncached async uart buffers support #87846

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

JarmouniA
Copy link
Collaborator

@JarmouniA JarmouniA commented Mar 29, 2025

When async UART is used & DCache is enabled, some SoCs, like STM32H7, require UART buffers to be placed in nocache memory to avoid cache coherence issues.

__nocache attribute will have no effect if CONFIG_NOCACHE_MEMORY=n

Fixes #87795

When async UART is used & DCache is enabled, some SoCs, like STM32H7,
require UART buffers to be placed in nocache memory to avoid cache
coherence issues.

Fixes issue 87795

Signed-off-by: Abderrahmane JARMOUNI <git@jarmouni.me>
Enable the sample to run on stm32h750b-dk board with async
UART backend

Signed-off-by: Abderrahmane JARMOUNI <git@jarmouni.me>
@JarmouniA JarmouniA marked this pull request as ready for review March 29, 2025 14:28
@github-actions github-actions bot requested review from dcpleung, kartben and nashif March 29, 2025 14:29
(.uart_dev = DEVICE_DT_GET(node_id),)) \
.data = &lbu_data##__VA_ARGS__, \
(.uart_dev = DEVICE_DT_GET(node_id),)) .data = \
&lbu_data##__VA_ARGS__, \
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep Clang-format happy :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to add this, clang-format isn't enforced.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it doesn't pass in CI too, is that okey?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's excluded in CI

./scripts/ci/check_compliance.py --annotate -e KconfigBasic -e SysbuildKconfigBasic -e ClangFormat \

@JarmouniA JarmouniA added the bug The issue is a bug, or the PR is fixing a bug label Mar 29, 2025
@@ -225,8 +225,15 @@ const struct log_backend_api log_backend_uart_api = {
.format_set = format_set,
};

#ifdef CONFIG_LOG_BACKEND_UART_ASYNC
Copy link
Collaborator Author

@JarmouniA JarmouniA Mar 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add && (defined(CONFIG_SOC_SERIES_STM32H7X) || defined(CONFIG_SOC_SERIES_STM32H7RSX)) here as well since it's the (only) series concerned by this AFAIK.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting buffer in __nocache will help but it will slow down the performance. Maybe it would be better to use STM guards for now. Other vendors may prefer to use cache line aligned memory and do the cache writeback which would have better performance. Nordic is using different appraoch. We have generic module used in drivers that detects if input buffer requires special action and uses memory pool to allocate buffer from a special location, do the copy and writeback if necessary.

#ifdef CONFIG_LOG_BACKEND_UART_ASYNC
#define NOCACHE_ATTR __nocache
#else
#define ALIGN_BUF
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this used somewhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, just a leftover, will remove.

@@ -225,8 +225,15 @@ const struct log_backend_api log_backend_uart_api = {
.format_set = format_set,
};

#ifdef CONFIG_LOG_BACKEND_UART_ASYNC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting buffer in __nocache will help but it will slow down the performance. Maybe it would be better to use STM guards for now. Other vendors may prefer to use cache line aligned memory and do the cache writeback which would have better performance. Nordic is using different appraoch. We have generic module used in drivers that detects if input buffer requires special action and uses memory pool to allocate buffer from a special location, do the copy and writeback if necessary.

@JarmouniA JarmouniA requested a review from erwango March 31, 2025 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Logging area: Samples Samples bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Uart log backend with async API does not work on STM32H750
3 participants