Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752358AbbEGOQu (ORCPT ); Thu, 7 May 2015 10:16:50 -0400 Received: from mail-wg0-f51.google.com ([74.125.82.51]:36143 "EHLO mail-wg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752217AbbEGOQL (ORCPT ); Thu, 7 May 2015 10:16:11 -0400 From: Robert Bragg To: intel-gfx@lists.freedesktop.org Cc: Daniel Vetter , Jani Nikula , David Airlie , Peter Zijlstra , Paul Mackerras , Ingo Molnar , Arnaldo Carvalho de Melo , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-api@vger.kernel.org Subject: [RFC PATCH 10/11] drm/i915: report OA buf overrun + report lost status Date: Thu, 7 May 2015 15:15:53 +0100 Message-Id: <1431008154-6833-11-git-send-email-robert@sixbynine.org> X-Mailer: git-send-email 2.3.2 In-Reply-To: <1431008154-6833-1-git-send-email-robert@sixbynine.org> References: <1431008154-6833-1-git-send-email-robert@sixbynine.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4358 Lines: 127 This adds two driver specific PERF_RECORD_DEVICE event types for reporting OA buffer overrun and report lost status bits to userspace. Signed-off-by: Robert Bragg --- drivers/gpu/drm/i915/i915_oa_perf.c | 53 ++++++++++++++++++++++++------------- include/uapi/drm/i915_drm.h | 27 +++++++++++++++++++ 2 files changed, 62 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_oa_perf.c b/drivers/gpu/drm/i915/i915_oa_perf.c index c3e5059..d0dad5d 100644 --- a/drivers/gpu/drm/i915/i915_oa_perf.c +++ b/drivers/gpu/drm/i915/i915_oa_perf.c @@ -159,6 +159,34 @@ static u32 forward_oa_snapshots(struct drm_i915_private *dev_priv, return dev_priv->oa_pmu.oa_buffer.gtt_offset + head; } +static void log_oa_status(struct drm_i915_private *dev_priv, + enum drm_i915_oa_event_type status) +{ + struct { + struct perf_event_header header; + drm_i915_oa_event_header_t i915_oa_header; + } oa_event; + struct perf_output_handle handle; + struct perf_sample_data sample_data; + struct perf_event *event = dev_priv->oa_pmu.exclusive_event; + int ret; + + oa_event.header.size = sizeof(oa_event); + oa_event.header.type = PERF_RECORD_DEVICE; + oa_event.i915_oa_header.type = status; + oa_event.i915_oa_header.__reserved_1 = 0; + + perf_event_header__init_id(&oa_event.header, &sample_data, event); + + ret = perf_output_begin(&handle, event, oa_event.header.size); + if (ret) + return; + + perf_output_put(&handle, oa_event); + perf_event__output_id_sample(event, &handle, &sample_data); + perf_output_end(&handle); +} + static void flush_oa_snapshots(struct drm_i915_private *dev_priv, bool skip_if_flushing) { @@ -189,25 +217,14 @@ static void flush_oa_snapshots(struct drm_i915_private *dev_priv, head = oastatus2 & GEN7_OASTATUS2_HEAD_MASK; tail = oastatus1 & GEN7_OASTATUS1_TAIL_MASK; - if (oastatus1 & (GEN7_OASTATUS1_OABUFFER_OVERFLOW | - GEN7_OASTATUS1_REPORT_LOST)) { + if (unlikely(oastatus1 & (GEN7_OASTATUS1_OABUFFER_OVERFLOW | + GEN7_OASTATUS1_REPORT_LOST))) { - /* XXX: How can we convey report-lost errors to userspace? It - * doesn't look like perf's _REPORT_LOST mechanism is - * appropriate in this case; that's just for cases where we - * run out of space for samples in the perf circular buffer. - * - * Maybe we can claim a special report-id and use that to - * forward status flags? - */ - pr_debug("OA buffer read error: addr = %p, head = %u, offset = %u, tail = %u cnt o'flow = %d, buf o'flow = %d, rpt lost = %d\n", - dev_priv->oa_pmu.oa_buffer.addr, - head, - head - dev_priv->oa_pmu.oa_buffer.gtt_offset, - tail, - oastatus1 & GEN7_OASTATUS1_COUNTER_OVERFLOW ? 1 : 0, - oastatus1 & GEN7_OASTATUS1_OABUFFER_OVERFLOW ? 1 : 0, - oastatus1 & GEN7_OASTATUS1_REPORT_LOST ? 1 : 0); + if (oastatus1 & GEN7_OASTATUS1_OABUFFER_OVERFLOW) + log_oa_status(dev_priv, I915_OA_RECORD_BUFFER_OVERFLOW); + + if (oastatus1 & GEN7_OASTATUS1_REPORT_LOST) + log_oa_status(dev_priv, I915_OA_RECORD_REPORT_LOST); I915_WRITE(GEN7_OASTATUS1, oastatus1 & ~(GEN7_OASTATUS1_OABUFFER_OVERFLOW | diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h index 7aa1d33..2871922 100644 --- a/include/uapi/drm/i915_drm.h +++ b/include/uapi/drm/i915_drm.h @@ -89,6 +89,33 @@ typedef struct _drm_i915_oa_attr { __reserved_1 : 63; } drm_i915_oa_attr_t; +/* Header for PERF_RECORD_DEVICE type events */ +typedef struct _drm_i915_oa_event_header { + __u32 type; + __u32 __reserved_1; +} drm_i915_oa_event_header_t; + +enum drm_i915_oa_event_type { + + /* + * struct { + * struct perf_event_header header; + * drm_i915_oa_event_header_t i915_oa_header; + * }; + */ + I915_OA_RECORD_BUFFER_OVERFLOW = 1, + + /* + * struct { + * struct perf_event_header header; + * drm_i915_oa_event_header_t i915_oa_header; + * }; + */ + I915_OA_RECORD_REPORT_LOST = 2, + + I915_OA_RECORD_MAX, /* non-ABI */ +}; + /* Each region is a minimum of 16k, and there are at most 255 of them. */ #define I915_NR_TEX_REGIONS 255 /* table size 2k - maximum due to use -- 2.3.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/