Repository navigation
arch/tricore: Add SMP/BMP support - #22246
Open
santhosh-c-c wants to merge 16 commits into
Open
santhosh-c-c wants to merge 16 commits into
santhosh-c-c wants to merge 16 commits into
Conversation
ARCH_CHIP_TC3XX and ARCH_CHIP_TC4XX are two independent options with a prompt, so a configuration can enable both families, or none, and then ARCH_CHIP has no value. Make them a choice, named after the family as ARCH_CHIP_TC3X and ARCH_CHIP_TC4X like the arm chip choice (ARCH_CHIP_STM32F4, ARCH_CHIP_SAMV7), and update their users and the two board configurations. Signed-off-by: Saravanan Sekar <saravanan@linumiz.com>
The TC3xx chip option ARCH_CHIP_TC39X names the TC39x series. Name it after the part of the a2g-tc397-5v-tft board, ARCH_CHIP_TC397, as the arm chips do (ARCH_CHIP_STM32F407VG), so that further TC3xx parts can be added to its choice, and update the board dependency and configuration. The TC4xx option ARCH_CHIP_TC4DX keeps its name. Both chip choices get a plain prompt. Signed-off-by: Saravanan Sekar <saravanan@linumiz.com>
The ASCLIN UART driver is common to TC3xx and TC4xx, but each family has its own option for it, TC3XX_UART0 and TC4XX_UART0, which the driver has to combine. Replace both with TRICORE_UART0 in a new src/common/aurix/Kconfig, for the options of the common AURIX drivers. It keeps the default of y, so the board configurations do not change. Signed-off-by: Saravanan Sekar <saravanan@linumiz.com>
The public chip.h of TC3xx and TC4xx has been empty since the system timer, ASCLIN and startup definitions moved to the internal headers, and only the UART driver still includes it. Drop both headers and that include. Signed-off-by: Saravanan Sekar <saravanan@linumiz.com>
The chip family options are ARCH_CHIP_TC3X and ARCH_CHIP_TC4X, but the chip and board directories, file names and identifiers still use tc3xx and tc4xx. Rename arch/tricore/src, arch/tricore/include, boards/tricore and Documentation/platforms/tricore tc3xx and tc4xx to tc3x and tc4x, ARCH_CHIP with them, the chip file names and the tc3xx_, tc4xx_, TC3XX_ and TC4XX_ prefixes, keeping the aligned columns. The board names stay. The chip and board directories both follow ARCH_CHIP, so they move in one step. No functional change. The Make.defs files move together with their CMakeLists.txt, and the board Make.defs only change the Toolchain.defs path, which CMake takes from ARCH_CHIP [skip-cmake-parity]. Signed-off-by: Saravanan Sekar <saravanan@linumiz.com>
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>
After tricore_clockconfig() the STM of CPU0 counts at the system PLL frequency, 500 MHz, but the systimer was set up for SCU_FREQUENCY, 100 MHz. NuttX time then ran five times too fast on TC4x: sleep(5) took one second. Pass the real STM frequency. Signed-off-by: Santhosh Charles <santhosh@linumiz.com>
tricore_doirq() read this_task() before it dispatched the interrupt, so a task that the handler made ready only ran at the next interrupt of that CPU. Read it after the dispatch, as the other ports do. With SMP a CPU without its own tick would else not run a task that another CPU gave it. Signed-off-by: Santhosh Charles <santhosh@linumiz.com>
UP_DMB(), UP_RMB() and UP_WMB() only stopped the compiler. With more than one CPU sharing memory they must also order the accesses on the bus, so make them dsync when SMP is enabled. Single CPU builds keep the plain compiler barrier. Signed-off-by: Santhosh Charles <santhosh@linumiz.com>
On SMP an interrupt must reach the CPU that was chosen for it. Keep that CPU in the TOS field of its SRC: up_affinity_irq() only changes TOS and no longer enables the interrupt, up_disable_irq() only clears the enable bit, and up_enable_irq() keeps the TOS of an SRC that has a CPU and otherwise routes it to the CPU that enables it. An SRC that nobody routed reads TOS 0xf on TC4x, but TOS 0 on TC3x like one routed to CPU0, so TC3x keeps a 256 byte bitmap of the routed SRCs. CPU0 now routes the GPSRs of every CPU to that CPU. Single CPU builds work as before. Signed-off-by: Santhosh Charles <santhosh@linumiz.com>
Each CPU links its own pool of context save areas. When a task moves to another CPU, or one CPU builds the first context of a task for another CPU, frames of one CPU end up in the free list of another, so one CPU slowly loses its frames and finally takes an FCD trap. A frame belongs to the CPU whose data scratchpad RAM holds it. At each context switch a CPU takes back its returned frames and gives back the foreign ones among its first free frames; every 64th switch it checks a low water mark and, when below it, asks the other CPUs by an inter-CPU interrupt to give back its frames. The idle loop does a full pass. tricore_smp.h describes the layout of the secondary CPUs. Signed-off-by: Santhosh Charles <santhosh@linumiz.com>
tricore_wdt_disable() also disabled the system (safety) watchdog when CPU1 or higher called it. The other CPUs may not write that watchdog, and on TC4x the write from CPU1 reset the chip in a loop. Only CPU0 disables it now; every CPU still disables its own watchdog. Signed-off-by: Santhosh Charles <santhosh@linumiz.com>
With SMP the other CPUs run this image instead of their own: CPU0 no longer releases them to __start1 and up at boot, and up_cpu_start() starts them at __start_secondary once the kernel runs. A secondary CPU builds its CSA pool, interrupt stack and idle stack in its own data scratchpad RAM, takes the trap and interrupt vectors of CPU0 and joins as its idle task. CPU0 attaches and enables the GPSR of every CPU pair as inter-CPU interrupt; an IPI is one write to the software broadcast register. On TC4x CPU0 lets every CPU use the interrupt router, the scratchpad RAMs and DLMUs, the STM of CPU0 and the console UART. The data cache stays bypassed, since data in a cached segment would not be coherent. The context switch now also balances the CSA frames and restores the critical section of the new task, and the idle loop waits for an interrupt instead of spinning so it can balance too. The idle stacks of the secondary CPUs are colored like the other stacks, so the stack usage shows right. SMP needs the GNU toolchain, as the secondary entry is only in the GNU startup code; a build with SMP and another toolchain stops with an error. Signed-off-by: Santhosh Charles <santhosh@linumiz.com>
santhosh-c-c
requested review from
Donny9,
GUIDINGLI,
acassis,
anchao,
gustavonihei,
jerpelea,
masayuki2009,
raiden00pl,
wangchdo,
xiaoxiang781216 and
yamt
as code owners
November 24, 2026 08:02
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Runs one SMP kernel on all CPUs of TC3x and TC4x. Today CPU0 releases the other cores to separate images, with CONFIG_SMP they run this image and join the kernel as idle tasks.
Fixes to the existing port, also without SMP:
Dependency
Impact