drm/i915/pmu: Fix KMD and GuC race on accessing busyness
authorUmesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
Tue, 25 Jan 2022 02:01:24 +0000 (18:01 -0800)
committerTvrtko Ursulin <tvrtko.ursulin@intel.com>
Tue, 1 Feb 2022 08:59:25 +0000 (08:59 +0000)
commit7d73c602154df56802a9e75ac212505fc1e9a2b6
treea877253d32c55b0c902b1ea2a8bd1f264120ec46
parent3c6f13ad723e7206f03bb2752b01d18202b7fc9d
drm/i915/pmu: Fix KMD and GuC race on accessing busyness

GuC updates shared memory and KMD reads it. Since this is not
synchronized, we run into a race where the value read is inconsistent.
Sometimes the inconsistency is in reading the upper MSB bytes of the
last_switch_in value. 2 types of cases are seen - upper 8 bits are zero
and upper 24 bits are zero. Since these are non-zero values, it is
not trivial to determine validity of these values. Instead we read the
values multiple times until they are consistent. In test runs, 3
attempts results in consistent values. The upper bound is set to 6
attempts and may need to be tuned as per any new occurences.

Since the duration that gt is parked can vary, the patch also updates
the gt timestamp on unpark before starting the worker.

v2:
- Initialize i
- Use READ_ONCE to access engine record

Fixes: 77cdd054dd2c ("drm/i915/pmu: Connect engine busyness stats from GuC to pmu")
Signed-off-by: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
Reviewed-by: Alan Previn <alan.previn.teres.alexis@intel.com>
Signed-off-by: John Harrison <John.C.Harrison@Intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220125020124.788679-2-umesh.nerlige.ramappa@intel.com
(cherry picked from commit 512712a824de9b856a4e61343e3e4390eba2c391)
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c