From patchwork Tue Jan 21 23:14:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jeff.mcgee@intel.com X-Patchwork-Id: 3520991 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1A1D6C02DC for ; Tue, 21 Jan 2014 23:07:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1834920122 for ; Tue, 21 Jan 2014 23:07:56 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 040F320117 for ; Tue, 21 Jan 2014 23:07:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BDAA5FAD23; Tue, 21 Jan 2014 15:07:53 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTP id 01400FAD17 for ; Tue, 21 Jan 2014 15:07:51 -0800 (PST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 21 Jan 2014 15:07:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.95,697,1384329600"; d="scan'208";a="462523460" Received: from jeffdesk.fso.intel.com ([10.5.53.1]) by fmsmga001.fm.intel.com with ESMTP; 21 Jan 2014 15:07:51 -0800 From: jeff.mcgee@intel.com To: intel-gfx@lists.freedesktop.org Date: Tue, 21 Jan 2014 17:14:32 -0600 Message-Id: <1390346074-15774-3-git-send-email-jeff.mcgee@intel.com> X-Mailer: git-send-email 1.8.5.2 In-Reply-To: <1390346074-15774-1-git-send-email-jeff.mcgee@intel.com> References: <1390346074-15774-1-git-send-email-jeff.mcgee@intel.com> Subject: [Intel-gfx] [PATCH 2/4] pm_rps: Remove repeat sysfs reads 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: , MIME-Version: 1.0 Sender: intel-gfx-bounces@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jeff McGee Storing values avoids some unnecessary overhead but more importantly allows all of our processing to be atomic. Signed-off-by: Jeff McGee --- tests/pm_rps.c | 98 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 51 insertions(+), 47 deletions(-) diff --git a/tests/pm_rps.c b/tests/pm_rps.c index e5cbfd1..37f7020 100644 --- a/tests/pm_rps.c +++ b/tests/pm_rps.c @@ -35,7 +35,6 @@ #include "drmtest.h" static bool verbose = false; -static int origmin, origmax; static const char sysfs_base_path[] = "/sys/class/drm/card%d/gt_%s_freq_mhz"; enum { @@ -44,9 +43,12 @@ enum { MAX, RP0, RP1, - RPn + RPn, + NUMFREQ }; +static int origfreqs[NUMFREQ]; + struct junk { const char *name; const char *mode; @@ -67,6 +69,14 @@ static int readval(FILE *filp) return val; } +static void read_freqs(int *freqs) +{ + int i; + + for (i = 0; i < NUMFREQ; i++) + freqs[i] = readval(stuff[i].filp); +} + static int do_writeval(FILE *filp, int val, int lerrno) { int ret, orig; @@ -90,16 +100,9 @@ static int do_writeval(FILE *filp, int val, int lerrno) #define writeval(filp, val) do_writeval(filp, val, 0) #define writeval_inval(filp, val) do_writeval(filp, val, EINVAL) -#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) { - if (val > fmax) { + if (val > readval(stuff[MAX].filp)) { writeval(stuff[MAX].filp, val); writeval(stuff[MIN].filp, val); } else { @@ -108,42 +111,41 @@ static void setfreq(int val) } } -static void checkit(void) +static void checkit(const int *freqs) { - igt_assert(fmin <= fmax); - igt_assert(fcur <= fmax); - igt_assert(fmin <= fcur); - igt_assert(frpn <= fmin); - igt_assert(fmax <= frp0); - igt_assert(frp1 <= frp0); - igt_assert(frpn <= frp1); - igt_assert(frp0 != 0); - igt_assert(frp1 != 0); + igt_assert(freqs[MIN] <= freqs[MAX]); + igt_assert(freqs[CUR] <= freqs[MAX]); + igt_assert(freqs[MIN] <= freqs[CUR]); + igt_assert(freqs[RPn] <= freqs[MIN]); + igt_assert(freqs[MAX] <= freqs[RP0]); + igt_assert(freqs[RP1] <= freqs[RP0]); + igt_assert(freqs[RPn] <= freqs[RP1]); + igt_assert(freqs[RP0] != 0); + igt_assert(freqs[RP1] != 0); } -static void dumpit(void) +static void dumpit(const int *freqs) { - struct junk *junk = stuff; - do { - printf("gt frequency %s (MHz): %d\n", junk->name, readval(junk->filp)); - junk++; - } while(junk->name != NULL); + int i; + + for (i = 0; i < NUMFREQ; i++) + printf("gt frequency %s (MHz): %d\n", stuff[i].name, freqs[i]); printf("\n"); } -#define dump() if (verbose) dumpit() +#define dump(x) if (verbose) dumpit(x) #define log(...) if (verbose) printf(__VA_ARGS__) static void min_max_config(void (*check)(void)) { - int fmid = (frpn + frp0) / 2; + int fmid = (origfreqs[RPn] + origfreqs[RP0]) / 2; log("Check original min and max...\n"); check(); log("Set min=RPn and max=RP0...\n"); - writeval(stuff[MIN].filp, frpn); - writeval(stuff[MAX].filp, frp0); + writeval(stuff[MIN].filp, origfreqs[RPn]); + writeval(stuff[MAX].filp, origfreqs[RP0]); check(); log("Increase min to midpoint...\n"); @@ -151,15 +153,15 @@ static void min_max_config(void (*check)(void)) check(); log("Increase min to RP0...\n"); - writeval(stuff[MIN].filp, frp0); + writeval(stuff[MIN].filp, origfreqs[RP0]); check(); log("Increase min above RP0 (invalid)...\n"); - writeval_inval(stuff[MIN].filp, frp0 + 1000); + writeval_inval(stuff[MIN].filp, origfreqs[RP0] + 1000); check(); log("Decrease max to RPn (invalid)...\n"); - writeval_inval(stuff[MAX].filp, frpn); + writeval_inval(stuff[MAX].filp, origfreqs[RPn]); check(); log("Decrease min to midpoint...\n"); @@ -167,7 +169,7 @@ static void min_max_config(void (*check)(void)) check(); log("Decrease min to RPn...\n"); - writeval(stuff[MIN].filp, frpn); + writeval(stuff[MIN].filp, origfreqs[RPn]); check(); log("Decrease min below RPn (invalid)...\n"); @@ -179,7 +181,7 @@ static void min_max_config(void (*check)(void)) check(); log("Decrease max to RPn...\n"); - writeval(stuff[MAX].filp, frpn); + writeval(stuff[MAX].filp, origfreqs[RPn]); check(); log("Decrease max below RPn (invalid)...\n"); @@ -187,7 +189,7 @@ static void min_max_config(void (*check)(void)) check(); log("Increase min to RP0 (invalid)...\n"); - writeval_inval(stuff[MIN].filp, frp0); + writeval_inval(stuff[MIN].filp, origfreqs[RP0]); check(); log("Increase max to midpoint...\n"); @@ -195,28 +197,31 @@ static void min_max_config(void (*check)(void)) check(); log("Increase max to RP0...\n"); - writeval(stuff[MAX].filp, frp0); + writeval(stuff[MAX].filp, origfreqs[RP0]); check(); log("Increase max above RP0 (invalid)...\n"); - writeval_inval(stuff[MAX].filp, frp0 + 1000); + writeval_inval(stuff[MAX].filp, origfreqs[RP0] + 1000); check(); } static void idle_check(void) { - dump(); - checkit(); + int freqs[NUMFREQ]; + + read_freqs(freqs); + dump(freqs); + checkit(freqs); } static void pm_rps_exit_handler(int sig) { - if (origmin > fmax) { - writeval(stuff[MAX].filp, origmax); - writeval(stuff[MIN].filp, origmin); + if (origfreqs[MIN] > readval(stuff[MAX].filp)) { + writeval(stuff[MAX].filp, origfreqs[MAX]); + writeval(stuff[MIN].filp, origfreqs[MIN]); } else { - writeval(stuff[MIN].filp, origmin); - writeval(stuff[MAX].filp, origmax); + writeval(stuff[MIN].filp, origfreqs[MIN]); + writeval(stuff[MAX].filp, origfreqs[MAX]); } } @@ -279,8 +284,7 @@ int main(int argc, char **argv) junk++; } while(junk->name != NULL); - origmin = fmin; - origmax = fmax; + read_freqs(origfreqs); igt_install_exit_handler(pm_rps_exit_handler); }