intel_pmu plugin: fix for compatibility issue with collectd 5.8
[collectd.git] / src / utils_config_cores.h
1 /**
2  * collectd - src/utils_config_cores.h
3  *
4  * Copyright(c) 2017 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 #ifndef PRIsz
32 #define PRIsz "zu"
33 #endif /* PRIsz */
34
35 struct core_group_s {
36   char *desc;
37   unsigned *cores;
38   size_t num_cores;
39 };
40 typedef struct core_group_s core_group_t;
41
42 struct core_groups_list_s {
43   core_group_t *cgroups;
44   size_t num_cgroups;
45 };
46 typedef struct core_groups_list_s core_groups_list_t;
47
48 /*
49  * NAME
50  *   config_cores_parse
51  *
52  * DESCRIPTION
53  *   Convert strings from config item into list of core groups.
54  *
55  * PARAMETERS
56  *   `ci'      Pointer to config item.
57  *   `cgl'     Pointer to core groups list to be filled.
58  *
59  * RETURN VALUE
60  *    Zero upon success or non-zero if an error occurred.
61  *
62  * NOTES
63  *    In case of an error, *cgl is not modified.
64  *    Numbers can be in decimal or hexadecimal format.
65  *    The memory allocated for *cgroups in list needs to be freed
66  *    with config_cores_cleanup.
67  *
68  * EXAMPLES
69  *    If config is "0-3" "[4-15]" it means that cores 0-3 are aggregated
70  *    into one group and cores 4 to 15 are stored individualily in
71  *    separate groups. Examples of allowed formats:
72  *    "0,3,4" "10-15" - cores collected into two groups
73  *    "0" "0x3" "7" - 3 cores, each in individual group
74  *    "[32-63]" - 32 cores, each in individual group
75  *
76  *    For empty string "" *cgl is not modified and zero is returned.
77  */
78 int config_cores_parse(const oconfig_item_t *ci, core_groups_list_t *cgl);
79
80 /*
81  * NAME
82  *   config_cores_default
83  *
84  * DESCRIPTION
85  *   Set number of cores starting from zero into individual
86  *   core groups in *cgl list.
87  *
88  * PARAMETERS
89  *   `num_cores'  Number of cores to be configured.
90  *   `cgl'        Pointer to core groups list.
91  *
92  * RETURN VALUE
93  *    Zero upon success or non-zero if an error occurred.
94  *
95  * NOTES
96  *    The memory allocated for *cgroups in list needs to be freed
97  *    with config_cores_cleanup. In case of error the memory is
98  *    freed by the function itself.
99  */
100 int config_cores_default(int num_cores, core_groups_list_t *cgl);
101
102 /*
103  * NAME
104  *   config_cores_cleanup
105  *
106  * DESCRIPTION
107  *   Free the memory allocated for cgroups and set
108  *   num_cgroups to zero.
109  *
110  * PARAMETERS
111  *   `cgl'     Pointer to core groups list.
112  */
113 void config_cores_cleanup(core_groups_list_t *cgl);
114
115 /*
116  * NAME
117  *   config_cores_cmp_cgroups
118  *
119  * DESCRIPTION
120  *   Function to compare cores in 2 core groups.
121  *
122  * PARAMETERS
123  *   `cg_a'      Pointer to core group a.
124  *   `cg_b'      Pointer to core group b.
125  *
126  * RETURN VALUE
127  *    1 if both groups contain the same cores
128  *    0 if none of their cores match
129  *    -1 if some but not all cores match
130  */
131 int config_cores_cmp_cgroups(const core_group_t *cg_a,
132                              const core_group_t *cg_b);
133
134 #endif /* UTILS_CONFIG_CORES_H */