summaryrefslogtreecommitdiffstats
path: root/cpukit/score/include/rtems/score/cpusetimpl.h
blob: 226c3a1806b610269878131f7ad75c9b4cad1c32 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/**
 *  @file
 *
 *  @brief Implementation Helper for CPU Set
 *
 *  This file contains the implementation helpers inlines and prototypes for
 *  CPU set methods.
 */

/*
 *  COPYRIGHT (c) 2014.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.org/license/LICENSE.
 */

#ifndef _RTEMS_SCORE_CPUSETIMPL_H
#define _RTEMS_SCORE_CPUSETIMPL_H

#include <rtems/score/cpuset.h>
#include <rtems/score/smp.h>

#include <limits.h>

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __RTEMS_HAVE_SYS_CPUSET_H__

/**
 * @brief Determine If the CPU Set if Valid
 *
 * This routine validates a cpuset size corresponds to the system
 * correct size, that at least one valid cpu is set and that no invalid
 * cpus are set.
 *
 * @param[in] cpuset is the cpuset to validate
 * @param[in] setsize is the number of CPUs in the cpuset
 *
 * @return true if the set is valid
 */
bool _CPU_set_Is_valid( const cpu_set_t *cpuset, size_t setsize );

/**
 * @brief Print the CPU Set
 *
 * This routine will print the value of the given cpuset.
 *
 * @param[in] description is a string to print before the value.
 * @param[in] cpuset is the cpuset to validate
 */
void _CPU_set_Show( const char *description, const cpu_set_t  *cpuset);

/**
 * @brief Print the Default CPU Set
 *
 * This routine will print the value of the default cpuset.
 *
 * @param[in] description is a string to print before the value.
 */
void _CPU_set_Show_default( const char *description );

/**
 * @brief Obtain the Default CPU Set
 *
 * This routine returns the default cpuset for this system.
 *
 * @return a pointer to the default cpuset.
 */
const CPU_set_Control *_CPU_set_Default(void);

/**
 * @brief Obtain the Maximum Number of CPUs Representable in CPU Set
 *
 * This routine returns maximum number of CPUs that can be represented
 * in the @a setsize specified.
 *
 * @return the number of representable cores in the cpuset
 */
RTEMS_INLINE_ROUTINE size_t _CPU_set_Maximum_CPU_count( size_t setsize )
{
  return setsize * CHAR_BIT;
}

/**
 * @brief Is this CPU Set Large Enough?
 *
 * This method can be used to determine if a particular cpuset is
 * large enough for the number of CPUs in the system.
 *
 * @param[in] setsize is the number of CPUs in the cpuset
 *
 * @return true if the @a setsize is sufficient
 */
RTEMS_INLINE_ROUTINE bool _CPU_set_Is_large_enough(
  size_t setsize
)
{
  return _CPU_set_Maximum_CPU_count( setsize ) >= _SMP_Get_processor_count();
}

/**
 * @brief Fill in CPU_set_Control
 *
 * This method fills in a CPU_set_Control based upon a cpu_set_t and
 * size information.
 *
 * @param[in] cpuset is the cpuset to validate
 * @param[in] setsize is the number of CPUs in the cpuset
 */
static inline void _CPU_set_Set(
  size_t           setsize,
  cpu_set_t       *cpuset,
  CPU_set_Control *set
)
{
  set->set     = &set->preallocated;
  set->setsize = setsize;
  CPU_COPY( set->set, cpuset );
}
#endif

/**
 * @brief Initialize the CPU Set Handler
 *
 * This routine validates a cpuset sets at least one valid cpu and that
 * it does not set any invalid cpus.
 */
#if __RTEMS_HAVE_SYS_CPUSET_H__ && defined( RTEMS_SMP )
void _CPU_set_Handler_initialization(void);
#else
#define _CPU_set_Handler_initialization()  do { } while ( 0 )
#endif

/**@}*/

#ifdef __cplusplus
}
#endif
#endif
/* end of include file */