fix(ulog): 修复异步 ulog 空唤醒与通知丢失问题,并优化告警输出 #11183
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
在此前的异步 ulog 实现中,存在以下问题:
在调用
rt_ringbuffer_put()之后,无论是否实际写入数据,都会释放通知信号量。当 ringbuffer 已满、写入长度为 0 时,
消费线程仍会被唤醒,导致空唤醒和不必要的调度开销。
ulog_async_waiting_log()在等待信号量前对其进行了 reset。如果生产者在 reset 之前刚好释放了信号量,该通知可能被清除,
从而导致唤醒丢失,异步日志处理被延迟。
此外,ulog 中存在多处重复的“只打印一次”警告逻辑,缺乏统一说明,
在高并发场景下也可能引发理解歧义。
你的解决方案是什么 (what is your solution)
仅在 ringbuffer 实际写入数据(
put_len > 0)后才释放通知信号量,确保每次唤醒都对应有效的日志数据,避免空唤醒。
移除
ulog_async_waiting_log()中对信号量的 reset,避免清除已有通知, 防止唤醒丢失。在异步 buffer 饱和导致部分写入时,输出一次性(best-effort)的告警提示。
新增轻量级
ulog_warn_once()辅助函数, 统一告警输出逻辑。Commit 1:整理并统一告警输出逻辑,仅涉及诊断信息,不影响异步唤醒语义。
Commit 2:修复异步 ulog 的唤醒与通知处理逻辑,避免空唤醒和通知丢失
请提供验证的bsp和config (provide the config and bsp)
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up