Commit Graph

158 Commits (ad4e7238293cbe994e7450e1bc415136875da322)

Author SHA1 Message Date
Gaurav-Aggarwal-AWS ad4e723829
Mark mutex as robust to prevent deadlocks (#1233)
Mark mutex as robust to prevent deadlocks

Prevent application hangs that occur when a thread dies while holding a
mutex, particularly during vTaskEndScheduler or exit calls. This is
achieved by setting the PTHREAD_MUTEX_ROBUST attribute on the mutex.

Fixes:
- GitHub issue: FreeRTOS/FreeRTOS-Kernel#1217
- Forum thread: freertos.org/t/22287

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
3 days ago
Cavin McKinley b421abc7c3
Update Community-Supported-Ports submod to fix RP2350 port - FreeRTOS-Kernel#1220 (#1232)
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
6 days ago
John Boiles 2b35979a1a
POSIX Simulator: Handle `pthread`s not created by FreeRTOS differently (#1223) 7 days ago
John Boiles a58579681c
POSIX Simulator: Remove unused __APPLE__ mach_vm.h include (#1225)
Remove unused __APPLE__ mach_vm.h include
1 week ago
iotah 3a7b3082cf
Update community supported ports submodulees (#1218)
Signed-off-by: Hua Zheng <hua.zheng@embeddedboys.com>
Co-authored-by: Hua Zheng <hua.zheng@embeddedboys.com>
4 weeks ago
Felix van Oost f05244a8d5
Pass core ID to port lock macros (#1212)
Pass core ID to task/ISR lock functions
1 month ago
Felix van Oost 31dd1e39cb
Pass core ID to critical nesting count macros (#1206)
* Pass core ID to CRITICAL_NESTING_COUNT macros

* Match existing data type for xCoreID

* Get core ID when interrupts are disabled

* Implement get core ID with interrupt disabled

* Get core ID inline within vTaskSuspendAll() to resolve compiler warning

* Fix formatting check

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

---------

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
Co-authored-by: Ching-Hsin,Lee <chinglee@amazon.com>
Co-authored-by: Gaurav Aggarwal <aggarg@amazon.com>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
1 month ago
Tony Josi 7e419c2dd5
Update partner supported and community supported ports submodulees (#1194) 3 months ago
Graham Sanderson 73f6e3a1b4
RP2040 Updates: (#1193)
* Standardize on configNUMBER_OF_CORES != 1 to select SMP functionality
* Fix SDK pico_sync interoperability (configSUPPORT_PICO_SYNC_INTEROP == 1)

Co-authored-by: graham sanderson <graham.sanderson@raspeberryi.com>
3 months ago
Vishwanath Martur f0d79459d6
Fix SMP debugging issue on rp2040 (#1174)
* Fix SMP debugging issue on rp2040

Related to #1172

Add `multicore_reset_core1` before `multicore_launch_core1` in `xPortStartScheduler` function to fix debugging issue on rp2040 with SMP enabled.

* Modify `portable/ThirdParty/GCC/RP2040/port.c` to include a call to `multicore_reset_core1` before `multicore_launch_core1` within the `#if portRUNNING_ON_BOTH_CORES` block.

* Recover comments back

---------

Co-authored-by: ActoryOu <jay2002824@gmail.com>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com>
3 months ago
ActoryOu a27d6650ee
Move configASSERT default definition above before including portable.h. (#1185)
Move configASSERT default definition above before including portable.h.
3 months ago
ActoryOu de276eb023
Fix spelling typos (#1168)
* Fix spelling

---------

Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com>
3 months ago
Paul Hollinsky 7215c89aa8
POSIX Port: Remove pthread_attr_setstacksize call (#1161)
We have removed the use of pthread_attr_setstack and as a result,
the task stack is no longer used as the corresponding pthread's stack.
There is no use of calling pthread_attr_setstacksize as the default is
always good enough and we don't need to handle OS specific cases.

This PR simplifies the code by removing the call to pthread_attr_setstacksize.

Signed-off-by: Paul Hollinsky <paulhollinsky@gmail.com>
3 months ago
Ian Thompson 5f3bab1a32
Xtensa support updated and moved to Partner-Supported submodules (#1156)
* Xtensa support moved to Partner-Supported ports

Removing legacy Xtensa port; leave README with pointer to latest code

* Updated submodule ThirdParty/FreeRTOS-Kernel-Partner-Supported-Ports
4 months ago
superroc 190906aeaf
Add portMEMORY_BARRIER defination to fix over-optimization in xTaskResumeAll. (#1116)
Co-authored-by: owen <owen@freqchip.com>
6 months ago
Gaurav-Aggarwal-AWS d844312131
Fix POSIX port to respect configUSE_TIME_SLICING (#1103)
Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
6 months ago
Florian La Roche f4f2e1596b
Fix gcc warning in posix port (#1098)
Fix warning from "gcc -Wsign-compare" in the file
portable/ThirdParty/GCC/Posix/port.c since PTHREAD_STACK_MIN
is used from system headers.

Signed-off-by: Florian La Roche <Florian.LaRoche@gmail.com>
Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com>
7 months ago
Angel Cascarino 17dfd0f808
Update XMOS xcore.ai port to be compatible with v11.x (#1096)
* Fix kexcept function

* Create dummy pxCurrentTCBs for xcore.ai port

* Additional commentary

* Add a layer of indirection to cope with singlecore

* Clarify use of _DoException
7 months ago
Eric Dawe 9e838293c2
Update README.md (#1094)
Fix spelling of the word 'the' ('thw') in line 29
7 months ago
maxiao bee9037c46
Fix compilation warning about undelcared pthread_setname_np (#1079)
Use _GNU_SOURCE macro instead of __USE_GNU and define it before
including portmacro.h. The reason is that portmacro.h includes limits.h
which in-turn includes features.h - this results in __USE_GNU getting
incorrectly undefined.
8 months ago
Florian La Roche c431b358c8
event_create(): check malloc() return value to be non-NULL (#1084)
* event_create(): check malloc() to be non-NULL

Check malloc() to return non-NULL before writing data
in the function event_create().

Signed-off-by: Florian La Roche <Florian.LaRoche@gmail.com>

* Code review suggestion

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

---------

Signed-off-by: Florian La Roche <Florian.LaRoche@gmail.com>
Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
Co-authored-by: Gaurav Aggarwal <aggarg@amazon.com>
8 months ago
chinglee-iot 2a014ce0b3
Update submodule pointer (#1040) 10 months ago
Devaraj Ranganna e143832ad4
tf-m: Update tf-m to TF-Mv2.0.0 release (#1038)
The `portable/ThirdParty/GCC/ARM_TFM/README.md` and
`portable/ThirdParty/GCC/ARM_TFM/os_wrapper_freertos.c` are updated to
support `TF-Mv2.0.0` of trusted-firmware-m release.

Signed-off-by: Devaraj Ranganna <devaraj.ranganna@arm.com>
10 months ago
Florian La Roche 8afb3a5b82
fix typos in comments: interace -> interface, swtich -> switch (#1022)
Fix typos in comments: interace -> interface, swtich -> switch.

Signed-off-by: Florian La Roche <Florian.LaRoche@gmail.com>
10 months ago
Kody Stribrny 8c49c54987
Fix TFM about link (#1021)
This page does not look to
exist anymore which is
failing our link verifier
check.
10 months ago
chinglee-iot d95451d924
Define portNOP in RP2040 port (#1003) 11 months ago
Soren Ptak 839ccb719b
Use Regex for Copyright Year in Header Check (#1002) 11 months ago
Aniruddha Kanhere 2fcb0f48b1
Fix small bugs in Kernel (#998)
* Fix small bugs

* Cast sizeof to BaseType_t

* Test removing assert to fix UT

* Revert change to tasks.c

Since configIDLE_TASK_NAME must be defined as a string according to
the documentation, the macro will always be NULL terminated. Which
means that the check `if( cIdleName[ xIdleTaskNameIndex ] == ( char ) 0x00 )`
will catch the end of string.

* Update coverity config; Add coverity version; Update pvPortMalloc declaration to match the definitions.

* Add port files to sed command

* Remove warnings about unused parameters in port code

---------

Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com>
12 months ago
Paul Bartell 23afc48fc3
Update version number (#983)
* Update version number to 11.0.1+ in task.h

* Update Third Party Port version to <DEVELOPMENT BRANCH>

* Update version to 11.0.1 in manifest.yml
1 year ago
chinglee-iot 1de764ba87
Delete kernel created task in vTaskEndScheduler (#962)
* Update vTaskDelete() to delete a task directly when scheduler is stopped instead of putting it on the xTasksWaitingTermination list.
* Delete the idle tasks and timer task in vTaskEndScheduler().
* Reclaim resources for all the tasks on the xTasksWaitingTermination list in vTaskEndScheduler().
* Update POSIX to no longer delete FreeRTOS tasks in the port.

---------

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
Co-authored-by: Gaurav Aggarwal <aggarg@amazon.com>
1 year ago
Phillip Stevens 8622bd5f49
Fix ThirdParty/GCC/ATmega formatting (#965)
Unnecessary white space was introduced in PR #768
which affected the formatting of assembly code. This PR
returns the correct formatting. No functional change.
1 year ago
Soren Ptak b1ee2e6e14
Fix MacOS Posix port (#957)
PR #914 caused Posix Port to fail to build on MacOS. This PR fixes
teh build failure.

This PR also adds a Matrix configuration to the GitHub kernel-demo
workflow to build the Posix Demos on MacOS.
---------

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
Phillip Stevens 14dd5b503a
use configSTACK_DEPTH_TYPE consequently (updated for 11.0.x) (#942)
* use configSTACK_DEPTH_TYPE consequently

* update default to uint32_t

* Update FreeRTOS.h

Revert for backwards compatibility

* Update portable.h

* configSTACK_DEPTH_TYPE - unify stack variable naming

* update lexicon.txt

* update typo lexicon.txt

* Update task.h

* Update timers.h

* fix merge typo

* fix stack type

* fix timer stack type

* fix timer stack more

* fix affinity set stack

* adjust ports to use configSTACK_DEPTH_TYPE

* fix vTaskListTasks

* set default stack depth type in portable.h

* fix History.txt

* update affinityset

* resolve reviewer comments

* fix prvTaskCheckFreeStackSpace for variable stack size type

* restore CoRoutine defines

* remove obsolete stack ttype casts

* fix (attempt) for format portable.h

* Formatting fixes

* prvTaskCheckFreeStackSpace make variable naming compliant

* Update portable/GCC/ARM_CM33/non_secure/port.c

Co-authored-by: Soren Ptak <ptaksoren@gmail.com>

* Update portable/GCC/ARM_CM23/non_secure/port.c

Co-authored-by: Soren Ptak <ptaksoren@gmail.com>

* Apply suggestions from code review

Update ulStackDepth to uxStackDepth

Co-authored-by: Soren Ptak <ptaksoren@gmail.com>

* Correct uxStackDepth in port.c

Also add uint32_t cast prvGetMPURegionSizeSetting.

* Update ARM CM3 MPU port.c

Revert casting of ( uint32_t ) pxBottomOfStack

* Code review suggestions

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

---------

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
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
Mikhail Paulyshka e6f6d0ecf4
Posix port - set name for threads (#950)
Co-authored-by: jasonpcarroll <23126711+jasonpcarroll@users.noreply.github.com>
1 year ago
Tony Josi c053ffeacc
Fix -Werror=unused-parameter in GCC posix prvTimerTickHandler() (#949) 1 year ago
Chris Morgan 3baa3dd98b POSIX port - Switch from allowing the user to specify the stack memory itself, to allowing them to specify the stack size
Change from pthread_attr_setstack() to pthread_attr_setstacksize(), and automatically adjust the stack size
to be at least PTHREAD_STACK_MIN if it wasn't already, removing the size warning.

This permits the user to increase the pthread stack size beyond the PTHREAD_STACK_MIN default of 16384 if
desired, without producing a warning in the typical case where stacks are minimized for RAM limited targets.

Continue to store thread paramters on the provided stack, for consistency with the MCU targets.

Previously pthread_attr_setstack() was used to enable user defined stacks.

Note that:

1. The stack size can still be specified by the user.

2. pxPortInitialiseStack(), and pthread_addr_setstack() was failing on stacks of typical size, as
   these are smaller than PTHREAD_STACK_MIN (16384) bytes, and printing out a series of warnings.
   Improve usability by having the posix port automatically increase the stack size to be
   at least PTHREAD_STACK_MIN as posix platforms have enough memory for this not to be a concern.

3. Reuse of stack memory will also result in valgrind 'invalid write' errors to what is demonstrably
   valid memory. Root cause is that Valgrind is tracking a stack pointer as the stack is used.
   Reuse of a stack buffer results in the stack being used at its start, in an area that Valgrind thinks
   is far away from the start of the stack. There are ways to notify Valgrind of these changes
   however this would require linking against and calling Valgrind functions from the FreeRTOS application using
   the posix port, https://valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.clientreq.

   Also, apparently it isn't permitted by posix to reuse stack memory once its been used in a pthread via pthread_attr_setstack(),
   see https://stackoverflow.com/a/5422134
1 year ago
Ching-Hsin Lee 62220666ba Revert pthread_attr_setstacksize 1 year ago
Ching-Hsin,Lee b6c0c51cbe Revert timer tick function 1 year ago
Ching-Hsin,Lee 5ed9c7022b Add back event signal 1 year ago
Ching-Hsin,Lee 14903c380e Remove redundent cancellation point 1 year ago
Ching-Hsin,Lee a7d39c3e3a format and header file 1 year ago
Ching-Hsin,Lee 0fac0859af Add back heap setup code 1 year ago
Ching-Hsin,Lee 3dade5b5a5 UPdate format 1 year ago
Ching-Hsin Lee 7ba4124c78 Add back the pthread stack fit 1 year ago
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 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 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