1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup RTEMSImplClassicScheduler |
---|
5 | * |
---|
6 | * @brief This source file contains the implementation of |
---|
7 | * rtems_scheduler_ident_by_processor_set(). |
---|
8 | */ |
---|
9 | |
---|
10 | /* |
---|
11 | * Copyright (c) 2017 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/scheduler.h> |
---|
29 | #include <rtems/score/assert.h> |
---|
30 | #include <rtems/score/schedulerimpl.h> |
---|
31 | |
---|
32 | rtems_status_code rtems_scheduler_ident_by_processor_set( |
---|
33 | size_t cpusetsize, |
---|
34 | const cpu_set_t *cpuset, |
---|
35 | rtems_id *id |
---|
36 | ) |
---|
37 | { |
---|
38 | Processor_mask set; |
---|
39 | Processor_mask_Copy_status status; |
---|
40 | uint32_t cpu_index; |
---|
41 | const Scheduler_Control *scheduler; |
---|
42 | |
---|
43 | if ( id == NULL ) { |
---|
44 | return RTEMS_INVALID_ADDRESS; |
---|
45 | } |
---|
46 | |
---|
47 | if ( cpuset == NULL ) { |
---|
48 | return RTEMS_INVALID_ADDRESS; |
---|
49 | } |
---|
50 | |
---|
51 | status = _Processor_mask_From_cpu_set_t( &set, cpusetsize, cpuset ); |
---|
52 | if ( status == PROCESSOR_MASK_COPY_INVALID_SIZE ) { |
---|
53 | return RTEMS_INVALID_SIZE; |
---|
54 | } |
---|
55 | |
---|
56 | _Processor_mask_And( &set, &set, _SMP_Get_online_processors() ); |
---|
57 | cpu_index = _Processor_mask_Find_last_set( &set ); |
---|
58 | if ( cpu_index == 0 ) { |
---|
59 | return RTEMS_INVALID_NAME; |
---|
60 | } |
---|
61 | |
---|
62 | scheduler = _Scheduler_Get_by_CPU( _Per_CPU_Get_by_index( cpu_index - 1) ); |
---|
63 | #if defined(RTEMS_SMP) |
---|
64 | if ( scheduler == NULL ) { |
---|
65 | return RTEMS_INCORRECT_STATE; |
---|
66 | } |
---|
67 | #else |
---|
68 | _Assert( scheduler != NULL ); |
---|
69 | #endif |
---|
70 | |
---|
71 | *id = _Scheduler_Build_id( _Scheduler_Get_index( scheduler ) ); |
---|
72 | return RTEMS_SUCCESSFUL; |
---|
73 | } |
---|