source: rtems/cpukit/score/src/cpuset.c @ 9db8705

4.11
Last change on this file since 9db8705 was 9db8705, checked in by Jennifer Averett <jennifer.averett@…>, on Feb 6, 2014 at 6:42:24 PM

score: Add cpuset support to Score.

This new Score Handler provides a structure to manage a
cpu_set_t plus helper routines to validate the contents
against the current system configuration.

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup ScoreCpuset
5 *
6 * @brief Routines to Control a CPU Set.
7 */
8
9/*
10 *  COPYRIGHT (c) 2014.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.org/license/LICENSE.
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#ifdef __RTEMS_HAVE_SYS_CPUSET_H__
23#include <sys/cpuset.h>
24#include <rtems/score/cpusetimpl.h>
25#include <rtems/score/assert.h>
26#include <rtems/score/percpu.h>
27
28static CPU_set_Control cpuset_default;
29
30/*
31 * _CPU_set_Handler_initialization
32 */
33void _CPU_set_Handler_initialization()
34{
35  int i;
36  int max_cpus;
37
38  /* We do not support a cpu count over CPU_SETSIZE  */
39  max_cpus = _SMP_Get_processor_count();
40
41  /* This should never happen */
42  _Assert( max_cpus <= CPU_SETSIZE );
43
44  /*  Initialize the affinity to be the set of all available CPU's   */
45  cpuset_default.set     = &cpuset_default.preallocated;
46  cpuset_default.setsize = sizeof( *cpuset_default.set );
47  CPU_ZERO_S( cpuset_default.setsize, &cpuset_default.preallocated );
48
49  for (i=0; i<max_cpus; i++) 
50    CPU_SET_S(i, cpuset_default.setsize, cpuset_default.set );
51}
52
53/**
54 * _CPU_set_Is_valid
55 *
56 * This routine validates a cpuset size corresponds to
57 * the system correct size, that at least one
58 * valid cpu is set and that no invalid cpus are set.
59 */
60int _CPU_set_Is_valid( const cpu_set_t *cpuset, size_t setsize )
61{
62  cpu_set_t             temp;
63
64  if ( !cpuset )
65    return -1;
66
67  if (setsize != cpuset_default.setsize )
68    return -1;
69
70  /* Validate at least 1 valid cpu is set in cpuset */
71  CPU_AND_S( cpuset_default.setsize, &temp, cpuset, cpuset_default.set );
72
73  if ( CPU_COUNT_S( setsize, &temp ) == 0 )
74    return -1;
75
76  /* Validate that no invalid cpu's are set in cpuset */
77  if ( !CPU_EQUAL_S( setsize, &temp, cpuset ) )
78    return -1;
79
80  return 0;
81}
82
83/**
84 * _CPU_set_Default
85 *
86 * This routine returns the default cpuset.
87 */
88const CPU_set_Control *_CPU_set_Default() 
89{
90  return &cpuset_default;
91}
92#endif
93
94
Note: See TracBrowser for help on using the repository browser.