Commit 347efb62 authored by Antonio Caggiano's avatar Antonio Caggiano 🦀

WIP: Intel driver test

parent 8ac82c70
Pipeline #223057 passed with stages
in 1 minute and 39 seconds
......@@ -39,3 +39,17 @@ test(
test_panfrost,
workdir: meson.source_root(),
args: '--gtest_output=xml:panfrost-report.xml')
# Intel test
test_intel = executable(
'test-intel',
'src/intel_test.cc',
dependencies: [dep_pps_gpu, dep_gtest, dep_i915perf]
)
#test(
# 'intel',
# test_intel,
# workdir: meson.source_root(),
# args: '--gtest_output=xml:intel-report.xml')
/*
* Copyright © 2020 Collabora, Ltd.
* Author: Antonio Caggiano <antonio.caggiano@collabora.com>
*
* SPDX-License-Identifier: MIT
*/
#include <cstring>
#include <gtest/gtest.h>
#include <perf_data_reader.h>
#include <pps/algorithm.h>
#include <pps/pds.h>
#include <pps/gpu/intel/intel_driver.h>
namespace pps::gpu
{
struct Report {
uint32_t version;
uint32_t timestamp;
uint32_t id;
};
TEST(Intel, Correlations)
{
auto drm_device = DrmDevice::create(0).value();
auto driver = IntelDriver();
driver.drm_device = std::move(drm_device);
driver.init_perfcnt();
driver.enable_all_counters();
driver.enable_perfcnt(1000000);
// Skip first sampling
auto cpu_timestamp = driver.dump_perfcnt();
// Get a correlation before sampling
auto corr_a = driver.correlations[1];
PPS_LOG("CPU timestamp: %lu", corr_a.cpu_timestamp);
PPS_LOG("GPU timestamp: %lu", corr_a.gpu_timestamp & 0xffffffff);
// Get sampling timestamp
cpu_timestamp = driver.dump_perfcnt();
PPS_LOG("DUMP CPU timestamp: %lu", cpu_timestamp);
EXPECT_GT(cpu_timestamp, corr_a.cpu_timestamp);
// Get a correlation after sampling
auto corr_b = driver.correlations.back();
PPS_LOG("CPU timestamp: %lu", corr_b.cpu_timestamp);
PPS_LOG("GPU timestamp: %lu", corr_b.gpu_timestamp & 0xffffffff);
EXPECT_LT(cpu_timestamp, corr_b.cpu_timestamp);
driver.disable_perfcnt();
}
TEST(Intel, PerfCnt)
{
auto dump_path = "test/data/gpu/intel/intel.dump";
auto dump_file = std::fopen(dump_path, "rb");
EXPECT_TRUE(dump_file != nullptr);
std::fseek(dump_file, 0, SEEK_END);
size_t dump_size = std::ftell(dump_file);
std::fseek(dump_file, 0, SEEK_SET);
std::vector<uint8_t> data = {};
data.resize(dump_size);
std::fread(data.data(), sizeof(data[0]), data.size(), dump_file);
auto drm_device = DrmDevice::create(0).value();
auto driver = IntelDriver();
driver.drm_device = std::move(drm_device);
driver.init_perfcnt();
const uint8_t *iter = data.data();
const uint8_t *end = iter + data.size();
// Collect samples
std::vector<const drm_i915_perf_record_header *> records;
std::vector<const Report *> reports;
const intel_perf_record_device_info *device_info = nullptr;
while (iter < end) {
auto header = reinterpret_cast<const drm_i915_perf_record_header *>(iter);
switch (header->type) {
case DRM_I915_PERF_RECORD_SAMPLE: {
auto report = reinterpret_cast<const Report *>(header + 1);
// Skip this as a timeline
if (reports.size() && report->id == reports.back()->id) {
break;
}
reports.emplace_back(report);
records.emplace_back(header);
break;
}
case DRM_I915_PERF_RECORD_OA_REPORT_LOST:
case DRM_I915_PERF_RECORD_OA_BUFFER_LOST:
EXPECT_EQ(header->size, sizeof(*header));
break;
default:
break;
}
iter += header->size;
}
auto group = std::find_if(std::begin(driver.groups),
std::end(driver.groups),
[](const CounterGroup &group) { return group.name == "RenderBasic"; });
assert(group != std::end(driver.groups) && "Failed to find RenderBasic group");
// In order to accumulate reports, we need the OA format of the metric set
// This can be retrieved by a DEVICE_INFO record type
for (size_t i = 0; i < records.size() - 1; ++i) {
auto a = records[i];
auto b = records[i + 1];
intel_perf_accumulate_reports(&driver.accu, device_info->oa_format, a, b);
const struct Report *rep_a = (const struct Report *)(a + 1);
const struct Report *rep_b = (const struct Report *)(b + 1);
fprintf(stdout,
"Recs %u %u %fms - %u %u %fms\n",
rep_a->version,
rep_a->id,
rep_a->timestamp / 1000000.0,
rep_b->version,
rep_b->id,
rep_b->timestamp / 1000000.0);
printf("counter_count %zu\n", group->counters.size());
for (auto c : group->counters) {
auto &counter = driver.counters[c];
auto value = counter.get_value(driver);
if (auto i_value = std::get_if<int64_t>(&value)) {
printf("%s %li\n", counter.name.c_str(), *i_value);
} else if (auto d_value = std::get_if<double>(&value)) {
printf("%s %f\n", counter.name.c_str(), *d_value);
}
}
}
}
} // namespace pps::gpu
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment