From patchwork Sat Sep 8 02:43:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ben Widawsky X-Patchwork-Id: 1426231 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork2.kernel.org (Postfix) with ESMTP id 69997DF283 for ; Sat, 8 Sep 2012 02:54:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4C974A0DFA for ; Fri, 7 Sep 2012 19:54:15 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from shiva.chad-versace.us (209-20-75-48.static.cloud-ips.com [209.20.75.48]) by gabe.freedesktop.org (Postfix) with ESMTP id 2B78EA0DBC for ; Fri, 7 Sep 2012 19:44:49 -0700 (PDT) Received: by shiva.chad-versace.us (Postfix, from userid 1005) id D66B0885B7; Sat, 8 Sep 2012 02:45:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on shiva.chad-versace.us X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=unavailable version=3.3.2 Received: from stallone.nims.intel.com (unknown [192.102.209.254]) by shiva.chad-versace.us (Postfix) with ESMTPSA id F0B47885D5; Sat, 8 Sep 2012 02:44:31 +0000 (UTC) From: Ben Widawsky To: intel-gfx@lists.freedesktop.org Date: Fri, 7 Sep 2012 19:43:45 -0700 Message-Id: <1347072225-10654-9-git-send-email-ben@bwidawsk.net> X-Mailer: git-send-email 1.7.12 In-Reply-To: <1347072225-10654-1-git-send-email-ben@bwidawsk.net> References: <1347072225-10654-1-git-send-email-ben@bwidawsk.net> MIME-Version: 1.0 Cc: Ben Widawsky Subject: [Intel-gfx] =?utf-8?q?=5BPATCH=5D_sysfs_rps_test_added?= X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Signed-off-by: Ben Widawsky --- tests/Makefile.am | 1 + tests/sysfs_rps.c | 179 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 tests/sysfs_rps.c diff --git a/tests/Makefile.am b/tests/Makefile.am index d4c7c46..d88a83a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -71,6 +71,7 @@ TESTS_progs = \ drm_vma_limiter_gtt \ drm_vma_limiter_cached \ sysfs_rc6_residency \ + sysfs_rps \ flip_test \ gem_wait_render_timeout \ gem_ctx_create \ diff --git a/tests/sysfs_rps.c b/tests/sysfs_rps.c new file mode 100644 index 0000000..b830797 --- /dev/null +++ b/tests/sysfs_rps.c @@ -0,0 +1,179 @@ +/* + * Copyright © 2012 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Authors: + * Ben Widawsky + * + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include "drmtest.h" + +static bool verbose = false; +static int origmin, origmax; + +#define restore_assert(COND) do { \ + if (!(COND)) { \ + writeval(stuff[MIN].filp, origmin); \ + writeval(stuff[MAX].filp, origmax); \ + assert(0); \ + } \ +} while (0); + +static const char sysfs_base_path[] = "/sys/class/drm/card%d/gt_%s_freq_mhz"; +enum { + CUR, + MIN, + MAX, + RP0, + RP1, + RPn +}; + +struct junk { + const char *name; + const char *mode; + FILE *filp; +} stuff[] = { + { "cur", "r", NULL }, { "min", "rb+", NULL }, { "max", "rb+", NULL }, { "RP0", "r", NULL }, { "RP1", "r", NULL }, { "RPn", "r", NULL }, { NULL, NULL, NULL } +}; + +static int readval(FILE *filp) +{ + int val; + fflush(filp); + rewind(filp); + fscanf(filp, "%d", &val); + return val; +} + +static void writeval(FILE *filp, int val) +{ + rewind(filp); + fprintf(filp, "%d", val); + fflush(filp); +} + +#define fcur (readval(stuff[CUR].filp)) +#define fmin (readval(stuff[MIN].filp)) +#define fmax (readval(stuff[MAX].filp)) +#define frp0 (readval(stuff[RP0].filp)) +#define frp1 (readval(stuff[RP1].filp)) +#define frpn (readval(stuff[RPn].filp)) + +static void setfreq(int val) +{ + writeval(stuff[MIN].filp, val); + writeval(stuff[MAX].filp, val); +} + +static void checkit(void) +{ + restore_assert(fmin <= fmax); + restore_assert(fcur <= fmax); + restore_assert(fmin <= fcur); + restore_assert(frpn <= fmin); + restore_assert(fmax <= frp0); + restore_assert(frp1 <= frp0); + restore_assert(frpn <= frp1); + restore_assert(frp0 != 0); + restore_assert(frp1 != 0); +} + +static void dumpit(void) +{ + struct junk *junk = stuff; + do { + printf("gt frequency %s (MHz): %d\n", junk->name, readval(junk->filp)); + junk++; + } while(junk->name != NULL); + + printf("\n"); +} + + +int main(int argc, char *argv[]) +{ + const int device = drm_get_card(0); + struct junk *junk = stuff; + int fd, ret; + + if (argc > 1) + verbose++; + + /* Use drm_open_any to verify device existence */ + fd = drm_open_any(); + close(fd); + + do { + int val = -1; + char *path; + ret = asprintf(&path, sysfs_base_path, device, junk->name); + assert(ret != -1); + junk->filp = fopen(path, junk->mode); + if (junk->filp == NULL) { + fprintf(stderr, "Kernel is too old. GTFO\n"); + exit(77); + } + val = readval(junk->filp); + assert(val >= 0); + junk++; + } while(junk->name != NULL); + + origmin = fmin; + origmax = fmax; + + if (verbose) + printf("Original min = %d\nOriginal max = %d\n", origmin, origmax); + + if (verbose) + dumpit(); + + checkit(); + setfreq(fmin); + if (verbose) + dumpit(); + restore_assert(fcur == fmin); + setfreq(fmax); + if (verbose) + dumpit(); + restore_assert(fcur == fmax); + checkit(); + + /* And some errors */ + writeval(stuff[MIN].filp, frpn - 1); + writeval(stuff[MAX].filp, frp0 + 1000); + checkit(); + + writeval(stuff[MIN].filp, fmax + 1000); + writeval(stuff[MAX].filp, fmin - 1); + checkit(); + + writeval(stuff[MIN].filp, origmin); + writeval(stuff[MAX].filp, origmax); + + exit(EXIT_SUCCESS); +}