mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-20 08:53:55 +08:00
Change-Id: I85f56b677bafdd75dd958b488522393fc18b68af Signed-off-by: Dunajski, Bartosz <bartosz.dunajski@intel.com>
73 lines
2.3 KiB
C++
73 lines
2.3 KiB
C++
/*
|
|
* Copyright (C) 2017-2019 Intel Corporation
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*
|
|
*/
|
|
|
|
#include "performance_counters_linux.h"
|
|
|
|
namespace NEO {
|
|
|
|
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;
|
|
}
|
|
|
|
PerformanceCountersLinux::~PerformanceCountersLinux() {
|
|
if (pAutoSamplingInterface) {
|
|
autoSamplingStopFunc(&pAutoSamplingInterface);
|
|
pAutoSamplingInterface = nullptr;
|
|
available = false;
|
|
}
|
|
|
|
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) {
|
|
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) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
} // namespace NEO
|