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 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
|
/*
* BSD LICENSE
*
* Copyright(c) 2014-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.
*/
#include "monitoring.h"
#include "cap.h"
#include "hw_monitoring.h"
#include "log.h"
#include "os_monitoring.h"
#include "perf_monitoring.h"
#include "types.h"
#include "utils.h"
#ifdef __linux__
#include "resctrl.h"
#include "resctrl_monitoring.h"
#endif
/**
* ---------------------------------------
* Local macros
* ---------------------------------------
*/
/**
* ---------------------------------------
* Local data types
* ---------------------------------------
*/
/**
* ---------------------------------------
* Local data structures
* ---------------------------------------
*/
/**
* ---------------------------------------
* Local Functions
* ---------------------------------------
*/
/*
* =======================================
* =======================================
*
* initialize and shutdown
*
* =======================================
* =======================================
*/
int
pqos_mon_init(const struct pqos_cpuinfo *cpu,
const struct pqos_cap *cap,
const struct pqos_config *cfg)
{
const struct pqos_capability *item = NULL;
int ret;
enum pqos_interface interface = _pqos_get_inter();
UNUSED_PARAM(cfg);
ASSERT(cfg != NULL);
/**
* If monitoring capability has been discovered
* then get max RMID supported by a CPU socket
* and allocate memory for RMID table
*/
ret = pqos_cap_get_type(cap, PQOS_CAP_TYPE_MON, &item);
if (ret != PQOS_RETVAL_OK) {
ret = PQOS_RETVAL_RESOURCE;
goto pqos_mon_init_exit;
}
ASSERT(item != NULL);
#ifdef __linux__
if (interface == PQOS_INTER_OS ||
interface == PQOS_INTER_OS_RESCTRL_MON)
ret = os_mon_init(cpu, cap);
if (ret != PQOS_RETVAL_OK)
return ret;
#endif
if (interface == PQOS_INTER_MSR)
ret = hw_mon_init(cpu, cap);
pqos_mon_init_exit:
return ret;
}
int
pqos_mon_fini(void)
{
int ret = PQOS_RETVAL_OK;
#ifdef __linux__
enum pqos_interface interface = _pqos_get_inter();
if (interface == PQOS_INTER_OS ||
interface == PQOS_INTER_OS_RESCTRL_MON)
ret = os_mon_fini();
if (interface == PQOS_INTER_MSR)
ret = hw_mon_fini();
#else
ret = hw_mon_fini();
#endif
return ret;
}
int
pqos_mon_poll_events(struct pqos_mon_data *group)
{
unsigned i;
int ret = PQOS_RETVAL_OK;
/** List of non virtual events */
const enum pqos_mon_event mon_event[] = {
PQOS_MON_EVENT_L3_OCCUP,
PQOS_MON_EVENT_LMEM_BW,
PQOS_MON_EVENT_TMEM_BW,
PQOS_PERF_EVENT_LLC_MISS,
PQOS_PERF_EVENT_LLC_REF,
(enum pqos_mon_event)PQOS_PERF_EVENT_CYCLES,
(enum pqos_mon_event)PQOS_PERF_EVENT_INSTRUCTIONS,
PQOS_PERF_EVENT_LLC_MISS_PCIE_READ,
PQOS_PERF_EVENT_LLC_MISS_PCIE_WRITE,
PQOS_PERF_EVENT_LLC_REF_PCIE_READ,
PQOS_PERF_EVENT_LLC_REF_PCIE_WRITE};
#ifdef __linux__
if (group->intl->resctrl.event != 0) {
ret = resctrl_lock_shared();
if (ret != PQOS_RETVAL_OK)
return ret;
}
#endif
for (i = 0; i < DIM(mon_event); i++) {
enum pqos_mon_event evt = mon_event[i];
/**
* poll hw event
*/
if (group->intl->hw.event & evt) {
ret = hw_mon_poll(group, evt);
if (ret != PQOS_RETVAL_OK)
goto poll_events_exit;
}
#ifdef __linux__
/**
* poll perf event
*/
if (group->intl->perf.event & evt) {
ret = perf_mon_poll(group, evt);
if (ret != PQOS_RETVAL_OK)
goto poll_events_exit;
}
/**
* poll resctrl event
*/
if (group->intl->resctrl.event & evt) {
ret = resctrl_mon_poll(group, evt);
if (ret != PQOS_RETVAL_OK)
goto poll_events_exit;
}
#endif
}
/**
* Calculate values of virtual events
*/
if (group->event & PQOS_MON_EVENT_RMEM_BW) {
const struct pqos_cap *cap = _pqos_get_cap();
const struct pqos_monitor *pmon;
uint64_t max_value = 0;
group->values.mbm_remote_delta = 0;
if (group->values.mbm_total_delta >
group->values.mbm_local_delta)
group->values.mbm_remote_delta =
group->values.mbm_total_delta -
group->values.mbm_local_delta;
ret = pqos_cap_get_event(cap, PQOS_MON_EVENT_RMEM_BW, &pmon);
if (ret == PQOS_RETVAL_OK)
max_value = 1LLU << pmon->counter_length;
if (max_value > 0 &&
group->values.mbm_local > group->values.mbm_total)
group->values.mbm_remote = max_value -
group->values.mbm_local +
group->values.mbm_total;
else
group->values.mbm_remote =
group->values.mbm_total - group->values.mbm_local;
}
if (group->event & PQOS_PERF_EVENT_IPC) {
if (group->values.ipc_unhalted_delta > 0)
group->values.ipc =
(double)group->values.ipc_retired_delta /
(double)group->values.ipc_unhalted_delta;
else
group->values.ipc = 0;
}
if (ret == PQOS_RETVAL_OK)
group->intl->valid_mbm_read = 1;
poll_events_exit:
#ifdef __linux__
if (group->intl->resctrl.event != 0)
resctrl_lock_release();
#endif
return ret;
}
|