@@ -543,10 +543,9 @@ static bool oa_buffer_check_unlocked(struct i915_perf_stream *stream)
543
543
{
544
544
u32 gtt_offset = i915_ggtt_offset (stream -> oa_buffer .vma );
545
545
int report_size = stream -> oa_buffer .format -> size ;
546
- u32 head , tail , read_tail ;
546
+ u32 tail , hw_tail ;
547
547
unsigned long flags ;
548
548
bool pollin ;
549
- u32 hw_tail ;
550
549
u32 partial_report_size ;
551
550
552
551
/* We have to consider the (unlikely) possibility that read() errors
@@ -556,6 +555,7 @@ static bool oa_buffer_check_unlocked(struct i915_perf_stream *stream)
556
555
spin_lock_irqsave (& stream -> oa_buffer .ptr_lock , flags );
557
556
558
557
hw_tail = stream -> perf -> ops .oa_hw_tail_read (stream );
558
+ hw_tail -= gtt_offset ;
559
559
560
560
/* The tail pointer increases in 64 byte increments, not in report_size
561
561
* steps. Also the report size may not be a power of 2. Compute
@@ -567,13 +567,6 @@ static bool oa_buffer_check_unlocked(struct i915_perf_stream *stream)
567
567
/* Subtract partial amount off the tail */
568
568
hw_tail = OA_TAKEN (hw_tail , partial_report_size );
569
569
570
- /* NB: The head we observe here might effectively be a little
571
- * out of date. If a read() is in progress, the head could be
572
- * anywhere between this head and stream->oa_buffer.tail.
573
- */
574
- head = stream -> oa_buffer .head - gtt_offset ;
575
- read_tail = stream -> oa_buffer .tail - gtt_offset ;
576
-
577
570
tail = hw_tail ;
578
571
579
572
/* Walk the stream backward until we find a report with report
@@ -587,7 +580,7 @@ static bool oa_buffer_check_unlocked(struct i915_perf_stream *stream)
587
580
* memory in the order they were written to.
588
581
* If not : (╯°□°)╯︵ ┻━┻
589
582
*/
590
- while (OA_TAKEN (tail , read_tail ) >= report_size ) {
583
+ while (OA_TAKEN (tail , stream -> oa_buffer . tail ) >= report_size ) {
591
584
void * report = stream -> oa_buffer .vaddr + tail ;
592
585
593
586
if (oa_report_id (stream , report ) ||
@@ -601,9 +594,9 @@ static bool oa_buffer_check_unlocked(struct i915_perf_stream *stream)
601
594
__ratelimit (& stream -> perf -> tail_pointer_race ))
602
595
drm_notice (& stream -> uncore -> i915 -> drm ,
603
596
"unlanded report(s) head=0x%x tail=0x%x hw_tail=0x%x\n" ,
604
- head , tail , hw_tail );
597
+ stream -> oa_buffer . head , tail , hw_tail );
605
598
606
- stream -> oa_buffer .tail = gtt_offset + tail ;
599
+ stream -> oa_buffer .tail = tail ;
607
600
608
601
pollin = OA_TAKEN (stream -> oa_buffer .tail ,
609
602
stream -> oa_buffer .head ) >= report_size ;
@@ -753,13 +746,6 @@ static int gen8_append_oa_reports(struct i915_perf_stream *stream,
753
746
754
747
spin_unlock_irqrestore (& stream -> oa_buffer .ptr_lock , flags );
755
748
756
- /*
757
- * NB: oa_buffer.head/tail include the gtt_offset which we don't want
758
- * while indexing relative to oa_buf_base.
759
- */
760
- head -= gtt_offset ;
761
- tail -= gtt_offset ;
762
-
763
749
/*
764
750
* An out of bounds or misaligned head or tail pointer implies a driver
765
751
* bug since we validate + align the tail pointers we read from the
@@ -895,9 +881,8 @@ static int gen8_append_oa_reports(struct i915_perf_stream *stream,
895
881
* We removed the gtt_offset for the copy loop above, indexing
896
882
* relative to oa_buf_base so put back here...
897
883
*/
898
- head += gtt_offset ;
899
884
intel_uncore_write (uncore , oaheadptr ,
900
- head & GEN12_OAG_OAHEADPTR_MASK );
885
+ ( head + gtt_offset ) & GEN12_OAG_OAHEADPTR_MASK );
901
886
stream -> oa_buffer .head = head ;
902
887
903
888
spin_unlock_irqrestore (& stream -> oa_buffer .ptr_lock , flags );
@@ -1042,12 +1027,6 @@ static int gen7_append_oa_reports(struct i915_perf_stream *stream,
1042
1027
1043
1028
spin_unlock_irqrestore (& stream -> oa_buffer .ptr_lock , flags );
1044
1029
1045
- /* NB: oa_buffer.head/tail include the gtt_offset which we don't want
1046
- * while indexing relative to oa_buf_base.
1047
- */
1048
- head -= gtt_offset ;
1049
- tail -= gtt_offset ;
1050
-
1051
1030
/* An out of bounds or misaligned head or tail pointer implies a driver
1052
1031
* bug since we validate + align the tail pointers we read from the
1053
1032
* hardware and we are in full control of the head pointer which should
@@ -1110,13 +1089,8 @@ static int gen7_append_oa_reports(struct i915_perf_stream *stream,
1110
1089
if (start_offset != * offset ) {
1111
1090
spin_lock_irqsave (& stream -> oa_buffer .ptr_lock , flags );
1112
1091
1113
- /* We removed the gtt_offset for the copy loop above, indexing
1114
- * relative to oa_buf_base so put back here...
1115
- */
1116
- head += gtt_offset ;
1117
-
1118
1092
intel_uncore_write (uncore , GEN7_OASTATUS2 ,
1119
- (head & GEN7_OASTATUS2_HEAD_MASK ) |
1093
+ (( head + gtt_offset ) & GEN7_OASTATUS2_HEAD_MASK ) |
1120
1094
GEN7_OASTATUS2_MEM_SELECT_GGTT );
1121
1095
stream -> oa_buffer .head = head ;
1122
1096
@@ -1704,15 +1678,15 @@ static void gen7_init_oa_buffer(struct i915_perf_stream *stream)
1704
1678
*/
1705
1679
intel_uncore_write (uncore , GEN7_OASTATUS2 , /* head */
1706
1680
gtt_offset | GEN7_OASTATUS2_MEM_SELECT_GGTT );
1707
- stream -> oa_buffer .head = gtt_offset ;
1681
+ stream -> oa_buffer .head = 0 ;
1708
1682
1709
1683
intel_uncore_write (uncore , GEN7_OABUFFER , gtt_offset );
1710
1684
1711
1685
intel_uncore_write (uncore , GEN7_OASTATUS1 , /* tail */
1712
1686
gtt_offset | OABUFFER_SIZE_16M );
1713
1687
1714
1688
/* Mark that we need updated tail pointers to read from... */
1715
- stream -> oa_buffer .tail = gtt_offset ;
1689
+ stream -> oa_buffer .tail = 0 ;
1716
1690
1717
1691
spin_unlock_irqrestore (& stream -> oa_buffer .ptr_lock , flags );
1718
1692
@@ -1746,7 +1720,7 @@ static void gen8_init_oa_buffer(struct i915_perf_stream *stream)
1746
1720
1747
1721
intel_uncore_write (uncore , GEN8_OASTATUS , 0 );
1748
1722
intel_uncore_write (uncore , GEN8_OAHEADPTR , gtt_offset );
1749
- stream -> oa_buffer .head = gtt_offset ;
1723
+ stream -> oa_buffer .head = 0 ;
1750
1724
1751
1725
intel_uncore_write (uncore , GEN8_OABUFFER_UDW , 0 );
1752
1726
@@ -1763,7 +1737,7 @@ static void gen8_init_oa_buffer(struct i915_perf_stream *stream)
1763
1737
intel_uncore_write (uncore , GEN8_OATAILPTR , gtt_offset & GEN8_OATAILPTR_MASK );
1764
1738
1765
1739
/* Mark that we need updated tail pointers to read from... */
1766
- stream -> oa_buffer .tail = gtt_offset ;
1740
+ stream -> oa_buffer .tail = 0 ;
1767
1741
1768
1742
/*
1769
1743
* Reset state used to recognise context switches, affecting which
@@ -1800,7 +1774,7 @@ static void gen12_init_oa_buffer(struct i915_perf_stream *stream)
1800
1774
intel_uncore_write (uncore , __oa_regs (stream )-> oa_status , 0 );
1801
1775
intel_uncore_write (uncore , __oa_regs (stream )-> oa_head_ptr ,
1802
1776
gtt_offset & GEN12_OAG_OAHEADPTR_MASK );
1803
- stream -> oa_buffer .head = gtt_offset ;
1777
+ stream -> oa_buffer .head = 0 ;
1804
1778
1805
1779
/*
1806
1780
* PRM says:
@@ -1816,7 +1790,7 @@ static void gen12_init_oa_buffer(struct i915_perf_stream *stream)
1816
1790
gtt_offset & GEN12_OAG_OATAILPTR_MASK );
1817
1791
1818
1792
/* Mark that we need updated tail pointers to read from... */
1819
- stream -> oa_buffer .tail = gtt_offset ;
1793
+ stream -> oa_buffer .tail = 0 ;
1820
1794
1821
1795
/*
1822
1796
* Reset state used to recognise context switches, affecting which
0 commit comments