Repository navigation
sched, mm: SMP fixes and BMP (threads bound to one CPU) - #22047
santhosh-c-c wants to merge 4 commits into
Conversation
|
May I ask why bringing up the BMP? didn't we agree that we wouldn't submit our boot code—leaving that for you to submit instead—and that we would then submit the BMP after making our own modifications? |
"BMP solution has no plan to merge into community for now" - This is from official email/document which we recieved from xiaomi during August/September timeline. If I may ask, what is the conflict here? Thanks |
yes, we have talk about this #21977 (comment) |
|
Could you clarify your plans for any upcoming feature pushes? Based on our previous discussions, our understanding was that you would handle the integration work—specifically removing the iLLD and incorporating the new drivers—while we would take care of the rest. but seem you have now pushed the BMP, which conflicts with the work we currently have in progress. |
We have initiated a discussion with Infineon to arrange a common meeting to organize the next steps and to avoid duplicated efforts. Otherwise, the origninal plan is to bring all the changes from our internal downstream https://gitlab.com/linumiz/infineon/release/nuttx-aurix to upstream. To summarize, so far https://gitlab.com/linumiz/infineon/release/nuttx-aurix/-/releases/v11.1.0-tricore with v11 release, most drivers and base is completed. If you would like open a quick chat now, I am available in Discord in NuttX channel as well - discord id: parthitce |
Xiaomi start developing BMP from 2025 Q2, the code is preparing upstream in the upcoming week. @zyfeier even has a topic about BMP in this year workshop: https://events.nuttx.apache.org/ From this patchset, your BMP implementation is in the very early stage, why do your team waste time to duplicate the work what Xiaomi already done from Tricore and then BMP? |
AFAIK there is no public sources available for BMP except #12020 and #12032. Also there wasn't any placeholders / DRAFT's in open state as of today which is active. Also BMP from our end is also was in development over the past months. Good luck with the workshop.
Sure, please suggest / review, we can improve the design and implementations. Looking forward.
Well likewise? As mentioned in my previous message here #22047 (comment), efforts for TriCore downstream is available in public from Linumiz. Ideal goal is to get all the efforts upstream gradually. We are happy to align to avoid further duplicated efforts. |
xiaoxiang781216
left a comment
There was a problem hiding this comment.
don't duplicate the work from other team.
Other team? @santhosh-c-c is from Linumiz. Otherwise, do we have a cocept of projects like Zephyr RTOS does? For example, we have the kanban for Zephyr TriCore here Infineon TriCore Aurix. If that's quick, we can create one and orchestrate from there? |
Other team mean Xiaomi. let's discuss on @zyfeier 's pr in the next week. |
GUIDINGLI
left a comment
There was a problem hiding this comment.
Sorry, clicked by mistake. Revoking my approval.
|
BTW, BMP is a general feature which shouldn't couple with tricore and start from sched and general arch interface, please drop ALL tricore specific change from this PR. |
Thanks for the review, I will address this by splitting the PR. |
Our work is based on these two patchset which come from @anchao. |
@xiaoxiang781216 I would rather propose to align in this PR. Thanks. |
Since your work isn't complete, can your BMP patchset run with the full network/filesystem stack on arm32 A/R/M, arm64 A/R? Why not align your work on the more mature and production implementation? |
The BMP part is minimal in sched/ on top of CONFIG_SMP and adds no arch code, so it is meant to run wherever NuttX SMP runs, with the same network and file system stack. As requested, I will split the TriCore parts out of this PR. |
| @@ -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 | |||
There was a problem hiding this comment.
this isn't real BMP, why not set affinity before create thread/task? which don't require to modify sched code.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
No, let's clarify the term:
SMP: one code and data manage multiple core
AMP: different code and data manage single core
BMP: one code and different data manage single core
There was a problem hiding this comment.
Thanks for clarifying. Is there a reference for these definitions?
There was a problem hiding this comment.
here: https://www.ghs.com/products/safety_critical/integrity_178_multicore.html
BTW, as far as I know, that tricore doesn't support the hardware cache coherence and then SMP can't work reliable on it. So, I’m curious how this PR manages to work reliably.
There was a problem hiding this comment.
Thanks, that page says the same: BMP is an enhanced and restricted form of SMP that statically binds an application's tasks to specific cores, with one kernel running across all cores (SMP). That is what this PR does.
On cache coherence: right, the TriCore data cache is not coherent, so with SMP the data cache is bypassed on all CPUs (DCON0.DCBYP, set in the boot code of every CPU). Kernel data is in the DLMU (uncached through the bypass) and stacks/heap in the DSPR (never cached), only the program cache stays on, which is safe for read-only flash code.
There was a problem hiding this comment.
Thanks, that page says the same:
BMP is an enhanced and restricted form of SMP that statically binds an application's tasks to specific cores, with one kernel running across all cores (SMP). That is what this PR does.
but it's still SMP with minor affinity change:
- No isolation between the cpu
- crash on one cpu impact other cpu
- the performance is poor than UP and BMP
On cache coherence: right, the TriCore data cache is not coherent, so with SMP the data cache is bypassed on all CPUs (DCON0.DCBYP, set in the boot code of every CPU). Kernel data is in the DLMU (uncached through the bypass) and stacks/heap in the DSPR (never cached), only the program cache stays on, which is safe for read-only flash code.
So, the performance isn't good, I would suggest you select other name for this feature and reserve BMP to the real implementation which:
- data is isolated between cpu
- one cpu crash doesn't impact other cpu
- data cache can be enabled without hardware cache coherence
- performance is same as UP and much better than SMP
and it's required for automative application.
So it isn't a real BMP, please choice another name to avoid the confusion. |
Return -EINVAL for a NULL mask or a wrong size instead of writing through the pointer when assertions are off. Signed-off-by: Santhosh Charles <santhosh@linumiz.com>
All CPUs shared one smp_call_data_s. When the time slices of tasks on two CPUs ended in the same tick, the second init cleared the data while it was still queued for the first CPU, and the pid of the first call was lost. Keep one call per target CPU and do not queue it again until that CPU has handled it. Signed-off-by: Santhosh Charles <santhosh@linumiz.com>
A thread that exits frees its own stack while it still runs on it, so the free goes to the delay list of its CPU. Only a malloc on that same CPU ever freed that list, so a CPU that never calls malloc kept the memory forever and the heap ran out (ENOMEM in ostest on a 64 KiB heap). When malloc fails, take the lists of every CPU and free them before giving up. A spinlock now guards the lists, since any CPU may empty them. Signed-off-by: Santhosh Charles <santhosh@linumiz.com>
With BMP one kernel runs on all CPUs, but every task stays on one CPU. A new task or thread runs on the CPU of its creator, or on the single CPU named in its attributes. An affinity must name exactly one CPU that exists, and a task that has started cannot move to another CPU. The scheduler never moves a task. nxsched_set_affinity() now also returns -EINVAL for a NULL mask, a wrong size or a mask without any existing CPU. SCHED_ALL_CPUS moves to sched.h so these checks can use it. Signed-off-by: Santhosh Charles <santhosh@linumiz.com>
343e86a to
9f894f3
Compare
|
@xiaoxiang781216 @zhangyu981027 @anchao As requested, I have split the PR:
On the name: I used |
As I said before, BMP need reserve to the real implementation to avoid confusing with Your implementation which is a very simple addition on top of SMP. |
jerpelea
left a comment
There was a problem hiding this comment.
please send the mm changes in a separate PR
|
@santhosh-c-c #22261 is the first part of real BMP implementation. |
| #endif | ||
|
|
||
| #if defined(CONFIG_SMP) && (defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)) | ||
| else if (free_delaylist_all(heap)) |
There was a problem hiding this comment.
but it's dangerous to free the memory blindly
There was a problem hiding this comment.
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.
| #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]; |
There was a problem hiding this comment.
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.


Summary
Fixes found while bringing up SMP, needed by any SMP user:
BMP on top of CONFIG_SMP (sched only, no arch code), following the
QNXmeaning of the term: one kernel, threads bound to a CPU.Impact
New option CONFIG_BMP (depends on SMP, default n). Builds without it are unchanged apart from the three fixes above.