From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniel Vetter Subject: Re: [PATCH] sysfs rps test added Date: Fri, 14 Sep 2012 20:32:36 +0200 Message-ID: <20120914183236.GG5799@phenom.ffwll.local> References: <1347072225-10654-1-git-send-email-ben@bwidawsk.net> <1347072225-10654-9-git-send-email-ben@bwidawsk.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail-wg0-f43.google.com (mail-wg0-f43.google.com [74.125.82.43]) by gabe.freedesktop.org (Postfix) with ESMTP id 5C7B3A111A for ; Fri, 14 Sep 2012 11:32:01 -0700 (PDT) Received: by wgbdq11 with SMTP id dq11so774129wgb.12 for ; Fri, 14 Sep 2012 11:32:00 -0700 (PDT) Content-Disposition: inline In-Reply-To: <1347072225-10654-9-git-send-email-ben@bwidawsk.net> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org To: Ben Widawsky Cc: intel-gfx@lists.freedesktop.org List-Id: intel-gfx@lists.freedesktop.org On Fri, Sep 07, 2012 at 07:43:45PM -0700, Ben Widawsky wrote: > Signed-off-by: Ben Widawsky > --- One small improvement would be nice: [snip] > +static void writeval(FILE *filp, int val) > +{ > + rewind(filp); > + fprintf(filp, "%d", val); > + fflush(filp); > +} Adding some assert here to check whether a write we expect to succeed indeed worked, and that a write we expect to return -EINVAL indeed fails with that error. -Daniel > + > +#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); > +} > -- > 1.7.12 > > _______________________________________________ > Intel-gfx mailing list > Intel-gfx@lists.freedesktop.org > http://lists.freedesktop.org/mailman/listinfo/intel-gfx -- Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch