mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-23 18:16:01 +03:00
gpu: nvgpu: hal for timestamps correlation
In order to perform timestamps correlation for FECS
traces, we need to collect GPU / GPU timestamps
samples. In virtualization case, it is possible for
a guest to get GPU timestamps by using read_ptimer.
However, if the CPU timestamp is read on guest side,
and the GPU timestamp is read on vm-server side,
then it introduces some latency that will create an
artificial offset for GPU timestamps (~2 us in
average). For better CPU / GPU timestamps correlation,
Added a command to collect all timestamps on vm-server
side.
Bug 1900475
Change-Id: Idfdc6ae4c16c501dc5e00053a5b75932c55148d6
Signed-off-by: Thomas Fleury <tfleury@nvidia.com>
Reviewed-on: http://git-master/r/1472447
(cherry picked from commit 56f56b5cd9)
Reviewed-on: http://git-master/r/1489183
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
committed by
mobile promotions
parent
77e2cbab23
commit
741e5c4517
@@ -533,76 +533,34 @@ static int gk20a_ctrl_get_buffer_info(
|
||||
&args->out.id, &args->out.length);
|
||||
}
|
||||
|
||||
static inline u64 get_cpu_timestamp_tsc(void)
|
||||
{
|
||||
return ((u64) get_cycles());
|
||||
}
|
||||
|
||||
static inline u64 get_cpu_timestamp_jiffies(void)
|
||||
{
|
||||
return (get_jiffies_64() - INITIAL_JIFFIES);
|
||||
}
|
||||
|
||||
static inline u64 get_cpu_timestamp_timeofday(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
do_gettimeofday(&tv);
|
||||
return timeval_to_jiffies(&tv);
|
||||
}
|
||||
|
||||
static inline int get_timestamps_zipper(struct gk20a *g,
|
||||
u64 (*get_cpu_timestamp)(void),
|
||||
struct nvgpu_gpu_get_cpu_time_correlation_info_args *args)
|
||||
{
|
||||
int err = 0;
|
||||
unsigned int i = 0;
|
||||
|
||||
if (gk20a_busy(g)) {
|
||||
nvgpu_err(g, "GPU not powered on");
|
||||
err = -EINVAL;
|
||||
goto end;
|
||||
}
|
||||
|
||||
for (i = 0; i < args->count; i++) {
|
||||
err = g->ops.bus.read_ptimer(g, &args->samples[i].gpu_timestamp);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
args->samples[i].cpu_timestamp = get_cpu_timestamp();
|
||||
}
|
||||
|
||||
end:
|
||||
gk20a_idle(g);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int nvgpu_gpu_get_cpu_time_correlation_info(
|
||||
struct gk20a *g,
|
||||
struct nvgpu_gpu_get_cpu_time_correlation_info_args *args)
|
||||
{
|
||||
int err = 0;
|
||||
u64 (*get_cpu_timestamp)(void) = NULL;
|
||||
struct nvgpu_cpu_time_correlation_sample *samples;
|
||||
int err;
|
||||
u32 i;
|
||||
|
||||
if (args->count > NVGPU_GPU_GET_CPU_TIME_CORRELATION_INFO_MAX_COUNT)
|
||||
return -EINVAL;
|
||||
|
||||
switch (args->source_id) {
|
||||
case NVGPU_GPU_GET_CPU_TIME_CORRELATION_INFO_SRC_ID_TSC:
|
||||
get_cpu_timestamp = get_cpu_timestamp_tsc;
|
||||
break;
|
||||
case NVGPU_GPU_GET_CPU_TIME_CORRELATION_INFO_SRC_ID_JIFFIES:
|
||||
get_cpu_timestamp = get_cpu_timestamp_jiffies;
|
||||
break;
|
||||
case NVGPU_GPU_GET_CPU_TIME_CORRELATION_INFO_SRC_ID_TIMEOFDAY:
|
||||
get_cpu_timestamp = get_cpu_timestamp_timeofday;
|
||||
break;
|
||||
default:
|
||||
nvgpu_err(g, "invalid cpu clock source id");
|
||||
return -EINVAL;
|
||||
samples = nvgpu_kzalloc(g, args->count *
|
||||
sizeof(struct nvgpu_cpu_time_correlation_sample));
|
||||
if (!samples) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
err = get_timestamps_zipper(g, get_cpu_timestamp, args);
|
||||
err = g->ops.bus.get_timestamps_zipper(g,
|
||||
args->source_id, args->count, samples);
|
||||
if (!err) {
|
||||
for (i = 0; i < args->count; i++) {
|
||||
args->samples[i].cpu_timestamp = samples[i].cpu_timestamp;
|
||||
args->samples[i].gpu_timestamp = samples[i].gpu_timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
nvgpu_kfree(g, samples);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user