Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/i915: Extract i915_cs_timestamp_{ns_to_ticks,tick_to_ns}()

Pull the code to do the CS timestamp ns<->ticks conversion into
helpers and use them all over.

The check in i915_perf_noa_delay_set() seems a bit dubious,
so we switch it to do what I assume it wanted to do all along
(ie. make sure the resulting delay in CS timestamp ticks
doesn't exceed 32bits)?

Cc: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200302143943.32676-5-ville.syrjala@linux.intel.com
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>

+17 -10
+1 -2
drivers/gpu/drm/i915/i915_debugfs.c
··· 1404 1404 i915_perf_noa_delay_set(void *data, u64 val) 1405 1405 { 1406 1406 struct drm_i915_private *i915 = data; 1407 - const u32 clk = RUNTIME_INFO(i915)->cs_timestamp_frequency_hz / 1000; 1408 1407 1409 1408 /* 1410 1409 * This would lead to infinite waits as we're doing timestamp 1411 1410 * difference on the CS with only 32bits. 1412 1411 */ 1413 - if (val > mul_u32_u32(U32_MAX, clk)) 1412 + if (i915_cs_timestamp_ns_to_ticks(i915, val) > U32_MAX) 1414 1413 return -EINVAL; 1415 1414 1416 1415 atomic64_set(&i915->perf.noa_programming_delay, val);
+12
drivers/gpu/drm/i915/i915_drv.h
··· 1921 1921 return HAS_LLC(i915) ? I915_MAP_WB : I915_MAP_WC; 1922 1922 } 1923 1923 1924 + static inline u64 i915_cs_timestamp_ns_to_ticks(struct drm_i915_private *i915, u64 val) 1925 + { 1926 + return DIV_ROUND_UP_ULL(val * RUNTIME_INFO(i915)->cs_timestamp_frequency_hz, 1927 + 1000000000); 1928 + } 1929 + 1930 + static inline u64 i915_cs_timestamp_ticks_to_ns(struct drm_i915_private *i915, u64 val) 1931 + { 1932 + return div_u64(val * 1000000000, 1933 + RUNTIME_INFO(i915)->cs_timestamp_frequency_hz); 1934 + } 1935 + 1924 1936 #endif
+2 -5
drivers/gpu/drm/i915/i915_perf.c
··· 1612 1612 struct drm_i915_gem_object *bo; 1613 1613 struct i915_vma *vma; 1614 1614 const u64 delay_ticks = 0xffffffffffffffff - 1615 - DIV_ROUND_UP_ULL(atomic64_read(&stream->perf->noa_programming_delay) * 1616 - RUNTIME_INFO(i915)->cs_timestamp_frequency_hz, 1617 - 1000000000); 1615 + i915_cs_timestamp_ns_to_ticks(i915, atomic64_read(&stream->perf->noa_programming_delay)); 1618 1616 const u32 base = stream->engine->mmio_base; 1619 1617 #define CS_GPR(x) GEN8_RING_CS_GPR(base, x) 1620 1618 u32 *batch, *ts0, *cs, *jump; ··· 3482 3484 3483 3485 static u64 oa_exponent_to_ns(struct i915_perf *perf, int exponent) 3484 3486 { 3485 - return div_u64(1000000000 * (2ULL << exponent), 3486 - RUNTIME_INFO(perf->i915)->cs_timestamp_frequency_hz); 3487 + return i915_cs_timestamp_ticks_to_ns(perf->i915, 2ULL << exponent); 3487 3488 } 3488 3489 3489 3490 /**
+1 -1
drivers/gpu/drm/i915/intel_device_info.c
··· 1052 1052 read_timestamp_frequency(dev_priv); 1053 1053 if (runtime->cs_timestamp_frequency_hz) { 1054 1054 runtime->cs_timestamp_period_ns = 1055 - div_u64(1e9, runtime->cs_timestamp_frequency_hz); 1055 + i915_cs_timestamp_ticks_to_ns(dev_priv, 1); 1056 1056 drm_dbg(&dev_priv->drm, 1057 1057 "CS timestamp wraparound in %lldms\n", 1058 1058 div_u64(mul_u32_u32(runtime->cs_timestamp_period_ns,
+1 -2
drivers/gpu/drm/i915/selftests/i915_perf.c
··· 262 262 263 263 delay = intel_read_status_page(stream->engine, 0x102); 264 264 delay -= intel_read_status_page(stream->engine, 0x100); 265 - delay = div_u64(mul_u32_u32(delay, 1000000000), 266 - RUNTIME_INFO(i915)->cs_timestamp_frequency_hz); 265 + delay = i915_cs_timestamp_ticks_to_ns(i915, delay); 267 266 pr_info("GPU delay: %uns, expected %lluns\n", 268 267 delay, expected); 269 268