Commit Graph

3565 Commits (main)
 

Author SHA1 Message Date
Ching-Hsin,Lee 6b698ff6bc Fix potential race condition 1 year ago
Chris Morgan 88d3540b54 POSIX port - Cancel and join all FreeRTOS managed pthreads upon shutdown
For a clean shutdown where memory is freed, it is necessary for all pthreads to be joined
at shutdown.

Previously there was explicit cancellation of the idle task and timer daemon task, however
there may be a number of other tasks in the system, both system created and user created,
and those tasks/threads were being left at shutdown.

This change calls pthread_cancel()/pthread_join() on all FreeRTOS managed pthreads upon
shutdown.
1 year ago
Chris Morgan ddc89fa985 POSIX - Switch from posix timers to a timer thread to fix signal handling with non-FreeRTOS pthreads
Improve upon the elegant approach of using signals to cause task/pthreads
suspension and scheduler execution by using directed signals.

This fixes:
- Deadlocks in non-FreeRTOS pthreads
- Multiple FreeRTOS tasks(pthreads) incorrectly running at the same time

By directing the signals using pthread_kill() the signal handler in the presently running
FreeRTOS task/pthread will be called, ensuring that the scheduler runs both in the context
of a FreeRTOS task/pthread and from the presently executing FreeRTOS task/pthread.

Details
==============

The POSIX port uses signals to preempt FreeRTOS tasks (implemented as pthreads), a very neat and elegant
approach to forcing tasks/pthreads to suspend and run the scheduler.

Signal handlers are process global.

Posix timers generate signals when the timer expires, and the signal is sent to the currently
running pthread.

In systems where there are pthreads that are NOT a result of creating FreeRTOS tasks, such as the
entry point thread that calls main(), or user created pthreads, this poses a serious issue.

While the POSIX port only allows a single FreeRTOS pthread to run at once, by causing all suspended
threads to not be scheduled due to their waiting on a pthread condition variable,
this isn't the case with non-FreeRTOS pthreads.

Thus it is possible that a non-FreeRTOS pthread is running when the timer expires and the signal
is generated. This results in the signal handler running in the non-FreeRTOS thread.

The sequence of events results in these events from signal handler context:
- vPortSystemTickHandler() being called
- The scheduler running
- Selecting another FreeRTOS task to run and switching the active task
- The newly selected task released from suspension by pthread_cond_signal()
- The presently active thread calling event_wait()
- The pthread calling pthread_cond_wait(), suspending the thread and allowing the host OS scheduler
  to schedule another thread to run.

If this occurs from a non-FreeRTOS thread this results in:
- The active FreeRTOS pthread (Task A/Thread A) continuing to run (as the signal handler that calls
  event_wait() ran instead in a non-FreeRTOS pthread.
- The pthread where the signal handler did run (Thread B) will call event_wait() and pthread_cond_wait(),
  but on the condition variable of the previously active FreeRTOS task, oops. This causes the
  non-FreeRTOS pthread to block unexpectedly relative to what the developer might have expected.
- The newly selected FreeRTOS Task (Task C/Thread C) will resume and start running.

At this point Task A/Thread A is running concurrently with Task C/Thread C. While this may not
necessarily be an issue, it does not replicate the expected behavior of a single Task running at
once.

Note that Thread B will resume if/when Task A/ThreadA is switched to. However, this could be delayed
by an arbitrary amount of time, or could never occur.

Also note that if there are multiple non-FreeRTOS pthreads that Thread D, E, F...etc could suffer the
same fate as Thread B, if the scheduler were to suspend Task C/Thread C and resume Task E/Thread E.

Implementation
==============

Timer details
-------------
A standalone pthread for the signal generation thread was chosen, rather than using
a posix timer_settime() handler function because the latter creates a temporary
pthread for each handler callback. This makes debugging much more difficult due to
gdb detecting the creation and destruction of these temporary threads.

Signal delivery
--------------
While signal handlers are per-thread, it is possible for pthreads to selectively block
signals, rather than using thread directed signals. However, the approach of blocking
signals in non-FreeRTOS pthreads adds complexity to each of these non-FreeRTOS pthreads
including ensuring that these signals are blocked at thread creation, prior to the thread
starting up. Directed signals removes the requirement for non-FreeRTOS pthreads to be aware
of and take action to protect against these signals, reducing complexity.
1 year ago
Soren Ptak 529de5606e
Revert #768 on the XCC/Xtensa portable files (#948) 1 year ago
chinglee-iot 94cb87ad30
Assign idle task to each core before SMP scheduler start (#945)
Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com>
1 year ago
Soren Ptak 460e953076
Add new common words to the cSpellWordList.txt (#946) 1 year ago
Gabriele Monaco 1947dd2f94
Added ability to change task notification index for streambuffers (#939)
* Added possibility to change notification index for streambuffers

* Uncrustify: triggered by comment.

* Minor code review suggestions.

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>

---------

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com>
Co-authored-by: Gaurav Aggarwal <aggarg@amazon.com>
1 year ago
Eric Jackson 4568507507
Fix documentation for xQueueTakeMutexRecursive (#943) 1 year ago
chinglee-iot be880a1fc8
Fix portSET_INTERRUPT_MASK_FROM_ISR definition for atomic operation (#940)
* Introduce portHAS_NESTED_INTERRUPTS to identify if port has nested interrupt or not.
* Update atomic.h to use portHAS_NESTED_INTERRUPTS instead of portSET_INTERRUPT_MASK_FROM_ISR definition.

---------

Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
Co-authored-by: ActoryOu <jay2002824@gmail.com>
1 year ago
dps.lwk 75c4044b7e
RP2040: Fix removal of idle_task_static_memory.c (#935)
Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com>
1 year ago
Jeff Tenney 5544c78299
Fix build error for MSP430 and Cortex A with IAR (#937)
* fix whitespace in asm macros

* Revert formatting ARM_CA5_No_GIC and ARM_CA9
1 year ago
Soren Ptak 58f0d36e76
Export MPU Section Attributes (#931)
Export the PRIVILEGED_FUNCTION, PRIVILEGED_DATA, and FREERTOS_SYSTEM_CALL
attributes to make it easier for end users to add their own privileged functions and
system calls.
1 year ago
dps.lwk 93380c02a1
RP2040: FreeRTOS-Kernel-Static use configKERNEL_PROVIDED_STATIC_MEMORY (#934)
Remove the idle_task_static_memory.c and use the new default implementations
to allows for FreeRTOS-Kernel-Static to be used with configNUMBER_OF_CORES > 1
1 year ago
Forty-Bot ec93432a59
Fix build with modern GCC (#933)
* GCC: MSP430F449: Add missing attributes

Apparently at some point in the past, GCC (or TI's GCC) used to define
these attributes. Define them ourselves so that we can compile the demo
application.

* GCC: MSP430F449: Make interrupts return void

If a return type of a function is not specified, it defaults to int. Set
the return type of interrupts to void to avoid warnings.

* GCC: MSP430F449: Define portPOINTER_SIZE_TYPE

portPOINTER_SIZE_TYPE defaults to uint32_t if undefined. Define it to
uint16_t, which is correct for this port.
1 year ago
Rahul Kar 4e7ca2d704
Update History.txt for V11.0.1 (#932)
* Update History for V11.0.1
1 year ago
chinglee-iot 5bb2b59db4
Update History.txt for v11.0.0 (#926)
* Update History.txt for v11.0.0
1 year ago
Rahul Kar b0439d3283
Rename sample configuration to template configuration (#927)
* Rename sample configuration to template configuration

* Rename sample configuration to template configuration in cmake example file
1 year ago
Soren Ptak 553b0ad5d3
Update comments related to portYIELD_FROM_ISR() in queue.h #925 1 year ago
Rahul Kar 1384c68dc7
Update sample configuration file (#923)
* Update sample configuration file in the examples folder

* Add SMP Configuration definitions

* Fix build issue in cmake example

* Add CoRoutine Configuration definitions

* Code review suggestions

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>

* Fix formatting

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>

---------

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
Co-authored-by: Gaurav Aggarwal <aggarg@amazon.com>
1 year ago
chinglee-iot e0bb21f832
Remove the sample smp configuration folder (#922)
* Remove the sample smp configuration folder
1 year ago
Darian bd0f87c18b
Add portTASK_SWITCH_HOOK (#867)
This commit adds a portTASK_SWITCH_HOOK() macro which allows ports to inject
behavior immediately after a context switch. For example, this macro could be
used by ports that need to set an end of stack watchpoint after a context
swtich.

Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com>
Co-authored-by: Soren Ptak <ptaksoren@gmail.com>
Co-authored-by: chinglee-iot <61685396+chinglee-iot@users.noreply.github.com>
Co-authored-by: Tony Josi <tonyjosi@amazon.com>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
1 year ago
Jeff Tenney 30e6b8a5ea
Detect more startup config errors on Cortex M (#832)
Verify that the application has correctly installed PendSV
and SVCall handlers. The application can choose to
disable these checks by setting configCHECK_HANDLER_INSTALLATION
to 0 in their FreeRTOSConfig.h.
1 year ago
RichardBarry 553caa18ce
Update the memory alignment within the Cortex-A9 port asm code (#426)
Update alignment in ARM_CA9 port.
1 year ago
chinglee-iot a79752a04a
Remove lint suppression comment (#920)
Remove lint suppression comment
1 year ago
chinglee-iot a2712b5e38
Add constanst suffix to prevent potential type conversion (#921)
Co-authored-by: Ubuntu <ubuntu@ip-172-31-34-245.ap-northeast-1.compute.internal>
1 year ago
chinglee-iot 5dbfd380f0
Add coverity example (#870)
* Add coverity example

* Update for CI

* Fix for CI 2

* Update kernel_misra.config

* Rename coverity example to coverity

* Update FreeRTOSConfig.h for coverity project

* Update MISRA.md

* Move coverity config to coverity_misra.config

* Update coverity misra config

* Add README.md file

* Update FreeRTOSConfig.h for coverity

* Fix uncrustify and spell

* Update README.md for relative link path

Update README.md for relative link path

* Update README.md for relative link 2

* Update MISRA.md for relateive path

* Fix for format

* Update coverity_misra.config

* Update configuration folder

* Update README.md for link

* Code review suggestions

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>

---------

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
Co-authored-by: Ubuntu <ubuntu@ip-172-31-34-245.ap-northeast-1.compute.internal>
Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com>
Co-authored-by: Soren Ptak <ptaksoren@gmail.com>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
Co-authored-by: Gaurav Aggarwal <aggarg@amazon.com>
1 year ago
Soren Ptak ac7fc396a0
Revert Portable/BCC formatting (#828)
Revert Portable/BCC formatting
1 year ago
Soren Ptak bcf7bdaa13
Revert Portable/oWatcom formatting (#829)
Revert the formatting on oWatcom ports
1 year ago
Soren Ptak 0debe8c669
Revert Portable/Paradigm formatting (#830)
Revert the formatting on Paradigm ports
1 year ago
Soren Ptak db5df4bfde
Revert Portable/CodeWarrior formatting (#831)
Revert the formatting on CodeWarrior ports
1 year ago
chinglee-iot de2c0c1a95
Update partner and community supported port submodule pointer (#919) 1 year ago
chinglee-iot d95b05ea5f
Suppress MISRA C:2012 rule 21.6 for snprintf (#877)
Suppress MISRA C:2012 rule 21.6 for snprintf
1 year ago
chinglee-iot 877484cd7e
Fix MISRA C 2012 Rule 11.1 deviations (#856)
* Update callback function prototype to align with definition
* Suppress unused function pointer parameter

---------

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
Co-authored-by: Ubuntu <ubuntu@ip-172-31-34-245.ap-northeast-1.compute.internal>
Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
Co-authored-by: Gaurav Aggarwal <aggarg@amazon.com>
1 year ago
chinglee-iot 15af8e072d
Add description about overrun warning in queue.c (#869)
* Add description about overrun warning in queue.c

* Remove the unreachable configASSERT

* Code review suggestions

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>

* Fix formatting

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>

---------

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
Co-authored-by: Ubuntu <ubuntu@ip-172-31-34-245.ap-northeast-1.compute.internal>
Co-authored-by: Soren Ptak <ptaksoren@gmail.com>
Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com>
Co-authored-by: Gaurav Aggarwal <aggarg@amazon.com>
1 year ago
Rahul Kar 93ef558fa8
Declare variable without initializer (#841)
Co-authored-by: Soren Ptak <ptaksoren@gmail.com>
Co-authored-by: chinglee-iot <61685396+chinglee-iot@users.noreply.github.com>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
1 year ago
chinglee-iot 51437bf943
Fix MISRA C 2012 rule 8.6 errors (#862)
* Fix MISRA C 2012 rule 8.6 errors

* Add suppression for hook function

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>

---------

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
Co-authored-by: Ubuntu <ubuntu@ip-172-31-34-245.ap-northeast-1.compute.internal>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
Co-authored-by: Gaurav Aggarwal <aggarg@amazon.com>
1 year ago
Rahul Kar 55094e2ddf
Fix MISRA_C_2012 rule 13.2 violation (#855)
* Assign volatile variables to local non-volatile variables before read

* Fix stack macro overflow check volatile access

* Explicit the read order of volatile variable

* Fix issue : ISO C90 forbids mixed declarations and code



---------

Co-authored-by: Ubuntu <ubuntu@ip-172-31-34-245.ap-northeast-1.compute.internal>
Co-authored-by: chinglee-iot <61685396+chinglee-iot@users.noreply.github.com>
Co-authored-by: Monika Singh <moninom@amazon.com>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
1 year ago
Rahul Kar d1a0202125
Fix MISRA_C_2012 rule 8.4 violation (#844)
Fix MISRA_C_2012 rule 8.4 violation
1 year ago
Rahul Kar 22eb827b3d
Add parameter name for function type (#845)
Co-authored-by: chinglee-iot <61685396+chinglee-iot@users.noreply.github.com>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
1 year ago
Rahul Kar ce41f6ec74
Fix MISRA_C_2012 rule 7.2 violation (#842)
* Add a u or U suffix for unsigned numerical literals

* Fix formatting

* Replace u with U for naming convention

---------

Co-authored-by: Soren Ptak <ptaksoren@gmail.com>
Co-authored-by: chinglee-iot <61685396+chinglee-iot@users.noreply.github.com>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
1 year ago
Rahul Kar 71d86f9a6e
Fix MISRA_C_2012 rule 17.7 violation (#848)
* Assign return value of xPortStartScheduler API to a variable

* Add void datatype

---------

Co-authored-by: chinglee-iot <61685396+chinglee-iot@users.noreply.github.com>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
1 year ago
Rahul Kar edce1e94b3
Fix MISRA_C_2012 rule 20.7 violation (#843)
* Wrap macro parameter expansion by parentheses
* Update parentheses in SMP macro definition

---------

Co-authored-by: Soren Ptak <ptaksoren@gmail.com>
Co-authored-by: Monika Singh <moninom@amazon.com>
Co-authored-by: chinglee-iot <61685396+chinglee-iot@users.noreply.github.com>
1 year ago
chinglee-iot 84c0047ccd
Suppress MISRA C:2012 rule 11.5 deviations (#878)
* Suppress MISRA C:2012 rule 11.5 deviations by comment also remove this rule in global config

---------

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
Co-authored-by: Ubuntu <ubuntu@ip-172-31-34-245.ap-northeast-1.compute.internal>
Co-authored-by: Rahul Kar <karahulx@amazon.com>
Co-authored-by: Soren Ptak <ptaksoren@gmail.com>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
Co-authored-by: Gaurav Aggarwal <aggarg@amazon.com>
1 year ago
Darian cd5c774b2b
Update xTaskGetIdleTaskHandle() For SMP (#868)
* Update xTaskGetIdleTaskHandle() in SMP

This commit updates xTaskGetIdleTaskHandle() for SMP in the following ways:

- xTaskGetIdleTaskHandle() no longer accepts xCoreID argument in SMP so that
there is not change in API between single-core and SMP
- xTaskGetIdleTaskHandle() now returns the Active idle task handle in SMP,
which matches the behavior in single-core.
- Added xTaskGetIdleTaskHandleForCore() in SMP which accepts an xCoreID
argument. This function can be used to obtain the Passive idle task handles.

* Update xTaskGetIdleTaskHandle

---------

Co-authored-by: Ching-Hsin Lee <chinglee@amazon.com>
Co-authored-by: chinglee-iot <61685396+chinglee-iot@users.noreply.github.com>
Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
1 year ago
chinglee-iot c0ce725293
Add SMP template port and example (#900)
* Add SMP template port and example
* Add readme file for smp configuration
* Update SMP build flow and add CI build

---------

Co-authored-by: Soren Ptak <ptaksoren@gmail.com>
Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com>
1 year ago
Rahul Kar f8ef5f605b
Fix prototype of MPU_vTimerSetReloadMode (#913) 1 year ago
Legend 592bfe0e01
Fix typo in comment (#910)
Co-authored-by: Tony Josi <tonyjosi@amazon.com>
Co-authored-by: Soren Ptak <ptaksoren@gmail.com>
Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com>
Co-authored-by: Nikhil Kamath <110539926+amazonKamath@users.noreply.github.com>
1 year ago
Soren Ptak 6a9f5a244a
Add portMEMORY_BARRIER() to RX MCU ports (#864)
* Add portMEMORY_BARRIER() to RX MCU ports

* Remove the memory barrier from the SH2A_FPU portable directory

---------

Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com>
1 year ago
Soren Ptak 6a41432498
Upgrade msvc port to winsock2 (#895)
* Add the changes needed to the MSVC windows port to get it to build with winsock2.h
* Rely upon the WIN32_LEAN_AND_MEAN define to include winsock2.h
1 year ago
Soren Ptak 147f34ab5f
Revert Portable/Renesas formatting (#876)
* Revert the formatting on Renesas ports
1 year ago