Repository navigation
schedule: zephyr_dma_domain: Make thread priority higher - #7367
Conversation
There was a problem hiding this comment.
Is there any central place where this define might be more appropriate? So as to be able to decide on ordering some things.
I like the idea behind the patch.
There was a problem hiding this comment.
@LaurentiuM1234 how did you decide on value 5?
How to you know the priority is less than logging?
There was a problem hiding this comment.
@LaurentiuM1234 how did you decide on value 5?
I guess it does look kinda random. I chose this value based on the following criteria: the thread's priority needs to be higher than the logging thread's (which is either the lowest or some custom value set by the user) but lower than highest priority of the threads used by SOF (which if I'm not mistaken is 1: edf scheduler's thread).
How to you know the priority is less than logging?
If not set to some other value by the user, the logging thread's priority is the lowest: CONFIG_NUM_PREEMPT_PRIORITIES - 1 so this case is covered. In the case user does decide to change the logging thread's priority then this solution will not hold if he/she sets it to a value lower than 5. In this case I thought of 2 options:
- Make ZEPHYR_DMA_DOMAIN_PRIO dependent on the logging thread's priority. Kinda like:
ZEPHYR_DMA_DOMAIN_PRIO = LOGGING_THREAD_PRIO - 1. This might be problematic if the user sets LOGGING_THREAD_PRIO to highest priority possible (a negative value) (not sure why you'd do that) as ZEPHYR_DMA_DOMAIN_PRIO would go out of bounds so an additional check may be required. Also, this might cause problems with the other threads as the zephyr dma domain thread may have a higher priority than them in which case I can't guarantee this won't affect the flow. - Add some sanity checks. Kinda like:
if (ZEPHYR_DMA_DOMAIN_PRIO > LOGGING_THREAD_PRIO) {
pr_warn("Some warning message here.");
}
Personally I prefer number 2.
Is there any central place where this define might be more appropriate? So as to be able to decide on ordering some things.
I like the idea behind the patch.
I think it would be best to keep the macro in zephyr_dma_domain.c as it's specific to it. It should be grouped with SEM_LIMIT and ZEPHYR_PDOMAIN_STACK_SIZE kinda like:
#define SEM_INIT 1
#define ZEPHYR_PDOMAIN_STACK_SIZE 8192
#define ZEPHYR_DMA_DOMAIN_THREAD_PRIO 5
I'll make sure to rectify this.
There was a problem hiding this comment.
Could this be based on a Zephyr Kconfig around the logging thread priorty ? e.g. have a Kconfig to make the Zephyr logging preemptive so that DMA pipeline preempts logging ?
There was a problem hiding this comment.
You could do that if you know that it always needs to be one greater than logging for example. The logging process thread by default is set to the lowest preemptible priority if not explicitly configured (priority K_LOWEST_APPLICATION_THREAD_PRIO)
#define ZEPHYR_DMA_DOMAIN_THREAD_PRIO CONFIG_LOG_PROCESS_THREAD_PRIORTY-1Otherwise the way I might go about it is exposing both to Kconfig and in the build Kconfig .prj file putting all the prio's nicely next to each other with some comments around it.
A BUILD_ASSERT() can be done with this as well to ensure that DMA_PRIO > LOG_PRIO at build time if you like.
BUILD_ASSERT(CONFIG_DMA_DOMAIN_THREAD_PRIO < CONFIG_LOG_PROCESS_THREAD_PRIORITY, "Some nice messaging here about why");There was a problem hiding this comment.
@teburd Thanks for the suggestion ! Should be a bit better now.
There was a problem hiding this comment.
Could this be based on a Zephyr Kconfig around the logging thread priorty ? e.g. have a Kconfig to make the Zephyr logging preemptive so that DMA pipeline preempts logging ?
This commit adds ZEPHYR_DMA_DOMAIN_THREAD_PRIO macro which holds the value of the thread priority for Zephyr DMA domain. Signed-off-by: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>
… higher Zephyr DMA domain thread should have a higher priority than the logging thread. Not meeting this criteria may cause problems such as buzzing noises after resuming a paused stream. This was the case on i.MX93. Signed-off-by: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>
|
Thanks for all the feedback. Now the DMA domain's thread priority depends on the logging thread's priority. This way we won't have to use a hardcoded value which seems random. Also, it's important to note that the Zephyr DMA domain's thread priority doesn't necessarily need to be @lgirdwood would it be problematic if the Zephyr DMA domain thread has a lower priority than edf_scheduler's thread priority? I did a small pause/resume test with Zephyr DMA domain thread priority = 0 and it seemed to work fine. If this wouldn't pose a problem I can remove this part of the comment: |
|
Can one of the admins verify this patch? |
|
I don't feel comfortable linking the DMA domain thread priority with the DMA thread log priority. I would go the other way around. define the DMA log thread priority based on the DMA domain thread priority and issue a build warning if the link cannot be done. |
|
@dbaluta Is the log process thread priority being set? If not and its not the lowest priority then.. that seems like a different issue. |
Seems more problematic. I'm not sure there's a reason right now to set the logging thread's priority to something !=
Is there a particular reason for this? I wouldn't mind making the logging thread's priority depend on the DMA thread's priority or setting them both to some values in the board's .config but I'm not sure I get the problem with the current solution.
It's not |
|
Marked this as a draft as the same test case used for testing Zephyr DMA domain fails. |
|
@LaurentiuM1234 Are you able to run one of the tracing tools (e.g. tracealyzer, tracecompass)? Those are invaluable for understanding whats running when and this sounds like a problem that could be greatly helped by that perhaps? |
|
Re-did the test and it seems to work fine. Reached about 368 rounds before stopping it manually. The issue because of which I marked this as a draft was probably caused by some mistake I've made during testing (e.g: not updating the .ri). The environment I've used is the following:
@dbaluta Let me know if you want me to test something else. Otherwise, I can remove the [DNM] tag and we can merge this. |
|
@lgirdwood this ready to be merged. |
| NULL, | ||
| NULL, | ||
| CONFIG_NUM_PREEMPT_PRIORITIES - 1, | ||
| ZEPHYR_DMA_DOMAIN_THREAD_PRIO, |
There was a problem hiding this comment.
why are you actually using such a low priority (a high priority number) for the DMA domain? With the Zephyr domain we use the highest available priority -CONFIG_NUM_COOP_PRIORITIES
There was a problem hiding this comment.
It's mostly due to the fact that its priority being in the preemptive range hasn't caused us any issues that I'm aware of. I think we can leave this in the preemptive range and switch over to cooperative range if there's ever a reason to.
|
@wszypelt @lgirdwood This is not touching code used in Intel configurations, so overriding the Intel checks to merge this. This has been pending for a long time. |
We need to make the Zephyr DMA domain thread's priorty higher than the logging thread priority. If this is not done we may have some issues such as some buzzing noises appearing after resuming a paused stream. This was the case for i.MX93. Presumably this is because the SAI FIFO is underrun (please correct me if I'm wrong).
This fixes the issue on i.MX93 but will require some more tests to make sure that it doesn't break anything on the other i.MX boards which will use Zephyr DMA domain. This is why I added the [DNM] tag.