mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01: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
@ -44,6 +44,7 @@ set(RUNTIME_SRCS_OS_INTERFACE_LINUX
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_library.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_library.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_memory_linux.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_metrics_library.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_thread_linux.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_thread_linux.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_time_linux.cpp
|
||||
|
@ -19,10 +19,6 @@ OSInterface::~OSInterface() {
|
||||
delete osInterfaceImpl;
|
||||
}
|
||||
|
||||
uint32_t OSInterface::getHwContextId() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool OSInterface::are64kbPagesEnabled() {
|
||||
return osEnabled64kbPages;
|
||||
}
|
||||
|
51
runtime/os_interface/linux/os_metrics_library.cpp
Normal file
51
runtime/os_interface/linux/os_metrics_library.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "runtime/os_interface/metrics_library.h"
|
||||
|
||||
namespace NEO {
|
||||
//////////////////////////////////////////////////////
|
||||
// FUNCTION: MetricsLibrary::oaConfigurationActivate
|
||||
//////////////////////////////////////////////////////
|
||||
bool MetricsLibrary::oaConfigurationActivate(
|
||||
const ConfigurationHandle_1_0 &handle) {
|
||||
ConfigurationActivateData_1_0 data = {};
|
||||
data.Type = GpuConfigurationActivationType::Tbs;
|
||||
|
||||
return api->functions.ConfigurationActivate(
|
||||
handle,
|
||||
&data) == StatusCode::Success;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// FUNCTION: MetricsLibrary::oaConfigurationDeactivate
|
||||
//////////////////////////////////////////////////////
|
||||
bool MetricsLibrary::oaConfigurationDeactivate(
|
||||
const ConfigurationHandle_1_0 &handle) {
|
||||
return api->functions.ConfigurationDeactivate(
|
||||
handle) == StatusCode::Success;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// FUNCTION: MetricsLibrary::userConfigurationCreate
|
||||
//////////////////////////////////////////////////////
|
||||
bool MetricsLibrary::userConfigurationCreate(
|
||||
const ContextHandle_1_0 &context,
|
||||
ConfigurationHandle_1_0 &handle) {
|
||||
// Not supported on Linux.
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// FUNCTION: MetricsLibrary::userConfigurationDelete
|
||||
//////////////////////////////////////////////////////
|
||||
bool MetricsLibrary::userConfigurationDelete(
|
||||
const ConfigurationHandle_1_0 &handle) {
|
||||
// Not supported on Linux.
|
||||
return true;
|
||||
}
|
||||
} // namespace NEO
|
@ -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
|
||||
|
@ -8,35 +8,17 @@
|
||||
#pragma once
|
||||
#include "runtime/os_interface/performance_counters.h"
|
||||
|
||||
#include "os_interface.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
typedef struct _drm_intel_context drm_intel_context;
|
||||
|
||||
namespace NEO {
|
||||
|
||||
class PerformanceCountersLinux : virtual public PerformanceCounters {
|
||||
public:
|
||||
PerformanceCountersLinux(OSTime *osTime);
|
||||
~PerformanceCountersLinux() override;
|
||||
void initialize(const HardwareInfo *hwInfo) override;
|
||||
void enableImpl() override;
|
||||
PerformanceCountersLinux() = default;
|
||||
~PerformanceCountersLinux() override = default;
|
||||
|
||||
protected:
|
||||
virtual bool getPerfmonConfig(InstrPmRegsCfg *pCfg);
|
||||
bool verifyPmRegsCfg(InstrPmRegsCfg *pCfg, uint32_t *pLastPmRegsCfgHandle, bool *pLastPmRegsCfgPending) override;
|
||||
|
||||
typedef int (*perfmonLoadConfig_t)(int fd, drm_intel_context *ctx, uint32_t *oaCfgId, uint32_t *gpCfgId);
|
||||
typedef void *(*dlopenFunc_t)(const char *, int);
|
||||
typedef void *(*dlsymFunc_t)(void *, const char *);
|
||||
|
||||
void *mdLibHandle;
|
||||
|
||||
perfmonLoadConfig_t perfmonLoadConfigFunc;
|
||||
dlopenFunc_t dlopenFunc = dlopen;
|
||||
dlsymFunc_t dlsymFunc = dlsym;
|
||||
decltype(&dlclose) dlcloseFunc = dlclose;
|
||||
decltype(&instrSetPlatformInfo) setPlatformInfoFunc = instrSetPlatformInfo;
|
||||
/////////////////////////////////////////////////////
|
||||
// Gpu oa/mmio configuration.
|
||||
/////////////////////////////////////////////////////
|
||||
bool enableCountersConfiguration() override;
|
||||
void releaseCountersConfiguration() override;
|
||||
};
|
||||
} // namespace NEO
|
||||
|
Reference in New Issue
Block a user