Discussion:
[PATCH 2/2] svga: add new num-failed-allocations HUD query
(too old to reply)
Brian Paul
2017-06-16 22:39:12 UTC
Permalink
Raw Message
This counter is incremented if we fail to allocate memory for
vertex/index/const buffers, textures, etc.
---
src/gallium/drivers/svga/svga_context.h | 1 +
src/gallium/drivers/svga/svga_pipe_query.c | 7 +++++++
src/gallium/drivers/svga/svga_resource.c | 17 +++++++++++++++--
src/gallium/drivers/svga/svga_screen.c | 2 ++
src/gallium/drivers/svga/svga_screen.h | 1 +
5 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/svga/svga_context.h b/src/gallium/drivers/svga/svga_context.h
index 2987c70..b1ccfc8 100644
--- a/src/gallium/drivers/svga/svga_context.h
+++ b/src/gallium/drivers/svga/svga_context.h
@@ -72,6 +72,7 @@ enum svga_hud {
SVGA_QUERY_NUM_STATE_OBJECTS,
SVGA_QUERY_NUM_SURFACE_VIEWS,
SVGA_QUERY_NUM_GENERATE_MIPMAP,
+ SVGA_QUERY_NUM_FAILED_ALLOCATIONS,

/*SVGA_QUERY_MAX has to be last because it is size of an array*/
SVGA_QUERY_MAX
diff --git a/src/gallium/drivers/svga/svga_pipe_query.c b/src/gallium/drivers/svga/svga_pipe_query.c
index 76360fd..6703b72 100644
--- a/src/gallium/drivers/svga/svga_pipe_query.c
+++ b/src/gallium/drivers/svga/svga_pipe_query.c
@@ -747,6 +747,7 @@ svga_create_query(struct pipe_context *pipe,
case SVGA_QUERY_NUM_BUFFER_UPLOADS:
case SVGA_QUERY_NUM_CONST_BUF_UPDATES:
case SVGA_QUERY_NUM_CONST_UPDATES:
+ case SVGA_QUERY_NUM_FAILED_ALLOCATIONS:
break;
case SVGA_QUERY_FLUSH_TIME:
case SVGA_QUERY_MAP_BUFFER_TIME:
@@ -826,6 +827,7 @@ svga_destroy_query(struct pipe_context *pipe, struct pipe_query *q)
case SVGA_QUERY_NUM_BUFFER_UPLOADS:
case SVGA_QUERY_NUM_CONST_BUF_UPDATES:
case SVGA_QUERY_NUM_CONST_UPDATES:
+ case SVGA_QUERY_NUM_FAILED_ALLOCATIONS:
/* nothing */
break;
default:
@@ -937,6 +939,7 @@ svga_begin_query(struct pipe_context *pipe, struct pipe_query *q)
case SVGA_QUERY_NUM_STATE_OBJECTS:
case SVGA_QUERY_NUM_SURFACE_VIEWS:
case SVGA_QUERY_NUM_GENERATE_MIPMAP:
+ case SVGA_QUERY_NUM_FAILED_ALLOCATIONS:
/* nothing */
break;
default:
@@ -1049,6 +1052,7 @@ svga_end_query(struct pipe_context *pipe, struct pipe_query *q)
case SVGA_QUERY_NUM_STATE_OBJECTS:
case SVGA_QUERY_NUM_SURFACE_VIEWS:
case SVGA_QUERY_NUM_GENERATE_MIPMAP:
+ case SVGA_QUERY_NUM_FAILED_ALLOCATIONS:
/* nothing */
break;
default:
@@ -1182,6 +1186,9 @@ svga_get_query_result(struct pipe_context *pipe,
case SVGA_QUERY_NUM_GENERATE_MIPMAP:
vresult->u64 = svga->hud.num_generate_mipmap;
break;
+ case SVGA_QUERY_NUM_FAILED_ALLOCATIONS:
+ vresult->u64 = svgascreen->hud.num_failed_allocations;
+ break;
default:
assert(!"unexpected query type in svga_get_query_result");
}
diff --git a/src/gallium/drivers/svga/svga_resource.c b/src/gallium/drivers/svga/svga_resource.c
index 6a297a2..874cfa0 100644
--- a/src/gallium/drivers/svga/svga_resource.c
+++ b/src/gallium/drivers/svga/svga_resource.c
@@ -33,14 +33,27 @@
#include "svga_format.h"


+/**
+ * This is the primary driver entrypoint for allocating graphics memory
+ * (vertex/index/constant buffers, textures, etc)
+ */
static struct pipe_resource *
svga_resource_create(struct pipe_screen *screen,
const struct pipe_resource *template)
{
+ struct pipe_resource *r;
+
if (template->target == PIPE_BUFFER)
- return svga_buffer_create(screen, template);
+ r = svga_buffer_create(screen, template);
else
- return svga_texture_create(screen, template);
+ r = svga_texture_create(screen, template);
+
+ if (!r) {
+ struct svga_screen *svgascreen = svga_screen(screen);
+ svgascreen->hud.num_failed_allocations++;
+ }
+
+ return r;
}


diff --git a/src/gallium/drivers/svga/svga_screen.c b/src/gallium/drivers/svga/svga_screen.c
index 3aa9945..0b63525 100644
--- a/src/gallium/drivers/svga/svga_screen.c
+++ b/src/gallium/drivers/svga/svga_screen.c
@@ -916,6 +916,8 @@ svga_get_driver_query_info(struct pipe_screen *screen,
PIPE_DRIVER_QUERY_TYPE_UINT64),
QUERY("num-generate-mipmap", SVGA_QUERY_NUM_GENERATE_MIPMAP,
PIPE_DRIVER_QUERY_TYPE_UINT64),
+ QUERY("num-failed-allocations", SVGA_QUERY_NUM_FAILED_ALLOCATIONS,
+ PIPE_DRIVER_QUERY_TYPE_UINT64),
};
#undef QUERY

diff --git a/src/gallium/drivers/svga/svga_screen.h b/src/gallium/drivers/svga/svga_screen.h
index 68834a6..12b9346 100644
--- a/src/gallium/drivers/svga/svga_screen.h
+++ b/src/gallium/drivers/svga/svga_screen.h
@@ -86,6 +86,7 @@ struct svga_screen
/** Memory used by all resources (buffers and surfaces) */
uint64_t total_resource_bytes;
uint64_t num_resources;
+ uint64_t num_failed_allocations;
} hud;
};

--
1.9.1
Neha Bhende
2017-06-16 23:00:21 UTC
Permalink
Raw Message
For the series,


Reviewed-by: Neha Bhende<***@vmware.com>


Regards,

Neha

________________________________
From: Brian Paul <***@vmware.com>
Sent: Friday, June 16, 2017 3:39:12 PM
To: mesa-***@lists.freedesktop.org
Cc: Charmaine Lee; Neha Bhende
Subject: [PATCH 2/2] svga: add new num-failed-allocations HUD query

This counter is incremented if we fail to allocate memory for
vertex/index/const buffers, textures, etc.
---
src/gallium/drivers/svga/svga_context.h | 1 +
src/gallium/drivers/svga/svga_pipe_query.c | 7 +++++++
src/gallium/drivers/svga/svga_resource.c | 17 +++++++++++++++--
src/gallium/drivers/svga/svga_screen.c | 2 ++
src/gallium/drivers/svga/svga_screen.h | 1 +
5 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/svga/svga_context.h b/src/gallium/drivers/svga/svga_context.h
index 2987c70..b1ccfc8 100644
--- a/src/gallium/drivers/svga/svga_context.h
+++ b/src/gallium/drivers/svga/svga_context.h
@@ -72,6 +72,7 @@ enum svga_hud {
SVGA_QUERY_NUM_STATE_OBJECTS,
SVGA_QUERY_NUM_SURFACE_VIEWS,
SVGA_QUERY_NUM_GENERATE_MIPMAP,
+ SVGA_QUERY_NUM_FAILED_ALLOCATIONS,

/*SVGA_QUERY_MAX has to be last because it is size of an array*/
SVGA_QUERY_MAX
diff --git a/src/gallium/drivers/svga/svga_pipe_query.c b/src/gallium/drivers/svga/svga_pipe_query.c
index 76360fd..6703b72 100644
--- a/src/gallium/drivers/svga/svga_pipe_query.c
+++ b/src/gallium/drivers/svga/svga_pipe_query.c
@@ -747,6 +747,7 @@ svga_create_query(struct pipe_context *pipe,
case SVGA_QUERY_NUM_BUFFER_UPLOADS:
case SVGA_QUERY_NUM_CONST_BUF_UPDATES:
case SVGA_QUERY_NUM_CONST_UPDATES:
+ case SVGA_QUERY_NUM_FAILED_ALLOCATIONS:
break;
case SVGA_QUERY_FLUSH_TIME:
case SVGA_QUERY_MAP_BUFFER_TIME:
@@ -826,6 +827,7 @@ svga_destroy_query(struct pipe_context *pipe, struct pipe_query *q)
case SVGA_QUERY_NUM_BUFFER_UPLOADS:
case SVGA_QUERY_NUM_CONST_BUF_UPDATES:
case SVGA_QUERY_NUM_CONST_UPDATES:
+ case SVGA_QUERY_NUM_FAILED_ALLOCATIONS:
/* nothing */
break;
default:
@@ -937,6 +939,7 @@ svga_begin_query(struct pipe_context *pipe, struct pipe_query *q)
case SVGA_QUERY_NUM_STATE_OBJECTS:
case SVGA_QUERY_NUM_SURFACE_VIEWS:
case SVGA_QUERY_NUM_GENERATE_MIPMAP:
+ case SVGA_QUERY_NUM_FAILED_ALLOCATIONS:
/* nothing */
break;
default:
@@ -1049,6 +1052,7 @@ svga_end_query(struct pipe_context *pipe, struct pipe_query *q)
case SVGA_QUERY_NUM_STATE_OBJECTS:
case SVGA_QUERY_NUM_SURFACE_VIEWS:
case SVGA_QUERY_NUM_GENERATE_MIPMAP:
+ case SVGA_QUERY_NUM_FAILED_ALLOCATIONS:
/* nothing */
break;
default:
@@ -1182,6 +1186,9 @@ svga_get_query_result(struct pipe_context *pipe,
case SVGA_QUERY_NUM_GENERATE_MIPMAP:
vresult->u64 = svga->hud.num_generate_mipmap;
break;
+ case SVGA_QUERY_NUM_FAILED_ALLOCATIONS:
+ vresult->u64 = svgascreen->hud.num_failed_allocations;
+ break;
default:
assert(!"unexpected query type in svga_get_query_result");
}
diff --git a/src/gallium/drivers/svga/svga_resource.c b/src/gallium/drivers/svga/svga_resource.c
index 6a297a2..874cfa0 100644
--- a/src/gallium/drivers/svga/svga_resource.c
+++ b/src/gallium/drivers/svga/svga_resource.c
@@ -33,14 +33,27 @@
#include "svga_format.h"


+/**
+ * This is the primary driver entrypoint for allocating graphics memory
+ * (vertex/index/constant buffers, textures, etc)
+ */
static struct pipe_resource *
svga_resource_create(struct pipe_screen *screen,
const struct pipe_resource *template)
{
+ struct pipe_resource *r;
+
if (template->target == PIPE_BUFFER)
- return svga_buffer_create(screen, template);
+ r = svga_buffer_create(screen, template);
else
- return svga_texture_create(screen, template);
+ r = svga_texture_create(screen, template);
+
+ if (!r) {
+ struct svga_screen *svgascreen = svga_screen(screen);
+ svgascreen->hud.num_failed_allocations++;
+ }
+
+ return r;
}


diff --git a/src/gallium/drivers/svga/svga_screen.c b/src/gallium/drivers/svga/svga_screen.c
index 3aa9945..0b63525 100644
--- a/src/gallium/drivers/svga/svga_screen.c
+++ b/src/gallium/drivers/svga/svga_screen.c
@@ -916,6 +916,8 @@ svga_get_driver_query_info(struct pipe_screen *screen,
PIPE_DRIVER_QUERY_TYPE_UINT64),
QUERY("num-generate-mipmap", SVGA_QUERY_NUM_GENERATE_MIPMAP,
PIPE_DRIVER_QUERY_TYPE_UINT64),
+ QUERY("num-failed-allocations", SVGA_QUERY_NUM_FAILED_ALLOCATIONS,
+ PIPE_DRIVER_QUERY_TYPE_UINT64),
};
#undef QUERY

diff --git a/src/gallium/drivers/svga/svga_screen.h b/src/gallium/drivers/svga/svga_screen.h
index 68834a6..12b9346 100644
--- a/src/gallium/drivers/svga/svga_screen.h
+++ b/src/gallium/drivers/svga/svga_screen.h
@@ -86,6 +86,7 @@ struct svga_screen
/** Memory used by all resources (buffers and surfaces) */
uint64_t total_resource_bytes;
uint64_t num_resources;
+ uint64_t num_failed_allocations;
} hud;
};

--
1.9.1
Marek Olšák
2017-06-17 12:01:34 UTC
Permalink
Raw Message
Reviewed-by: Marek Olšák <***@amd.com>

Marek

On Sat, Jun 17, 2017 at 12:39 AM, Brian Paul <***@vmware.com> wrote:
> Use a dummy implementation of the access() function. Use \ path separator.
> Add a few comments.
> ---
> src/gallium/auxiliary/hud/hud_context.c | 36 +++++++++++++++++++++++++++------
> 1 file changed, 30 insertions(+), 6 deletions(-)
>
> diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c
> index 9dd2fbf..cb7ed44 100644
> --- a/src/gallium/auxiliary/hud/hud_context.c
> +++ b/src/gallium/auxiliary/hud/hud_context.c
> @@ -958,26 +958,50 @@ static void strcat_without_spaces(char *dst, const char *src)
> *dst = 0;
> }
>
> +
> +#ifdef PIPE_OS_WINDOWS
> +#define W_OK 0
> +static int
> +access(const char *pathname, int mode)
> +{
> + /* no-op */
> + return 0;
> +}
> +
> +#define PATH_SEP "\\"
> +
> +#else
> +
> +#define PATH_SEP "/"
> +
> +#endif
> +
> +
> +/**
> + * If the GALLIUM_HUD_DUMP_DIR env var is set, we'll write the raw
> + * HUD values to files at ${GALLIUM_HUD_DUMP_DIR}/<stat> where <stat>
> + * is a HUD variable such as "fps", or "cpu"
> + */
> static void
> hud_graph_set_dump_file(struct hud_graph *gr)
> {
> -#ifndef PIPE_OS_WINDOWS
> const char *hud_dump_dir = getenv("GALLIUM_HUD_DUMP_DIR");
> - char *dump_file;
>
> if (hud_dump_dir && access(hud_dump_dir, W_OK) == 0) {
> - dump_file = malloc(strlen(hud_dump_dir) + sizeof("/") + sizeof(gr->name));
> + char *dump_file = malloc(strlen(hud_dump_dir) + sizeof(PATH_SEP)
> + + sizeof(gr->name));
> if (dump_file) {
> strcpy(dump_file, hud_dump_dir);
> - strcat(dump_file, "/");
> + strcat(dump_file, PATH_SEP);
> strcat_without_spaces(dump_file, gr->name);
> gr->fd = fopen(dump_file, "w+");
> - if (gr->fd)
> + if (gr->fd) {
> + /* flush output after each line is written */
> setvbuf(gr->fd, NULL, _IOLBF, 0);
> + }
> free(dump_file);
> }
> }
> -#endif
> }
>
> /**
> --
> 1.9.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-***@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Emil Velikov
2017-06-17 12:50:36 UTC
Permalink
Raw Message
On 16 June 2017 at 23:39, Brian Paul <***@vmware.com> wrote:
> Use a dummy implementation of the access() function. Use \ path separator.
> Add a few comments.
> ---
> src/gallium/auxiliary/hud/hud_context.c | 36 +++++++++++++++++++++++++++------
> 1 file changed, 30 insertions(+), 6 deletions(-)
>
> diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c
> index 9dd2fbf..cb7ed44 100644
> --- a/src/gallium/auxiliary/hud/hud_context.c
> +++ b/src/gallium/auxiliary/hud/hud_context.c
> @@ -958,26 +958,50 @@ static void strcat_without_spaces(char *dst, const char *src)
> *dst = 0;
> }
>
> +
> +#ifdef PIPE_OS_WINDOWS
> +#define W_OK 0
> +static int
> +access(const char *pathname, int mode)
Windows has the _access and _access_s which seem to provide equivalent
functionality, right?

JFYI, by no means an objection/blocker.

-Emil
Loading...