File: resctrl.h

package info (click to toggle)
intel-cmt-cat 25.04-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,724 kB
  • sloc: ansic: 52,004; python: 11,324; makefile: 2,197; perl: 1,165; javascript: 37; sh: 23
file content (195 lines) | stat: -rw-r--r-- 5,839 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
/*
 * BSD LICENSE
 *
 * Copyright(c) 2018-2023 Intel Corporation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in
 *     the documentation and/or other materials provided with the
 *     distribution.
 *   * Neither the name of Intel Corporation nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.O
 *
 */

/**
 * @brief Internal header file for resctrl common functions
 */

#ifndef __PQOS_RESCTRL_H__
#define __PQOS_RESCTRL_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "pqos.h"
#include "types.h"

#include <limits.h> /**< CHAR_BIT*/

#ifndef RESCTRL_PATH
#define RESCTRL_PATH "/sys/fs/resctrl"
#endif
#define RESCTRL_PATH_INFO        RESCTRL_PATH "/info"
#define RESCTRL_PATH_INFO_L3_MON RESCTRL_PATH_INFO "/L3_MON"
#define RESCTRL_PATH_INFO_L3     RESCTRL_PATH_INFO "/L3"
#define RESCTRL_PATH_INFO_L3CODE RESCTRL_PATH_INFO "/L3CODE"
#define RESCTRL_PATH_INFO_L3DATA RESCTRL_PATH_INFO "/L3DATA"
#define RESCTRL_PATH_INFO_L2     RESCTRL_PATH_INFO "/L2"
#define RESCTRL_PATH_INFO_L2CODE RESCTRL_PATH_INFO "/L2CODE"
#define RESCTRL_PATH_INFO_L2DATA RESCTRL_PATH_INFO "/L2DATA"
#define RESCTRL_PATH_INFO_MB     RESCTRL_PATH_INFO "/MB"
#define RESCTRL_PATH_INFO_SMBA   RESCTRL_PATH_INFO "/SMBA"

/**
 * Max supported number of CPU's
 */
#define RESCTRL_MAX_CPUS 4096

/**
 * @brief Obtain shared lock on resctrl filesystem
 *
 * @return Operational status
 * @retval PQOS_RETVAL_OK on success
 */
PQOS_LOCAL int resctrl_lock_shared(void);

/**
 * @brief Obtain exclusive lock on resctrl filesystem
 *
 * @return Operational status
 * @retval PQOS_RETVAL_OK on success
 */
PQOS_LOCAL int resctrl_lock_exclusive(void);

/**
 * @brief Release lock on resctrl filesystem
 *
 * @return Operational status
 * @retval PQOS_RETVAL_OK on success
 */
PQOS_LOCAL int resctrl_lock_release(void);

/**
 * @brief Mount the resctrl file system with given CDP option
 *
 * @param l3_cdp_cfg L3 CDP option
 * @param l2_cdp_cfg L2 CDP option
 * @param mba_cfg requested MBA config
 *
 * @return Operational status
 * @retval PQOS_RETVAL_OK on success
 */
PQOS_LOCAL int resctrl_mount(const enum pqos_cdp_config l3_cdp_cfg,
                             const enum pqos_cdp_config l2_cdp_cfg,
                             const enum pqos_mba_config mba_cfg);

/**
 * @brief Unmount the resctrl file system
 *
 * @return Operational status
 * @retval PQOS_RETVAL_OK on success
 */
PQOS_LOCAL int resctrl_umount(void);

/**
 * @brief Structure to hold parsed cpu mask
 *
 * Structure contains table with cpu bit mask. Each table item holds
 * information about 8 bit in mask.
 *
 * Example bitmask tables:
 *  - cpus file contains 'ABC' mask = [ ..., 0x0A, 0xBC ]
 *  - cpus file contains 'ABCD' mask = [ ..., 0xAB, 0xCD ]
 */
struct resctrl_cpumask {
        uint8_t tab[RESCTRL_MAX_CPUS / CHAR_BIT]; /**< bit mask table */
};

/**
 * @brief Set lcore bit in cpu mask
 *
 * @param [in] lcore Core number
 * @param [in] mask Modified cpu mask
 */
PQOS_LOCAL void resctrl_cpumask_set(const unsigned lcore,
                                    struct resctrl_cpumask *mask);

/**
 * @brief Unset lcore bit in cpu mask
 *
 * @param [in] lcore Core number
 * @param [in] mask Modified cpu mask
 */
PQOS_LOCAL void resctrl_cpumask_unset(const unsigned lcore,
                                      struct resctrl_cpumask *mask);

/**
 * @brief Check if lcore is set in cpu mask
 *
 * @param [in] lcore Core number
 * @param [in] mask Cpu mask
 *
 * @return Returns 1 when bit corresponding to lcore is set in mask
 * @retval 1 if cpu bit is set in mask
 * @retval 0 if cpu bit is not set in mask
 */
PQOS_LOCAL int resctrl_cpumask_get(const unsigned lcore,
                                   const struct resctrl_cpumask *mask);

/**
 * @brief Write CPU mask to file
 *
 * @param [in] fd write file descriptor
 * @param [in] mask CPU mask to write
 *
 * @return Operational status
 * @retval PQOS_RETVAL_OK on success
 */
PQOS_LOCAL int resctrl_cpumask_write(FILE *fd,
                                     const struct resctrl_cpumask *mask);

/**
 * @brief Read CPU mask from file
 *
 * @param [in] fd read file descriptor
 * @param [out] mask CPU mask to write
 *
 * @return Operational status
 * @retval PQOS_RETVAL_OK on success
 */
PQOS_LOCAL int resctrl_cpumask_read(FILE *fd, struct resctrl_cpumask *mask);

/**
 * @brief Check if resctrl is supported
 *
 * @return Support status
 * @retval PQOS_RETVAL_OK if supported, error code otherwise
 */
int resctrl_is_supported(void);

#ifdef __cplusplus
}
#endif

#endif /* __PQOS_RESCTRL_H__ */