summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c
diff options
context:
space:
mode:
authorThomas Fleury <tfleury@nvidia.com>2017-04-27 14:28:27 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2017-06-15 14:53:10 -0400
commit741e5c45179db066ddf5bed0be6f36e4d0d4010e (patch)
tree815f83070ae0fcf37a7b234caf8a2f86997f99bb /drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c
parent77e2cbab237637f71367df25384164b8c936a31a (diff)
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 56f56b5cd9d2e75cf7d2613b5e115bfebdbee0ce) Reviewed-on: http://git-master/r/1489183 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c')
-rw-r--r--drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c78
1 files changed, 18 insertions, 60 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c b/drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c
index 90a3fbd4..025a30fe 100644
--- a/drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c
+++ b/drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c
@@ -533,76 +533,34 @@ static int gk20a_ctrl_get_buffer_info(
533 &args->out.id, &args->out.length); 533 &args->out.id, &args->out.length);
534} 534}
535 535
536static inline u64 get_cpu_timestamp_tsc(void)
537{
538 return ((u64) get_cycles());
539}
540
541static inline u64 get_cpu_timestamp_jiffies(void)
542{
543 return (get_jiffies_64() - INITIAL_JIFFIES);
544}
545
546static inline u64 get_cpu_timestamp_timeofday(void)
547{
548 struct timeval tv;
549
550 do_gettimeofday(&tv);
551 return timeval_to_jiffies(&tv);
552}
553
554static inline int get_timestamps_zipper(struct gk20a *g,
555 u64 (*get_cpu_timestamp)(void),
556 struct nvgpu_gpu_get_cpu_time_correlation_info_args *args)
557{
558 int err = 0;
559 unsigned int i = 0;
560
561 if (gk20a_busy(g)) {
562 nvgpu_err(g, "GPU not powered on");
563 err = -EINVAL;
564 goto end;
565 }
566
567 for (i = 0; i < args->count; i++) {
568 err = g->ops.bus.read_ptimer(g, &args->samples[i].gpu_timestamp);
569 if (err)
570 return err;
571
572 args->samples[i].cpu_timestamp = get_cpu_timestamp();
573 }
574
575end:
576 gk20a_idle(g);
577 return err;
578}
579
580static int nvgpu_gpu_get_cpu_time_correlation_info( 536static int nvgpu_gpu_get_cpu_time_correlation_info(
581 struct gk20a *g, 537 struct gk20a *g,
582 struct nvgpu_gpu_get_cpu_time_correlation_info_args *args) 538 struct nvgpu_gpu_get_cpu_time_correlation_info_args *args)
583{ 539{
584 int err = 0; 540 struct nvgpu_cpu_time_correlation_sample *samples;
585 u64 (*get_cpu_timestamp)(void) = NULL; 541 int err;
542 u32 i;
586 543
587 if (args->count > NVGPU_GPU_GET_CPU_TIME_CORRELATION_INFO_MAX_COUNT) 544 if (args->count > NVGPU_GPU_GET_CPU_TIME_CORRELATION_INFO_MAX_COUNT)
588 return -EINVAL; 545 return -EINVAL;
589 546
590 switch (args->source_id) { 547 samples = nvgpu_kzalloc(g, args->count *
591 case NVGPU_GPU_GET_CPU_TIME_CORRELATION_INFO_SRC_ID_TSC: 548 sizeof(struct nvgpu_cpu_time_correlation_sample));
592 get_cpu_timestamp = get_cpu_timestamp_tsc; 549 if (!samples) {
593 break; 550 return -ENOMEM;
594 case NVGPU_GPU_GET_CPU_TIME_CORRELATION_INFO_SRC_ID_JIFFIES:
595 get_cpu_timestamp = get_cpu_timestamp_jiffies;
596 break;
597 case NVGPU_GPU_GET_CPU_TIME_CORRELATION_INFO_SRC_ID_TIMEOFDAY:
598 get_cpu_timestamp = get_cpu_timestamp_timeofday;
599 break;
600 default:
601 nvgpu_err(g, "invalid cpu clock source id");
602 return -EINVAL;
603 } 551 }
604 552
605 err = get_timestamps_zipper(g, get_cpu_timestamp, args); 553 err = g->ops.bus.get_timestamps_zipper(g,
554 args->source_id, args->count, samples);
555 if (!err) {
556 for (i = 0; i < args->count; i++) {
557 args->samples[i].cpu_timestamp = samples[i].cpu_timestamp;
558 args->samples[i].gpu_timestamp = samples[i].gpu_timestamp;
559 }
560 }
561
562 nvgpu_kfree(g, samples);
563
606 return err; 564 return err;
607} 565}
608 566