Commit 57a0838d authored by Corentin Noël's avatar Corentin Noël Committed by Antonio Caggiano
Browse files

gpu/intel: Precisely compute the period exponent



Use the formula as specified in the intel drm header.
Signed-off-by: Corentin Noël's avatarCorentin Noël <corentin.noel@collabora.com>
Reviewed-by: Antonio Caggiano's avatarAntonio Caggiano <antonio.caggiano@collabora.com>
parent b80d7350
Pipeline #282409 passed with stages
in 3 minutes and 2 seconds
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <strings.h> #include <strings.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <unistd.h> #include <unistd.h>
#include <math.h>
#include <i915_drm.h> #include <i915_drm.h>
#include <perf_data_reader.h> #include <perf_data_reader.h>
...@@ -282,31 +283,6 @@ bool IntelDriver::init_perfcnt() ...@@ -282,31 +283,6 @@ bool IntelDriver::init_perfcnt()
return true; return true;
} }
/// @return The OA exponent which essentially is a power of 2 of the timestamp frequency
/// and it is used to tell the driver how often a report should be written to the stream.
uint32_t oa_exponent_for_period(const uint64_t timestamp_frequency,
const uint64_t sampling_period_ns)
{
constexpr uint32_t device_period_count = 32;
std::array<uint64_t, device_period_count> device_periods;
for (uint32_t i = 0; i < device_period_count; i++) {
device_periods[i] = 1000000000ull * (1u << i) / timestamp_frequency;
}
for (uint32_t i = 1; i < device_period_count; i++) {
if (sampling_period_ns >= device_periods[i - 1] && sampling_period_ns < device_periods[i]) {
if ((device_periods[i] - sampling_period_ns) >
(sampling_period_ns - device_periods[i - 1])) {
return i - 1;
}
return i;
}
}
return -1;
}
int IntelDriver::perf_open(const intel_perf_metric_set &metric_set, int IntelDriver::perf_open(const intel_perf_metric_set &metric_set,
const uint64_t sampling_period_ns) const uint64_t sampling_period_ns)
{ {
...@@ -324,7 +300,10 @@ int IntelDriver::perf_open(const intel_perf_metric_set &metric_set, ...@@ -324,7 +300,10 @@ int IntelDriver::perf_open(const intel_perf_metric_set &metric_set,
properties[p++] = DRM_I915_PERF_PROP_OA_FORMAT; properties[p++] = DRM_I915_PERF_PROP_OA_FORMAT;
properties[p++] = metric_set.perf_oa_format; properties[p++] = metric_set.perf_oa_format;
auto oa_exponent = oa_exponent_for_period(timestamp_frequency, sampling_period_ns); // The period_exponent gives a sampling period as follows:
// sample_period = timestamp_period * 2^(period_exponent + 1)
// where timestamp_period is 80ns for Haswell+
auto oa_exponent = (uint32_t) log2(sampling_period_ns * timestamp_frequency / 1000000000ull) - 1;
properties[p++] = DRM_I915_PERF_PROP_OA_EXPONENT; properties[p++] = DRM_I915_PERF_PROP_OA_EXPONENT;
properties[p++] = oa_exponent; properties[p++] = oa_exponent;
......
Supports Markdown
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