File: pmt.cpp

package info (click to toggle)
intel-compute-runtime 20.44.18297-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 34,780 kB
  • sloc: cpp: 379,729; lisp: 4,931; python: 299; sh: 196; makefile: 8
file content (89 lines) | stat: -rw-r--r-- 3,409 bytes parent folder | download
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
/*
 * Copyright (C) 2020 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "level_zero/tools/source/sysman/linux/pmt.h"

#include "shared/source/debug_settings/debug_settings_manager.h"

#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/mman.h>

namespace L0 {
const std::string PlatformMonitoringTech::baseTelemDevice("/dev/telem");
const std::string PlatformMonitoringTech::baseTelemSysFS("/sys/class/pmt_telem/telem");

void PlatformMonitoringTech::init(const std::string &deviceName, FsAccess *pFsAccess) {
    pmtSupported = false;

    std::string deviceNumber("1"); // Temporarily hardcoded
    std::string telemetryDeviceEntry = baseTelemDevice + deviceNumber;
    if (!pFsAccess->fileExists(telemetryDeviceEntry)) {
        NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
                              "Telemetry support not available. No file %s\n", telemetryDeviceEntry.c_str());
        return;
    }

    std::string guid;
    std::string guidPath = baseTelemSysFS + deviceNumber + std::string("/guid");
    ze_result_t result = pFsAccess->read(guidPath, guid);
    if (ZE_RESULT_SUCCESS != result) {
        NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
                              "Telemetry sysfs entry not available %s\n", guidPath.c_str());
        return;
    }

    std::string sizePath = baseTelemSysFS + deviceNumber + std::string("/size");
    result = pFsAccess->read(sizePath, size);
    if (ZE_RESULT_SUCCESS != result) {
        NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
                              "Telemetry sysfs entry not available %s\n", sizePath.c_str());
        return;
    }

    std::string offsetPath = baseTelemSysFS + deviceNumber + std::string("/offset");
    result = pFsAccess->read(offsetPath, baseOffset);
    if (ZE_RESULT_SUCCESS != result) {
        NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
                              "Telemetry sysfs entry not available %s\n", offsetPath.c_str());
        return;
    }

    int fd = open(static_cast<const char *>(telemetryDeviceEntry.c_str()), O_RDONLY);
    if (fd == -1) {
        NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
                              "Failure opening telemetry file %s : %s \n", telemetryDeviceEntry.c_str(), strerror(errno));
        return;
    }

    mappedMemory = static_cast<char *>(mmap(nullptr, static_cast<size_t>(size), PROT_READ, MAP_SHARED, fd, 0));
    if (mappedMemory == MAP_FAILED) {
        NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
                              "Failure mapping telemetry file %s : %s \n", telemetryDeviceEntry.c_str(), strerror(errno));
        close(fd);
        return;
    }

    if (close(fd) == -1) {
        NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
                              "Failure closing telemetry file %s : %s \n", telemetryDeviceEntry.c_str(), strerror(errno));
        munmap(mappedMemory, size);
        return;
    }

    mappedMemory += baseOffset;
    pmtSupported = true;
}

PlatformMonitoringTech::~PlatformMonitoringTech() {
    if (mappedMemory != nullptr) {
        munmap(mappedMemory - baseOffset, size);
    }
}

} // namespace L0