[libdrm 3/4] etnaviv: add permon support

Wladimir J. van der Laan laanwj at gmail.com
Tue Jun 20 13:43:05 UTC 2017


On Fri, Jun 09, 2017 at 12:27:36PM +0200, Christian Gmeiner wrote:
> Query all domains and their signals and provide it this information
> via struct etna_perfmon and the corresponding api functions.

Comments in-line.

> Signed-off-by: Christian Gmeiner <christian.gmeiner at gmail.com>
> ---
>  etnaviv/Makefile.sources     |   1 +
>  etnaviv/etnaviv-symbol-check |   4 +
>  etnaviv/etnaviv_drmif.h      |  10 +++
>  etnaviv/etnaviv_perfmon.c    | 206 +++++++++++++++++++++++++++++++++++++++++++
>  etnaviv/etnaviv_priv.h       |  21 +++++
>  5 files changed, 242 insertions(+)
>  create mode 100644 etnaviv/etnaviv_perfmon.c
> 
> diff --git a/etnaviv/Makefile.sources b/etnaviv/Makefile.sources
> index 5258056..0eb7378 100644
> --- a/etnaviv/Makefile.sources
> +++ b/etnaviv/Makefile.sources
> @@ -3,6 +3,7 @@ LIBDRM_ETNAVIV_FILES := \
>  	etnaviv_gpu.c \
>  	etnaviv_bo.c \
>  	etnaviv_bo_cache.c \
> +	etnaviv_perfmon.c \
>  	etnaviv_pipe.c \
>  	etnaviv_cmd_stream.c \
>  	etnaviv_drm.h \
> --- /dev/null
> +++ b/etnaviv/etnaviv_perfmon.c
> @@ -0,0 +1,206 @@
> +/*
> + * Copyright (C) 2017 Etnaviv Project
> + * Copyright (C) 2017 Zodiac Inflight Innovations
> + *
> + * 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.
> + *
> + * Authors:
> + *    Christian Gmeiner <christian.gmeiner at gmail.com>
> + */
> +
> +#ifdef HAVE_CONFIG_H
> +# include <config.h>
> +#endif
> +
> +#include "etnaviv_priv.h"
> +
> +static int
> +etna_perfmon_query_signals(struct etna_perfmon *pm, struct etna_perfmon_domain *dom)
> +{
> +	struct etna_device *dev = pm->pipe->gpu->dev;
> +	struct drm_etnaviv_pm_signal req = {
> +		.pipe = pm->pipe->id,
> +		.domain = dom->id
> +	};
> +
> +	do {
> +		struct etna_perfmon_signal *sig;
> +		int ret;
> +
> +		ret = drmCommandWriteRead(dev->fd, DRM_ETNAVIV_PM_QUERY_SIG, &req, sizeof(req));
> +		if (ret)
> +			break;

What does it means if ret is non-zero here? If there is an error, would we
want to log a debug message at least, and possibly return non-zero
from this function?
(same comment for etna_perfmon_query_domains)

> +		if (req.iter == 0xff)
> +			return 0;

0xff is a magic value, used a few times - maybe define a constant?
(same comment for etna_perfmon_query_domains)

> +
> +		sig = calloc(1, sizeof(*sig));
> +		if (!sig)
> +			return -ENOMEM;
> +
> +		INFO_MSG("perfmon signal:");
> +		INFO_MSG("iter       = %d", req.iter);
> +		INFO_MSG("name       = %s", req.name);
> +
> +		sig->domain = dom;
> +		sig->signal = req.iter;
> +		strncpy(sig->name, req.name, sizeof(sig->name));
> +		list_addtail(&sig->head, &dom->signals);
> +
> +		req.iter++;
> +	} while (req.iter != 0xff);
> +
> +	return 0;
> +}
> +
> +static int
> +etna_perfmon_query_domains(struct etna_perfmon *pm)
> +{
> +	struct etna_device *dev = pm->pipe->gpu->dev;
> +	struct drm_etnaviv_pm_domain req = {
> +		.pipe = pm->pipe->id
> +	};
> +
> +	do {
> +		struct etna_perfmon_domain *dom;
> +		int ret;
> +
> +		ret = drmCommandWriteRead(dev->fd, DRM_ETNAVIV_PM_QUERY_DOM, &req, sizeof(req));
> +		if (ret)
> +			break;
> +
> +		if (req.iter == 0xff)
> +			return 0;
> +
> +		dom = calloc(1, sizeof(*dom));
> +		if (!dom)
> +			return -ENOMEM;
> +		list_inithead(&dom->signals);
> +
> +		dom->id = req.iter;
> +		strncpy(dom->name, req.name, sizeof(dom->name));
> +		list_addtail(&dom->head, &pm->domains);
> +
> +		INFO_MSG("perfmon domain:");
> +		INFO_MSG("iter       = %d", req.iter);
> +		INFO_MSG("name       = %s", req.name);
> +		INFO_MSG("nr_signals = %d", req.nr_signals);
> +
> +
> +		/* Query all available signals for this domain. */
> +		if (req.nr_signals > 0) {
> +			ret = etna_perfmon_query_signals(pm, dom);
> +			if (ret)
> +				return ret;
> +		}
> +		req.iter++;
> +
> +	} while (req.iter != 0xff);
> +
> +   return 0;
> +}
> +
> +static void
> +etna_perfmon_free_signals(struct etna_perfmon_domain *dom)
> +{
> +   struct etna_perfmon_signal *sig, *next;
> +
> +   LIST_FOR_EACH_ENTRY_SAFE(sig, next, &dom->signals, head) {
> +      list_del(&sig->head);
> +      free(sig);
> +   }
> +}
> +
> +static void
> +etna_perfmon_free_domains(struct etna_perfmon *pm)
> +{
> +   struct etna_perfmon_domain *dom, *next;
> +
> +   LIST_FOR_EACH_ENTRY_SAFE(dom, next, &pm->domains, head) {
> +      etna_perfmon_free_signals(dom);
> +      list_del(&dom->head);
> +      free(dom);
> +   }
> +}
> +
> +struct etna_perfmon *etna_perfmon_create(struct etna_pipe *pipe)
> +{
> +	struct etna_perfmon *pm;
> +	int ret;
> +
> +	pm = calloc(1, sizeof(*pm));
> +	if (!pm) {
> +		ERROR_MSG("allocation failed");
> +		goto fail;
> +	}
> +
> +    list_inithead(&pm->domains);
> +
> +    pm->pipe = pipe;
> +
> +    /* query all available domains and sources for this device */
> +    ret = etna_perfmon_query_domains(pm);
> +    if (ret)
> +       goto fail;
> +
> +	return pm;
> +
> +fail:
> +	return NULL;
> +}
> +
> +void etna_perfmon_del(struct etna_perfmon *pm)
> +{
> +    if (!pm)
> +       return;
> +
> +    etna_perfmon_free_domains(pm);
> +    free(pm);
> +}
> +
> +struct etna_perfmon_domain *
> +etna_perfmon_get_dom_by_name(struct etna_perfmon *pm, const char *name)
> +{
> +    struct etna_perfmon_domain *dom;
> +
> +    if (pm) {
> +       LIST_FOR_EACH_ENTRY(dom, &pm->domains, head) {
> +          if (!strcmp(dom->name, name))
> +             return dom;
> +       }
> +    }
> +
> +    return NULL;
> +}
> +
> +struct etna_perfmon_signal *
> +etna_perfmon_get_sig_by_name(struct etna_perfmon_domain *dom, const char *name)
> +{
> +    struct etna_perfmon_signal *signal;
> +
> +    if (dom) {
> +       LIST_FOR_EACH_ENTRY(signal, &dom->signals, head) {
> +          if (!strcmp(signal->name, name))
> +             return signal;
> +       }
> +    }
> +
> +    return NULL;
> +}
> diff --git a/etnaviv/etnaviv_priv.h b/etnaviv/etnaviv_priv.h
> index 1334ba3..37ffd80 100644
> --- a/etnaviv/etnaviv_priv.h
> +++ b/etnaviv/etnaviv_priv.h
> @@ -151,6 +151,27 @@ struct etna_cmd_stream_priv {
>  	void *reset_notify_priv;
>  };
>  
> +struct etna_perfmon {
> +	struct list_head domains;
> +	struct etna_pipe *pipe;
> +};
> +
> +struct etna_perfmon_domain
> +{
> +   struct list_head head;
> +   struct list_head signals;
> +   uint8_t id;
> +   char name[64];
> +};
> +
> +struct etna_perfmon_signal
> +{
> +   struct list_head head;
> +   struct etna_perfmon_domain *domain;
> +   uint8_t signal;
> +   char name[64];
> +};
> +
>  #define ALIGN(v,a) (((v) + (a) - 1) & ~((a) - 1))
>  #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
>  
> -- 
> 2.9.4
> 
> _______________________________________________
> etnaviv mailing list
> etnaviv at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/etnaviv


More information about the etnaviv mailing list