[Sysman] Update memory module for zesInit

Related-To: LOCI-4118

Signed-off-by: Joshua Santosh Ranjan <joshua.santosh.ranjan@intel.com>
This commit is contained in:
Joshua Santosh Ranjan
2023-03-08 10:35:11 +00:00
committed by Compute-Runtime-Automation
parent 593b3cf4fd
commit 790ef57c3f
58 changed files with 4664 additions and 17 deletions

View File

@@ -17,8 +17,8 @@ class SysmanHwDeviceIdDrm : public NEO::HwDeviceIdDrm {
public:
using NEO::HwDeviceIdDrm::HwDeviceIdDrm;
SysmanHwDeviceIdDrm() = delete;
int openFileDescriptor();
int closeFileDescriptor();
MOCKABLE_VIRTUAL int openFileDescriptor();
MOCKABLE_VIRTUAL int closeFileDescriptor();
private:
std::mutex fdMutex{};

View File

@@ -8,11 +8,14 @@
#include "level_zero/sysman/source/linux/os_sysman_imp.h"
#include "shared/source/helpers/gfx_core_helper.h"
#include "shared/source/os_interface/driver_info.h"
#include "shared/source/os_interface/linux/drm_neo.h"
#include "shared/source/os_interface/os_interface.h"
#include "level_zero/sysman/source/firmware_util/firmware_util.h"
#include "level_zero/sysman/source/linux/fs_access.h"
#include "level_zero/sysman/source/linux/pmt/pmt.h"
#include "level_zero/sysman/source/linux/pmu/pmu.h"
namespace L0 {
namespace Sysman {
@@ -55,6 +58,7 @@ ze_result_t LinuxSysmanImp::init() {
osInterface.getDriverModel()->as<NEO::Drm>()->cleanup();
// Close Drm handles
sysmanHwDeviceId->closeFileDescriptor();
pPmuInterface = PmuInterface::create(this);
return createPmtHandles();
}
@@ -155,6 +159,30 @@ LinuxSysmanImp::LinuxSysmanImp(SysmanDeviceImp *pParentSysmanDeviceImp) {
rootDeviceIndex = pParentSysmanDeviceImp->getRootDeviceIndex();
}
void LinuxSysmanImp::createFwUtilInterface() {
const auto pciBusInfo = pParentSysmanDeviceImp->getRootDeviceEnvironment().osInterface->getDriverModel()->getPciBusInfo();
const uint16_t domain = static_cast<uint16_t>(pciBusInfo.pciDomain);
const uint8_t bus = static_cast<uint8_t>(pciBusInfo.pciBus);
const uint8_t device = static_cast<uint8_t>(pciBusInfo.pciDevice);
const uint8_t function = static_cast<uint8_t>(pciBusInfo.pciFunction);
pFwUtilInterface = FirmwareUtil::create(domain, bus, device, function);
}
FirmwareUtil *LinuxSysmanImp::getFwUtilInterface() {
if (pFwUtilInterface == nullptr) {
createFwUtilInterface();
}
return pFwUtilInterface;
}
void LinuxSysmanImp::releaseFwUtilInterface() {
if (nullptr != pFwUtilInterface) {
delete pFwUtilInterface;
pFwUtilInterface = nullptr;
}
}
LinuxSysmanImp::~LinuxSysmanImp() {
if (nullptr != pSysfsAccess) {
delete pSysfsAccess;
@@ -168,6 +196,11 @@ LinuxSysmanImp::~LinuxSysmanImp() {
delete pFsAccess;
pFsAccess = nullptr;
}
if (nullptr != pPmuInterface) {
delete pPmuInterface;
pPmuInterface = nullptr;
}
releaseFwUtilInterface();
releasePmtObject();
}

View File

@@ -22,9 +22,11 @@ class Drm;
namespace L0 {
namespace Sysman {
class PlatformMonitoringTech;
class PmuInterface;
class FsAccess;
class ProcfsAccess;
class SysfsAccess;
class FirmwareUtil;
class LinuxSysmanImp : public OsSysman, NEO::NonCopyableOrMovableClass {
public:
@@ -33,6 +35,8 @@ class LinuxSysmanImp : public OsSysman, NEO::NonCopyableOrMovableClass {
ze_result_t init() override;
FirmwareUtil *getFwUtilInterface();
PmuInterface *getPmuInterface() { return pPmuInterface; }
FsAccess &getFsAccess();
ProcfsAccess &getProcfsAccess();
SysfsAccess &getSysfsAccess();
@@ -45,6 +49,7 @@ class LinuxSysmanImp : public OsSysman, NEO::NonCopyableOrMovableClass {
NEO::Drm *getDrm();
void releasePmtObject();
ze_result_t createPmtHandles();
std::string devicePciBdf = "";
NEO::ExecutionEnvironment *executionEnvironment = nullptr;
uint32_t rootDeviceIndex;
@@ -55,11 +60,15 @@ class LinuxSysmanImp : public OsSysman, NEO::NonCopyableOrMovableClass {
SysfsAccess *pSysfsAccess = nullptr;
std::map<uint32_t, L0::Sysman::PlatformMonitoringTech *> mapOfSubDeviceIdToPmtObject;
uint32_t subDeviceCount = 0;
FirmwareUtil *pFwUtilInterface = nullptr;
PmuInterface *pPmuInterface = nullptr;
void releaseFwUtilInterface();
private:
LinuxSysmanImp() = delete;
SysmanDeviceImp *pParentSysmanDeviceImp = nullptr;
static const std::string deviceDir;
void createFwUtilInterface();
};
} // namespace Sysman

View File

@@ -0,0 +1,19 @@
#
# Copyright (C) 2020-2023 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
set(L0_SRCS_SYSMAN_LINUX_PMU
${CMAKE_CURRENT_SOURCE_DIR}/pmu_imp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pmu_imp.h
${CMAKE_CURRENT_SOURCE_DIR}/pmu.h
)
if(UNIX)
target_sources(${L0_STATIC_LIB_NAME}
PRIVATE
${L0_SRCS_SYSMAN_LINUX_PMU}
)
endif()
# Make our source files visible to parent
set_property(GLOBAL PROPERTY L0_SRCS_SYSMAN_PMU_LINUX ${L0_SRCS_SYSMAN_PMU_LINUX})

View File

@@ -0,0 +1,23 @@
/*
* Copyright (C) 2020-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include <cstdint>
namespace L0 {
namespace Sysman {
class LinuxSysmanImp;
class PmuInterface {
public:
virtual ~PmuInterface() = default;
virtual int64_t pmuInterfaceOpen(uint64_t config, int group, uint32_t format) = 0;
virtual int pmuRead(int fd, uint64_t *data, ssize_t sizeOfdata) = 0;
static PmuInterface *create(LinuxSysmanImp *pLinuxSysmanImp);
};
} // namespace Sysman
} // namespace L0

View File

@@ -0,0 +1,104 @@
/*
* Copyright (C) 2020-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "level_zero/sysman/source/linux/pmu/pmu_imp.h"
#include "shared/source/memory_manager/memory_manager.h"
namespace L0 {
namespace Sysman {
const std::string PmuInterfaceImp::deviceDir("device");
const std::string PmuInterfaceImp::sysDevicesDir("/sys/devices/");
static constexpr int64_t perfEventOpenSyscallNumber = 298;
// Get event id
uint32_t PmuInterfaceImp::getEventType() {
std::string i915DirName("i915");
const bool isIntegratedDevice = pDevice->getRootDeviceEnvironment().getHardwareInfo()->capabilityTable.isIntegratedDevice;
if (!isIntegratedDevice) {
std::string bdfDir;
// ID or type of Pmu driver for discrete graphics is obtained by reading sysfs node as explained below:
// For instance DG1 in PCI slot 0000:03:00.0:
// $ cat /sys/devices/i915_0000_03_00.0/type
// 23
ze_result_t result = pSysfsAccess->readSymLink(deviceDir, bdfDir);
if (ZE_RESULT_SUCCESS != result) {
return 0;
}
const auto loc = bdfDir.find_last_of('/');
auto bdf = bdfDir.substr(loc + 1);
std::replace(bdf.begin(), bdf.end(), ':', '_');
i915DirName = "i915_" + bdf;
}
// For integrated graphics type of PMU driver is obtained by reading /sys/devices/i915/type node
// # cat /sys/devices/i915/type
// 18
const std::string eventTypeSysfsNode = sysDevicesDir + i915DirName + "/" + "type";
auto eventTypeVal = 0u;
if (ZE_RESULT_SUCCESS != pFsAccess->read(eventTypeSysfsNode, eventTypeVal)) {
return 0;
}
return eventTypeVal;
}
int PmuInterfaceImp::getErrorNo() {
return errno;
}
inline int64_t PmuInterfaceImp::perfEventOpen(perf_event_attr *attr, pid_t pid, int cpu, int groupFd, uint64_t flags) {
attr->size = sizeof(*attr);
return this->syscallFunction(perfEventOpenSyscallNumber, attr, pid, cpu, groupFd, flags);
}
int64_t PmuInterfaceImp::pmuInterfaceOpen(uint64_t config, int group, uint32_t format) {
struct perf_event_attr attr = {};
int nrCpus = get_nprocs_conf();
int cpu = 0;
int64_t ret = 0;
attr.type = getEventType();
if (attr.type == 0) {
return -ENOENT;
}
if (group >= 0) {
format &= ~PERF_FORMAT_GROUP;
}
attr.read_format = static_cast<uint64_t>(format);
attr.config = config;
do {
ret = perfEventOpen(&attr, -1, cpu++, group, 0);
} while ((ret < 0 && getErrorNo() == EINVAL) && (cpu < nrCpus));
return ret;
}
int PmuInterfaceImp::pmuRead(int fd, uint64_t *data, ssize_t sizeOfdata) {
ssize_t len;
len = this->readFunction(fd, data, sizeOfdata);
if (len != sizeOfdata) {
return -1;
}
return 0;
}
PmuInterfaceImp::PmuInterfaceImp(LinuxSysmanImp *pLinuxSysmanImp) {
pSysfsAccess = &pLinuxSysmanImp->getSysfsAccess();
pFsAccess = &pLinuxSysmanImp->getFsAccess();
pDevice = pLinuxSysmanImp->getSysmanDeviceImp();
}
PmuInterface *PmuInterface::create(LinuxSysmanImp *pLinuxSysmanImp) {
PmuInterfaceImp *pPmuInterfaceImp = new PmuInterfaceImp(pLinuxSysmanImp);
UNRECOVERABLE_IF(nullptr == pPmuInterfaceImp);
return pPmuInterfaceImp;
}
} // namespace Sysman
} // namespace L0

View File

@@ -0,0 +1,45 @@
/*
* Copyright (C) 2020-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "level_zero/sysman/source/linux/fs_access.h"
#include "level_zero/sysman/source/linux/os_sysman_imp.h"
#include "level_zero/sysman/source/linux/pmu/pmu.h"
#include <linux/perf_event.h>
#include <string>
#include <sys/sysinfo.h>
#include <unistd.h>
namespace L0 {
namespace Sysman {
class PmuInterfaceImp : public PmuInterface, NEO::NonCopyableOrMovableClass {
public:
PmuInterfaceImp() = delete;
PmuInterfaceImp(LinuxSysmanImp *pLinuxSysmanImp);
~PmuInterfaceImp() override = default;
int64_t pmuInterfaceOpen(uint64_t config, int group, uint32_t format) override;
int pmuRead(int fd, uint64_t *data, ssize_t sizeOfdata) override;
protected:
virtual int getErrorNo();
virtual int64_t perfEventOpen(perf_event_attr *attr, pid_t pid, int cpu, int groupFd, uint64_t flags);
decltype(&read) readFunction = read;
decltype(&syscall) syscallFunction = syscall;
private:
uint32_t getEventType();
FsAccess *pFsAccess = nullptr;
SysfsAccess *pSysfsAccess = nullptr;
SysmanDeviceImp *pDevice = nullptr;
static const std::string deviceDir;
static const std::string sysDevicesDir;
};
} // namespace Sysman
} // namespace L0