From patchwork Mon Dec 12 11:53:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9470635 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 41BC360760 for ; Mon, 12 Dec 2016 11:57:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3676B27F89 for ; Mon, 12 Dec 2016 11:57:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B4C6283F4; Mon, 12 Dec 2016 11:57:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D22E927F89 for ; Mon, 12 Dec 2016 11:57:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0D6006E2E0; Mon, 12 Dec 2016 11:57:05 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 045EB6E2C7; Mon, 12 Dec 2016 11:54:04 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id a20so10756942wme.2; Mon, 12 Dec 2016 03:54:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=BmUc4yDfLu0zOVQmBWLDWqdIb2RKbuSp3XKFLoy5yuQ=; b=w6j74UKtn0ogx+7rZ/oIYX6P0iq3Eu17E0Fr0f8Q0w4ZMlau8KpQMO41CiifPgM/7T Vri7uYyhh5qpOZScTlYED3Qpjc9G272xn4hrsMroDk1zlUTtbDOPywyp7dAajY6/WxLu 2US/k/BDymMY+IgCEVEnata4kX8Uye2KIdIT7NW6PTGaGLyOg6P2B1Fir2jq5Idj6sr+ jqx1wPHqFruoj6R7oglo5zRFRt7iCwEc0mUPT06wndowo5iZUFHT7BnFSBH4aj6FBFzN B1EU1OC7+tFyse2bIOFgXaeowrQodnl/6E6hmyU2FkRq+Msip9jEupRxW+oAguGhkK/1 5+kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=BmUc4yDfLu0zOVQmBWLDWqdIb2RKbuSp3XKFLoy5yuQ=; b=gbb7nFkecDIssHWqYC/00rDBuX8hjO+Q1gHuLqXU0XsMAkMxY167UAjR6NhpsYui2U j0YrxUjzVDd8RRWM9RAVO4JD28cxHj2dPazpekg1SeYJ4Scg4iHZG6KjbncO5rbKLCfL VbaV5NbI/TNTVqQ9bhX0BVxDYsQc+cGe0M9R6T7tRdT0LhoCqlPA0FU5QNquOCqs6I6D iXa68lQtNXAPHX9DFwAUD4N0xhMPl1bxtPkLYSoA+K+zBvAqMtgCdP/xPzmiV0PpgL5d jjJJgsMuNCd/IZRCAAff02TwtVR8Ch5HsZ8PhPWvcDMd9QUeR6EHgAKhUdZJTVCtTxtX S7KA== X-Gm-Message-State: AKaTC02Gb786IvXxQg8f664+EqsA7Zz8ae7XfmnDq4wlb+9Y4FBBbWiUo1IDVY1rrSlOdA== X-Received: by 10.28.95.85 with SMTP id t82mr16255604wmb.56.1481543642326; Mon, 12 Dec 2016 03:54:02 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id u81sm35077381wmu.10.2016.12.12.03.54.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Dec 2016 03:54:01 -0800 (PST) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH 06/34] drm: Add a simple linear congruent generator PRNG Date: Mon, 12 Dec 2016 11:53:22 +0000 Message-Id: <20161212115350.780-7-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161212115350.780-1-chris@chris-wilson.co.uk> References: <20161212115350.780-1-chris@chris-wilson.co.uk> Cc: intel-gfx@lists.freedesktop.org, joonas.lahtinen@linux.intel.com 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" X-Virus-Scanned: ClamAV using ClamSMTP For testing, we want a reproducible PRNG, a plain linear congruent generator is suitable for our very limited selftests. Signed-off-by: Chris Wilson --- drivers/gpu/drm/Kconfig | 5 +++++ drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/lib/drm_rand.c | 51 ++++++++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/lib/drm_rand.h | 9 ++++++++ 4 files changed, 66 insertions(+) create mode 100644 drivers/gpu/drm/lib/drm_rand.c create mode 100644 drivers/gpu/drm/lib/drm_rand.h diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index fd341ab69c46..04d1d0a32c5c 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -48,10 +48,15 @@ config DRM_DEBUG_MM If in doubt, say "N". +config DRM_LIB_RAND + bool + default n + config DRM_DEBUG_MM_SELFTEST tristate "kselftests for DRM range manager (struct drm_mm)" depends on DRM depends on DEBUG_KERNEL + select DRM_LIB_RAND default n help This option provides a kernel module that can be used to test diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index c8aed3688b20..363eb1a23151 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -18,6 +18,7 @@ drm-y := drm_auth.o drm_bufs.o drm_cache.o \ drm_plane.o drm_color_mgmt.o drm_print.o \ drm_dumb_buffers.o drm_mode_config.o +drm-$(CONFIG_DRM_LIB_RAND) += lib/drm_rand.o obj-$(CONFIG_DRM_DEBUG_MM_SELFTEST) += selftests/test-drm_mm.o drm-$(CONFIG_COMPAT) += drm_ioc32.o diff --git a/drivers/gpu/drm/lib/drm_rand.c b/drivers/gpu/drm/lib/drm_rand.c new file mode 100644 index 000000000000..f203c47bb525 --- /dev/null +++ b/drivers/gpu/drm/lib/drm_rand.c @@ -0,0 +1,51 @@ +#include +#include +#include + +#include "drm_rand.h" + +u32 drm_lcg_random(u32 *state) +{ + u32 s = *state; + +#define rol(x, k) (((x) << (k)) | ((x) >> (32 - (k)))) + s = (s ^ rol(s, 5) ^ rol(s, 24)) + 0x37798849; +#undef rol + + *state = s; + return s; +} +EXPORT_SYMBOL(drm_lcg_random); + +int *drm_random_reorder(int *order, int count, u32 *state) +{ + int n; + + for (n = count-1; n > 1; n--) { + int r = drm_lcg_random(state) % (n + 1); + if (r != n) { + int tmp = order[n]; + order[n] = order[r]; + order[r] = tmp; + } + } + + return order; +} +EXPORT_SYMBOL(drm_random_reorder); + +int *drm_random_order(int count, u32 *state) +{ + int *order; + int n; + + order = kmalloc_array(count, sizeof(*order), GFP_TEMPORARY); + if (!order) + return order; + + for (n = 0; n < count; n++) + order[n] = n; + + return drm_random_reorder(order, count, state); +} +EXPORT_SYMBOL(drm_random_order); diff --git a/drivers/gpu/drm/lib/drm_rand.h b/drivers/gpu/drm/lib/drm_rand.h new file mode 100644 index 000000000000..a3f22d115aac --- /dev/null +++ b/drivers/gpu/drm/lib/drm_rand.h @@ -0,0 +1,9 @@ +#ifndef __DRM_RAND_H__ +#define __DRM_RAND_H + +u32 drm_lcg_random(u32 *state); + +int *drm_random_reorder(int *order, int count, u32 *state); +int *drm_random_order(int count, u32 *state); + +#endif /* __DRM_RAND_H__ */