Skip to content

Commit 802a582

Browse files
committed
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 <[email protected]> Signed-off-by: Ville Syrjälä <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Reviewed-by: Chris Wilson <[email protected]>
1 parent 56f1b31 commit 802a582

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

drivers/gpu/drm/i915/i915_debugfs.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,13 +1404,12 @@ static int
14041404
i915_perf_noa_delay_set(void *data, u64 val)
14051405
{
14061406
struct drm_i915_private *i915 = data;
1407-
const u32 clk = RUNTIME_INFO(i915)->cs_timestamp_frequency_hz / 1000;
14081407

14091408
/*
14101409
* This would lead to infinite waits as we're doing timestamp
14111410
* difference on the CS with only 32bits.
14121411
*/
1413-
if (val > mul_u32_u32(U32_MAX, clk))
1412+
if (i915_cs_timestamp_ns_to_ticks(i915, val) > U32_MAX)
14141413
return -EINVAL;
14151414

14161415
atomic64_set(&i915->perf.noa_programming_delay, val);

drivers/gpu/drm/i915/i915_drv.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,4 +1921,16 @@ i915_coherent_map_type(struct drm_i915_private *i915)
19211921
return HAS_LLC(i915) ? I915_MAP_WB : I915_MAP_WC;
19221922
}
19231923

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+
19241936
#endif

drivers/gpu/drm/i915/i915_perf.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,9 +1612,7 @@ static int alloc_noa_wait(struct i915_perf_stream *stream)
16121612
struct drm_i915_gem_object *bo;
16131613
struct i915_vma *vma;
16141614
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));
16181616
const u32 base = stream->engine->mmio_base;
16191617
#define CS_GPR(x) GEN8_RING_CS_GPR(base, x)
16201618
u32 *batch, *ts0, *cs, *jump;
@@ -3484,8 +3482,7 @@ i915_perf_open_ioctl_locked(struct i915_perf *perf,
34843482

34853483
static u64 oa_exponent_to_ns(struct i915_perf *perf, int exponent)
34863484
{
3487-
return div_u64(1000000000 * (2ULL << exponent),
3488-
RUNTIME_INFO(perf->i915)->cs_timestamp_frequency_hz);
3485+
return i915_cs_timestamp_ticks_to_ns(perf->i915, 2ULL << exponent);
34893486
}
34903487

34913488
/**

drivers/gpu/drm/i915/intel_device_info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ void intel_device_info_runtime_init(struct drm_i915_private *dev_priv)
10521052
read_timestamp_frequency(dev_priv);
10531053
if (runtime->cs_timestamp_frequency_hz) {
10541054
runtime->cs_timestamp_period_ns =
1055-
div_u64(1e9, runtime->cs_timestamp_frequency_hz);
1055+
i915_cs_timestamp_ticks_to_ns(dev_priv, 1);
10561056
drm_dbg(&dev_priv->drm,
10571057
"CS timestamp wraparound in %lldms\n",
10581058
div_u64(mul_u32_u32(runtime->cs_timestamp_period_ns,

drivers/gpu/drm/i915/selftests/i915_perf.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,7 @@ static int live_noa_delay(void *arg)
262262

263263
delay = intel_read_status_page(stream->engine, 0x102);
264264
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);
267266
pr_info("GPU delay: %uns, expected %lluns\n",
268267
delay, expected);
269268

0 commit comments

Comments
 (0)