File: paffinity.h

package info (click to toggle)
openmpi 1.6.5-9.1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 91,628 kB
  • ctags: 44,305
  • sloc: ansic: 408,966; cpp: 44,454; sh: 27,828; makefile: 10,486; asm: 3,882; python: 1,239; lex: 805; perl: 549; csh: 253; fortran: 232; f90: 126; tcl: 12
file content (398 lines) | stat: -rw-r--r-- 14,848 bytes parent folder | download | duplicates (2)
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
/*
 * Copyright (c) 2004-2008 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2005 The University of Tennessee and The University
 *                         of Tennessee Research Foundation.  All rights
 *                         reserved.
 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, 
 *                         University of Stuttgart.  All rights reserved.
 * Copyright (c) 2004-2005 The Regents of the University of California.
 *                         All rights reserved.
 * Copyright (c) 2007-2011 Cisco Systems, Inc.  All rights reserved.
 * Copyright (c) 2009      Sun Microsystems, Inc.  All rights reserved.
 * Copyright (c) 2010      IBM Corporation.  All rights reserved.
 * $COPYRIGHT$
 * 
 * Additional copyrights may follow
 * 
 * $HEADER$
 */
/**
 * @file
 *
 * paffinity (processor affinity) framework component interface
 * definitions.
 *
 * Intent
 *
 * This is an extremely simple framework that is used to support the
 * OS-specific API for placement of processes on processors.  It does
 * *not* decide scheduling issues -- it is simply for assigning the
 * current process it to a specific processor set.  As such, the
 * components are likely to be extremely short/simple -- there will
 * likely be one component for each OS/API that we support (e.g.,
 * Linux, IRIX, etc.).  As a direct consequence, there will likely
 * only be one component that is useable on a given platform (making
 * selection easy).
 *
 * It is *not* an error if there is no paffinity component available;
 * processor affinity services are simply not available.  Hence,
 * paffinity component functions are invoked through short wrapper
 * functions in paffinity/base (that check to see if there is a
 * selected component before invoking function pointers).  If there is
 * no selected component, they return an appropriate error code.
 *
 * In the paffinity interface, we make the distinction between LOGICAL
 * and PHYSICAL processors.  LOGICAL processors are defined to have
 * some corresponding PHYSICAL processor that both exists and is
 * currently online.  LOGICAL processors numbered countiguously
 * starting with 0.  PHYSICAL processors are numbered according to the
 * underlying operating system; they are represented by integers, but
 * no guarantees are made about their values.
 *
 * Hence, LOGICAL processor IDs are convenient for humans and are in
 * the range of [0,N-1] (assuming N processors are currently online).
 * Each LOGICAL processor has a 1:1 relationship with a PHYSICAL
 * processor, but the PHYSICAL processor's ID can be any unique
 * integer value.
 * 
 * ***NOTE*** Obtaining information about socket/core IDs is not well
 * supported in many OS's.  Programmers using this paffinity interface
 * should fully expect to sometimes get OPAL_ERR_NOT_SUPPORTED back
 * when calling such functions.

 * General scheme
 *
 * The component has one function: query().  It simply returns a
 * priority (for the unlikely event where there are multiple
 * components available on a given platform).
 *
 * The module has the following functions:
 *
 * - module_init: initialze the module
 * - set: set this process's affinity to a specific processor set
 * - get: get this process's processor affinity set
 * - map physical (socket ID, core ID) -> physical processor ID
 * - map physical processor ID -> physical (socket ID, core ID)
 * - get the number of logical processors
 * - get the number of logical sockets
 * - get the number of logical cores on a specific socket
 * - map logical processor ID -> physical processor ID
 * - map logical socket ID -> physical socket ID
 * - map physical socket ID, logical core ID -> physical core ID
 * - module_finalize: finalize the module
 */

#ifndef OPAL_PAFFINITY_H
#define OPAL_PAFFINITY_H

#include "opal_config.h"

#ifdef HAVE_STRING_H
#include <string.h>
#endif

#include "opal/mca/mca.h"
#include "opal/mca/base/base.h"

/* ******************************************************************** */

/** Process locality definitions */
#define OPAL_PROC_ON_CLUSTER    0x10
#define OPAL_PROC_ON_CU         0x08
#define OPAL_PROC_ON_NODE       0x04
#define OPAL_PROC_ON_BOARD      0x02
#define OPAL_PROC_ON_SOCKET     0x01
#define OPAL_PROC_NON_LOCAL     0x00
#define OPAL_PROC_ALL_LOCAL     0x1f

/** Process locality macros */
#define OPAL_PROC_ON_LOCAL_SOCKET(n)    ((n) & OPAL_PROC_ON_SOCKET)
#define OPAL_PROC_ON_LOCAL_BOARD(n)     ((n) & OPAL_PROC_ON_BOARD)
#define OPAL_PROC_ON_LOCAL_NODE(n)      ((n) & OPAL_PROC_ON_NODE)
#define OPAL_PROC_ON_LOCAL_CU(n)        ((n) & OPAL_PROC_ON_CU)
#define OPAL_PROC_ON_LOCAL_CLUSTER(n)   ((n) & OPAL_PROC_ON_CLUSTER)

/* Process binding modes */
#define OPAL_PAFFINITY_DO_NOT_BIND          0x01
#define OPAL_PAFFINITY_BIND_TO_CORE         0x02
#define OPAL_PAFFINITY_BIND_TO_SOCKET       0x04
#define OPAL_PAFFINITY_BIND_TO_BOARD        0x08
#define OPAL_PAFFINITY_BIND_IF_SUPPORTED    0x80
/* ******************************************************************** */


/**
 * Buffer type for paffinity processor masks.
 * Copied almost directly from PLPA.
 */

/**
 * \internal
 * Internal type used for the underlying bitmask unit
 */
typedef unsigned long int opal_paffinity_base_bitmask_t;

/**
 * \internal
 * Number of bits in opal_paffinity_base_bitmask_t
 */
#define OPAL_PAFFINITY_BITMASK_T_NUM_BITS (sizeof(opal_paffinity_base_bitmask_t) * 8)
/**
 * \internal
 * How many bits we want
 */
#define OPAL_PAFFINITY_BITMASK_CPU_MAX 1024
/**
 * \internal
 * How many opal_paffinity_base_bitmask_t's we need
 */
#define OPAL_PAFFINITY_BITMASK_NUM_ELEMENTS (OPAL_PAFFINITY_BITMASK_CPU_MAX / OPAL_PAFFINITY_BITMASK_T_NUM_BITS)

/**
 * \internal
 * How many bytes in a cpu set
 */
#define OPAL_PAFFINITY_CPU_SET_NUM_BYTES (OPAL_PAFFINITY_BITMASK_NUM_ELEMENTS * sizeof(opal_paffinity_base_bitmask_t))

/**
 * Public processor bitmask type
 */
typedef struct opal_paffinity_base_cpu_set_t { 
    opal_paffinity_base_bitmask_t bitmask[OPAL_PAFFINITY_BITMASK_NUM_ELEMENTS];
} opal_paffinity_base_cpu_set_t;

/***************************************************************************/

/**
 * \internal
 * Internal macro for identifying the byte in a bitmask array 
 */
#define OPAL_PAFFINITY_CPU_BYTE(num) ((num) / OPAL_PAFFINITY_BITMASK_T_NUM_BITS)

/**
 * \internal
 * Internal macro for identifying the bit in a bitmask array 
 */
#define OPAL_PAFFINITY_CPU_BIT(num) ((num) % OPAL_PAFFINITY_BITMASK_T_NUM_BITS)

/***************************************************************************/

/**
 * Public macro to zero out a OPAL_PAFFINITY cpu set 
 */
#define OPAL_PAFFINITY_CPU_ZERO(cpuset) \
    memset(&(cpuset), 0, sizeof(opal_paffinity_base_cpu_set_t))

/**
 * Public macro to set a bit in a OPAL_PAFFINITY cpu set 
 */
#define OPAL_PAFFINITY_CPU_SET(num, cpuset) \
    (cpuset).bitmask[OPAL_PAFFINITY_CPU_BYTE(num)] |= ((opal_paffinity_base_bitmask_t) 1 << OPAL_PAFFINITY_CPU_BIT(num))

/**
 * Public macro to clear a bit in a OPAL_PAFFINITY cpu set 
 */
#define OPAL_PAFFINITY_CPU_CLR(num, cpuset) \
    (cpuset).bitmask[OPAL_PAFFINITY_CPU_BYTE(num)] &= ~((opal_paffinity_base_bitmask_t) 1 << OPAL_PAFFINITY_CPU_BIT(num))

/**
 * Public macro to test if a bit is set in a OPAL_PAFFINITY cpu set 
 */
#define OPAL_PAFFINITY_CPU_ISSET(num, cpuset) \
    (0 != (((cpuset).bitmask[OPAL_PAFFINITY_CPU_BYTE(num)]) & ((opal_paffinity_base_bitmask_t) 1 << OPAL_PAFFINITY_CPU_BIT(num))))

/**
 * Public macro to test if a process is bound anywhere
 */
#define OPAL_PAFFINITY_PROCESS_IS_BOUND(cpuset, bound)                  \
    do {                                                                \
        int i, num_processors, num_bound;                               \
        *(bound) = false;                                               \
        if (OPAL_SUCCESS ==                                             \
            opal_paffinity_base_get_processor_info(&num_processors)) {  \
            num_bound = 0;                                              \
            for (i = 0; i < OPAL_PAFFINITY_BITMASK_CPU_MAX; i++) {      \
                if (OPAL_PAFFINITY_CPU_ISSET(i, (cpuset))) {            \
                    num_bound++;                                        \
                }                                                       \
            }                                                           \
            if (0 < num_bound && (1 == num_processors ||                \
                                  num_bound < num_processors)) {        \
                *(bound) = true;                                        \
            }                                                           \
        }                                                               \
    } while(0);

/***************************************************************************/

/**
 * Module initialization function.  Should return OPAL_SUCCESS.
 */
typedef int (*opal_paffinity_base_module_init_1_1_0_fn_t)(void);

/**
 * Module function to set this process' affinity to a specific set of
 * PHYSICAL CPUs.
 */
typedef int (*opal_paffinity_base_module_set_fn_t)(opal_paffinity_base_cpu_set_t cpumask);


/**
 * Module function to get this process' affinity to a specific set of
 * PHYSICAL CPUs.  Returns any binding in the cpumask. This function -only-
 * returns something other than OPAL_SUCCESS if an actual error is encountered.
 * You will need to check the mask to find out if this process is actually
 * bound somewhere specific - a macro for that purpose is provided above
 */
typedef int (*opal_paffinity_base_module_get_fn_t)(opal_paffinity_base_cpu_set_t *cpumask);

/**
 * Returns mapping of PHYSICAL socket:core -> PHYSICAL processor id.
 * 
 * Return OPAL_SUCCESS or OPAL_ERR_NOT_SUPPORTED if not
 * supported
 */
typedef int (*opal_paffinity_base_module_get_map_to_processor_id_fn_t)(int physical_socket,
                                                                       int physical_core,
                                                                       int *physical_processor_id);

/**
 * Provides mapping of PHYSICAL processor id -> PHYSICAL socket:core.
 * 
 * Return OPAL_SUCCESS or OPAL_ERR_NOT_SUPPORTED if not
 * supported
 */
typedef int (*opal_paffinity_base_module_get_map_to_socket_core_fn_t)(int physical_processor_id,
                                                                      int *physical_socket,
                                                                      int *physical_core);

/**
 * Provides number of LOGICAL processors in a host.
 * 
 * Return OPAL_SUCCESS or OPAL_ERR_NOT_SUPPORTED if not
 * supported
 */
typedef int (*opal_paffinity_base_module_get_processor_info_fn_t)(int *num_processors);

/**
 * Provides the number of LOGICAL sockets in a host.
 * 
 * Return OPAL_SUCCESS or OPAL_ERR_NOT_SUPPORTED if not
 * supported
 */
typedef int (*opal_paffinity_base_module_get_socket_info_fn_t)(int *num_sockets);

/**
 * Provides the number of LOGICAL cores in a PHYSICAL socket. currently supported
 * only in Linux hosts
 * 
 * Returns OPAL_SUCCESS or OPAL_ERR_NOT_SUPPORTED if not
 * supported.
 */
typedef int (*opal_paffinity_base_module_get_core_info_fn_t)(int physical_socket, int *num_cores);

/**
 * Return the PHYSICAL processor ID that corresponds to the
 * given LOGICAL processor ID.
 *
 * Return OPAL_ERR_NOT_SUPPORTED if not supported.
 */
typedef int (*opal_paffinity_base_module_get_physical_processor_id_fn_t)(int logical_processor_id);

/**
 * Return the PHYSICAL socket ID that corresponds to the given
 * LOGICAL socket ID.
 * 
 * Return OPAL_ERR_NOT_SUPPORTED if not supported.
 */
typedef int (*opal_paffinity_base_module_get_physical_socket_id_fn_t)(int logical_socket_id);

/**
 * Return the PHYSICAL core ID that corresponds to the given LOGICAL
 * core ID on the given PHYSICAL socket ID.
 * 
 * Return OPAL_ERR_NOT_SUPPORTED if not supported.
 */
typedef int (*opal_paffinity_base_module_get_physical_core_id_fn_t)(int physical_socket_id, int logical_core_id);


/**
 * Module finalize function.  Invoked by the base on the selected
 * module when the paffinity framework is being shut down.
 */
typedef int (*opal_paffinity_base_module_finalize_fn_t)(void);


/**
 * Structure for paffinity components.
 */
struct opal_paffinity_base_component_2_0_0_t {
    /** MCA base component */
    mca_base_component_t base_version;
    /** MCA base data */
    mca_base_component_data_t base_data;
};
/**
 * Convenience typedef
 */
typedef struct opal_paffinity_base_component_2_0_0_t opal_paffinity_base_component_2_0_0_t;
typedef struct opal_paffinity_base_component_2_0_0_t opal_paffinity_base_component_t;


/**
 * Structure for paffinity modules
 */
struct opal_paffinity_base_module_1_1_0_t {
    /** Module initialization function */
    opal_paffinity_base_module_init_1_1_0_fn_t                  paff_module_init;

    /** Set this process' affinity */
    opal_paffinity_base_module_set_fn_t                         paff_module_set;

    /** Get this process' affinity */
    opal_paffinity_base_module_get_fn_t                         paff_module_get;

    /** Map socket:core to processor ID */
    opal_paffinity_base_module_get_map_to_processor_id_fn_t     paff_get_map_to_processor_id;

    /** Map processor ID to socket:core */
    opal_paffinity_base_module_get_map_to_socket_core_fn_t      paff_get_map_to_socket_core;

    /** Return the max processor ID */
    opal_paffinity_base_module_get_processor_info_fn_t          paff_get_processor_info;

    /** Return the max socket number */
    opal_paffinity_base_module_get_socket_info_fn_t             paff_get_socket_info;

    /** Return the max core number */
    opal_paffinity_base_module_get_core_info_fn_t               paff_get_core_info;

    /* Return physical processor id */
    opal_paffinity_base_module_get_physical_processor_id_fn_t   paff_get_physical_processor_id;
    
    /* Return physical socket id */
    opal_paffinity_base_module_get_physical_socket_id_fn_t      paff_get_physical_socket_id;
    
    /* Return physical core id */
    opal_paffinity_base_module_get_physical_core_id_fn_t        paff_get_physical_core_id;
    
    /** Shut down this module */
    opal_paffinity_base_module_finalize_fn_t                    paff_module_finalize;
};
/**
 * Convenience typedef
 */
typedef struct opal_paffinity_base_module_1_1_0_t opal_paffinity_base_module_1_1_0_t;
typedef struct opal_paffinity_base_module_1_1_0_t opal_paffinity_base_module_t;


/*
 * Macro for use in components that are of type paffinity
 */
#define OPAL_PAFFINITY_BASE_VERSION_2_0_0 \
    MCA_BASE_VERSION_2_0_0, \
    "paffinity", 2, 0, 0

#endif /* OPAL_PAFFINITY_H */