Commit b2c88f5b authored by Damien Lespiau's avatar Damien Lespiau Committed by Daniel Vetter

drm/i915: Keep the CRC values into a circular buffer

There are a few good properties to a circular buffer, for instance it
has a number of entries (before we were always dumping the full buffer).
Signed-off-by: default avatarDamien Lespiau <damien.lespiau@intel.com>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent 926321d5
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
*/ */
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include <linux/circ_buf.h>
#include <linux/ctype.h> #include <linux/ctype.h>
#include <linux/debugfs.h> #include <linux/debugfs.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -1739,25 +1740,28 @@ static int i915_pipe_crc(struct seq_file *m, void *data) ...@@ -1739,25 +1740,28 @@ static int i915_pipe_crc(struct seq_file *m, void *data)
struct drm_device *dev = node->minor->dev; struct drm_device *dev = node->minor->dev;
struct drm_i915_private *dev_priv = dev->dev_private; struct drm_i915_private *dev_priv = dev->dev_private;
enum pipe pipe = (enum pipe)node->info_ent->data; enum pipe pipe = (enum pipe)node->info_ent->data;
const struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe]; struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
int i; int head, tail;
int start;
if (dev_priv->pipe_crc[pipe].source == INTEL_PIPE_CRC_SOURCE_NONE) { if (dev_priv->pipe_crc[pipe].source == INTEL_PIPE_CRC_SOURCE_NONE) {
seq_puts(m, "none\n"); seq_puts(m, "none\n");
return 0; return 0;
} }
start = atomic_read(&pipe_crc->slot) + 1;
seq_puts(m, " timestamp CRC1 CRC2 CRC3 CRC4 CRC5\n"); seq_puts(m, " timestamp CRC1 CRC2 CRC3 CRC4 CRC5\n");
for (i = 0; i < INTEL_PIPE_CRC_ENTRIES_NR; i++) { head = atomic_read(&pipe_crc->head);
const struct intel_pipe_crc_entry *entry = tail = atomic_read(&pipe_crc->tail);
&pipe_crc->entries[(start + i) %
INTEL_PIPE_CRC_ENTRIES_NR]; while (CIRC_CNT(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) >= 1) {
struct intel_pipe_crc_entry *entry = &pipe_crc->entries[tail];
seq_printf(m, "%12u %8x %8x %8x %8x %8x\n", entry->timestamp, seq_printf(m, "%12u %8x %8x %8x %8x %8x\n", entry->timestamp,
entry->crc[0], entry->crc[1], entry->crc[2], entry->crc[0], entry->crc[1], entry->crc[2],
entry->crc[3], entry->crc[4]); entry->crc[3], entry->crc[4]);
BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
tail = (tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
atomic_set(&pipe_crc->tail, tail);
} }
return 0; return 0;
......
...@@ -1230,11 +1230,11 @@ struct intel_pipe_crc_entry { ...@@ -1230,11 +1230,11 @@ struct intel_pipe_crc_entry {
uint32_t crc[5]; uint32_t crc[5];
}; };
#define INTEL_PIPE_CRC_ENTRIES_NR 200 #define INTEL_PIPE_CRC_ENTRIES_NR 128
struct intel_pipe_crc { struct intel_pipe_crc {
struct intel_pipe_crc_entry entries[INTEL_PIPE_CRC_ENTRIES_NR]; struct intel_pipe_crc_entry entries[INTEL_PIPE_CRC_ENTRIES_NR];
enum intel_pipe_crc_source source; enum intel_pipe_crc_source source;
atomic_t slot; atomic_t head, tail;
}; };
typedef struct drm_i915_private { typedef struct drm_i915_private {
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <linux/sysrq.h> #include <linux/sysrq.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/circ_buf.h>
#include <drm/drmP.h> #include <drm/drmP.h>
#include <drm/i915_drm.h> #include <drm/i915_drm.h>
#include "i915_drv.h" #include "i915_drv.h"
...@@ -1195,20 +1196,30 @@ static void ivb_pipe_crc_update(struct drm_device *dev, enum pipe pipe) ...@@ -1195,20 +1196,30 @@ static void ivb_pipe_crc_update(struct drm_device *dev, enum pipe pipe)
struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe]; struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
struct intel_pipe_crc_entry *entry; struct intel_pipe_crc_entry *entry;
ktime_t now; ktime_t now;
int ts, slot; int ts, head, tail;
head = atomic_read(&pipe_crc->head);
tail = atomic_read(&pipe_crc->tail);
if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
DRM_ERROR("CRC buffer overflowing\n");
return;
}
entry = &pipe_crc->entries[head];
now = ktime_get(); now = ktime_get();
ts = ktime_to_us(now); ts = ktime_to_us(now);
slot = (atomic_read(&pipe_crc->slot) + 1) % INTEL_PIPE_CRC_ENTRIES_NR;
entry = &pipe_crc->entries[slot];
entry->timestamp = ts; entry->timestamp = ts;
entry->crc[0] = I915_READ(PIPE_CRC_RES_1_IVB(pipe)); entry->crc[0] = I915_READ(PIPE_CRC_RES_1_IVB(pipe));
entry->crc[1] = I915_READ(PIPE_CRC_RES_2_IVB(pipe)); entry->crc[1] = I915_READ(PIPE_CRC_RES_2_IVB(pipe));
entry->crc[2] = I915_READ(PIPE_CRC_RES_3_IVB(pipe)); entry->crc[2] = I915_READ(PIPE_CRC_RES_3_IVB(pipe));
entry->crc[3] = I915_READ(PIPE_CRC_RES_4_IVB(pipe)); entry->crc[3] = I915_READ(PIPE_CRC_RES_4_IVB(pipe));
entry->crc[4] = I915_READ(PIPE_CRC_RES_5_IVB(pipe)); entry->crc[4] = I915_READ(PIPE_CRC_RES_5_IVB(pipe));
atomic_set(&dev_priv->pipe_crc[pipe].slot, slot);
head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
atomic_set(&pipe_crc->head, head);
} }
#else #else
static void ivb_pipe_crc_update(struct drm_device *dev, int pipe) {} static void ivb_pipe_crc_update(struct drm_device *dev, int pipe) {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment