source: rtems/cpukit/rtems/src/scheduleraddprocessor.c @ 6b5f22dc

Last change on this file since 6b5f22dc was 6b5f22dc, checked in by Sebastian Huber <sebastian.huber@…>, on 11/26/20 at 10:45:47

rtems: Canonicalize Doxygen @file comments

Use common phrases for the file brief descriptions.

Update #3706.

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