Skip to content

Commit a383a02

Browse files
committed
drm/i915/perf: Remove gtt_offset from stream->oa_buffer.head/.tail
There is no reason to add gtt_offset to the cached head/tail pointers stream->oa_buffer.head and stream->oa_buffer.tail. This causes the code to constantly add gtt_offset and subtract gtt_offset and is error prone. It is much simpler to maintain stream->oa_buffer.head and stream->oa_buffer.tail without adding gtt_offset to them and just allow for the gtt_offset when reading/writing from/to HW registers. v2: Minor tweak to commit message due to dropping patch in previous series Signed-off-by: Ashutosh Dixit <[email protected]> Reviewed-by: Umesh Nerlige Ramappa <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent ae0e5e6 commit a383a02

File tree

1 file changed

+13
-39
lines changed

1 file changed

+13
-39
lines changed

drivers/gpu/drm/i915/i915_perf.c

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -543,10 +543,9 @@ static bool oa_buffer_check_unlocked(struct i915_perf_stream *stream)
543543
{
544544
u32 gtt_offset = i915_ggtt_offset(stream->oa_buffer.vma);
545545
int report_size = stream->oa_buffer.format->size;
546-
u32 head, tail, read_tail;
546+
u32 tail, hw_tail;
547547
unsigned long flags;
548548
bool pollin;
549-
u32 hw_tail;
550549
u32 partial_report_size;
551550

552551
/* 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)
556555
spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags);
557556

558557
hw_tail = stream->perf->ops.oa_hw_tail_read(stream);
558+
hw_tail -= gtt_offset;
559559

560560
/* The tail pointer increases in 64 byte increments, not in report_size
561561
* 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)
567567
/* Subtract partial amount off the tail */
568568
hw_tail = OA_TAKEN(hw_tail, partial_report_size);
569569

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-
577570
tail = hw_tail;
578571

579572
/* 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)
587580
* memory in the order they were written to.
588581
* If not : (╯°□°)╯︵ ┻━┻
589582
*/
590-
while (OA_TAKEN(tail, read_tail) >= report_size) {
583+
while (OA_TAKEN(tail, stream->oa_buffer.tail) >= report_size) {
591584
void *report = stream->oa_buffer.vaddr + tail;
592585

593586
if (oa_report_id(stream, report) ||
@@ -601,9 +594,9 @@ static bool oa_buffer_check_unlocked(struct i915_perf_stream *stream)
601594
__ratelimit(&stream->perf->tail_pointer_race))
602595
drm_notice(&stream->uncore->i915->drm,
603596
"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);
605598

606-
stream->oa_buffer.tail = gtt_offset + tail;
599+
stream->oa_buffer.tail = tail;
607600

608601
pollin = OA_TAKEN(stream->oa_buffer.tail,
609602
stream->oa_buffer.head) >= report_size;
@@ -753,13 +746,6 @@ static int gen8_append_oa_reports(struct i915_perf_stream *stream,
753746

754747
spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags);
755748

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-
763749
/*
764750
* An out of bounds or misaligned head or tail pointer implies a driver
765751
* 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,
895881
* We removed the gtt_offset for the copy loop above, indexing
896882
* relative to oa_buf_base so put back here...
897883
*/
898-
head += gtt_offset;
899884
intel_uncore_write(uncore, oaheadptr,
900-
head & GEN12_OAG_OAHEADPTR_MASK);
885+
(head + gtt_offset) & GEN12_OAG_OAHEADPTR_MASK);
901886
stream->oa_buffer.head = head;
902887

903888
spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags);
@@ -1042,12 +1027,6 @@ static int gen7_append_oa_reports(struct i915_perf_stream *stream,
10421027

10431028
spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags);
10441029

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-
10511030
/* An out of bounds or misaligned head or tail pointer implies a driver
10521031
* bug since we validate + align the tail pointers we read from the
10531032
* 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,
11101089
if (start_offset != *offset) {
11111090
spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags);
11121091

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-
11181092
intel_uncore_write(uncore, GEN7_OASTATUS2,
1119-
(head & GEN7_OASTATUS2_HEAD_MASK) |
1093+
((head + gtt_offset) & GEN7_OASTATUS2_HEAD_MASK) |
11201094
GEN7_OASTATUS2_MEM_SELECT_GGTT);
11211095
stream->oa_buffer.head = head;
11221096

@@ -1704,15 +1678,15 @@ static void gen7_init_oa_buffer(struct i915_perf_stream *stream)
17041678
*/
17051679
intel_uncore_write(uncore, GEN7_OASTATUS2, /* head */
17061680
gtt_offset | GEN7_OASTATUS2_MEM_SELECT_GGTT);
1707-
stream->oa_buffer.head = gtt_offset;
1681+
stream->oa_buffer.head = 0;
17081682

17091683
intel_uncore_write(uncore, GEN7_OABUFFER, gtt_offset);
17101684

17111685
intel_uncore_write(uncore, GEN7_OASTATUS1, /* tail */
17121686
gtt_offset | OABUFFER_SIZE_16M);
17131687

17141688
/* Mark that we need updated tail pointers to read from... */
1715-
stream->oa_buffer.tail = gtt_offset;
1689+
stream->oa_buffer.tail = 0;
17161690

17171691
spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags);
17181692

@@ -1746,7 +1720,7 @@ static void gen8_init_oa_buffer(struct i915_perf_stream *stream)
17461720

17471721
intel_uncore_write(uncore, GEN8_OASTATUS, 0);
17481722
intel_uncore_write(uncore, GEN8_OAHEADPTR, gtt_offset);
1749-
stream->oa_buffer.head = gtt_offset;
1723+
stream->oa_buffer.head = 0;
17501724

17511725
intel_uncore_write(uncore, GEN8_OABUFFER_UDW, 0);
17521726

@@ -1763,7 +1737,7 @@ static void gen8_init_oa_buffer(struct i915_perf_stream *stream)
17631737
intel_uncore_write(uncore, GEN8_OATAILPTR, gtt_offset & GEN8_OATAILPTR_MASK);
17641738

17651739
/* Mark that we need updated tail pointers to read from... */
1766-
stream->oa_buffer.tail = gtt_offset;
1740+
stream->oa_buffer.tail = 0;
17671741

17681742
/*
17691743
* Reset state used to recognise context switches, affecting which
@@ -1800,7 +1774,7 @@ static void gen12_init_oa_buffer(struct i915_perf_stream *stream)
18001774
intel_uncore_write(uncore, __oa_regs(stream)->oa_status, 0);
18011775
intel_uncore_write(uncore, __oa_regs(stream)->oa_head_ptr,
18021776
gtt_offset & GEN12_OAG_OAHEADPTR_MASK);
1803-
stream->oa_buffer.head = gtt_offset;
1777+
stream->oa_buffer.head = 0;
18041778

18051779
/*
18061780
* PRM says:
@@ -1816,7 +1790,7 @@ static void gen12_init_oa_buffer(struct i915_perf_stream *stream)
18161790
gtt_offset & GEN12_OAG_OATAILPTR_MASK);
18171791

18181792
/* Mark that we need updated tail pointers to read from... */
1819-
stream->oa_buffer.tail = gtt_offset;
1793+
stream->oa_buffer.tail = 0;
18201794

18211795
/*
18221796
* Reset state used to recognise context switches, affecting which

0 commit comments

Comments
 (0)