1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief CBS Scheduler Budget Handler |
---|
5 | * @ingroup ScoreScheduler |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * Copyright (C) 2011 Petr Benes. |
---|
10 | * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.com/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/score/schedulercbs.h> |
---|
22 | #include <rtems/score/thread.h> |
---|
23 | #include <rtems/score/wkspace.h> |
---|
24 | |
---|
25 | Scheduler_CBS_Server **_Scheduler_CBS_Server_list; |
---|
26 | |
---|
27 | void _Scheduler_CBS_Budget_callout( |
---|
28 | Thread_Control *the_thread |
---|
29 | ) |
---|
30 | { |
---|
31 | Priority_Control new_priority; |
---|
32 | Scheduler_CBS_Per_thread *sched_info; |
---|
33 | Scheduler_CBS_Server_id server_id; |
---|
34 | |
---|
35 | /* Put violating task to background until the end of period. */ |
---|
36 | new_priority = the_thread->Start.initial_priority; |
---|
37 | if ( the_thread->real_priority != new_priority ) |
---|
38 | the_thread->real_priority = new_priority; |
---|
39 | if ( the_thread->current_priority != new_priority ) |
---|
40 | _Thread_Change_priority(the_thread, new_priority, true); |
---|
41 | |
---|
42 | /* Invoke callback function if any. */ |
---|
43 | sched_info = (Scheduler_CBS_Per_thread *) the_thread->scheduler_info; |
---|
44 | if ( sched_info->cbs_server->cbs_budget_overrun ) { |
---|
45 | _Scheduler_CBS_Get_server_id( |
---|
46 | sched_info->cbs_server->task_id, |
---|
47 | &server_id |
---|
48 | ); |
---|
49 | sched_info->cbs_server->cbs_budget_overrun( server_id ); |
---|
50 | } |
---|
51 | } |
---|
52 | |
---|
53 | int _Scheduler_CBS_Initialize(void) |
---|
54 | { |
---|
55 | unsigned int i; |
---|
56 | _Scheduler_CBS_Server_list = (Scheduler_CBS_Server **) _Workspace_Allocate( |
---|
57 | _Scheduler_CBS_Maximum_servers * sizeof(Scheduler_CBS_Server*) ); |
---|
58 | if ( !_Scheduler_CBS_Server_list ) |
---|
59 | return SCHEDULER_CBS_ERROR_NO_MEMORY; |
---|
60 | for (i = 0; i<_Scheduler_CBS_Maximum_servers; i++) { |
---|
61 | _Scheduler_CBS_Server_list[i] = NULL; |
---|
62 | } |
---|
63 | return SCHEDULER_CBS_OK; |
---|
64 | } |
---|