/usr/include/powercap/powercap-rapl.h is in libpowercap-dev 0.1.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /**
* A simple interface for configuring RAPL using the intel_rapl kernel module.
* Note that not all RAPL zones support short_term constraints.
* Unless otherwise stated, all functions return 0 on success or a negative value on error.
*
* Setter functions do not verify that written values are accepted by RAPL.
* Users may want to add a debug option to their software that follows writes/sets with a read/get.
*
* These operations do basic I/O - it may reasonably be expected that callers need to handle I/O errors.
* For example, it has been seen that "powercap_rapl_get_max_power_uw" sets errno=ENODATA for power zones.
*
* @author Connor Imes
* @date 2016-05-12
*/
#ifndef _POWERCAP_RAPL_H_
#define _POWERCAP_RAPL_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <unistd.h>
#include "powercap.h"
/**
* Files for each zone.
*/
typedef struct powercap_rapl_zone_files {
powercap_zone zone;
powercap_constraint constraint_long;
powercap_constraint constraint_short;
} powercap_rapl_zone_files;
/**
* All files for a RAPL package/socket.
*/
typedef struct powercap_rapl_pkg {
powercap_rapl_zone_files pkg;
powercap_rapl_zone_files core;
powercap_rapl_zone_files uncore;
powercap_rapl_zone_files dram;
powercap_rapl_zone_files psys;
} powercap_rapl_pkg;
/**
* Zone enumeration.
*/
typedef enum powercap_rapl_zone {
POWERCAP_RAPL_ZONE_PACKAGE,
POWERCAP_RAPL_ZONE_CORE,
POWERCAP_RAPL_ZONE_UNCORE,
POWERCAP_RAPL_ZONE_DRAM,
POWERCAP_RAPL_ZONE_PSYS
} powercap_rapl_zone;
/**
* Long/short term constraint enumeration.
*/
typedef enum powercap_rapl_constraint {
POWERCAP_RAPL_CONSTRAINT_LONG,
POWERCAP_RAPL_CONSTRAINT_SHORT
} powercap_rapl_constraint;
/**
* Get the number of packages/sockets found.
* Returns 0 and sets errno if none are found.
*/
uint32_t powercap_rapl_get_num_packages(void);
/**
* Initialize the struct for the package with the given identifier.
* Read-only access can be requested, which may prevent the need for elevated privileges.
*/
int powercap_rapl_init(uint32_t package, powercap_rapl_pkg* pkg, int read_only);
/**
* Clean up file descriptors.
*/
int powercap_rapl_destroy(powercap_rapl_pkg* pkg);
/**
* Check if a zone is supported.
* The uncore power zone is usually only available on client-side hardware.
* The DRAM power zone is usually only available on server-side hardware.
* Some systems may expose zones like DRAM without actually supporting power caps for them.
* The PSys power zone may be available on Skylake processors and later.
* Returns 1 if supported, 0 if unsupported, a negative value in case of error.
*/
int powercap_rapl_is_zone_supported(const powercap_rapl_pkg* pkg, powercap_rapl_zone zone);
/**
* Check if a constraint is supported for a zone.
* Returns 1 if supported, 0 if unsupported, a negative value in case of error.
*/
int powercap_rapl_is_constraint_supported(const powercap_rapl_pkg* pkg, powercap_rapl_zone zone, powercap_rapl_constraint constraint);
/**
* Check if a file is supported for the given zone.
* Returns 1 if supported, 0 if unsupported, a negative value in case of error.
*/
int powercap_rapl_is_zone_file_supported(const powercap_rapl_pkg* pkg, powercap_rapl_zone zone, powercap_zone_file file);
/**
* Check if a file is supported for the given zone and constraint.
* Returns 1 if supported, 0 if unsupported, a negative value in case of error.
*/
int powercap_rapl_is_constraint_file_supported(const powercap_rapl_pkg* pkg, powercap_rapl_zone zone, powercap_rapl_constraint constraint, powercap_constraint_file file);
/**
* Get the zone name.
* Returns a non-negative value for the number of bytes read, a negative value in case of error.
*/
ssize_t powercap_rapl_get_name(const powercap_rapl_pkg* pkg, powercap_rapl_zone zone, char* buf, size_t size);
/**
* Check if zone is enabled.
* Returns 1 if enabled, 0 if disabled, a negative value in case of error.
*/
int powercap_rapl_is_enabled(const powercap_rapl_pkg* pkg, powercap_rapl_zone zone);
/**
* Enable/disable a zone.
*/
int powercap_rapl_set_enabled(const powercap_rapl_pkg* pkg, powercap_rapl_zone zone, int enabled);
/**
* Get the max energy range in microjoules.
*/
int powercap_rapl_get_max_energy_range_uj(const powercap_rapl_pkg* pkg, powercap_rapl_zone zone, uint64_t* val);
/**
* Get the current energy in microjoules.
*/
int powercap_rapl_get_energy_uj(const powercap_rapl_pkg* pkg, powercap_rapl_zone zone, uint64_t* val);
/**
* Reset the energy_uj value to 0.
* Returns 0 on success, a negative value in case of error.
* NOTE: As of this writing, RAPL does not support resetting the energy counter.
*/
int powercap_rapl_reset_energy_uj(const powercap_rapl_pkg* pkg, powercap_rapl_zone zone);
/**
* Get the max power range in microwatts.
* NOTE: As of this writing, RAPL does not support this file.
*/
int powercap_rapl_get_max_power_range_uw(const powercap_rapl_pkg* pkg, powercap_rapl_zone zone, uint64_t* val);
/**
* Get the current power in microwatts.
* NOTE: As of this writing, RAPL does not support this file.
*/
int powercap_rapl_get_power_uw(const powercap_rapl_pkg* pkg, powercap_rapl_zone zone, uint64_t* val);
/**
* Get the maximum power in microwatts.
*/
int powercap_rapl_get_max_power_uw(const powercap_rapl_pkg* pkg, powercap_rapl_zone zone, powercap_rapl_constraint constraint, uint64_t* val);
/**
* Get the minimum power allowed in microwatts.
* NOTE: As of this writing, RAPL does not support this file.
*/
int powercap_rapl_get_min_power_uw(const powercap_rapl_pkg* pkg, powercap_rapl_zone zone, powercap_rapl_constraint constraint, uint64_t* val);
/**
* Get the power limit in microwatts.
*/
int powercap_rapl_get_power_limit_uw(const powercap_rapl_pkg* pkg, powercap_rapl_zone zone, powercap_rapl_constraint constraint, uint64_t* val);
/**
* Set the power limit in microwatts.
*/
int powercap_rapl_set_power_limit_uw(const powercap_rapl_pkg* pkg, powercap_rapl_zone zone, powercap_rapl_constraint constraint, uint64_t val);
/**
* Get the maximum time window in microseconds.
* NOTE: As of this writing, RAPL does not support this file.
*/
int powercap_rapl_get_max_time_window_us(const powercap_rapl_pkg* pkg, powercap_rapl_zone zone, powercap_rapl_constraint constraint, uint64_t* val);
/**
* Get the minimum time window in microseconds.
* NOTE: As of this writing, RAPL does not support this file.
*/
int powercap_rapl_get_min_time_window_us(const powercap_rapl_pkg* pkg, powercap_rapl_zone zone, powercap_rapl_constraint constraint, uint64_t* val);
/**
* Get the time window in microseconds.
*/
int powercap_rapl_get_time_window_us(const powercap_rapl_pkg* pkg, powercap_rapl_zone zone, powercap_rapl_constraint constraint, uint64_t* val);
/**
* Set the time window in microseconds.
*/
int powercap_rapl_set_time_window_us(const powercap_rapl_pkg* pkg, powercap_rapl_zone zone, powercap_rapl_constraint constraint, uint64_t val);
/**
* Get the constraint name.
* Returns a non-negative value for the number of bytes read, a negative value in case of error.
*/
ssize_t powercap_rapl_get_constraint_name(const powercap_rapl_pkg* pkg, powercap_rapl_zone zone, powercap_rapl_constraint constraint, char* buf, size_t size);
#ifdef __cplusplus
}
#endif
#endif
|