1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @ingroup RTEMSScoreScheduler |
---|
7 | * |
---|
8 | * @brief This source file contains the implementation of |
---|
9 | * _Sched_Count(), _Sched_Index(), _Sched_Name_to_index(), and |
---|
10 | * _Sched_Processor_count(). |
---|
11 | */ |
---|
12 | |
---|
13 | /* |
---|
14 | * Copyright (c) 2015 embedded brains GmbH & Co. KG |
---|
15 | * |
---|
16 | * Redistribution and use in source and binary forms, with or without |
---|
17 | * modification, are permitted provided that the following conditions |
---|
18 | * are met: |
---|
19 | * 1. Redistributions of source code must retain the above copyright |
---|
20 | * notice, this list of conditions and the following disclaimer. |
---|
21 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
22 | * notice, this list of conditions and the following disclaimer in the |
---|
23 | * documentation and/or other materials provided with the distribution. |
---|
24 | * |
---|
25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
35 | * POSSIBILITY OF SUCH DAMAGE. |
---|
36 | */ |
---|
37 | |
---|
38 | #ifdef HAVE_CONFIG_H |
---|
39 | #include "config.h" |
---|
40 | #endif |
---|
41 | |
---|
42 | #include <sys/lock.h> |
---|
43 | |
---|
44 | #include <rtems/score/schedulerimpl.h> |
---|
45 | |
---|
46 | int _Sched_Count( void ) |
---|
47 | { |
---|
48 | return (int) _Scheduler_Count; |
---|
49 | } |
---|
50 | |
---|
51 | int _Sched_Index( void ) |
---|
52 | { |
---|
53 | Thread_Control *executing = _Thread_Get_executing(); |
---|
54 | |
---|
55 | return (int) _Scheduler_Get_index( _Thread_Scheduler_get_home( executing ) ); |
---|
56 | } |
---|
57 | |
---|
58 | int _Sched_Name_to_index( const char *name, size_t len ) |
---|
59 | { |
---|
60 | uint32_t name_32 = 0; |
---|
61 | size_t i = 0; |
---|
62 | |
---|
63 | while ( i < 4 && i < len ) { |
---|
64 | name_32 |= ( (uint32_t) ( (uint8_t) *name ) ) << ( ( 3 - i ) * 8 ); |
---|
65 | ++name; |
---|
66 | ++i; |
---|
67 | } |
---|
68 | |
---|
69 | for ( i = 0 ; i < _Scheduler_Count ; ++i ) { |
---|
70 | const Scheduler_Control *scheduler = &_Scheduler_Table[ i ]; |
---|
71 | |
---|
72 | if ( scheduler->name == name_32 ) { |
---|
73 | return (int) i; |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | return -1; |
---|
78 | } |
---|
79 | |
---|
80 | int _Sched_Processor_count( int index ) |
---|
81 | { |
---|
82 | size_t i = (size_t) index; |
---|
83 | |
---|
84 | if ( i < _Scheduler_Count ) { |
---|
85 | return _Scheduler_Get_processor_count( &_Scheduler_Table[ i ] ); |
---|
86 | } else { |
---|
87 | return 0; |
---|
88 | } |
---|
89 | } |
---|