RTEMS
scheduleridentbyprocessorset.c
1 /*
2  * Copyright (c) 2017 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 #ifdef HAVE_CONFIG_H
16 #include "config.h"
17 #endif
18 
19 #include <rtems/rtems/tasks.h>
20 #include <rtems/score/assert.h>
22 
24  size_t cpusetsize,
25  const cpu_set_t *cpuset,
26  rtems_id *id
27 )
28 {
29  Processor_mask set;
30  Processor_mask_Copy_status status;
31  uint32_t cpu_index;
32  const Scheduler_Control *scheduler;
33 
34  if ( id == NULL ) {
35  return RTEMS_INVALID_ADDRESS;
36  }
37 
38  status = _Processor_mask_From_cpu_set_t( &set, cpusetsize, cpuset );
39  if ( status == PROCESSOR_MASK_COPY_INVALID_SIZE ) {
40  return RTEMS_INVALID_SIZE;
41  }
42 
44  cpu_index = _Processor_mask_Find_last_set( &set );
45  if ( cpu_index == 0 ) {
46  return RTEMS_INVALID_NAME;
47  }
48 
49  scheduler = _Scheduler_Get_by_CPU( _Per_CPU_Get_by_index( cpu_index - 1) );
50 #if defined(RTEMS_SMP)
51  if ( scheduler == NULL ) {
52  return RTEMS_INCORRECT_STATE;
53  }
54 #else
55  _Assert( scheduler != NULL );
56 #endif
57 
58  *id = _Scheduler_Build_id( _Scheduler_Get_index( scheduler ) );
59  return RTEMS_SUCCESSFUL;
60 }
rtems_status_code rtems_scheduler_ident_by_processor_set(size_t cpusetsize, const cpu_set_t *cpuset, rtems_id *id)
Identifies a scheduler instance by a processor set.
RTEMS_INLINE_ROUTINE Processor_mask_Copy_status _Processor_mask_From_cpu_set_t(Processor_mask *dst, size_t src_size, const cpu_set_t *src)
Copies one mask to another.
static __inline__ const Scheduler_Control * _Scheduler_Get_by_CPU(const Per_CPU_Control *cpu)
Gets the scheduler for the cpu.
Definition: schedulerimpl.h:99
static __inline__ const Processor_mask * _SMP_Get_online_processors(void)
Gets all online processors.
Definition: smpimpl.h:318
Inlined Routines Associated with the Manipulation of the Scheduler.
RTEMS_INLINE_ROUTINE uint32_t _Processor_mask_Find_last_set(const Processor_mask *a)
Finds the last set of the processor mask.
Information for the Assert Handler.
This status code indicates successful completion.
Definition: status.h:86
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:82
RTEMS_INLINE_ROUTINE void _Processor_mask_And(Processor_mask *a, const Processor_mask *b, const Processor_mask *c)
Performs a bitwise a = b & c.
This status code indicates that an object was in wrong state for the requested operation.
Definition: status.h:160
This header file defines the main parts of the Tasks Manager API.
This status code indicates that a specified address was invalid.
Definition: status.h:133
static __inline__ Objects_Id _Scheduler_Build_id(uint32_t scheduler_index)
Builds an object build id.
Objects_Id rtems_id
Values of this type identify an RTEMS object.
Definition: types.h:99
Scheduler control.
Definition: scheduler.h:264
This status code indicates that an object name was invalid.
Definition: status.h:101
static __inline__ uint32_t _Scheduler_Get_index(const Scheduler_Control *scheduler)
Gets the index of the scheduler.
This status code indicates that a specified size was invalid.
Definition: status.h:128
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
Definition: assert.h:100