gpu: nvgpu: Improve accuracy of dGPU clk measurement

- This patch replaces "nvgpu_current_time_ms" with "nvgpu_hr_timestamp_us".
- "nvgpu_hr_timestamp_us" gives timestamp in microseconds and has better
accuracy than "nvgpu_current_time_ms" (which gives timestamp in millisecond)

Bug 200503143

Change-Id: I6a10e8e1b3e8ff842aa23f58bf2ba9344af232a6
Signed-off-by: Vaibhav Kachore <vkachore@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/2125959
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Vaibhav Kachore
2019-06-21 11:45:42 +05:30
committed by mobile promotions
parent 80a5b864d3
commit 318d6451e9
7 changed files with 52 additions and 9 deletions

View File

@@ -31,7 +31,7 @@
#include <nvgpu/io.h> #include <nvgpu/io.h>
#include <nvgpu/list.h> #include <nvgpu/list.h>
#include <nvgpu/clk_arb.h> #include <nvgpu/clk_arb.h>
#include <nvgpu/timers.h> #include <nvgpu/soc.h>
#include <nvgpu/gk20a.h> #include <nvgpu/gk20a.h>
#include <nvgpu/clk.h> #include <nvgpu/clk.h>
#include <nvgpu/clk_arb.h> #include <nvgpu/clk_arb.h>
@@ -189,13 +189,14 @@ u32 gv100_get_rate_cntr(struct gk20a *g, struct namemap_cfg *c) {
/* Counter is 36bits , 32 bits on addr[0] and 4 lsb on addr[1] others zero*/ /* Counter is 36bits , 32 bits on addr[0] and 4 lsb on addr[1] others zero*/
cntr_start = (u64)gk20a_readl(g, c->cntr.reg_cntr_addr[0]); cntr_start = (u64)gk20a_readl(g, c->cntr.reg_cntr_addr[0]);
cntr_start += ((u64)gk20a_readl(g, c->cntr.reg_cntr_addr[1]) << 32); cntr_start += ((u64)gk20a_readl(g, c->cntr.reg_cntr_addr[1]) << 32);
start_time = (u64)nvgpu_current_time_ms(); start_time = (u64)nvgpu_hr_timestamp_us();
nvgpu_udelay(XTAL_CNTR_DELAY); nvgpu_udelay(XTAL_CNTR_DELAY);
stop_time = (u64)nvgpu_current_time_ms(); stop_time = (u64)nvgpu_hr_timestamp_us();
cntr_stop = (u64)gk20a_readl(g, c->cntr.reg_cntr_addr[0]); cntr_stop = (u64)gk20a_readl(g, c->cntr.reg_cntr_addr[0]);
cntr_stop += ((u64)gk20a_readl(g, c->cntr.reg_cntr_addr[1]) << 32); cntr_stop += ((u64)gk20a_readl(g, c->cntr.reg_cntr_addr[1]) << 32);
/*Calculate the difference with Acutal time and convert to KHz*/ /*Calculate the difference with Acutal time and convert to KHz*/
cntr = ((u32)(cntr_stop - cntr_start) / (u32)(stop_time-start_time)); cntr = (u32)(((cntr_stop - cntr_start) * 1000U) /
(u32)(stop_time-start_time));
nvgpu_mutex_release(&clk->clk_mutex); nvgpu_mutex_release(&clk->clk_mutex);
return cntr; return cntr;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved. * Copyright (c) 2017-2019, NVIDIA CORPORATION. All rights reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"), * copy of this software and associated documentation files (the "Software"),
@@ -34,5 +34,5 @@ bool nvgpu_is_bpmp_running(struct gk20a *g);
bool nvgpu_is_soc_t194_a01(struct gk20a *g); bool nvgpu_is_soc_t194_a01(struct gk20a *g);
int nvgpu_init_soc_vars(struct gk20a *g); int nvgpu_init_soc_vars(struct gk20a *g);
void nvgpu_delay_usecs(unsigned int usecs); void nvgpu_delay_usecs(unsigned int usecs);
u64 nvgpu_us_counter(void);
#endif /* NVGPU_SOC_H */ #endif /* NVGPU_SOC_H */

View File

@@ -111,6 +111,8 @@ void nvgpu_udelay(unsigned int usecs);
*/ */
s64 nvgpu_current_time_ms(void); s64 nvgpu_current_time_ms(void);
s64 nvgpu_current_time_ns(void); s64 nvgpu_current_time_ns(void);
s64 nvgpu_current_time_us(void);
u64 nvgpu_hr_timestamp_us(void);
u64 nvgpu_hr_timestamp(void); u64 nvgpu_hr_timestamp(void);
#endif /* NVGPU_TIMERS_H */ #endif /* NVGPU_TIMERS_H */

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved. * Copyright (c) 2017-2019, NVIDIA CORPORATION. All rights reserved.
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License, * under the terms and conditions of the GNU General Public License,
@@ -127,3 +127,8 @@ int nvgpu_init_soc_vars(struct gk20a *g)
#endif #endif
return 0; return 0;
} }
u64 nvgpu_us_counter(void)
{
return (u64)nvgpu_current_time_us();
}

View File

@@ -242,6 +242,18 @@ s64 nvgpu_current_time_ms(void)
return ktime_to_ms(ktime_get()); return ktime_to_ms(ktime_get());
} }
/**
* nvgpu_current_time_us - Time in microseconds from a monotonic clock.
*
* Return a clock in microsecond units. The start time of the clock is
* unspecified; the time returned can be compared with older ones to measure
* durations. The source clock does not jump when the system clock is adjusted.
*/
s64 nvgpu_current_time_us(void)
{
return ktime_to_us(ktime_get());
}
/** /**
* nvgpu_current_time_ns - Time in nanoseconds from a monotonic clock. * nvgpu_current_time_ns - Time in nanoseconds from a monotonic clock.
* *
@@ -254,6 +266,18 @@ s64 nvgpu_current_time_ns(void)
return ktime_to_ns(ktime_get()); return ktime_to_ns(ktime_get());
} }
/**
* nvgpu_hr_timestamp_us - Time in microseconds from a monotonic clock.
*
* Return a clock in microsecond units. The start time of the clock is
* unspecified; the time returned can be compared with older ones to measure
* durations. The source clock does not jump when the system clock is adjusted.
*/
u64 nvgpu_hr_timestamp_us(void)
{
return nvgpu_us_counter();
}
/** /**
* nvgpu_hr_timestamp - Opaque 'high resolution' time stamp. * nvgpu_hr_timestamp - Opaque 'high resolution' time stamp.
* *

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. * Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"), * copy of this software and associated documentation files (the "Software"),
@@ -20,6 +20,7 @@
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
*/ */
#include <nvgpu/timers.h>
#include <nvgpu/soc.h> #include <nvgpu/soc.h>
bool nvgpu_platform_is_silicon(struct gk20a *g) bool nvgpu_platform_is_silicon(struct gk20a *g)
@@ -55,3 +56,8 @@ bool nvgpu_is_soc_t194_a01(struct gk20a *g)
void nvgpu_delay_usecs(unsigned int usecs) void nvgpu_delay_usecs(unsigned int usecs)
{ {
} }
u64 nvgpu_us_counter(void)
{
return (u64)nvgpu_current_time_us();
}

View File

@@ -34,7 +34,7 @@
#define NSEC_PER_MSEC 1000000 #define NSEC_PER_MSEC 1000000
#define NSEC_PER_SEC 1000000000 #define NSEC_PER_SEC 1000000000
static inline s64 nvgpu_current_time_us(void) s64 nvgpu_current_time_us(void)
{ {
struct timeval now; struct timeval now;
s64 time_now; s64 time_now;
@@ -248,3 +248,8 @@ u64 nvgpu_hr_timestamp(void)
{ {
return (u64)nvgpu_current_time_us(); return (u64)nvgpu_current_time_us();
} }
u64 nvgpu_hr_timestamp_us(void)
{
return nvgpu_us_counter();
}