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

Kamil Konieczny kamil.konieczny at linux.intel.com
Thu Apr 24 17:43:48 UTC 2025


Hi Shuicheng,
On 2025-04-16 at 16:30:51 +0000, Shuicheng Lin wrote:
> 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);

s/int/unsigned int/

Add also an empty line here. Please use checkpatch.pl script
from Linux kernel to spot such and other issues, you could also
look into CONTRIBUTING.md for script options.

Apply same in other places.

Regards,
Kamil

> +	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
> 


More information about the igt-dev mailing list