Repository navigation
sched, mm: SMP fixes and BMP (threads bound to one CPU) #22047
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
base: master
Are you sure you want to change the base?
Changes from all commits
0b4be2d
ccd7eed
86e8582
9f894f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,7 +46,8 @@ | |
| ****************************************************************************/ | ||
|
|
||
| #ifdef CONFIG_SMP | ||
| static struct smp_call_data_s g_call_data; | ||
| static struct smp_call_data_s g_call_data[CONFIG_SMP_NCPUS]; | ||
| static volatile bool g_call_pending[CONFIG_SMP_NCPUS]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's define by DEFINE_PER_CPU_BSS_SMP https://github.com/apache/nuttx/pull/22261/changes#diff-c52fe2ff2c90e3d863728334401a22b53dc58457840d6242af67c5a62d381cbdR104, so the framework will layout all percpu in one continue block on each cpu for better cache utilization. |
||
| #endif | ||
|
|
||
| /**************************************************************************** | ||
|
|
@@ -69,6 +70,7 @@ static int nxsched_roundrobin_handler(FAR void *cookie) | |
| irqstate_t flags; | ||
|
|
||
| flags = enter_critical_section(); | ||
| g_call_pending[this_cpu()] = false; | ||
| tcb = nxsched_get_tcb(pid); | ||
|
|
||
| if (!tcb || tcb->task_state == TSTATE_TASK_INVALID || | ||
|
|
@@ -195,10 +197,15 @@ clock_t nxsched_process_roundrobin(FAR struct tcb_s *tcb, clock_t ticks, | |
| DEBUGASSERT(tcb->task_state == TSTATE_TASK_RUNNING); | ||
| if (tcb->cpu != this_cpu()) | ||
| { | ||
| nxsched_smp_call_init(&g_call_data, | ||
| nxsched_roundrobin_handler, | ||
| (FAR void *)(uintptr_t)tcb->pid); | ||
| nxsched_smp_call_single_async(tcb->cpu, &g_call_data); | ||
| if (!g_call_pending[tcb->cpu]) | ||
| { | ||
| g_call_pending[tcb->cpu] = true; | ||
| nxsched_smp_call_init(&g_call_data[tcb->cpu], | ||
| nxsched_roundrobin_handler, | ||
| (FAR void *)(uintptr_t)tcb->pid); | ||
| nxsched_smp_call_single_async(tcb->cpu, | ||
| &g_call_data[tcb->cpu]); | ||
| } | ||
| } | ||
| else if (nxsched_switch_running(tcb->cpu, true)) | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,7 +82,13 @@ int nxsched_set_affinity(pid_t pid, size_t cpusetsize, | |
|
|
||
| /* Make sure that affinity mask is valid */ | ||
|
|
||
| if (*mask == 0) | ||
| #ifdef CONFIG_BMP | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this isn't real BMP, why not set affinity before create thread/task? which don't require to modify sched code.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The sched change makes the binding enforced instead of a convention, the kernel refuses multi-CPU masks and moving a running task, so a missed affinity attribute cannot break it.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you reuse SMP_DEFAULT_CPUSET==0 to trigger this special mode instead reusing BMP? BMP is better to reserve for the real bound multiple process.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The BMP name follows QNX, which uses it for a single kernel instance with tasks bound by affinity [1]. One instance per core, as in #12020/#12032, is AMP in the same QNX terms, so I would prefer to keep BMP for this one. [1] https://www.qnx.com/developers/docs/8.0/com.qnx.doc.neutrino.prog/topic/multicore.html
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you study #12020 or some AutoSAR implementation? the approach in this PR isn't the real BMP mode, so please don't reuse this name which just make confusion, and incorporate your special action into SMP_DEFAULT_CPUSET==0 is a good choice.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, let's clarify the term:
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for clarifying. Is there a reference for these definitions?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here: https://www.ghs.com/products/safety_critical/integrity_178_multicore.html
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, that page says the same:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
but it's still SMP with minor affinity change:
So, the performance isn't good, I would suggest you select other name for this feature and reserve BMP to the real implementation which:
and it's required for automative application. |
||
| if (mask == NULL || cpusetsize != sizeof(cpu_set_t) || *mask == 0 || | ||
| (*mask & ~SCHED_ALL_CPUS) != 0 || (*mask & (*mask - 1)) != 0) | ||
| #else | ||
| if (mask == NULL || cpusetsize != sizeof(cpu_set_t) || *mask == 0 || | ||
| (*mask & SCHED_ALL_CPUS) == 0) | ||
| #endif | ||
| { | ||
| return -EINVAL; | ||
| } | ||
|
|
@@ -115,6 +121,15 @@ int nxsched_set_affinity(pid_t pid, size_t cpusetsize, | |
| goto errout_with_csection; | ||
| } | ||
|
|
||
| #ifdef CONFIG_BMP | ||
| if (tcb->task_state != TSTATE_TASK_INACTIVE && | ||
| *mask != ((cpu_set_t)1 << tcb->cpu)) | ||
| { | ||
| ret = -EINVAL; | ||
| goto errout_with_csection; | ||
| } | ||
| #endif | ||
|
|
||
| /* Set the new affinity mask. */ | ||
|
|
||
| tcb->affinity = *mask; | ||
|
|
||
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.
but it's dangerous to free the memory blindly
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 better approach is export delay free api and call it in idle loop. please wait @huojianchaoyy upstream the patch which make delay free publicly, so you can fix this problem easier.