[Intel-gfx] [PATCH 06/46] drm/i915: Add some selftests for sg_table manipulation

Tvrtko Ursulin tvrtko.ursulin at linux.intel.com
Fri Feb 10 12:01:17 UTC 2017


On 10/02/2017 10:43, Chris Wilson wrote:
> On Fri, Feb 10, 2017 at 10:24:41AM +0000, Tvrtko Ursulin wrote:
>>> +static int igt_sg_alloc(void *ignored)
>>> +{
>>> +	IGT_TIMEOUT(end_time);
>>> +	const unsigned long max_order = 20; /* approximating a 4GiB object */
>>> +	struct rnd_state prng;
>>> +	unsigned long prime;
>>> +
>>> +	for_each_prime_number(prime, max_order) {
>>> +		unsigned long size = BIT(prime);
>>> +		int offset;
>>> +
>>> +		for (offset = -1; offset <= 1; offset++) {
>>> +			unsigned long sz = size + offset;
>>> +			const npages_fn_t *npages;
>>> +			struct pfn_table pt;
>>> +			int err;
>>> +
>>> +			for (npages = npages_funcs; *npages; npages++) {
>>> +				prandom_seed_state(&prng,
>>> +						   i915_selftest.random_seed);
>>> +				if (!alloc_table(&pt, sz, sz, *npages, &prng))
>>> +					return 0; /* out of memory, give up */
>>
>> We need to define at least some amount of testing which must pass
>> otherwise it is just too weak in my opinion.
>>
>> 	return prime < TBD ? -Esomething : 0;
>>
>> ?
>
> Following our last discussion, it does a minimum of one prime [2].
>
> static int igt_sg_alloc(void *ignored)
> {
>         IGT_TIMEOUT(end_time);
>         const unsigned long max_order = 20; /* approximating a 4GiB object */
>         struct rnd_state prng;
>         unsigned long prime;
>         int alloc_error = -ENOMEM;
>
>         for_each_prime_number(prime, max_order) {
>                 unsigned long size = BIT(prime);
>                 int offset;
>
>                 for (offset = -1; offset <= 1; offset++) {
>                         unsigned long sz = size + offset;
>                         const npages_fn_t *npages;
>                         struct pfn_table pt;
>                         int err;
>
>                         for (npages = npages_funcs; *npages; npages++) {
>                                 prandom_seed_state(&prng,
>                                                    i915_selftest.random_seed);
>                                 if (!alloc_table(&pt, sz, sz, *npages, &prng))
>                                         return alloc_error;
>
>                                 prandom_seed_state(&prng,
>                                                    i915_selftest.random_seed);
>                                 err = expect_pfn_sgtable(&pt, *npages, &prng,
>                                                          "sg_alloc_table",
>                                                          end_time);
>                                 sg_free_table(&pt.st);
>                                 if (err)
>                                         return err;
>                         }
>                 }
>
>                 alloc_error = 0;
>         }
>
>         return 0;
> }
>
> Something like
>
> /* Make sure we test at least one continuation before accepting oom */
> if (size > MAX_SG_PER_PAGE) /* can't remember what the define is! */
> 	alloc_error = 0;
>
> ?

SG_MAX_SINGLE_ALLOC. Sounds good. r-b on that.

Regards,

Tvrtko



More information about the Intel-gfx mailing list