summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/gk20a/ctrl_gk20a.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/gk20a/ctrl_gk20a.c')
-rw-r--r--drivers/gpu/nvgpu/gk20a/ctrl_gk20a.c43
1 files changed, 5 insertions, 38 deletions
diff --git a/drivers/gpu/nvgpu/gk20a/ctrl_gk20a.c b/drivers/gpu/nvgpu/gk20a/ctrl_gk20a.c
index 39581eb2..3e34b6b8 100644
--- a/drivers/gpu/nvgpu/gk20a/ctrl_gk20a.c
+++ b/drivers/gpu/nvgpu/gk20a/ctrl_gk20a.c
@@ -626,50 +626,17 @@ static int nvgpu_gpu_get_gpu_time(
626 struct gk20a *g, 626 struct gk20a *g,
627 struct nvgpu_gpu_get_gpu_time_args *args) 627 struct nvgpu_gpu_get_gpu_time_args *args)
628{ 628{
629 int err = 0; 629 u64 time;
630 const unsigned int max_iterations = 3; 630 int err;
631 unsigned int i = 0;
632 u32 gpu_timestamp_hi_prev = 0;
633 631
634 err = gk20a_busy(g->dev); 632 err = gk20a_busy(g->dev);
635 if (err) 633 if (err)
636 return err; 634 return err;
637 635
638 /* Note. The GPU nanosecond timer consists of two 32-bit 636 err = g->ops.read_ptimer(g, &time);
639 * registers (high & low). To detect a possible low register 637 if (!err)
640 * wrap-around between the reads, we need to read the high 638 args->gpu_timestamp = time;
641 * register before and after low. The wraparound happens
642 * approximately once per 4 secs. */
643 639
644 /* get initial gpu_timestamp_hi value */
645 gpu_timestamp_hi_prev = gk20a_readl(g, timer_time_1_r());
646
647 for (i = 0; i < max_iterations; ++i) {
648 u32 gpu_timestamp_hi = 0;
649 u32 gpu_timestamp_lo = 0;
650
651 rmb(); /* maintain read order */
652 gpu_timestamp_lo = gk20a_readl(g, timer_time_0_r());
653 rmb(); /* maintain read order */
654 gpu_timestamp_hi = gk20a_readl(g, timer_time_1_r());
655
656 if (gpu_timestamp_hi == gpu_timestamp_hi_prev) {
657 args->gpu_timestamp =
658 (((u64)gpu_timestamp_hi) << 32) |
659 gpu_timestamp_lo;
660 goto clean_up;
661 }
662
663 /* wrap-around detected, retry */
664 gpu_timestamp_hi_prev = gpu_timestamp_hi;
665 }
666
667 /* too many iterations, bail out */
668 gk20a_err(dev_from_gk20a(g),
669 "Failed to read GPU time. Clock or bus unstable?\n");
670 err = -EBUSY;
671
672clean_up:
673 gk20a_idle(g->dev); 640 gk20a_idle(g->dev);
674 return err; 641 return err;
675} 642}