From: Daniel Vetter <daniel@ffwll.ch>
To: Ben Widawsky <ben@bwidawsk.net>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH] sysfs rps test added
Date: Fri, 14 Sep 2012 20:32:36 +0200 [thread overview]
Message-ID: <20120914183236.GG5799@phenom.ffwll.local> (raw)
In-Reply-To: <1347072225-10654-9-git-send-email-ben@bwidawsk.net>
On Fri, Sep 07, 2012 at 07:43:45PM -0700, Ben Widawsky wrote:
> Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
> ---
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
prev parent reply other threads:[~2012-09-14 18:32 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-08 2:43 [PATCH 0/8 v2] Moar sysfs stuff Ben Widawsky
2012-09-08 2:43 ` [REPOST PATCH 1/7] drm/i915: variable renames Ben Widawsky
2012-09-08 2:43 ` [REPOST PATCH 2/7] drm/i915: #define gpu freq multipler Ben Widawsky
2012-09-08 2:43 ` [REPOST PATCH 3/7 v2] drm/i915: Add current/max/min GPU freq to sysfs Ben Widawsky
2012-09-08 2:43 ` [PATCH 4/7] drm/i915: POSTING_READ the new rps value Ben Widawsky
2012-09-09 18:26 ` Chris Wilson
2012-09-08 2:43 ` [PATCH 5/7] drm/i915: Error checks in gen6_set_rps Ben Widawsky
2012-09-09 18:25 ` Chris Wilson
2012-09-12 21:37 ` Daniel Vetter
2012-09-08 2:43 ` [PATCH 6/7 v3] drm/i915: Add setters for min/max frequency Ben Widawsky
2012-09-12 14:46 ` Daniel Vetter
2012-09-13 1:12 ` [PATCH 6/7 v4] " Ben Widawsky
2012-09-08 2:43 ` [REPOST PATCH 7/7] drm/i915: Show render P state thresholds in sysfs Ben Widawsky
2012-09-14 16:51 ` Daniel Vetter
2012-09-08 2:43 ` [PATCH] sysfs rps test added Ben Widawsky
2012-09-14 18:32 ` Daniel Vetter [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120914183236.GG5799@phenom.ffwll.local \
--to=daniel@ffwll.ch \
--cc=ben@bwidawsk.net \
--cc=intel-gfx@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox