[igt-dev] [PATCH igt] tests: Add a random load generator

Antonio Argenziano antonio.argenziano at intel.com
Tue Jan 23 19:03:48 UTC 2018



On 21/01/18 12:20, Chris Wilson wrote:
> Apply a random load to one or all engines in order to apply stress to
> RPS as it tries to constantly adjust the GPU frequency to meet the
> changing workload.
> 
> Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
> ---
>   tests/Makefile.sources |   1 +
>   tests/gem_exec_load.c  | 124 +++++++++++++++++++++++++++++++++++++++++++++++++
>   2 files changed, 125 insertions(+)
>   create mode 100644 tests/gem_exec_load.c
> 
> diff --git a/tests/Makefile.sources b/tests/Makefile.sources
> index 6d3857949..5c6242bca 100644
> --- a/tests/Makefile.sources
> +++ b/tests/Makefile.sources
> @@ -83,6 +83,7 @@ TESTS_progs = \
>   	gem_exec_gttfill \
>   	gem_exec_latency \
>   	gem_exec_lut_handle \
> +	gem_exec_load \
>   	gem_exec_nop \
>   	gem_exec_parallel \
>   	gem_exec_params \
> diff --git a/tests/gem_exec_load.c b/tests/gem_exec_load.c
> new file mode 100644
> index 000000000..d3618f6c0
> --- /dev/null
> +++ b/tests/gem_exec_load.c
> @@ -0,0 +1,124 @@
> +/*
> + * Copyright © 2018 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.
> + */
> +
> +#include "igt.h"
> +#include "igt_rand.h"
> +#include "igt_sysfs.h"
> +
> +IGT_TEST_DESCRIPTION("Apply a random load to each engine");
> +
> +static inline uint32_t randmax(uint32_t *state, uint32_t ep_ro)
> +{
> +	return (uint64_t)hars_petruska_f54_1_random(state) * ep_ro >> 32;
> +}
> +
> +static void one(int fd, unsigned int engine, int scale, unsigned int timeout)
> +{
> +	struct timespec tv = {};
> +	uint32_t prng = engine;
> +	igt_spin_t *spin[2] = {};
> +	unsigned int max;
> +	int sysfs;
> +
> +	sysfs = igt_sysfs_open(fd, NULL);
> +
> +	max = sysfs < 0 ? 1 : igt_sysfs_get_u32(sysfs, "gt_max_freq_mhz");
> +
> +	do {
> +		/*
> +		 * For every second, we randomly assign a desire % busyness
> +		 * and the frequency with which to submit a batch, defining
> +		 * a pulse-width modulation (pwm).
> +		 */
> +		unsigned int pwm = randmax(&prng, 1000);
> +		unsigned int load = randmax(&prng, pwm / scale);
> +		const unsigned int interval = 1e6 / pwm;
> +		unsigned int cur =
> +			sysfs < 0 ? 1 : igt_sysfs_get_u32(sysfs, "gt_cur_freq_mhz");
> +
> +		while (pwm--) {
> +			if (randmax(&prng, pwm * cur) <= load * max) {
> +				spin[1] = __igt_spin_batch_new(fd, 0, engine, 0);
> +				load--;
> +			}
> +			igt_spin_batch_free(fd, spin[0]);
> +			spin[0] = spin[1];
> +			spin[1] = NULL;
> +
> +			usleep(interval);
> +		}
> +	} while (igt_seconds_elapsed(&tv) < timeout);

Why not igt_until_timeout()?

-Antonio


More information about the igt-dev mailing list