1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @ingroup RTEMSScoreSchedulerEDF |
---|
7 | * |
---|
8 | * @brief This source file contains the implementation of |
---|
9 | * _Scheduler_EDF_Map_priority(), _Scheduler_EDF_Unmap_priority(), |
---|
10 | * _Scheduler_EDF_Release_job(), and _Scheduler_EDF_Cancel_job(). |
---|
11 | */ |
---|
12 | |
---|
13 | /* |
---|
14 | * Copyright (C) 2011 Petr Benes. |
---|
15 | * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). |
---|
16 | * |
---|
17 | * Redistribution and use in source and binary forms, with or without |
---|
18 | * modification, are permitted provided that the following conditions |
---|
19 | * are met: |
---|
20 | * 1. Redistributions of source code must retain the above copyright |
---|
21 | * notice, this list of conditions and the following disclaimer. |
---|
22 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
23 | * notice, this list of conditions and the following disclaimer in the |
---|
24 | * documentation and/or other materials provided with the distribution. |
---|
25 | * |
---|
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
30 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
36 | * POSSIBILITY OF SUCH DAMAGE. |
---|
37 | */ |
---|
38 | |
---|
39 | #ifdef HAVE_CONFIG_H |
---|
40 | #include "config.h" |
---|
41 | #endif |
---|
42 | |
---|
43 | #include <rtems/score/scheduleredfimpl.h> |
---|
44 | |
---|
45 | Priority_Control _Scheduler_EDF_Map_priority( |
---|
46 | const Scheduler_Control *scheduler, |
---|
47 | Priority_Control priority |
---|
48 | ) |
---|
49 | { |
---|
50 | return SCHEDULER_EDF_PRIO_MSB | SCHEDULER_PRIORITY_MAP( priority ); |
---|
51 | } |
---|
52 | |
---|
53 | Priority_Control _Scheduler_EDF_Unmap_priority( |
---|
54 | const Scheduler_Control *scheduler, |
---|
55 | Priority_Control priority |
---|
56 | ) |
---|
57 | { |
---|
58 | return SCHEDULER_PRIORITY_UNMAP( priority & ~SCHEDULER_EDF_PRIO_MSB ); |
---|
59 | } |
---|
60 | |
---|
61 | void _Scheduler_EDF_Release_job( |
---|
62 | const Scheduler_Control *scheduler, |
---|
63 | Thread_Control *the_thread, |
---|
64 | Priority_Node *priority_node, |
---|
65 | uint64_t deadline, |
---|
66 | Thread_queue_Context *queue_context |
---|
67 | ) |
---|
68 | { |
---|
69 | (void) scheduler; |
---|
70 | |
---|
71 | _Thread_Wait_acquire_critical( the_thread, queue_context ); |
---|
72 | |
---|
73 | /* |
---|
74 | * There is no integer overflow problem here due to the |
---|
75 | * SCHEDULER_PRIORITY_MAP(). The deadline is in clock ticks. With the |
---|
76 | * minimum clock tick interval of 1us, the uptime is limited to about 146235 |
---|
77 | * years. |
---|
78 | */ |
---|
79 | _Priority_Node_set_priority( |
---|
80 | priority_node, |
---|
81 | SCHEDULER_PRIORITY_MAP( deadline ) |
---|
82 | ); |
---|
83 | |
---|
84 | if ( _Priority_Node_is_active( priority_node ) ) { |
---|
85 | _Thread_Priority_changed( |
---|
86 | the_thread, |
---|
87 | priority_node, |
---|
88 | PRIORITY_GROUP_LAST, |
---|
89 | queue_context |
---|
90 | ); |
---|
91 | } else { |
---|
92 | _Thread_Priority_add( the_thread, priority_node, queue_context ); |
---|
93 | } |
---|
94 | |
---|
95 | _Thread_Wait_release_critical( the_thread, queue_context ); |
---|
96 | } |
---|
97 | |
---|
98 | void _Scheduler_EDF_Cancel_job( |
---|
99 | const Scheduler_Control *scheduler, |
---|
100 | Thread_Control *the_thread, |
---|
101 | Priority_Node *priority_node, |
---|
102 | Thread_queue_Context *queue_context |
---|
103 | ) |
---|
104 | { |
---|
105 | (void) scheduler; |
---|
106 | |
---|
107 | _Thread_Wait_acquire_critical( the_thread, queue_context ); |
---|
108 | |
---|
109 | if ( _Priority_Node_is_active( priority_node ) ) { |
---|
110 | _Thread_Priority_remove( the_thread, priority_node, queue_context ); |
---|
111 | _Priority_Node_set_inactive( priority_node ); |
---|
112 | } |
---|
113 | |
---|
114 | _Thread_Wait_release_critical( the_thread, queue_context ); |
---|
115 | } |
---|