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 #define TX_SOURCE_CODE
24 #define TX_THREAD_SMP_SOURCE_CODE
25
26
27 /* Include necessary system files. */
28
29 #include "tx_api.h"
30 #include "tx_thread.h"
31 #include "tx_timer.h"
32 #include "tx_trace.h"
33
34
35 /**************************************************************************/
36 /* */
37 /* FUNCTION RELEASE */
38 /* */
39 /* _tx_thread_time_slice_change PORTABLE SMP */
40 /* 6.1 */
41 /* AUTHOR */
42 /* */
43 /* William E. Lamie, Microsoft Corporation */
44 /* */
45 /* DESCRIPTION */
46 /* */
47 /* This function processes thread time slice change requests. The */
48 /* previous time slice is returned to the caller. If the new request */
49 /* is made for an executing thread, it is also placed in the actual */
50 /* time-slice countdown variable. */
51 /* */
52 /* INPUT */
53 /* */
54 /* thread_ptr Pointer to thread */
55 /* new_time_slice New time slice */
56 /* old_time_slice Old time slice */
57 /* */
58 /* OUTPUT */
59 /* */
60 /* status Service return status */
61 /* */
62 /* CALLS */
63 /* */
64 /* None */
65 /* */
66 /* CALLED BY */
67 /* */
68 /* Application Code */
69 /* */
70 /* RELEASE HISTORY */
71 /* */
72 /* DATE NAME DESCRIPTION */
73 /* */
74 /* 09-30-2020 William E. Lamie Initial Version 6.1 */
75 /* */
76 /**************************************************************************/
_tx_thread_time_slice_change(TX_THREAD * thread_ptr,ULONG new_time_slice,ULONG * old_time_slice)77 UINT _tx_thread_time_slice_change(TX_THREAD *thread_ptr, ULONG new_time_slice, ULONG *old_time_slice)
78 {
79
80 TX_INTERRUPT_SAVE_AREA
81
82 ULONG core_index;
83
84
85 /* Lockout interrupts while the thread is being resumed. */
86 TX_DISABLE
87
88 /* If trace is enabled, insert this event into the trace buffer. */
89 TX_TRACE_IN_LINE_INSERT(TX_TRACE_THREAD_TIME_SLICE_CHANGE, thread_ptr, new_time_slice, thread_ptr -> tx_thread_new_time_slice, 0, TX_TRACE_THREAD_EVENTS)
90
91 /* Log this kernel call. */
92 TX_EL_THREAD_TIME_SLICE_CHANGE_INSERT
93
94 /* Return the old time slice. */
95 *old_time_slice = thread_ptr -> tx_thread_new_time_slice;
96
97 /* Setup the new time-slice. */
98 thread_ptr -> tx_thread_time_slice = new_time_slice;
99 thread_ptr -> tx_thread_new_time_slice = new_time_slice;
100
101 /* Pickup index. */
102 core_index = thread_ptr -> tx_thread_smp_core_mapped;
103
104 /* Determine if this thread is the currently executing thread. */
105 #ifndef TX_THREAD_SMP_DYNAMIC_CORE_MAX
106
107 if ((core_index < ((ULONG) TX_THREAD_SMP_MAX_CORES)) && (thread_ptr == _tx_thread_current_ptr[core_index]))
108 #else
109
110 if ((core_index < _tx_thread_smp_max_cores) && (thread_ptr == _tx_thread_current_ptr[core_index]))
111 #endif
112 {
113
114 /* Yes, update the time-slice countdown variable. */
115 _tx_timer_time_slice[core_index] = new_time_slice;
116 }
117
118 /* Restore interrupts. */
119 TX_RESTORE
120
121 /* Return completion status. */
122 return(TX_SUCCESS);
123 }
124
125