1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** ThreadX Component                                                     */
16 /**                                                                       */
17 /**   Timer - High Level SMP Support                                      */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define TX_SOURCE_CODE
23 #define TX_THREAD_SMP_SOURCE_CODE
24 
25 
26 /* Include necessary system files.  */
27 
28 #include "tx_api.h"
29 #include "tx_initialize.h"
30 #include "tx_timer.h"
31 #include "tx_thread.h"
32 
33 
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _tx_timer_smp_core_exclude                         PORTABLE SMP     */
39 /*                                                           6.1          */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    William E. Lamie, Microsoft Corporation                             */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function allows the application to exclude one or more cores   */
47 /*    from executing the specified timer.                                 */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    timer_ptr                             Pointer to the timer          */
52 /*    exclusion_map                         Bit map of exclusion list,    */
53 /*                                            where bit 0 set means that  */
54 /*                                            this thread cannot run on   */
55 /*                                            core0, etc.                 */
56 /*                                                                        */
57 /*  OUTPUT                                                                */
58 /*                                                                        */
59 /*    Status                                                              */
60 /*                                                                        */
61 /*  CALLS                                                                 */
62 /*                                                                        */
63 /*    None                                                                */
64 /*                                                                        */
65 /*  CALLED BY                                                             */
66 /*                                                                        */
67 /*    Application Code                                                    */
68 /*                                                                        */
69 /*  RELEASE HISTORY                                                       */
70 /*                                                                        */
71 /*    DATE              NAME                      DESCRIPTION             */
72 /*                                                                        */
73 /*  09-30-2020     William E. Lamie         Initial Version 6.1           */
74 /*                                                                        */
75 /**************************************************************************/
_tx_timer_smp_core_exclude(TX_TIMER * timer_ptr,ULONG exclusion_map)76 UINT  _tx_timer_smp_core_exclude(TX_TIMER *timer_ptr, ULONG exclusion_map)
77 {
78 
79 TX_INTERRUPT_SAVE_AREA
80 
81 UINT    status;
82 
83 
84     /* First, make sure the timer pointer is valid.  */
85     if (timer_ptr == TX_NULL)
86     {
87 
88         /* Return pointer error.  */
89         status =  TX_TIMER_ERROR;
90     }
91 
92     /* Check for valid ID.  */
93     else if (timer_ptr -> tx_timer_id != TX_TIMER_ID)
94     {
95 
96         /* Return pointer error.  */
97         status =  TX_TIMER_ERROR;
98     }
99     else
100     {
101 
102         /* Disable interrupts.  */
103         TX_DISABLE
104 
105         /* Now store in the core exclusion information.  */
106         timer_ptr -> tx_timer_internal.tx_timer_internal_smp_cores_excluded =  (timer_ptr -> tx_timer_internal.tx_timer_internal_smp_cores_excluded & ~(((ULONG) TX_THREAD_SMP_CORE_MASK))) |
107                                                                                    (exclusion_map & ((ULONG) TX_THREAD_SMP_CORE_MASK));
108 
109         /* Restore interrupts.  */
110         TX_RESTORE
111 
112         /* Return success.  */
113         status =  TX_SUCCESS;
114     }
115 
116     /* Return success.  */
117     return(status);
118 }
119 
120