2 * collectd - src/utils_config_cores.h
4 * Copyright(c) 2018 Intel Corporation. All rights reserved.
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
25 * Kamil Wiatrowski <kamilx.wiatrowski@intel.com>
28 #ifndef UTILS_CONFIG_CORES_H
29 #define UTILS_CONFIG_CORES_H 1
31 #include "configfile.h"
42 typedef struct core_group_s core_group_t;
44 struct core_groups_list_s {
45 core_group_t *cgroups;
48 typedef struct core_groups_list_s core_groups_list_t;
55 * Convert strings from config item into list of core groups.
58 * `ci' Pointer to config item.
59 * `cgl' Pointer to core groups list to be filled.
62 * Zero upon success or non-zero if an error occurred.
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.
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
78 * For empty string "" *cgl is not modified and zero is returned.
80 int config_cores_parse(const oconfig_item_t *ci, core_groups_list_t *cgl);
84 * config_cores_default
87 * Set number of cores starting from zero into individual
88 * core groups in *cgl list.
91 * `num_cores' Number of cores to be configured.
92 * `cgl' Pointer to core groups list.
95 * Zero upon success or non-zero if an error occurred.
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.
102 int config_cores_default(int num_cores, core_groups_list_t *cgl);
106 * config_cores_cleanup
109 * Free the memory allocated for cgroups and set
110 * num_cgroups to zero.
113 * `cgl' Pointer to core groups list.
115 void config_cores_cleanup(core_groups_list_t *cgl);
119 * config_cores_cmp_cgroups
122 * Function to compare cores in 2 core groups.
125 * `cg_a' Pointer to core group a.
126 * `cg_b' Pointer to core group b.
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
133 int config_cores_cmp_cgroups(const core_group_t *cg_a,
134 const core_group_t *cg_b);
136 #endif /* UTILS_CONFIG_CORES_H */