Modify the SW tail logic in OA
Subsystems (2)
cover Modify the SW tail logic in OA
OA unit updates the HW TAIL register to indicate that a new report is available, although it does not guarantee that the report is visible in memory. Also the currently running workload contributes to some latency in seeing this report in memory. In the past we would set some fields in the OA report and check if the fields are populated to non-zero values by the HW, but this is no longer sufficient since some parts of the report may land out of order under heavy workloads. Drop this WA and add a new logic that just waits for a fixed number of HW TAIL report increments before returning data to the user. User will always see the reports lagging by this fixed number, however we do not have realtime use cases for OAG since OAG reports are mainly post processed.
Umesh Nerlige Ramappa (3):
drm/xe/xe_oa: Clear status only if relevant bits are set drm/xe/xe_oa: Avoid checking and setting fields in the OA report drm/xe/xe_oa: Add a lag to the reports that is exported to user
drivers/gpu/drm/xe/xe_oa.c | 88 ++++++-------------------------------- 1 file changed, 12 insertions(+), 76 deletions(-)
Signature · 1 line
2.51.0
PATCH 1/3 drm/xe/xe_oa: Clear status only if relevant bits are set
OA monitors only a few bits in the status field. The current read-modify-write will write to the MMIO even if none of the relevant bits are set. Clear the status only if relevant bits are set.
--- drivers/gpu/drm/xe/xe_oa.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/xe/xe_oa.c +5 -3
@@ -524,14 +524,16 @@ static int __xe_oa_read(struct xe_oa_stream *stream, char __user *buf, size_t count, size_t *offset) {/* Only clear our bits to avoid side-effects */ - stream->oa_status = xe_mmio_rmw32(&stream->gt->mmio, __oa_regs(stream)->oa_status, -OASTATUS_RELEVANT_BITS ,0 ); + stream->oa_status = xe_mmio_read32(&stream->gt->mmio, __oa_regs(stream)->oa_status);/* * Signal to userspace that there is non-zero OA status to read via * @DRM_XE_OBSERVATION_IOCTL_STATUS observation stream fd ioctl */ -if (stream->oa_status &OASTATUS_RELEVANT_BITS ) +if (stream->oa_status &OASTATUS_RELEVANT_BITS ) { +xe_mmio_write32 (&stream->gt->mmio,__oa_regs (stream)->oa_status, + stream->oa_status & ~OASTATUS_RELEVANT_BITS );return -EIO ; + }return xe_oa_append_reports (stream, buf, count, offset); }
Signature · 1 line
2.51.0
PATCH 2/3 drm/xe/xe_oa: Avoid checking and setting fields in the OA report
In reply to Umesh Nerlige RamappaOA unit updates the HW TAIL register to indicate that a new report is available, although it does not guarantee that the report is visible in memory. Also the currently running workload contributes to some latency in seeing this report in memory. In the past we would set some fields in the OA report and check if the fields are populated to non-zero values by the HW, but this is no longer sufficient since some parts of the report may land out of order under heavy workloads. Drop this WA and add a new logic in subsequent patches to return updated reports to the user.
--- drivers/gpu/drm/xe/xe_oa.c | 73 ++------------------------------------ 1 file changed, 2 insertions(+), 71 deletions(-)
drivers/gpu/drm/xe/xe_oa.c +2 -71
@@ -213,38 +213,10 @@ static u32 xe_oa_hw_tail_read(struct xe_oa_stream *stream)#define oa_report_header_64bit (__s) \ ((__s)->oa_buffer.format->header == HDR_64_BIT) -static u64 oa_report_id (struct xe_oa_stream *stream,void *report) -{ -return oa_report_header_64bit (stream) ? *(u64 *)report : *(u32 *)report; -} - -static void oa_report_id_clear (struct xe_oa_stream *stream,u32 *report) -{ -if (oa_report_header_64bit (stream)) - *(u64 *)report =0 ; -else - *report =0 ; -} - -static u64 oa_timestamp (struct xe_oa_stream *stream,void *report) -{ -return oa_report_header_64bit (stream) ? - *((u64 *)report +1 ) : - *((u32 *)report +1 ); -} - -static void oa_timestamp_clear (struct xe_oa_stream *stream,u32 *report) -{ -if (oa_report_header_64bit (stream)) - *(u64 *)&report[2 ] =0 ; -else - report[1 ] =0 ; -} -static bool xe_oa_buffer_check_unlocked (struct xe_oa_stream *stream) {u32 gtt_offset =xe_bo_ggtt_addr (stream->oa_buffer.bo); -u32 tail, hw_tail, partial_report_size, available; +u32 hw_tail, partial_report_size, available;int report_size = stream->oa_buffer.format->size;unsigned long flags;
@@ -264,31 +236,7 @@ static bool xe_oa_buffer_check_unlocked(struct xe_oa_stream *stream)/* Subtract partial amount off the tail */ hw_tail =xe_oa_circ_diff (stream, hw_tail, partial_report_size); - tail = hw_tail; - -/* -* Walk the stream backward until we find a report with report id and timestamp -* not 0. We can't tell whether a report has fully landed in memory before the -* report id and timestamp of the following report have landed. -* -* This is assuming that the writes of the OA unit land in memory in the order -* they were written. If not : (╯°□°)╯︵ ┻━┻ -*/ -while (xe_oa_circ_diff (stream, tail, stream->oa_buffer.tail) >= report_size) { -void *report = stream->oa_buffer.vaddr + tail; - -if (oa_report_id (stream, report) ||oa_timestamp (stream, report)) -break ; - - tail =xe_oa_circ_diff (stream, tail, report_size); - } - -if (xe_oa_circ_diff (stream, hw_tail, tail) > report_size) -drm_dbg (&stream->oa->xe->drm, -"unlanded report(s) head=0x%x tail=0x%x hw_tail=0x%x\n" , - stream->oa_buffer.head, tail, hw_tail); - - stream->oa_buffer.tail = tail; + stream->oa_buffer.tail = hw_tail; available =xe_oa_circ_diff (stream, stream->oa_buffer.tail, stream->oa_buffer.head); stream->pollin = available >= stream->wait_num_reports * report_size;
@@ -369,23 +317,6 @@ static int xe_oa_append_reports(struct xe_oa_stream *stream, char __user *buf, ret =xe_oa_append_report (stream, buf, count, offset, report);if (ret)break ; - -if (!(stream->oa_buffer.circ_size % report_size)) { -/* Clear out report id and timestamp to detect unlanded reports */ -oa_report_id_clear (stream, (void *)report); -oa_timestamp_clear (stream, (void *)report); - }else { -u8 *oa_buf_end = stream->oa_buffer.vaddr + stream->oa_buffer.circ_size; -u32 part = oa_buf_end - report; - -/* Zero out the entire report */ -if (report_size <= part) { -memset (report,0 , report_size); - }else { -memset (report,0 , part); -memset (oa_buf_base,0 , report_size - part); - } - } }if (start_offset != *offset) {
Signature · 1 line
2.51.0
PATCH 3/3 drm/xe/xe_oa: Add a lag to the reports that is exported to user
In reply to Umesh Nerlige RamappaWhen running heavy workloads, reading the OA reports too soon does not guarantee that the report has landed in memory. To make sure correct reports are copied to user buffer, only return reports that lag the current HW_TAIL register by 32 reports. This is an empirical number based on a heavy render workload and several test iterations.
--- drivers/gpu/drm/xe/xe_oa.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/gpu/drm/xe/xe_oa.c +7 -4
@@ -216,7 +216,7 @@ static u32 xe_oa_hw_tail_read(struct xe_oa_stream *stream)static bool xe_oa_buffer_check_unlocked (struct xe_oa_stream *stream) {u32 gtt_offset =xe_bo_ggtt_addr (stream->oa_buffer.bo); -u32 hw_tail, partial_report_size, available; +u32 hw_tail, partial_report_size, available, lag;int report_size = stream->oa_buffer.format->size;unsigned long flags;
@@ -226,17 +226,20 @@ static bool xe_oa_buffer_check_unlocked(struct xe_oa_stream *stream) hw_tail -= gtt_offset;/* -* The tail pointer increases in 64 byte (cacheline size), not in report_size +* The hw_tail pointer increases in 64 byte (cacheline size), not in report_size * increments. Also report size may not be a power of 2. Compute potential * partially landed report in OA buffer. */ partial_report_size =xe_oa_circ_diff (stream, hw_tail, stream->oa_buffer.tail); partial_report_size %= report_size; -/* Subtract partial amount off the tail */ +/* Subtract partial amount off the hw_tail */ hw_tail =xe_oa_circ_diff (stream, hw_tail, partial_report_size); - stream->oa_buffer.tail = hw_tail; +#define LAG_REPORTS 32 + lag =xe_oa_circ_diff (stream, hw_tail, stream->oa_buffer.tail); +if (lag >=LAG_REPORTS * report_size) + stream->oa_buffer.tail = hw_tail; available =xe_oa_circ_diff (stream, stream->oa_buffer.tail, stream->oa_buffer.head); stream->pollin = available >= stream->wait_num_reports * report_size;
Signature · 1 line
2.51.0