Re: [Intel-gfx] [PATCH 2/2] intel_frequency: A tool to manipulate Intel GPU frequency

2015-01-11 Thread Jordan Justen
On 2015-01-10 20:19:29, Ben Widawsky wrote:
> +   printf("Usage: %s [-ef] [--min | --max] [-g (min|max|efficient)][-s 
> frequency_mhz]\n\n", prog);

-ef => -f

Add space before [-s

> +   printf("%s A program to manipulate Intel GPU frequencies.\n\n", prog);
> +   printf("Options: \n");
> +   printf("  -eLock frequency to the most efficient 
> frequency\n");
> +   printf("  -g, --get=Get the frequency (optional arg: 
> \"cur\"|\"min\"|\"max\"|\"eff\")\n");
> +   printf("  -s, --set Lock frequency to an absolute value (MHz)\n");
> +   printf("  -c, --custom  Set a min, or max frequency \"min=X | 
> max=Y\"\n");
> +   printf("  -m  --max Lock frequency to max frequency\n");
> +   printf("  --min Lock frequency to min (never a good idea, 
> DEBUG ONLY)\n");
> +   printf("Examples:\n");
> +   printf("intel_frequency -gmin,cur Get the current and minimum 
> frequency\n");
> +   printf("intel_frequency -s 400Lock frequency to 400Mhz\n");

Add -c example?

Series Reviewed-by: Jordan Justen 
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH 2/2] intel_frequency: A tool to manipulate Intel GPU frequency

2015-01-10 Thread Ben Widawsky
Ken gave me the good idea of -d, --defaults to go back to the hardware specified
defaults. I will send out a v2 if nobody else has any complaints.

On Sat, Jan 10, 2015 at 08:19:29PM -0800, Ben Widawsky wrote:
> WARNING: very minimally tested
> 
> In general you should not need this tool. It's primary purpose is for
> benchmarking, and for debugging performance issues.
> 
> For many kernel releases now sysfs has supported reading and writing the GPU
> frequency. Therefore, this tool provides no new functionality. What it does
> provide is an easy to package (for distros) tool that handles the most common
> scenarios.
> 
> Signed-off-by: Ben Widawsky 
> 
> Here are some sample usages:
> 
> $ sudo intel_frequency --get=cur,min,max,eff
> cur: 200 MHz
> min: 200 MHz
> RP1: 200 MHz
> max: 1200 MHz
> 
> $ sudo intel_frequency -g
> cur: 200 MHz
> min: 200 MHz
> RP1: 200 MHz
> max: 1200 MHz
> 
> $ sudo intel_frequency -geff
> RP1: 200 MHz
> 
> $ sudo intel_frequency --set min=300
> $ sudo intel_frequency --get min
> cur: 300 MHz
> min: 300 MHz
> RP1: 200 MHz
> max: 1200 MHz
> 
> $ sudo intel_frequency --custom max=900
> $ sudo intel_frequency --get max
> cur: 300 MHz
> min: 300 MHz
> RP1: 200 MHz
> max: 900 MHz
> 
> $ sudo ./tools/intel_frequency --max
> $ sudo ./tools/intel_frequency -g
> cur: 1200 MHz
> min: 1200 MHz
> RP1: 200 MHz
> max: 1200 MHz
> 
> $ sudo intel_frequency -e
> $ sudo intel_frequency -g
> cur: 200 MHz
> min: 200 MHz
> RP1: 200 MHz
> max: 200 MHz
> 
> $ sudo intel_frequency --max
> $ sudo intel_frequency -g
> cur: 1200 MHz
> min: 1200 MHz
> RP1: 200 MHz
> max: 1200 MHz
> 
> $ sudo intel_frequency --min
> $ sudo intel_frequency -g
> cur: 200 MHz
> min: 200 MHz
> RP1: 200 MHz
> max: 200 MHz
> ---
>  tools/Makefile.sources  |   1 +
>  tools/intel_frequency.c | 325 
> 
>  2 files changed, 326 insertions(+)
>  create mode 100644 tools/intel_frequency.c
> 
> diff --git a/tools/Makefile.sources b/tools/Makefile.sources
> index b85a6b8..2bea389 100644
> --- a/tools/Makefile.sources
> +++ b/tools/Makefile.sources
> @@ -14,6 +14,7 @@ bin_PROGRAMS =  \
>   intel_dump_decode   \
>   intel_error_decode  \
>   intel_forcewaked\
> + intel_frequency \
>   intel_framebuffer_dump  \
>   intel_gpu_time  \
>   intel_gpu_top   \
> diff --git a/tools/intel_frequency.c b/tools/intel_frequency.c
> new file mode 100644
> index 000..87b1741
> --- /dev/null
> +++ b/tools/intel_frequency.c
> @@ -0,0 +1,325 @@
> +/*
> + * Copyright © 2015 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.
> + *
> + */
> +
> +#define _GNU_SOURCE
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "drmtest.h"
> +#include "intel_chipset.h"
> +
> +static int device, devid;
> +
> +enum {
> + CUR=0,
> + MIN,
> + EFF,
> + MAX,
> + RP0,
> + RPn
> +};
> +
> +struct freq_info {
> + const char *name;
> + const char *mode;
> + FILE *filp;
> + char *path;
> +};
> +
> +static struct freq_info info[] = {
> + { "cur", "r"  },
> + { "min", "rb+" },
> + { "RP1", "r" },
> + { "max", "rb+" },
> + { "RP0", "r" },
> + { "RPn", "r" }
> +};
> +
> +static char *
> +get_sysfs_path(const char *which)
> +{
> + static const char fmt[] = "/sys/class/drm/card%1d/gt_%3s_freq_mhz";
> + char *path;
> + int ret;
> +
> +#define STATIC_STRLEN(string) (sizeof(string) / sizeof(string [0]))
> + ret = asprintf(&path, fmt, device, which);
> + assert(ret == (STATIC_STRLEN(fmt) - 3));
> +#undef STATIC_STRLEN
> +
> + return path;
> +}
> +
> +static void
> +initialize_freq_info(struct freq_info *freq_info)
> +{
> + if (freq_info->filp)
> + re

[Intel-gfx] [PATCH 2/2] intel_frequency: A tool to manipulate Intel GPU frequency

2015-01-10 Thread Ben Widawsky
WARNING: very minimally tested

In general you should not need this tool. It's primary purpose is for
benchmarking, and for debugging performance issues.

For many kernel releases now sysfs has supported reading and writing the GPU
frequency. Therefore, this tool provides no new functionality. What it does
provide is an easy to package (for distros) tool that handles the most common
scenarios.

Signed-off-by: Ben Widawsky 

Here are some sample usages:

$ sudo intel_frequency --get=cur,min,max,eff
cur: 200 MHz
min: 200 MHz
RP1: 200 MHz
max: 1200 MHz

$ sudo intel_frequency -g
cur: 200 MHz
min: 200 MHz
RP1: 200 MHz
max: 1200 MHz

$ sudo intel_frequency -geff
RP1: 200 MHz

$ sudo intel_frequency --set min=300
$ sudo intel_frequency --get min
cur: 300 MHz
min: 300 MHz
RP1: 200 MHz
max: 1200 MHz

$ sudo intel_frequency --custom max=900
$ sudo intel_frequency --get max
cur: 300 MHz
min: 300 MHz
RP1: 200 MHz
max: 900 MHz

$ sudo ./tools/intel_frequency --max
$ sudo ./tools/intel_frequency -g
cur: 1200 MHz
min: 1200 MHz
RP1: 200 MHz
max: 1200 MHz

$ sudo intel_frequency -e
$ sudo intel_frequency -g
cur: 200 MHz
min: 200 MHz
RP1: 200 MHz
max: 200 MHz

$ sudo intel_frequency --max
$ sudo intel_frequency -g
cur: 1200 MHz
min: 1200 MHz
RP1: 200 MHz
max: 1200 MHz

$ sudo intel_frequency --min
$ sudo intel_frequency -g
cur: 200 MHz
min: 200 MHz
RP1: 200 MHz
max: 200 MHz
---
 tools/Makefile.sources  |   1 +
 tools/intel_frequency.c | 325 
 2 files changed, 326 insertions(+)
 create mode 100644 tools/intel_frequency.c

diff --git a/tools/Makefile.sources b/tools/Makefile.sources
index b85a6b8..2bea389 100644
--- a/tools/Makefile.sources
+++ b/tools/Makefile.sources
@@ -14,6 +14,7 @@ bin_PROGRAMS =\
intel_dump_decode   \
intel_error_decode  \
intel_forcewaked\
+   intel_frequency \
intel_framebuffer_dump  \
intel_gpu_time  \
intel_gpu_top   \
diff --git a/tools/intel_frequency.c b/tools/intel_frequency.c
new file mode 100644
index 000..87b1741
--- /dev/null
+++ b/tools/intel_frequency.c
@@ -0,0 +1,325 @@
+/*
+ * Copyright © 2015 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.
+ *
+ */
+
+#define _GNU_SOURCE
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "drmtest.h"
+#include "intel_chipset.h"
+
+static int device, devid;
+
+enum {
+   CUR=0,
+   MIN,
+   EFF,
+   MAX,
+   RP0,
+   RPn
+};
+
+struct freq_info {
+   const char *name;
+   const char *mode;
+   FILE *filp;
+   char *path;
+};
+
+static struct freq_info info[] = {
+   { "cur", "r"  },
+   { "min", "rb+" },
+   { "RP1", "r" },
+   { "max", "rb+" },
+   { "RP0", "r" },
+   { "RPn", "r" }
+};
+
+static char *
+get_sysfs_path(const char *which)
+{
+   static const char fmt[] = "/sys/class/drm/card%1d/gt_%3s_freq_mhz";
+   char *path;
+   int ret;
+
+#define STATIC_STRLEN(string) (sizeof(string) / sizeof(string [0]))
+   ret = asprintf(&path, fmt, device, which);
+   assert(ret == (STATIC_STRLEN(fmt) - 3));
+#undef STATIC_STRLEN
+
+   return path;
+}
+
+static void
+initialize_freq_info(struct freq_info *freq_info)
+{
+   if (freq_info->filp)
+   return;
+
+   freq_info->path = get_sysfs_path(freq_info->name);
+   assert(freq_info->path);
+   freq_info->filp = fopen(freq_info->path, freq_info->mode);
+   assert(freq_info->filp);
+}
+
+static void wait_freq_settle(void)
+{
+   struct timespec ts;
+
+   /* FIXME: Lazy sleep without check. */
+   ts.tv_sec = 0;
+   ts.tv_nsec = 2;
+   clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);
+}
+
+static void set_frequency(struct freq_info *freq_info, int val)
+