1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** ThreadX Component */
17 /** */
18 /** Thread */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23
24 #define TX_SOURCE_CODE
25 #define TX_THREAD_SMP_SOURCE_CODE
26
27
28 /* Include necessary system files. */
29
30 #include "tx_api.h"
31 #include "tx_thread.h"
32 #include "tx_timer.h"
33
34
35 /**************************************************************************/
36 /* */
37 /* FUNCTION RELEASE */
38 /* */
39 /* _tx_thread_smp_core_preempt SMP/Linux/GCC */
40 /* 6.1 */
41 /* AUTHOR */
42 /* */
43 /* William E. Lamie, Microsoft Corporation */
44 /* */
45 /* DESCRIPTION */
46 /* */
47 /* This function preempts the specified core in situations where the */
48 /* thread corresponding to this core is no longer ready or when the */
49 /* core must be used for a higher-priority thread. If the specified is */
50 /* the current core, this processing is skipped since the will give up */
51 /* control subsequently on its own. */
52 /* */
53 /* INPUT */
54 /* */
55 /* core The core to preempt */
56 /* */
57 /* OUTPUT */
58 /* */
59 /* None */
60 /* */
61 /* CALLS */
62 /* */
63 /* ReleaseSemaphore Let scheduler run to preempt */
64 /* thread on core */
65 /* _tx_win32_debug_entry_insert Make debug log entry */
66 /* */
67 /* CALLED BY */
68 /* */
69 /* ThreadX Source */
70 /* */
71 /* RELEASE HISTORY */
72 /* */
73 /* DATE NAME DESCRIPTION */
74 /* */
75 /* 09-30-2020 William E. Lamie Initial Version 6.1 */
76 /* */
77 /**************************************************************************/
_tx_thread_smp_core_preempt(UINT core)78 void _tx_thread_smp_core_preempt(UINT core)
79 {
80
81 TX_THREAD *preempt_thread;
82
83
84 /* Protection is in force at this point. */
85
86 /* Pickup the thread pointer on the selected core. */
87 preempt_thread = _tx_thread_current_ptr[core];
88
89 /* Determine if there is a thread to preempt. */
90 if (preempt_thread)
91 {
92
93 /* Yes, set the deferred preemption flag for this thread. This preemption will be
94 completed in the scheduler. */
95 preempt_thread -> tx_thread_linux_deferred_preempt = TX_TRUE;
96
97 /* Debug entry. */
98 _tx_linux_debug_entry_insert("CORE_PREEMPT_deferred", __FILE__, __LINE__);
99
100 /* Release the semaphore that the main scheduling thread is waiting
101 on. Note that the main scheduling algorithm will take care of
102 preempting the thread on this core. */
103 tx_linux_sem_post(&_tx_linux_scheduler_semaphore);
104 }
105 }
106
107
108