Skip to content

sched, mm: SMP fixes and BMP (threads bound to one CPU) - #22047

Open
santhosh-c-c wants to merge 4 commits into
apache:masterfrom
linumiz:tricore-bmp-upstream
Open

santhosh-c-c wants to merge 4 commits into
apache:masterfrom
linumiz:tricore-bmp-upstream

Conversation

@santhosh-c-c

@santhosh-c-c santhosh-c-c commented Nov 19, 2026 •

Copy link
Copy Markdown

Summary

Fixes found while bringing up SMP, needed by any SMP user:

  • sched: roundrobin: use one SMP call per CPU. All CPUs shared one smp_call_data_s, so a second request overwrote the first.
  • mm: heap: free the delay lists of all CPUs on SMP. An exiting thread frees its stack into the delay list of its CPU. Only a malloc on that same CPU frees that list, so a CPU that never allocates again keeps the memory (ENOMEM in ostest on a 64 KiB heap). When malloc fails, the lists of all CPUs are now freed before giving up.
  • sched: check the mask of nxsched_get_affinity().

BMP on top of CONFIG_SMP (sched only, no arch code), following the QNX meaning of the term: one kernel, threads bound to a CPU.

  • a new task or thread runs on the CPU of its creator, or on the single CPU named in its creation attributes
  • an affinity mask must name exactly one existing CPU
  • a task that has started cannot move to another CPU (sched_setaffinity() returns -EINVAL)

Impact

New option CONFIG_BMP (depends on SMP, default n). Builds without it are unchanged apart from the three fixes above.

@zhangyu981027

Copy link
Copy Markdown
Contributor

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?

@parthitce

Copy link
Copy Markdown
Contributor

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

@zhangyu981027

Copy link
Copy Markdown
Contributor

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)

@zhangyu981027

Copy link
Copy Markdown
Contributor

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.

@parthitce

Copy link
Copy Markdown
Contributor

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

@xiaoxiang781216

xiaoxiang781216 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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

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/
image

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?

@parthitce

Copy link
Copy Markdown
Contributor

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

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/ image

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.

From this patchset, your BMP implementation is in the very early stage,

Sure, please suggest / review, we can improve the design and implementations. Looking forward.

why do your team waste time to duplicate the work what Xiaomi already done from Tricore and then BMP?

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.

GUIDINGLI
GUIDINGLI previously approved these changes Nov 19, 2026

@xiaoxiang781216 xiaoxiang781216 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

don't duplicate the work from other team.

@parthitce

Copy link
Copy Markdown
Contributor

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?

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

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 GUIDINGLI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry, clicked by mistake. Revoking my approval.

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

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.

@santhosh-c-c

Copy link
Copy Markdown
Author

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.

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

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

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/ image

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.

Our work is based on these two patchset which come from @anchao.

@parthitce

Copy link
Copy Markdown
Contributor

Other team mean Xiaomi. let's discuss on @zyfeier 's pr in the next week.

@xiaoxiang781216 I would rather propose to align in this PR. Thanks.

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

Other team mean Xiaomi. let's discuss on @zyfeier 's pr in the next week.

@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?

@santhosh-c-c

Copy link
Copy Markdown
Author

Other team mean Xiaomi. let's discuss on @zyfeier 's pr in the next week.

@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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

@santhosh-c-c santhosh-c-c Nov 20, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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

@xiaoxiang781216 xiaoxiang781216 Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for clarifying. Is there a reference for these definitions?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

@xiaoxiang781216 xiaoxiang781216 Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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:

  1. No isolation between the cpu
  2. crash on one cpu impact other cpu
  3. 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:

  1. data is isolated between cpu
  2. one cpu crash doesn't impact other cpu
  3. data cache can be enabled without hardware cache coherence
  4. performance is same as UP and much better than SMP

and it's required for automative application.

@xiaoxiang781216

xiaoxiang781216 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Other team mean Xiaomi. let's discuss on @zyfeier 's pr in the next week.

@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.

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>
@santhosh-c-c santhosh-c-c changed the title arch/tricore: Add SMP and BMP support sched, mm: SMP fixes and BMP (threads bound to one CPU) Nov 24, 2026
@santhosh-c-c

Copy link
Copy Markdown
Author

@xiaoxiang781216 @zhangyu981027 @anchao As requested, I have split the PR:

On the name: I used BMP in the QNX sense, one kernel instance with threads bound to a CPU, I would prefer to keep it this way. Please take a look, Thanks

@xiaoxiang781216

xiaoxiang781216 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

@xiaoxiang781216 @zhangyu981027 @anchao As requested, I have split the PR:

On the name: I used BMP in the QNX sense, one kernel instance with threads bound to a CPU, I would prefer to keep it this way. Please take a look, Thanks

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 jerpelea left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please send the mm changes in a separate PR

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

@santhosh-c-c #22261 is the first part of real BMP implementation.

Comment thread mm/mm_heap/mm_malloc.c
#endif

#if defined(CONFIG_SMP) && (defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__))
else if (free_delaylist_all(heap))

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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.

#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];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants