From patchwork Thu Oct 19 06:15:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Gmeiner X-Patchwork-Id: 10016033 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5EA4F60215 for ; Thu, 19 Oct 2017 06:16:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 511EB28C7B for ; Thu, 19 Oct 2017 06:16:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4613128C7D; Thu, 19 Oct 2017 06:16:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BABB928C7C for ; Thu, 19 Oct 2017 06:15:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4EC0F6E9F3; Thu, 19 Oct 2017 06:15:58 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id C76E46E9E1; Thu, 19 Oct 2017 06:15:56 +0000 (UTC) Received: by mail-wm0-x242.google.com with SMTP id l68so13991759wmd.5; Wed, 18 Oct 2017 23:15:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=R0vcTon9clCUFjFbVVXlQ75zbuaCzH8mFeEEGQYmAAc=; b=Ds65ZYdBhf1D8JRFmeORUAYUzyQctXinXKxlqOiMRnNGQyHsCc+ToFIyQeDixGnCJw qdFEnhWfqAMYBF2vQiBgPuVl2QZr8Yf/kTP8ar09mo6BpSCfZwm+BE2b4S9uFVpnot62 Npg5B/TwAOwDmG2YK4Xe1L8TSOIPZ4JvG0FVKc7MObIrzQmM2UszCjzpj0j23CpDDulB JQzwW8KRr6XRfqNDwWNwj5yA64MVLXdMIZsShdI1cKprOD7UeH82aPxDWLRm+3YGV/a5 VVWDw4HVu/Ns+tzSohWMUpziWufEgnnZBF2vEIN9+Wkceex8M87gtqHnJbJFIZ7Qj7sm rxmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=R0vcTon9clCUFjFbVVXlQ75zbuaCzH8mFeEEGQYmAAc=; b=ZXPxncOD5ug6bQ0e2pEyaPx2w4YX4MnDv2zWB1+uSs6ocM7qnsVZ5rtXqIZM7lOUYn sxQVoJhCWFqd3U+nbQzg6eVcuuyfVZqLpovbmxwaE4xfC1exbzKbXSssumBfHScQQANB nCOGSSF1VhoV0mjIxQZ5rWvL4J9a8HNl7WFqbMvFaOrgZNB4CKUAQnsDySVDa4KIzyLY thhp4q9aF4+HFQCNtXZSGQJSyqvXl4bRKf0jiqXvBGa2u1vLWfiXs8cikovXGS36z6on TuDl1LtnUxTA8mu69z2ll3YPCFlphj+KN74kNy32a4N8WbtwLyzSV1rr6ZokLC77EY6h qNRg== X-Gm-Message-State: AMCzsaUM0msdBE7oV4NcBkfvxXE0Q013BHAF9EraWGJYAUR8+tlIGZT2 fg55YX0m1HtDLLw/17PjVAd92w== X-Google-Smtp-Source: ABhQp+QVWtTExwtIpJ+L99GBQjE2bHUYyoDK65lOBF+bhOX1HJDHnm19jIR9txHeJDWAjBdWnEDMVQ== X-Received: by 10.28.245.11 with SMTP id t11mr603364wmh.113.1508393755151; Wed, 18 Oct 2017 23:15:55 -0700 (PDT) Received: from localhost.localdomain (193-83-18-195.adsl.highway.telekom.at. [193.83.18.195]) by smtp.gmail.com with ESMTPSA id e77sm1241629wmi.16.2017.10.18.23.15.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Oct 2017 23:15:54 -0700 (PDT) From: Christian Gmeiner To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm 2/3] etnaviv: add permon support Date: Thu, 19 Oct 2017 08:15:46 +0200 Message-Id: <20171019061547.11676-2-christian.gmeiner@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171019061547.11676-1-christian.gmeiner@gmail.com> References: <20171019061547.11676-1-christian.gmeiner@gmail.com> Cc: linux+etnaviv@armlinux.org.uk, etnaviv@lists.freedesktop.org, cphealy@gmail.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Query all domains and their signals and provide it this information via struct etna_perfmon and the corresponding api functions. Signed-off-by: Christian Gmeiner --- etnaviv/Makefile.sources | 1 + etnaviv/etnaviv-symbol-check | 4 + etnaviv/etnaviv_drmif.h | 10 +++ etnaviv/etnaviv_perfmon.c | 196 +++++++++++++++++++++++++++++++++++++++++++ etnaviv/etnaviv_priv.h | 21 +++++ 5 files changed, 232 insertions(+) create mode 100644 etnaviv/etnaviv_perfmon.c diff --git a/etnaviv/Makefile.sources b/etnaviv/Makefile.sources index 52580567..0eb73783 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 \ diff --git a/etnaviv/etnaviv-symbol-check b/etnaviv/etnaviv-symbol-check index 0e2030e4..bd95b459 100755 --- a/etnaviv/etnaviv-symbol-check +++ b/etnaviv/etnaviv-symbol-check @@ -42,6 +42,10 @@ etna_cmd_stream_flush etna_cmd_stream_flush2 etna_cmd_stream_finish etna_cmd_stream_reloc +etna_perfmon_create +etna_perfmon_del +etna_perfmon_get_dom_by_name +etna_perfmon_get_sig_by_name EOF done) diff --git a/etnaviv/etnaviv_drmif.h b/etnaviv/etnaviv_drmif.h index 87704acd..0a7f6a3a 100644 --- a/etnaviv/etnaviv_drmif.h +++ b/etnaviv/etnaviv_drmif.h @@ -35,6 +35,9 @@ struct etna_pipe; struct etna_gpu; struct etna_device; struct etna_cmd_stream; +struct etna_perfmon; +struct etna_perfmon_domain; +struct etna_perfmon_signal; enum etna_pipe_id { ETNA_PIPE_3D = 0, @@ -190,4 +193,11 @@ struct etna_reloc { void etna_cmd_stream_reloc(struct etna_cmd_stream *stream, const struct etna_reloc *r); +/* performance monitoring functions: + */ +struct etna_perfmon *etna_perfmon_create(struct etna_pipe *pipe); +void etna_perfmon_del(struct etna_perfmon *perfmon); +struct etna_perfmon_domain *etna_perfmon_get_dom_by_name(struct etna_perfmon *pm, const char *name); +struct etna_perfmon_signal *etna_perfmon_get_sig_by_name(struct etna_perfmon_domain *dom, const char *name); + #endif /* ETNAVIV_DRMIF_H_ */ diff --git a/etnaviv/etnaviv_perfmon.c b/etnaviv/etnaviv_perfmon.c new file mode 100644 index 00000000..16e37285 --- /dev/null +++ b/etnaviv/etnaviv_perfmon.c @@ -0,0 +1,196 @@ +/* + * 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 + */ + +#ifdef HAVE_CONFIG_H +# include +#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; + + sig = calloc(1, sizeof(*sig)); + if (!sig) + return -ENOMEM; + + INFO_MSG("perfmon signal:"); + INFO_MSG("id = %d", req.id); + INFO_MSG("name = %s", req.name); + + sig->domain = dom; + sig->signal = req.id; + strncpy(sig->name, req.name, sizeof(sig->name)); + list_addtail(&sig->head, &dom->signals); + } while (req.iter != 0xffff); + + 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; + + dom = calloc(1, sizeof(*dom)); + if (!dom) + return -ENOMEM; + list_inithead(&dom->signals); + + dom->id = req.id; + strncpy(dom->name, req.name, sizeof(dom->name)); + list_addtail(&dom->head, &pm->domains); + + INFO_MSG("perfmon domain:"); + INFO_MSG("id = %d", req.id); + 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; + } + } 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 1334ba3f..37ffd803 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]))