source: rtems/cpukit/rtems/src/scheduleraddprocessor.c @ d78d529

5
Last change on this file since d78d529 was 05ca53d, checked in by Sebastian Huber <sebastian.huber@…>, on 10/31/16 at 12:08:33

rtems: Add scheduler processor add/remove

Update #2797.

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 * Copyright (c) 2016 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/rtems/tasks.h>
20#include <rtems/score/assert.h>
21#include <rtems/score/schedulerimpl.h>
22#include <rtems/config.h>
23
24rtems_status_code rtems_scheduler_add_processor(
25  rtems_id scheduler_id,
26  uint32_t cpu_index
27)
28{
29  uint32_t                 scheduler_index;
30#if defined(RTEMS_SMP)
31  Per_CPU_Control         *cpu;
32  rtems_status_code        status;
33#endif
34
35  scheduler_index = _Scheduler_Get_index_by_id( scheduler_id );
36
37  if ( scheduler_index >= _Scheduler_Count ) {
38    return RTEMS_INVALID_ID;
39  }
40
41  if ( cpu_index >= rtems_configuration_get_maximum_processors() ) {
42    return RTEMS_NOT_CONFIGURED;
43  }
44
45#if defined(RTEMS_SMP)
46  cpu = _Per_CPU_Get_by_index( cpu_index );
47
48  if ( _Scheduler_Initial_assignments[ cpu_index ].scheduler == NULL ) {
49    return RTEMS_NOT_CONFIGURED;
50  }
51
52  if ( !_Per_CPU_Is_processor_online( cpu ) ) {
53    return RTEMS_INCORRECT_STATE;
54  }
55
56  _Objects_Allocator_lock();
57
58  if ( cpu->Scheduler.control == NULL ) {
59    const Scheduler_Control *scheduler;
60    Scheduler_Context       *scheduler_context;
61    Priority_Control         idle_priority;
62    Thread_Control          *idle;
63    Scheduler_Node          *scheduler_node;
64    ISR_lock_Context         lock_context;
65    Thread_queue_Context     queue_context;
66    Per_CPU_Control         *cpu_self;
67
68    scheduler = &_Scheduler_Table[ scheduler_index ];
69    scheduler_context = _Scheduler_Get_context( scheduler );
70    idle_priority =
71      _Scheduler_Map_priority( scheduler, scheduler->maximum_priority );
72
73    idle = cpu->Scheduler.idle_if_online_and_unused;
74    _Assert( idle != NULL );
75    cpu->Scheduler.idle_if_online_and_unused = NULL;
76
77    idle->Scheduler.home = scheduler;
78    idle->Start.initial_priority = idle_priority;
79    scheduler_node =
80      _Thread_Scheduler_get_node_by_index( idle, scheduler_index );
81    _Priority_Node_set_priority( &idle->Real_priority, idle_priority );
82    _Priority_Initialize_one(
83      &scheduler_node->Wait.Priority,
84      &idle->Real_priority
85    );
86    _Assert( _Chain_Is_empty( &idle->Scheduler.Wait_nodes ) );
87    _Chain_Initialize_one(
88      &idle->Scheduler.Wait_nodes,
89      &scheduler_node->Thread.Wait_node
90    );
91    _Assert( _Chain_Is_empty( &idle->Scheduler.Scheduler_nodes ) );
92    _Chain_Initialize_one(
93      &idle->Scheduler.Scheduler_nodes,
94      &scheduler_node->Thread.Scheduler_node.Chain
95    );
96
97    _ISR_lock_ISR_disable( &lock_context );
98    _Scheduler_Acquire_critical( scheduler, &lock_context );
99    ++scheduler_context->processor_count;
100    cpu->Scheduler.control = scheduler;
101    cpu->Scheduler.context = scheduler_context;
102    ( *scheduler->Operations.add_processor )( scheduler, idle );
103    cpu_self = _Thread_Dispatch_disable_critical(
104      &queue_context.Lock_context.Lock_context
105    );
106    _Scheduler_Release_critical( scheduler, &lock_context );
107    _ISR_lock_ISR_enable( &lock_context );
108    _Thread_Dispatch_enable( cpu_self );
109    status = RTEMS_SUCCESSFUL;
110  } else {
111    status = RTEMS_RESOURCE_IN_USE;
112  }
113
114  _Objects_Allocator_unlock();
115  return status;
116#else
117  return RTEMS_RESOURCE_IN_USE;
118#endif
119}
Note: See TracBrowser for help on using the repository browser.