From patchwork Fri Jul 14 15:18:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liviu Dudau X-Patchwork-Id: 107812 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp1104592obm; Fri, 14 Jul 2017 08:20:15 -0700 (PDT) X-Received: by 10.99.174.14 with SMTP id q14mr4004202pgf.111.1500045615288; Fri, 14 Jul 2017 08:20:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500045615; cv=none; d=google.com; s=arc-20160816; b=GfeD872t3Ulu7aJd8B0oAR/1i6/DZQgky7LlKBLYTwdAb3tQq/xBSYq87yBs6zPNik LfRCrkVjRjoJVQU7bpVfXXsmgzZHW+NizA+/tjieI4Pw237a2ufOIZ9I0UOEL2NR8Dmu JU7YTtdpBXK3v7PcCgpCn3vFFhqnqyr2SWmpDrf0/InIC9lxlgYrEXB8XvW6qOXF+4Sy wW8NAX1z5m4ofr/7H7MJX+den7QMBVexPyuifBjoM5P98c48GAJYKOtWix1cVoKC2r3e ULQast/onfyLqrdNP833+4kiFDD+jTvKuqYlNcTrQt9upLwfMCBs0jn4J4N8Mko4L322 3LYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:cc:references:in-reply-to:message-id:date :subject:to:from:delivered-to:arc-authentication-results; bh=AWVv9CKeW43iwVETBqyzX+m500GfmFY2acZ2zYeVXpQ=; b=OFQjZx6UA0MC85OEBbzv7ct6RFpKhfgYZgGpFzGpSYf77drDlYBmzF/cxEzV0alsj8 wUyFQn1yXGolR0YCEjQPIHFddQw4YXM51/3sgqN1zf3xsm7Q74c+BidArtKL203D6Ffs EN00HKrQew/vEuK3wx25FuajlEdeG95Xpk7kaEq23hqZjaNOB1P8z/92Cc9nWW4L+C0p UYdPW/Z+UISi4P5jHVqdgtbVDd/3KkbABZzVzaNuO72gBm3EqLpJ/t5nDxNGskdC/5oc iCIvUt//8GqoZIp7q4gwCdzgc/R8BdIn+CeIDTIApK7Rv7ded5SQK3+SiC05XiSzpD9R e5Ww== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id q18si6840856pgd.436.2017.07.14.08.20.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Jul 2017 08:20:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7FB036E87B; Fri, 14 Jul 2017 15:19:09 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from cam-smtp0.cambridge.arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9C8B36E862; Fri, 14 Jul 2017 15:19:01 +0000 (UTC) Received: from e110455-lin.cambridge.arm.com (e110455-lin.cambridge.arm.com [10.2.131.9]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id v6EFIuFN000867; Fri, 14 Jul 2017 16:18:57 +0100 From: Liviu Dudau To: Intel GFX discussion Subject: [PATCH i-g-t v2 4/7] lib: Add function to hash a framebuffer Date: Fri, 14 Jul 2017 16:18:53 +0100 Message-Id: <20170714151856.32041-5-liviu.dudau@arm.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170714151856.32041-1-liviu.dudau@arm.com> References: <20170714151856.32041-1-liviu.dudau@arm.com> Cc: Boris Brezillon , DRI devel X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Brian Starkey 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). Signed-off-by: Brian Starkey --- lib/igt_fb.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/igt_fb.h | 5 +++++ 2 files changed, 70 insertions(+) diff --git a/lib/igt_fb.c b/lib/igt_fb.c index d2b7e9e3..f613bb2e 100644 --- a/lib/igt_fb.c +++ b/lib/igt_fb.c @@ -1302,3 +1302,68 @@ void igt_get_all_cairo_formats(const uint32_t **formats, int *format_count) *formats = drm_formats; *format_count = n_formats; } + +/* + * 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_crc(struct igt_fb *fb, igt_crc_t *crc) +{ +#define FNV1a_OFFSET_BIAS 2166136261 +#define 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; + + if (fb->is_dumb) + map = kmstest_dumb_map_buffer(fb->fd, fb->gem_handle, fb->size, + PROT_READ); + else + map = gem_mmap__gtt(fb->fd, fb->gem_handle, fb->size, + PROT_READ); + ptr = map; + + /* + * 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(fb->stride); + if (!line) { + munmap(map, fb->size); + return -ENOMEM; + } + + hash = FNV1a_OFFSET_BIAS; + + for (y = 0; y < fb->height; y++, ptr += fb->stride) { + + memcpy(line, ptr, fb->stride); + + for (x = 0; x < fb->width * cpp; x++) { + hash ^= line[x]; + hash *= FNV1a_PRIME; + } + } + + crc->n_words = 1; + crc->crc[0] = hash; + + free(line); + munmap(map, fb->size); + + return 0; +#undef FNV1a_OFFSET_BIAS +#undef FNV1a_PRIME +} diff --git a/lib/igt_fb.h b/lib/igt_fb.h index 4a680cef..04430e9d 100644 --- a/lib/igt_fb.h +++ b/lib/igt_fb.h @@ -43,6 +43,8 @@ typedef struct _cairo cairo_t; #include +#include "igt_crc.h" + /** * igt_fb_t: * @fb_id: KMS ID of the framebuffer @@ -156,5 +158,8 @@ uint32_t igt_drm_format_to_bpp(uint32_t drm_format); const char *igt_format_str(uint32_t drm_format); void igt_get_all_cairo_formats(const uint32_t **formats, int *format_count); +/* Get a hash for a framebuffer */ +int igt_fb_get_crc(struct igt_fb *fb, igt_crc_t *crc); + #endif /* __IGT_FB_H__ */