Merge pull request #2618 from ajssmith/amqp1_dev1_branch
[collectd.git] / src / utils_config_cores.h
1 /**
2  * collectd - src/utils_config_cores.h
3  *
4  * Copyright(c) 2018 Intel Corporation. All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  *
24  * Authors:
25  *   Kamil Wiatrowski <kamilx.wiatrowski@intel.com>
26  **/
27
28 #ifndef UTILS_CONFIG_CORES_H
29 #define UTILS_CONFIG_CORES_H 1
30
31 #include "configfile.h"
32
33 #ifndef PRIsz
34 #define PRIsz "zu"
35 #endif /* PRIsz */
36
37 struct core_group_s {
38   char *desc;
39   unsigned *cores;
40   size_t num_cores;
41 };
42 typedef struct core_group_s core_group_t;
43
44 struct core_groups_list_s {
45   core_group_t *cgroups;
46   size_t num_cgroups;
47 };
48 typedef struct core_groups_list_s core_groups_list_t;
49
50 /*
51  * NAME
52  *   config_cores_parse
53  *
54  * DESCRIPTION
55  *   Convert strings from config item into list of core groups.
56  *
57  * PARAMETERS
58  *   `ci'      Pointer to config item.
59  *   `cgl'     Pointer to core groups list to be filled.
60  *
61  * RETURN VALUE
62  *    Zero upon success or non-zero if an error occurred.
63  *
64  * NOTES
65  *    In case of an error, *cgl is not modified.
66  *    Numbers can be in decimal or hexadecimal format.
67  *    The memory allocated for *cgroups in list needs to be freed
68  *    with config_cores_cleanup.
69  *
70  * EXAMPLES
71  *    If config is "0-3" "[4-15]" it means that cores 0-3 are aggregated
72  *    into one group and cores 4 to 15 are stored individualily in
73  *    separate groups. Examples of allowed formats:
74  *    "0,3,4" "10-15" - cores collected into two groups
75  *    "0" "0x3" "7" - 3 cores, each in individual group
76  *    "[32-63]" - 32 cores, each in individual group
77  *
78  *    For empty string "" *cgl is not modified and zero is returned.
79  */
80 int config_cores_parse(const oconfig_item_t *ci, core_groups_list_t *cgl);
81
82 /*
83  * NAME
84  *   config_cores_default
85  *
86  * DESCRIPTION
87  *   Set number of cores starting from zero into individual
88  *   core groups in *cgl list.
89  *
90  * PARAMETERS
91  *   `num_cores'  Number of cores to be configured.
92  *   `cgl'        Pointer to core groups list.
93  *
94  * RETURN VALUE
95  *    Zero upon success or non-zero if an error occurred.
96  *
97  * NOTES
98  *    The memory allocated for *cgroups in list needs to be freed
99  *    with config_cores_cleanup. In case of error the memory is
100  *    freed by the function itself.
101  */
102 int config_cores_default(int num_cores, core_groups_list_t *cgl);
103
104 /*
105  * NAME
106  *   config_cores_cleanup
107  *
108  * DESCRIPTION
109  *   Free the memory allocated for cgroups and set
110  *   num_cgroups to zero.
111  *
112  * PARAMETERS
113  *   `cgl'     Pointer to core groups list.
114  */
115 void config_cores_cleanup(core_groups_list_t *cgl);
116
117 /*
118  * NAME
119  *   config_cores_cmp_cgroups
120  *
121  * DESCRIPTION
122  *   Function to compare cores in 2 core groups.
123  *
124  * PARAMETERS
125  *   `cg_a'      Pointer to core group a.
126  *   `cg_b'      Pointer to core group b.
127  *
128  * RETURN VALUE
129  *    1 if both groups contain the same cores
130  *    0 if none of their cores match
131  *    -1 if some but not all cores match
132  */
133 int config_cores_cmp_cgroups(const core_group_t *cg_a,
134                              const core_group_t *cg_b);
135
136 #endif /* UTILS_CONFIG_CORES_H */