public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Matthew Auld <matthew.auld@intel.com>
To: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>,
	igt-dev@lists.freedesktop.org
Cc: tvrtko.ursulin@intel.com, thomas.hellstrom@intel.com,
	daniel.vetter@intel.com, petri.latvala@intel.com
Subject: Re: [igt-dev] [PATCH i-g-t v9 15/19] tests/i915/vm_bind: Add i915_capture library routines
Date: Tue, 13 Dec 2022 13:14:50 +0000	[thread overview]
Message-ID: <4bf51ced-dd46-6e95-695d-384eff1375be@intel.com> (raw)
In-Reply-To: <20221212231254.2303-16-niranjana.vishwanathapura@intel.com>

On 12/12/2022 23:12, Niranjana Vishwanathapura wrote:
> In preparation of i915_vm_bind_capture test, move some common
> capture decode routines to library for code sharing.
> 
> Signed-off-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
> ---
>   lib/i915/i915_capture.c       | 96 +++++++++++++++++++++++++++++++++++
>   lib/i915/i915_capture.h       | 14 +++++
>   lib/meson.build               |  1 +
>   tests/i915/gem_exec_capture.c | 88 +-------------------------------
>   4 files changed, 112 insertions(+), 87 deletions(-)
>   create mode 100644 lib/i915/i915_capture.c
>   create mode 100644 lib/i915/i915_capture.h
> 
> diff --git a/lib/i915/i915_capture.c b/lib/i915/i915_capture.c
> new file mode 100644
> index 000000000..7430c9256
> --- /dev/null
> +++ b/lib/i915/i915_capture.c
> @@ -0,0 +1,96 @@
> +// SPDX-License-Identifier: MIT
> +/*
> + * Copyright © 2022 Intel Corporation
> + */
> +
> +#include <stdlib.h>
> +#include <string.h>
> +#include <zlib.h>
> +
> +#include "i915_capture.h"
> +
> +static unsigned long zlib_inflate(uint32_t **ptr, unsigned long len)
> +{
> +	struct z_stream_s zstream;
> +	void *out;
> +
> +	memset(&zstream, 0, sizeof(zstream));
> +
> +	zstream.next_in = (unsigned char *)*ptr;
> +	zstream.avail_in = 4*len;
> +
> +	if (inflateInit(&zstream) != Z_OK)
> +		return 0;
> +
> +	out = malloc(128*4096); /* approximate obj size */
> +	zstream.next_out = out;
> +	zstream.avail_out = 128*4096;
> +
> +	do {
> +		switch (inflate(&zstream, Z_SYNC_FLUSH)) {
> +		case Z_STREAM_END:
> +			goto end;
> +		case Z_OK:
> +			break;
> +		default:
> +			inflateEnd(&zstream);
> +			return 0;
> +		}
> +
> +		if (zstream.avail_out)
> +			break;
> +
> +		out = realloc(out, 2*zstream.total_out);
> +		if (out == NULL) {
> +			inflateEnd(&zstream);
> +			return 0;
> +		}
> +
> +		zstream.next_out = (unsigned char *)out + zstream.total_out;
> +		zstream.avail_out = zstream.total_out;
> +	} while (1);
> +end:
> +	inflateEnd(&zstream);
> +	free(*ptr);
> +	*ptr = out;
> +	return zstream.total_out / 4;
> +}
> +
> +unsigned long
> +ascii85_decode(char *in, uint32_t **out, bool inflate, char **end)

Needs some doc. There are some examples in lib.

Otherwise,
Reviewed-by: Matthew Auld <matthew.auld@intel.com>

> +{
> +	unsigned long len = 0, size = 1024;
> +
> +	*out = realloc(*out, sizeof(uint32_t)*size);
> +	if (*out == NULL)
> +		return 0;
> +
> +	while (*in >= '!' && *in <= 'z') {
> +		uint32_t v = 0;
> +
> +		if (len == size) {
> +			size *= 2;
> +			*out = realloc(*out, sizeof(uint32_t)*size);
> +			if (*out == NULL)
> +				return 0;
> +		}
> +
> +		if (*in == 'z') {
> +			in++;
> +		} else {
> +			v += in[0] - 33; v *= 85;
> +			v += in[1] - 33; v *= 85;
> +			v += in[2] - 33; v *= 85;
> +			v += in[3] - 33; v *= 85;
> +			v += in[4] - 33;
> +			in += 5;
> +		}
> +		(*out)[len++] = v;
> +	}
> +	*end = in;
> +
> +	if (!inflate)
> +		return len;
> +
> +	return zlib_inflate(out, len);
> +}
> diff --git a/lib/i915/i915_capture.h b/lib/i915/i915_capture.h
> new file mode 100644
> index 000000000..26481b8e4
> --- /dev/null
> +++ b/lib/i915/i915_capture.h
> @@ -0,0 +1,14 @@
> +/* SPDX-License-Identifier: MIT */
> +/*
> + * Copyright © 2022 Intel Corporation
> + */
> +#ifndef _I915_CAPTURE_H_
> +#define _I915_CAPTURE_H_
> +
> +#include <stdbool.h>
> +#include <stdint.h>
> +
> +unsigned long
> +ascii85_decode(char *in, uint32_t **out, bool inflate, char **end);
> +
> +#endif /* _I915_CAPTURE_ */
> diff --git a/lib/meson.build b/lib/meson.build
> index a01482c38..9d353da16 100644
> --- a/lib/meson.build
> +++ b/lib/meson.build
> @@ -14,6 +14,7 @@ lib_sources = [
>   	'i915/intel_memory_region.c',
>   	'i915/intel_mocs.c',
>   	'i915/i915_blt.c',
> +	'i915/i915_capture.c',
>   	'i915/i915_crc.c',
>   	'i915/i915_vm_bind.c',
>   	'igt_collection.c',
> diff --git a/tests/i915/gem_exec_capture.c b/tests/i915/gem_exec_capture.c
> index 2db58266f..f8f8d1ece 100644
> --- a/tests/i915/gem_exec_capture.c
> +++ b/tests/i915/gem_exec_capture.c
> @@ -22,10 +22,10 @@
>    */
>   
>   #include <sys/poll.h>
> -#include <zlib.h>
>   #include <sched.h>
>   
>   #include "i915/gem.h"
> +#include "i915/i915_capture.h"
>   #include "i915/gem_create.h"
>   #include "igt.h"
>   #include "igt_device.h"
> @@ -42,92 +42,6 @@ struct offset {
>   	bool found;
>   };
>   
> -static unsigned long zlib_inflate(uint32_t **ptr, unsigned long len)
> -{
> -	struct z_stream_s zstream;
> -	void *out;
> -
> -	memset(&zstream, 0, sizeof(zstream));
> -
> -	zstream.next_in = (unsigned char *)*ptr;
> -	zstream.avail_in = 4*len;
> -
> -	if (inflateInit(&zstream) != Z_OK)
> -		return 0;
> -
> -	out = malloc(128*4096); /* approximate obj size */
> -	zstream.next_out = out;
> -	zstream.avail_out = 128*4096;
> -
> -	do {
> -		switch (inflate(&zstream, Z_SYNC_FLUSH)) {
> -		case Z_STREAM_END:
> -			goto end;
> -		case Z_OK:
> -			break;
> -		default:
> -			inflateEnd(&zstream);
> -			return 0;
> -		}
> -
> -		if (zstream.avail_out)
> -			break;
> -
> -		out = realloc(out, 2*zstream.total_out);
> -		if (out == NULL) {
> -			inflateEnd(&zstream);
> -			return 0;
> -		}
> -
> -		zstream.next_out = (unsigned char *)out + zstream.total_out;
> -		zstream.avail_out = zstream.total_out;
> -	} while (1);
> -end:
> -	inflateEnd(&zstream);
> -	free(*ptr);
> -	*ptr = out;
> -	return zstream.total_out / 4;
> -}
> -
> -static unsigned long
> -ascii85_decode(char *in, uint32_t **out, bool inflate, char **end)
> -{
> -	unsigned long len = 0, size = 1024;
> -
> -	*out = realloc(*out, sizeof(uint32_t)*size);
> -	if (*out == NULL)
> -		return 0;
> -
> -	while (*in >= '!' && *in <= 'z') {
> -		uint32_t v = 0;
> -
> -		if (len == size) {
> -			size *= 2;
> -			*out = realloc(*out, sizeof(uint32_t)*size);
> -			if (*out == NULL)
> -				return 0;
> -		}
> -
> -		if (*in == 'z') {
> -			in++;
> -		} else {
> -			v += in[0] - 33; v *= 85;
> -			v += in[1] - 33; v *= 85;
> -			v += in[2] - 33; v *= 85;
> -			v += in[3] - 33; v *= 85;
> -			v += in[4] - 33;
> -			in += 5;
> -		}
> -		(*out)[len++] = v;
> -	}
> -	*end = in;
> -
> -	if (!inflate)
> -		return len;
> -
> -	return zlib_inflate(out, len);
> -}
> -
>   static int check_error_state(int dir, struct offset *obj_offsets, int obj_count,
>   			     uint64_t obj_size, bool incremental)
>   {

  reply	other threads:[~2022-12-13 13:15 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-12 23:12 [igt-dev] [PATCH i-g-t v9 00/19] vm_bind: Add VM_BIND validation support Niranjana Vishwanathapura
2022-12-12 23:12 ` [igt-dev] [PATCH i-g-t v9 01/19] lib/i915: memory region gtt_alignment support Niranjana Vishwanathapura
2022-12-12 23:12 ` [igt-dev] [PATCH i-g-t v9 02/19] lib/i915: Move common syncobj functions to library Niranjana Vishwanathapura
2023-01-13 10:02   ` Matthew Auld
2022-12-12 23:12 ` [igt-dev] [PATCH i-g-t v9 03/19] lib/vm_bind: import uapi definitions Niranjana Vishwanathapura
2022-12-12 23:12 ` [igt-dev] [PATCH i-g-t v9 04/19] lib/vm_bind: Add vm_bind/unbind and execbuf3 ioctls Niranjana Vishwanathapura
2022-12-12 23:12 ` [igt-dev] [PATCH i-g-t v9 05/19] lib/vm_bind: Add vm_bind mode support for VM Niranjana Vishwanathapura
2022-12-12 23:12 ` [igt-dev] [PATCH i-g-t v9 06/19] lib/vm_bind: Add vm_bind specific library functions Niranjana Vishwanathapura
2022-12-12 23:12 ` [igt-dev] [PATCH i-g-t v9 07/19] lib/vm_bind: Add __prime_handle_to_fd() Niranjana Vishwanathapura
2022-12-12 23:12 ` [igt-dev] [PATCH i-g-t v9 08/19] tests/i915/vm_bind: Add vm_bind sanity test Niranjana Vishwanathapura
2022-12-12 23:12 ` [igt-dev] [PATCH i-g-t v9 09/19] tests/i915/vm_bind: Add basic VM_BIND test support Niranjana Vishwanathapura
2022-12-12 23:12 ` [igt-dev] [PATCH i-g-t v9 10/19] tests/i915/vm_bind: Add userptr subtest Niranjana Vishwanathapura
2022-12-12 23:12 ` [igt-dev] [PATCH i-g-t v9 11/19] tests/i915/vm_bind: Add gem_exec3_basic test Niranjana Vishwanathapura
2022-12-12 23:12 ` [igt-dev] [PATCH i-g-t v9 12/19] tests/i915/vm_bind: Add gem_exec3_balancer test Niranjana Vishwanathapura
2022-12-12 23:12 ` [igt-dev] [PATCH i-g-t v9 13/19] tests/i915/vm_bind: Add gem_lmem_swapping@vm_bind sub test Niranjana Vishwanathapura
2022-12-12 23:12 ` [igt-dev] [PATCH i-g-t v9 14/19] tests/i915/vm_bind: Add gem_shrink@vm_bind* subtests Niranjana Vishwanathapura
2022-12-12 23:12 ` [igt-dev] [PATCH i-g-t v9 15/19] tests/i915/vm_bind: Add i915_capture library routines Niranjana Vishwanathapura
2022-12-13 13:14   ` Matthew Auld [this message]
2022-12-13 16:11     ` Niranjana Vishwanathapura
2023-01-13 10:06   ` Matthew Auld
2023-01-18  6:26     ` Niranjana Vishwanathapura
2023-01-18  7:12       ` Niranjana Vishwanathapura
2022-12-12 23:12 ` [igt-dev] [PATCH i-g-t v9 16/19] tests/i915/vm_bind: Test capture of persistent mappings Niranjana Vishwanathapura
2022-12-12 23:12 ` [igt-dev] [PATCH i-g-t v9 17/19] lib/vm_bind: Add execbuf3 support to igt_spin_factory Niranjana Vishwanathapura
2023-01-13 11:38   ` Matthew Auld
2023-01-18  6:34     ` Niranjana Vishwanathapura
2022-12-12 23:12 ` [igt-dev] [PATCH i-g-t v9 18/19] tests/i915/vm_bind: Use execbuf3 spinner Niranjana Vishwanathapura
2023-01-13 11:39   ` Matthew Auld
2022-12-12 23:12 ` [igt-dev] [PATCH i-g-t v9 19/19] tests/i915/vm_bind: Add userptr invalidation test Niranjana Vishwanathapura
2023-01-13 14:27   ` Matthew Auld
2023-01-18  6:34     ` Niranjana Vishwanathapura
2022-12-12 23:50 ` [igt-dev] ✓ Fi.CI.BAT: success for vm_bind: Add VM_BIND validation support (rev13) Patchwork
2022-12-13 17:48 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

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=4bf51ced-dd46-6e95-695d-384eff1375be@intel.com \
    --to=matthew.auld@intel.com \
    --cc=daniel.vetter@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=niranjana.vishwanathapura@intel.com \
    --cc=petri.latvala@intel.com \
    --cc=thomas.hellstrom@intel.com \
    --cc=tvrtko.ursulin@intel.com \
    /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