From: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
To: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org,
nd <nd@arm.com>
Cc: Petri Latvala <petri.latvala@intel.com>,
Simon Ser <contact@emersion.fr>,
Liviu Dudau <liviu.dudau@arm.com>,
Simon Ser <simon.ser@intel.com>,
Maxime Ripard <maxime@cerno.tech>,
Daniel Vetter <daniel@ffwll.ch>,
Brian Starkey <brian.starkey@arm.com>
Subject: [igt-dev] [PATCH i-g-t v8 3/4] lib: Add function to hash a framebuffer
Date: Thu, 23 Apr 2020 21:26:04 -0400 [thread overview]
Message-ID: <20200424012605.2279679-4-rodrigosiqueiramelo@gmail.com> (raw)
In-Reply-To: <20200424012605.2279679-1-rodrigosiqueiramelo@gmail.com>
From: Brian Starkey <rodrigosiqueiramelo@gmail.com>
To use writeback buffers as a CRC source, we need to be able to hash
them. Implement a simple FVA-1a hashing routine for this purpose.
Doing a bytewise hash on the framebuffer directly can be very slow if
the memory is noncached. By making a copy of each line in the FB first
(which can take advantage of word-access speedup), we can do the hash
on a cached copy, which is much faster (10x speedup on my platform).
Changes since V7 (Maxime Ripard):
* Maxime Ripard:
- Replace `gem_mmap__gtt` by `igt_fb_map_buffer` on `igt_fb_get_crc()`
* Rodrigo Siqueira:
- Rename igt_fb_get_crc to igt_fb_get_fnv1a_crc
Changes since V6 (Simon Ser):
* Use plain uint32_t for FNV1a_OFFSET_BIAS and FNV1a_PRIME
* Return -EINVAL in case fb->num_planes != 1
* Just copy fb->width * cpp instead of copy the whole stride
v5: use igt_memcpy_from_wc() instead of plain memcpy, as suggested by
Chris Wilson
Signed-off-by: Brian Starkey <brian.starkey@arm.com>
[rebased and updated to the most recent API]
Signed-off-by: Liviu Dudau <liviu.dudau@arm.com>
[rebased and updated]
Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Reviewed-by: Simon Ser <simon.ser@intel.com>
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
---
lib/igt_fb.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++
lib/igt_fb.h | 2 ++
2 files changed, 65 insertions(+)
diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 5ed586e7..562206b1 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -3785,6 +3785,69 @@ bool igt_fb_supported_format(uint32_t drm_format)
return true;
}
+/*
+ * This implements the FNV-1a hashing algorithm instead of CRC, for
+ * simplicity
+ * http://www.isthe.com/chongo/tech/comp/fnv/index.html
+ *
+ * hash = offset_basis
+ * for each octet_of_data to be hashed
+ * hash = hash xor octet_of_data
+ * hash = hash * FNV_prime
+ * return hash
+ *
+ * 32 bit offset_basis = 2166136261
+ * 32 bit FNV_prime = 224 + 28 + 0x93 = 16777619
+ */
+int igt_fb_get_fnv1a_crc(struct igt_fb *fb, igt_crc_t *crc)
+{
+ const uint32_t FNV1a_OFFSET_BIAS = 2166136261;
+ const uint32_t FNV1a_PRIME = 16777619;
+ uint32_t hash;
+ void *map;
+ char *ptr, *line = NULL;
+ int x, y, cpp = igt_drm_format_to_bpp(fb->drm_format) / 8;
+ uint32_t stride = calc_plane_stride(fb, 0);
+
+ if (fb->num_planes != 1)
+ return -EINVAL;
+
+ ptr = igt_fb_map_buffer(fb->fd, fb);
+ igt_assert(ptr);
+ map = ptr;
+
+ /*
+ * Framebuffers are often uncached, which can make byte-wise accesses
+ * very slow. We copy each line of the FB into a local buffer to speed
+ * up the hashing.
+ */
+ line = malloc(stride);
+ if (!line) {
+ munmap(map, fb->size);
+ return -ENOMEM;
+ }
+
+ hash = FNV1a_OFFSET_BIAS;
+
+ for (y = 0; y < fb->height; y++, ptr += stride) {
+
+ igt_memcpy_from_wc(line, ptr, fb->width * cpp);
+
+ for (x = 0; x < fb->width * cpp; x++) {
+ hash ^= line[x];
+ hash *= FNV1a_PRIME;
+ }
+ }
+
+ crc->n_words = 1;
+ crc->crc[0] = hash;
+
+ free(line);
+ igt_fb_unmap_buffer(fb, map);
+
+ return 0;
+}
+
/**
* igt_format_is_yuv:
* @drm_format: drm fourcc
diff --git a/lib/igt_fb.h b/lib/igt_fb.h
index 587f7a44..4221d8b9 100644
--- a/lib/igt_fb.h
+++ b/lib/igt_fb.h
@@ -207,5 +207,7 @@ int igt_format_plane_bpp(uint32_t drm_format, int plane);
void igt_format_array_fill(uint32_t **formats_array, unsigned int *count,
bool allow_yuv);
+int igt_fb_get_fnv1a_crc(struct igt_fb *fb, igt_crc_t *crc);
+
#endif /* __IGT_FB_H__ */
--
2.26.0
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
next prev parent reply other threads:[~2020-04-24 1:26 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-24 1:26 [igt-dev] [PATCH i-g-t v8 0/4] Add support for testing writeback connectors Rodrigo Siqueira
2020-04-24 1:26 ` [igt-dev] [PATCH i-g-t v8 1/4] lib/igt_kms: Add writeback support Rodrigo Siqueira
2020-04-24 1:26 ` [igt-dev] [PATCH i-g-t v8 2/4] kms_writeback: Add initial writeback tests Rodrigo Siqueira
2020-04-24 1:26 ` Rodrigo Siqueira [this message]
2020-04-24 1:26 ` [igt-dev] [PATCH i-g-t v8 4/4] kms_writeback: Add writeback-check-output Rodrigo Siqueira
2020-04-24 1:51 ` [igt-dev] ✗ GitLab.Pipeline: failure for Add support for testing writeback connectors (rev2) Patchwork
2020-05-04 11:56 ` Arkadiusz Hiler
2020-05-06 22:56 ` Rodrigo Siqueira
2020-04-24 2:02 ` [igt-dev] ✓ Fi.CI.BAT: success " Patchwork
2020-04-24 4:39 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2020-04-29 15:37 ` [Intel-gfx] [PATCH i-g-t v8 0/4] Add support for testing writeback connectors Maxime Ripard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200424012605.2279679-4-rodrigosiqueiramelo@gmail.com \
--to=rodrigosiqueiramelo@gmail.com \
--cc=brian.starkey@arm.com \
--cc=contact@emersion.fr \
--cc=daniel@ffwll.ch \
--cc=igt-dev@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=liviu.dudau@arm.com \
--cc=maxime@cerno.tech \
--cc=nd@arm.com \
--cc=petri.latvala@intel.com \
--cc=simon.ser@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox