[PATCH i-g-t 1/3] tests/intel: replace div64_u64_round_up() with DIV_ROUND_UP

Sokolowski, Jan jan.sokolowski at intel.com
Tue Apr 22 11:55:32 UTC 2025


>DIV_ROUND_UP is defined in igt_aux.h with the same function as
>div64_u64_round_up().
>
>Cc: Matt Roper <matthew.d.roper at intel.com>
>Signed-off-by: Shuicheng Lin <shuicheng.lin at intel.com>
>---
> tests/intel/gem_exec_balancer.c |  9 ++-------
> tests/intel/gem_exec_fair.c     | 11 +++--------
> tests/intel/gem_exec_schedule.c |  9 ++-------
> tests/intel/gem_watchdog.c      |  9 ++-------
> 4 files changed, 9 insertions(+), 29 deletions(-)
>
>diff --git a/tests/intel/gem_exec_balancer.c b/tests/intel/gem_exec_balancer.c
>index 46ea19a2a..1ad87036b 100644
>--- a/tests/intel/gem_exec_balancer.c
>+++ b/tests/intel/gem_exec_balancer.c
>@@ -2636,15 +2636,10 @@ static int read_ctx_timestamp_frequency(int i915)
> 	return value;
> }
> 
>-static uint64_t div64_u64_round_up(uint64_t x, uint64_t y)
>-{
>-	return (x + y - 1) / y;
>-}
>-
> static uint64_t ticks_to_ns(int i915, uint64_t ticks)
> {
>-	return div64_u64_round_up(ticks * NSEC_PER_SEC,
>-				  read_ctx_timestamp_frequency(i915));
>+	int f = read_ctx_timestamp_frequency(i915);

Personally, I'd use the end result type already, that is, use uint64_t, instead of int.
On the other hand, read_ctx_timestamp_frequency returns int, so what I've just said is just a minor nitpick.

>+	return DIV_ROUND_UP(ticks * NSEC_PER_SEC, f);
> }
> 
> static void __fairslice(int i915,
>diff --git a/tests/intel/gem_exec_fair.c b/tests/intel/gem_exec_fair.c
>index 19df66921..cdceb8927 100644
>--- a/tests/intel/gem_exec_fair.c
>+++ b/tests/intel/gem_exec_fair.c
>@@ -187,23 +187,18 @@ static int read_timestamp_frequency(int i915)
> 	return value;
> }
> 
>-static uint64_t div64_u64_round_up(uint64_t x, uint64_t y)
>-{
>-	return (x + y - 1) / y;
>-}
>-
> static uint64_t ns_to_ctx_ticks(int i915, uint64_t ns)
> {
> 	int f = read_timestamp_frequency(i915);
> 	if (intel_gen(intel_get_drm_devid(i915)) == 11)
> 		f = 12500000; /* gen11!!! are you feeling alright? CTX vs CS */
>-	return div64_u64_round_up(ns * f, NSEC64);
>+	return DIV_ROUND_UP(ns * f, NSEC64);
> }
> 
> static uint64_t ticks_to_ns(int i915, uint64_t ticks)
> {
>-	return div64_u64_round_up(ticks * NSEC64,
>-				  read_timestamp_frequency(i915));
>+	int f = read_timestamp_frequency(i915);
>+	return DIV_ROUND_UP(ticks * NSEC64, f);
> }
> 
> static void delay(int i915,
>diff --git a/tests/intel/gem_exec_schedule.c b/tests/intel/gem_exec_schedule.c
>index 84219b4cf..1055e8501 100644
>--- a/tests/intel/gem_exec_schedule.c
>+++ b/tests/intel/gem_exec_schedule.c
>@@ -3031,15 +3031,10 @@ static int read_timestamp_frequency(int i915)
> 	return value;
> }
> 
>-static uint64_t div64_u64_round_up(uint64_t x, uint64_t y)
>-{
>-	return (x + y - 1) / y;
>-}
>-
> static uint64_t ticks_to_ns(int i915, uint64_t ticks)
> {
>-	return div64_u64_round_up(ticks * NSEC_PER_SEC,
>-				  read_timestamp_frequency(i915));
>+	int f = read_timestamp_frequency(i915);
>+	return DIV_ROUND_UP(ticks * NSEC_PER_SEC, f);
> }
> 
> static int cmp_u32(const void *A, const void *B)
>diff --git a/tests/intel/gem_watchdog.c b/tests/intel/gem_watchdog.c
>index 1edde8b3c..4cb92c68e 100644
>--- a/tests/intel/gem_watchdog.c
>+++ b/tests/intel/gem_watchdog.c
>@@ -289,11 +289,6 @@ static unsigned int offset_in_page(void *addr)
> 	return (uintptr_t)addr & 4095;
> }
> 
>-static uint64_t div64_u64_round_up(uint64_t x, uint64_t y)
>-{
>-	return (x + y - 1) / y;
>-}
>-
> static int read_timestamp_frequency(int i915)
> {
> 	int value = 0;
>@@ -307,8 +302,8 @@ static int read_timestamp_frequency(int i915)
> 
> static uint64_t ns_to_ticks(int i915, uint64_t ns)
> {
>-	return div64_u64_round_up(ns * read_timestamp_frequency(i915),
>-				  NSEC_PER_SEC);
>+	int f = read_timestamp_frequency(i915);
>+	return DIV_ROUND_UP(ns * f, NSEC_PER_SEC);
> }
> 
> static uint32_t __batch_create(int i915, uint32_t offset)
>-- 
>2.25.1

LGTM
Reviewed-by: Jan Sokolowski <jan.sokolowski at intel.com>



More information about the igt-dev mailing list