mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-28 16:48:45 +08:00
Metrics Library Performance Counters implementation.
Signed-off-by: Piotr Maciejewski <piotr.maciejewski@intel.com> Change-Id: I0f00dca1892f4857baaebc75ba2208a4f33db1bf
This commit is contained in:
committed by
sys_ocldev
parent
369982995d
commit
d1d794c658
@@ -7,66 +7,58 @@
|
||||
|
||||
#include "performance_counters_linux.h"
|
||||
|
||||
#include "runtime/device/device.h"
|
||||
#include "runtime/helpers/hw_helper.h"
|
||||
|
||||
namespace NEO {
|
||||
////////////////////////////////////////////////////
|
||||
// PerformanceCounters::create
|
||||
////////////////////////////////////////////////////
|
||||
std::unique_ptr<PerformanceCounters> PerformanceCounters::create(Device *device) {
|
||||
auto counter = std::make_unique<PerformanceCountersLinux>();
|
||||
auto gen = device->getHardwareInfo().platform.eRenderCoreFamily;
|
||||
auto &hwHelper = HwHelper::get(gen);
|
||||
UNRECOVERABLE_IF(counter == nullptr);
|
||||
|
||||
std::unique_ptr<PerformanceCounters> PerformanceCounters::create(OSTime *osTime) {
|
||||
return std::unique_ptr<PerformanceCounters>(new PerformanceCountersLinux(osTime));
|
||||
}
|
||||
PerformanceCountersLinux::PerformanceCountersLinux(OSTime *osTime) : PerformanceCounters(osTime) {
|
||||
mdLibHandle = nullptr;
|
||||
perfmonLoadConfigFunc = nullptr;
|
||||
counter->clientType.Gen = static_cast<MetricsLibraryApi::ClientGen>(hwHelper.getMetricsLibraryGenId());
|
||||
return counter;
|
||||
}
|
||||
|
||||
PerformanceCountersLinux::~PerformanceCountersLinux() {
|
||||
if (pAutoSamplingInterface) {
|
||||
autoSamplingStopFunc(&pAutoSamplingInterface);
|
||||
pAutoSamplingInterface = nullptr;
|
||||
available = false;
|
||||
}
|
||||
//////////////////////////////////////////////////////
|
||||
// PerformanceCountersLinux::enableCountersConfiguration
|
||||
//////////////////////////////////////////////////////
|
||||
bool PerformanceCountersLinux::enableCountersConfiguration() {
|
||||
// Release previous counters configuration so the user
|
||||
// can change configuration between kernels.
|
||||
releaseCountersConfiguration();
|
||||
|
||||
if (mdLibHandle) {
|
||||
dlcloseFunc(mdLibHandle);
|
||||
mdLibHandle = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void PerformanceCountersLinux::initialize(const HardwareInfo *hwInfo) {
|
||||
PerformanceCounters::initialize(hwInfo);
|
||||
mdLibHandle = dlopenFunc("libmd.so", RTLD_LAZY | RTLD_LOCAL);
|
||||
if (mdLibHandle) {
|
||||
perfmonLoadConfigFunc = reinterpret_cast<perfmonLoadConfig_t>(dlsymFunc(mdLibHandle, "drm_intel_perfmon_load_config"));
|
||||
}
|
||||
setPlatformInfoFunc(hwInfo->platform.eProductFamily, (void *)(&hwInfo->featureTable));
|
||||
}
|
||||
|
||||
void PerformanceCountersLinux::enableImpl() {
|
||||
if (mdLibHandle && perfmonLoadConfigFunc) {
|
||||
PerformanceCounters::enableImpl();
|
||||
}
|
||||
}
|
||||
|
||||
bool PerformanceCountersLinux::verifyPmRegsCfg(InstrPmRegsCfg *pCfg, uint32_t *pLastPmRegsCfgHandle, bool *pLastPmRegsCfgPending) {
|
||||
if (perfmonLoadConfigFunc == nullptr) {
|
||||
// Create oa configuration.
|
||||
if (!metricsLibrary->oaConfigurationCreate(
|
||||
context,
|
||||
oaConfiguration)) {
|
||||
DEBUG_BREAK_IF(true);
|
||||
return false;
|
||||
}
|
||||
if (PerformanceCounters::verifyPmRegsCfg(pCfg, pLastPmRegsCfgHandle, pLastPmRegsCfgPending)) {
|
||||
return getPerfmonConfig(pCfg);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool PerformanceCountersLinux::getPerfmonConfig(InstrPmRegsCfg *pCfg) {
|
||||
unsigned int oaCfgHandle = pCfg->OaCounters.Handle;
|
||||
unsigned int gpCfgHandle = pCfg->GpCounters.Handle;
|
||||
int fd = osInterface->get()->getDrm()->getFileDescriptor();
|
||||
if (perfmonLoadConfigFunc(fd, nullptr, &oaCfgHandle, &gpCfgHandle) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (pCfg->OaCounters.Handle != 0 && oaCfgHandle != pCfg->OaCounters.Handle) {
|
||||
return false;
|
||||
}
|
||||
if (pCfg->GpCounters.Handle != 0 && gpCfgHandle != pCfg->GpCounters.Handle) {
|
||||
|
||||
// Enable oa configuration.
|
||||
if (!metricsLibrary->oaConfigurationActivate(
|
||||
oaConfiguration)) {
|
||||
DEBUG_BREAK_IF(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// PerformanceCountersLinux::releaseCountersConfiguration
|
||||
//////////////////////////////////////////////////////
|
||||
void PerformanceCountersLinux::releaseCountersConfiguration() {
|
||||
// Oa configuration.
|
||||
if (oaConfiguration.IsValid()) {
|
||||
metricsLibrary->oaConfigurationDeactivate(oaConfiguration);
|
||||
metricsLibrary->oaConfigurationDelete(oaConfiguration);
|
||||
oaConfiguration.data = nullptr;
|
||||
}
|
||||
}
|
||||
} // namespace NEO
|
||||
|
||||
Reference in New Issue
Block a user