# FreeRTOS SMP Port to VS

**URL:** <https://forums.freertos.org/t/freertos-smp-port-to-vs/19888>\
**Category:** Kernel\
**Created:** [April 26, 2024, 9:35am UTC](https://forums.freertos.org/t/freertos-smp-port-to-vs/19888 "2024-04-26T09:35:20Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![wuxuangle](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/wuxuangle/32/4503_2.png) [@wuxuangle](https://forums.freertos.org/u/wuxuangle)\
**Post date:** [April 26, 2024, 9:35am UTC](https://forums.freertos.org/t/freertos-smp-port-to-vs/19888/1 "2024-04-26T09:35:20Z")

</div>

I hope to use freertos smp on vs to complete the simulation function of smp. How to operate specifically?

---

<div class="post-metadata">

**Author:** ![wuxuangle](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/wuxuangle/32/4503_2.png) [@wuxuangle](https://forums.freertos.org/u/wuxuangle)\
**Post date:** [April 26, 2024, 9:39am UTC](https://forums.freertos.org/t/freertos-smp-port-to-vs/19888/2 "2024-04-26T09:39:29Z")

</div>

Dear brother，or is there an exiting port file available？

---

<div class="post-metadata">

**Author:** ![wuxuangle](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/wuxuangle/32/4503_2.png) [@wuxuangle](https://forums.freertos.org/u/wuxuangle)\
**Post date:** [April 26, 2024, 9:58am UTC](https://forums.freertos.org/t/freertos-smp-port-to-vs/19888/3 "2024-04-26T09:58:17Z")

</div>

Dear brothers, or how should i transplant? can you provide a detailed list to me?

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [April 26, 2024, 6:14pm UTC](https://forums.freertos.org/t/freertos-smp-port-to-vs/19888/4 "2024-04-26T18:14:09Z")

</div>

> [@wuxuangle](#):
>
> I hope to use freertos smp on vs to complete the simulation function of smp.

Can you elaborate what you mean by VS? Visual Studio (VS) is just a build platform. Are you asking about the FreeRTOS Windows Simulator port? If yes, we do not have SMP port for Windows Simulator. This page provides more details about SMP - [Symmetric Multiprocessing (SMP) with FreeRTOS - FreeRTOS](https://www.freertos.org/symmetric-multiprocessing-introduction.html).

---

<div class="post-metadata">

**Author:** ![wuxuangle](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/wuxuangle/32/4503_2.png) [@wuxuangle](https://forums.freertos.org/u/wuxuangle)\
**Post date:** [April 27, 2024, 2:13am UTC](https://forums.freertos.org/t/freertos-smp-port-to-vs/19888/5 "2024-04-27T02:13:58Z")

</div>

Yes, VS refers to Visual Studio (VS). If there isn’t an off-the-shelf Visual Studio simulation port for FreeRTOS SMP, then I would like to explore with you the feasibility of using Visual Studio (VS) combined with FreeRTOS SMP to simulate SMP behavior. If this is possible, we could preemptively avoid some design risks during the design phase. If the aforementioned idea is feasible, what should I do to implement the simulation port? Or, to implement this port, what specific aspects of work do I need to complete (and it would be great if you could provide a checklist for designing this port)? Lastly, thank you.

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [May 6, 2024, 5:08am UTC](https://forums.freertos.org/t/freertos-smp-port-to-vs/19888/6 "2024-05-06T05:08:12Z")

</div>

> [@wuxuangle](#):
>
> If the aforementioned idea is feasible, what should I do to implement the simulation port?

You need to write SMP port for Windows Simulator. You can use the single core Windows Simulator port as starting point. You can also refer to the existing SMP ports-

- [FreeRTOS-Kernel/portable/ThirdParty/xClang/XCOREAI at main · FreeRTOS/FreeRTOS-Kernel · GitHub](https://github.com/FreeRTOS/FreeRTOS-Kernel/tree/main/portable/ThirdParty/xClang/XCOREAI)
- [FreeRTOS-Kernel/portable/ThirdParty/GCC/RP2040 at main · FreeRTOS/FreeRTOS-Kernel · GitHub](https://github.com/FreeRTOS/FreeRTOS-Kernel/tree/main/portable/ThirdParty/GCC/RP2040)

---

<div class="post-metadata">

**Author:** ![wuxuangle](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/wuxuangle/32/4503_2.png) [@wuxuangle](https://forums.freertos.org/u/wuxuangle)\
**Post date:** [May 6, 2024, 7:11am UTC](https://forums.freertos.org/t/freertos-smp-port-to-vs/19888/7 "2024-05-06T07:11:18Z")

</div>

Thank you, do you think that using multiple processes can be used to simulate cores? If so, can each core be simulated with a separate process, and then bind all the processes to the same core on an x86 architecture? After that, can the threads created by FreeRTOS be bound to each of these processes? Would this approach achieve the desired effect?

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [May 6, 2024, 8:53am UTC](https://forums.freertos.org/t/freertos-smp-port-to-vs/19888/8 "2024-05-06T08:53:16Z")

</div>

> [@wuxuangle](#):
>
> do you think that using multiple processes can be used to simulate cores?

One FreeRTOS application is one process as of today - so I am not sure how you’ll use separate processes to simulate cores. You need to elaborate more on how do you plan to do that.

---

<div class="post-metadata">

**Author:** ![wuxuangle](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/wuxuangle/32/4503_2.png) [@wuxuangle](https://forums.freertos.org/u/wuxuangle)\
**Post date:** [May 6, 2024, 1:01pm UTC](https://forums.freertos.org/t/freertos-smp-port-to-vs/19888/9 "2024-05-06T13:01:25Z")

</div>

Dear AggarG, the idea of simulating an SMP (Symmetric Multi-Processing) multi-core setup using processes is just a preliminary thought of mine. I haven’t really figured out the specifics, and I’m just curious to know if it’s feasible. From your hints, it seems that simulating cores with processes might not work very well. It appears that we can only rely on the two cores of the x86 on a PC to simulate two cores in an SMP setup, then create a Windows thread 1 to simulate the SysTick behavior running on Core A, create a Windows thread 2 to simulate the PendSV behavior running on Core A, and create a Windows thread 3 to simulate the PendSV behavior running on Core B. Windows thread 1 and Windows thread 2 can communicate with Windows thread 3 bidirectionally. This way, if there is a FreeRTOS thread scheduling on Core A, it can simultaneously notify Core B to perform FreeRTOS thread scheduling; if there is a FreeRTOS thread scheduling on Core B, it can simultaneously notify Core A to perform FreeRTOS thread scheduling. What do you think? Is this line of thinking feasible?

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [May 6, 2024, 5:13pm UTC](https://forums.freertos.org/t/freertos-smp-port-to-vs/19888/10 "2024-05-06T17:13:51Z")

</div>

> [@wuxuangle](#):
>
> What do you think? Is this line of thinking feasible?

This seems like it should work. You may stumble upon some problems when you start implementing it - feel free to post them here.

---

<div class="post-metadata">

**Author:** ![wuxuangle](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/wuxuangle/32/4503_2.png) [@wuxuangle](https://forums.freertos.org/u/wuxuangle)\
**Post date:** [May 7, 2024, 12:31am UTC](https://forums.freertos.org/t/freertos-smp-port-to-vs/19888/11 "2024-05-07T00:31:12Z")

</div>

AggarG, thank you, I feel that I will be troubling you again soon.

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [May 7, 2024, 5:05am UTC](https://forums.freertos.org/t/freertos-smp-port-to-vs/19888/12 "2024-05-07T05:05:08Z")

</div>

Looking forward to hear from you soon! Feel free to contribute your port once you are done 😉

---

<div class="post-metadata">

**Author:** ![wuxuangle](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/wuxuangle/32/4503_2.png) [@wuxuangle](https://forums.freertos.org/u/wuxuangle)\
**Post date:** [May 8, 2024, 6:11am UTC](https://forums.freertos.org/t/freertos-smp-port-to-vs/19888/13 "2024-05-08T06:11:27Z")

</div>

If I am successful, I would be very willing to share the steps involved in the porting process as well as the porting files.

My plan is as follows:

1. To port the latest version v11.1.0, which supports SMP (Symmetric Multi-Processing), to Microsoft Visual C++ 6.0.
2. First, successfully implement a single-core version of the task scheduler: a periodic timer sends a semaphore to Task 1, which then sends a message to Task 2.
3. Then, convert the single-core version to an SMP version: the periodic timer and Task 1 are bound to Core A, Task 2 is bound to Core B, and the idle task can run on both Core A and Core B.

Currently, I have made some simple modifications and completed steps 1 and 2, but the outcome of step 2 has not met the expected results.

---

<div class="post-metadata">

**Author:** ![wuxuangle](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/wuxuangle/32/4503_2.png) [@wuxuangle](https://forums.freertos.org/u/wuxuangle)\
**Post date:** [May 9, 2024, 1:51am UTC](https://forums.freertos.org/t/freertos-smp-port-to-vs/19888/14 "2024-05-09T01:51:20Z")

</div>

Dear AGGARG:

In the callback function of the software timer in v11.1.0, I called xSemaphoreGive(xSemaphore). Upon examining the call stack, I found that it got stuck in the function xTaskPriorityDisinherit with the assertion configASSERT(pxTCB == pxCurrentTCB), as pxTCB and pxCurrentTCB were not equal, causing it to keep getting stuck there. The semaphore xSemaphore was obtained through xSemaphoreCreateMutex, and the sending was performed using xSemaphoreGive, all of which was done according to the manual. What might be the issue here? Could you please help me analyze it?  
Let me add some more information: pxCurrentTCB points to xTimerTaskTCB, while pxTCB points to the timer that I created.

Thank you

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [May 9, 2024, 8:08am UTC](https://forums.freertos.org/t/freertos-smp-port-to-vs/19888/15 "2024-05-09T08:08:57Z")

</div>

> [@wuxuangle](#):
>
> In the callback function of the software timer in v11.1.0, I called xSemaphoreGive(xSemaphore).

A mutex is meant for protecting resources from simultaneous access and its usage looks like the following :

```auto
1. Acquire mutex.
2. Use resource.
3. Release mutex.

```

It is expected that the task that releases the mutex must be the same that acquired it before.

A Semaphore, on the other hand, is meant for synchronization and there is no such restriction. If you are trying to synchronize tasks, you need to create a semaphore using xSemaphoreCreateBinary (instead of creating a mutex using xSemaphoreCreateMutex).

---

<div class="post-metadata">

**Author:** ![wuxuangle](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/wuxuangle/32/4503_2.png) [@wuxuangle](https://forums.freertos.org/u/wuxuangle)\
**Post date:** [May 9, 2024, 8:55am UTC](https://forums.freertos.org/t/freertos-smp-port-to-vs/19888/16 "2024-05-09T08:55:03Z")

</div>

Thank you very much for your answer. There seems to be quite a few differences between this version of FreeRTOS-SMP and FreeRTOS V7.2.0, huh. Well, I will follow your steps to re-operate the Mutex.

Thank you very much. After replacing with xSemaphoreCreateBinary, the scheduling timing meets the requirements.

---

<div class="post-metadata">

**Author:** ![RAc](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rac/32/1389_2.png) [@RAc](https://forums.freertos.org/u/RAc)\
**Post date:** [May 9, 2024, 9:25am UTC](https://forums.freertos.org/t/freertos-smp-port-to-vs/19888/17 "2024-05-09T09:25:42Z")

</div>

No. The semantics of semaphores and muteces and their differences have been unaltered pretty much from day one, as far as I can tell.

---

<div class="post-metadata">

**Author:** ![wuxuangle](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/wuxuangle/32/4503_2.png) [@wuxuangle](https://forums.freertos.org/u/wuxuangle)\
**Post date:** [May 10, 2024, 12:08pm UTC](https://forums.freertos.org/t/freertos-smp-port-to-vs/19888/18 "2024-05-10T12:08:26Z")

</div>

The functions that need to be added in the port file are as follows:  
void vportGet\_CoreId();  
void vportSet\_IntMask();  
void vportClear\_IntMask();  
void vportRelease\_TaskLock();  
void vportGet\_TaskLock();  
void vportRelease\_IsrLock();  
void vportGet\_IsrLock();  
void vportEnter\_CriticalFromIsr();  
void vportExit\_Critical\_FromIsr();  
void vPortGenerateSimulatedInterruptCore( uint32\_t x, uint32\_t ulInterruptNumber );  
The functions that need to be modified in the port are as follows:  
void prvProcessSimulatedInterrupts( void )  
uint32\_t prvProcessYieldInterrupt( void )  
uint32\_t prvProcessTickInterrupt( void )  
vPortSetInterruptHandler( uint32\_t ulInterruptNumber,uint32\_t ( \* pvHandler )( void ) )  
BaseType\_t xPortStartScheduler( void )  
StackType\_t \* pxPortInitialiseStack( StackType\_t \* pxTopOfStack,TaskFunction\_t pxCode,void \* pvParameters )

---

<div class="post-metadata">

**Author:** ![wuxuangle](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/wuxuangle/32/4503_2.png) [@wuxuangle](https://forums.freertos.org/u/wuxuangle)\
**Post date:** [May 10, 2024, 12:15pm UTC](https://forums.freertos.org/t/freertos-smp-port-to-vs/19888/19 "2024-05-10T12:15:16Z")

</div>

During the process of modifying the `BaseType_t xPortStartScheduler(void)` function, I have a few questions:

1. How can I ensure that the highest priority tasks on each core are started first?  
[wuxu]:Similar to the approach on a single core, resume the highest-priority task on another core.
2. If I run a `prvProcessSimulatedInterrupts` on core 0, how can I run another instance of `prvProcessSimulatedInterrupts` on core 1?  
[wuxu]:CreateThread(NULL,0,prvProcessSimulatedInterrupts,…)，Bind to core 1, where prvProcessSimulatedInterrupts is modified to be a re-entrant function supporting two cores.，will be ok.  
I am looking forward to your response.

---

<div class="post-metadata">

**Author:** ![wuxuangle](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/wuxuangle/32/4503_2.png) [@wuxuangle](https://forums.freertos.org/u/wuxuangle)\
**Post date:** [May 11, 2024, 1:47am UTC](https://forums.freertos.org/t/freertos-smp-port-to-vs/19888/20 "2024-05-11T01:47:48Z")

</div>

Dear AGGARG:

Another issue is:the portYield is mostly defined as portYield(x) in SMP scenarios, but in the task: portTASK\_FUNCTION, the taskYIELD() is defined using portYield() instead, where portTASK\_FUNCTION is located within #configNUMBER\_OF\_CORES \> 1.  
The issue is affecting my compilation, and my principle is to modify only the port files without making changes to the source files.

I am looking forward to your response.

[Next page](https://forums.freertos.org/t/freertos-smp-port-to-vs/19888.md?page=2)
