From patchwork Sun Mar 12 23:30:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Erico Nunes X-Patchwork-Id: 13171899 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0D896C6FD1F for ; Sun, 12 Mar 2023 23:31:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 92DD610E449; Sun, 12 Mar 2023 23:31:48 +0000 (UTC) Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by gabe.freedesktop.org (Postfix) with ESMTPS id E988510E29E; Sun, 12 Mar 2023 23:31:43 +0000 (UTC) Received: by mail-ed1-x52b.google.com with SMTP id da10so42033341edb.3; Sun, 12 Mar 2023 16:31:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678663902; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ug0UWV1hH6yIQRdNc6r9G/GtUMEjsZqb/YaG3qyeq7U=; b=i5IFouup19hffz23+1uI4jLWHgu99D6QbX66DDD5Btyk5eNuJR/EdQkH81hJKua6mn Z2KjCaHIMP4FMK8Z5eSwp5ihDp2pPnzTOFjWd6u9BlS/ZvJ5pM5r6/z3jmLdzK6dmXee 2PZnD379UbhZAwXFgpb5O4zHowm8ZtpcAfB128L85XoAkchYWjkg7fD7mPCYJkPxOKjJ Qj1uJzaFdW4WwApYHN08ERYvaGkv9O2ZDWXsfPtxcgQ4Pkc4mIlUVDvGLYHQyJRnu9/E xdyRXp4rZc81dCpWyi3rT9J+bgJ5lIMc20KwcIAW7g27aSamCAeVU6dPjCiturmY9Too mrHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678663902; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ug0UWV1hH6yIQRdNc6r9G/GtUMEjsZqb/YaG3qyeq7U=; b=LrQQT1StlW45DpDVuaqdx182h7+nADqbdyQUgLlzV3YNVBWwsLY4vonRDydc8neeOe I+/GF48vZBMFxb9ehPX5dyAWQMQyuq4Ab4u4+c4AuSVb4Q6bMBq3PnQ03EPa9QnZc6Wz 2PvK39I7FypxGAX4FygTlDPawB435rwu7OVAlqCAuxmDJkS/nNO2gPNJziu4HbmwpE/l 1U5YVVakwAkgKCwOclXSj2ejLxXHwYL5rrrS+YFy/ISR6gvpnUP5uFWtaS5Dpvq2CNM+ uO07ZZ9o9LtLZPvo0rYOuMPDTRQZpSbfWpKHEYn+t6yCDQkH/KHtCyg1mPMVsoIOb7cM +mXg== X-Gm-Message-State: AO0yUKWQLEp/JqO13VnbMc5FXLCaJgdtstBBJu3ocHouyY71P/Np3XDW R7udgYe8JnbJH7kCxG3Szx7C80APR/K7zQ== X-Google-Smtp-Source: AK7set+bXCN4Mt45oF5XVHG28M27QQ6mDhu55XzmI+LM6RlFn0Ysif3IPDBiBk6S5gNX1T2txKQXQA== X-Received: by 2002:a17:907:6e01:b0:8e0:4baf:59d7 with SMTP id sd1-20020a1709076e0100b008e04baf59d7mr43197922ejc.31.1678663902296; Sun, 12 Mar 2023 16:31:42 -0700 (PDT) Received: from centennial.enunes.eu (ip-78-45-66-209.bb.vodafone.cz. [78.45.66.209]) by smtp.gmail.com with ESMTPSA id vv11-20020a170907a68b00b009226f644a07sm2009958ejc.139.2023.03.12.16.31.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Mar 2023 16:31:41 -0700 (PDT) From: Erico Nunes To: Qiang Yu , dri-devel@lists.freedesktop.org Subject: [PATCH 1/3] drm/lima: add usage counting method to ctx_mgr Date: Mon, 13 Mar 2023 00:30:50 +0100 Message-Id: <20230312233052.21095-2-nunes.erico@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230312233052.21095-1-nunes.erico@gmail.com> References: <20230312233052.21095-1-nunes.erico@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Airlie , Erico Nunes , lima@lists.freedesktop.org, linux-kernel@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" lima maintains a context manager per drm_file, similar to amdgpu. In order to account for the complete usage per drm_file, all of the associated contexts need to be considered. Previously released contexts also need to be accounted for but their drm_sched_entity info is gone once they get released, so account for it in the ctx_mgr. Signed-off-by: Erico Nunes --- drivers/gpu/drm/lima/lima_ctx.c | 30 +++++++++++++++++++++++++++++- drivers/gpu/drm/lima/lima_ctx.h | 3 +++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/lima/lima_ctx.c b/drivers/gpu/drm/lima/lima_ctx.c index 891d5cd5019a..e008e586fad0 100644 --- a/drivers/gpu/drm/lima/lima_ctx.c +++ b/drivers/gpu/drm/lima/lima_ctx.c @@ -15,6 +15,7 @@ int lima_ctx_create(struct lima_device *dev, struct lima_ctx_mgr *mgr, u32 *id) if (!ctx) return -ENOMEM; ctx->dev = dev; + ctx->mgr = mgr; kref_init(&ctx->refcnt); for (i = 0; i < lima_pipe_num; i++) { @@ -42,10 +43,17 @@ int lima_ctx_create(struct lima_device *dev, struct lima_ctx_mgr *mgr, u32 *id) static void lima_ctx_do_release(struct kref *ref) { struct lima_ctx *ctx = container_of(ref, struct lima_ctx, refcnt); + struct lima_ctx_mgr *mgr = ctx->mgr; int i; - for (i = 0; i < lima_pipe_num; i++) + for (i = 0; i < lima_pipe_num; i++) { + struct lima_sched_context *context = &ctx->context[i]; + struct drm_sched_entity *entity = &context->base; + + mgr->elapsed_ns[i] += entity->elapsed_ns; + lima_sched_context_fini(ctx->dev->pipe + i, ctx->context + i); + } kfree(ctx); } @@ -99,3 +107,23 @@ void lima_ctx_mgr_fini(struct lima_ctx_mgr *mgr) xa_destroy(&mgr->handles); mutex_destroy(&mgr->lock); } + +void lima_ctx_mgr_usage(struct lima_ctx_mgr *mgr, u64 usage[lima_pipe_num]) +{ + struct lima_ctx *ctx; + unsigned long id; + + for (int i = 0; i < lima_pipe_num; i++) + usage[i] = mgr->elapsed_ns[i]; + + mutex_lock(&mgr->lock); + xa_for_each(&mgr->handles, id, ctx) { + for (int i = 0; i < lima_pipe_num; i++) { + struct lima_sched_context *context = &ctx->context[i]; + struct drm_sched_entity *entity = &context->base; + + usage[i] += entity->elapsed_ns; + } + } + mutex_unlock(&mgr->lock); +} diff --git a/drivers/gpu/drm/lima/lima_ctx.h b/drivers/gpu/drm/lima/lima_ctx.h index 74e2be09090f..6068863880eb 100644 --- a/drivers/gpu/drm/lima/lima_ctx.h +++ b/drivers/gpu/drm/lima/lima_ctx.h @@ -12,6 +12,7 @@ struct lima_ctx { struct kref refcnt; struct lima_device *dev; + struct lima_ctx_mgr *mgr; struct lima_sched_context context[lima_pipe_num]; atomic_t guilty; @@ -23,6 +24,7 @@ struct lima_ctx { struct lima_ctx_mgr { struct mutex lock; struct xarray handles; + u64 elapsed_ns[lima_pipe_num]; }; int lima_ctx_create(struct lima_device *dev, struct lima_ctx_mgr *mgr, u32 *id); @@ -31,5 +33,6 @@ struct lima_ctx *lima_ctx_get(struct lima_ctx_mgr *mgr, u32 id); void lima_ctx_put(struct lima_ctx *ctx); void lima_ctx_mgr_init(struct lima_ctx_mgr *mgr); void lima_ctx_mgr_fini(struct lima_ctx_mgr *mgr); +void lima_ctx_mgr_usage(struct lima_ctx_mgr *mgr, u64 usage[lima_pipe_num]); #endif From patchwork Sun Mar 12 23:30:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Erico Nunes X-Patchwork-Id: 13171898 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8C1C3C6FD1F for ; Sun, 12 Mar 2023 23:31:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DE15D10E443; Sun, 12 Mar 2023 23:31:47 +0000 (UTC) Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by gabe.freedesktop.org (Postfix) with ESMTPS id 101D810E440; Sun, 12 Mar 2023 23:31:45 +0000 (UTC) Received: by mail-ed1-x52f.google.com with SMTP id y4so12475841edo.2; Sun, 12 Mar 2023 16:31:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678663903; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=H0/tNTjxjj5Y4CDnyWnc8sLr+X7IlP2dT2pnrIFsJj4=; b=Q1omTo4kyCm1U6Y6EIoU6QS9Ka4/F1X6BERxWFXkhTkoTv4HqfptVZykp2rxOrwabh FqhHs5eBk3UI+ZdlJbUxAJ/fWDV5tJTUxnvuO8yAzPusQr6dZAqcMEp9iFAtFYg/+DzQ Kcp+bSuVYKhn5ym/vpDjkcuCxulmoYtp5Gp5MctBH9RgB4KzmL9CXUVu/7vppAscRChX Z1RPOWNkgW9TO94qilWVPEGDNqYvCwNFdPnz9gJ1xSOpSQjqEY9y1KlWa7YJrEz/k+XY UszavXltChrgzJiAWVewYybhxUser7zUv0O73C1iBEzFRy1dEMKYyvrPT3p73CKfOgYE D8ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678663903; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H0/tNTjxjj5Y4CDnyWnc8sLr+X7IlP2dT2pnrIFsJj4=; b=3kRE6RdUFsvCJeORU4xhdO1UuaYYV9IMtaWQoKK+YpZeD65WaF51G/3ajuxcOwZX+i 6KVQtwgNWVaSPcYJJHcMJr6qmkRCn/nP6NcdDfx5fyb0EjJFOsxAVMwgahYjripCfLZv v+Fex3eX5jDU/xYNR/Yl8mGoftYNSzU/Ggwz2gvOjJPJZR/4QzMW8qTkTD1jkHPRH7gh GEbwgSSfvtcerYI0/Rzam14LsvyBLnSQRn90EQ2AogFdGwYHUwczaCFRaor1DVQ6LzAY pA3wUlDzBpvszTA43B+dSoyQnhtQUrW9VtGKwbMxzsMyvwBALwHlhSbNaAuMMCmjGl+k heXQ== X-Gm-Message-State: AO0yUKU3mjtJLZkiOWPj0u1Y9t89SRjRdYGr6cpPuKIVjUl9Ky2sNrH1 Q9mI6pCCmPzrke8cCOLOeG8= X-Google-Smtp-Source: AK7set/HD1FOoDlZBN3zmKjLDLlp4nulhIfT+1b32Ihq3mvgl1O4WjG1MB6UYdpuTw76CR7Gi/jCaA== X-Received: by 2002:aa7:cb18:0:b0:4fb:fd22:29c0 with SMTP id s24-20020aa7cb18000000b004fbfd2229c0mr2260760edt.26.1678663903337; Sun, 12 Mar 2023 16:31:43 -0700 (PDT) Received: from centennial.enunes.eu (ip-78-45-66-209.bb.vodafone.cz. [78.45.66.209]) by smtp.gmail.com with ESMTPSA id vv11-20020a170907a68b00b009226f644a07sm2009958ejc.139.2023.03.12.16.31.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Mar 2023 16:31:42 -0700 (PDT) From: Erico Nunes To: Qiang Yu , dri-devel@lists.freedesktop.org Subject: [PATCH 2/3] drm/lima: allocate unique id per drm_file Date: Mon, 13 Mar 2023 00:30:51 +0100 Message-Id: <20230312233052.21095-3-nunes.erico@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230312233052.21095-1-nunes.erico@gmail.com> References: <20230312233052.21095-1-nunes.erico@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Airlie , Erico Nunes , lima@lists.freedesktop.org, linux-kernel@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To track if fds are pointing to the same execution context and export the expected information to fdinfo, similar to what is done in other drivers. Signed-off-by: Erico Nunes --- drivers/gpu/drm/lima/lima_device.h | 3 +++ drivers/gpu/drm/lima/lima_drv.c | 12 ++++++++++++ drivers/gpu/drm/lima/lima_drv.h | 1 + 3 files changed, 16 insertions(+) diff --git a/drivers/gpu/drm/lima/lima_device.h b/drivers/gpu/drm/lima/lima_device.h index 41b9d7b4bcc7..71b2db60d161 100644 --- a/drivers/gpu/drm/lima/lima_device.h +++ b/drivers/gpu/drm/lima/lima_device.h @@ -106,6 +106,9 @@ struct lima_device { struct lima_dump_head dump; struct list_head error_task_list; struct mutex error_task_list_lock; + + struct xarray active_contexts; + u32 next_context_id; }; static inline struct lima_device * diff --git a/drivers/gpu/drm/lima/lima_drv.c b/drivers/gpu/drm/lima/lima_drv.c index 7b8d7178d09a..d23c0b77a252 100644 --- a/drivers/gpu/drm/lima/lima_drv.c +++ b/drivers/gpu/drm/lima/lima_drv.c @@ -218,6 +218,11 @@ static int lima_drm_driver_open(struct drm_device *dev, struct drm_file *file) if (!priv) return -ENOMEM; + err = xa_alloc_cyclic(&ldev->active_contexts, &priv->id, priv, + xa_limit_32b, &ldev->next_context_id, GFP_KERNEL); + if (err < 0) + goto err_out0; + priv->vm = lima_vm_create(ldev); if (!priv->vm) { err = -ENOMEM; @@ -237,6 +242,9 @@ static int lima_drm_driver_open(struct drm_device *dev, struct drm_file *file) static void lima_drm_driver_postclose(struct drm_device *dev, struct drm_file *file) { struct lima_drm_priv *priv = file->driver_priv; + struct lima_device *ldev = to_lima_dev(dev); + + xa_erase(&ldev->active_contexts, priv->id); lima_ctx_mgr_fini(&priv->ctx_mgr); lima_vm_put(priv->vm); @@ -388,6 +396,8 @@ static int lima_pdev_probe(struct platform_device *pdev) ldev->dev = &pdev->dev; ldev->id = (enum lima_gpu_id)of_device_get_match_data(&pdev->dev); + xa_init_flags(&ldev->active_contexts, XA_FLAGS_ALLOC); + platform_set_drvdata(pdev, ldev); /* Allocate and initialize the DRM device. */ @@ -444,6 +454,8 @@ static int lima_pdev_remove(struct platform_device *pdev) struct lima_device *ldev = platform_get_drvdata(pdev); struct drm_device *ddev = ldev->ddev; + xa_destroy(&ldev->active_contexts); + sysfs_remove_bin_file(&ldev->dev->kobj, &lima_error_state_attr); drm_dev_unregister(ddev); diff --git a/drivers/gpu/drm/lima/lima_drv.h b/drivers/gpu/drm/lima/lima_drv.h index c738d288547b..e49b7ab651d0 100644 --- a/drivers/gpu/drm/lima/lima_drv.h +++ b/drivers/gpu/drm/lima/lima_drv.h @@ -20,6 +20,7 @@ struct lima_sched_task; struct drm_lima_gem_submit_bo; struct lima_drm_priv { + int id; struct lima_vm *vm; struct lima_ctx_mgr ctx_mgr; }; From patchwork Sun Mar 12 23:30:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Erico Nunes X-Patchwork-Id: 13171897 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E6772C6FD19 for ; Sun, 12 Mar 2023 23:31:52 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0D32E10E446; Sun, 12 Mar 2023 23:31:48 +0000 (UTC) Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6AD8910E441; Sun, 12 Mar 2023 23:31:46 +0000 (UTC) Received: by mail-ed1-x533.google.com with SMTP id g10so13052473eda.1; Sun, 12 Mar 2023 16:31:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678663905; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fhdKUD0TAzd/uf+JAXT2IFzkYdIwo6ITZjySQ+D1PHE=; b=azPy5XcGlzr++jtHV3Dz2BfDG54xn1DZmdZVW/yrxOPDggNzgdJCe5NY/N53tgfy5y 5ylErCksi1wEOEr9GpO1WtOqQ+TYwO+/oHNzuwjvSoheLsq7bj9ZViSJdmWOX3okfz3O AYnYl64mFt4m/NqNtAzN8lRCzTQYp0jlwYR8S/ItddVUV5lyH5ACOVuo5/rmCol7a1dD R14jFVP+Fji9b/FiVFFwdP1ExLJPFKH6x2PTDnd/uIEFeOiyj5m7EoBjDmlspAqUveDD nWF1LYVIdpve7VMYQ5b/MM57G8ONaFV91d5kOWspMK2fl9SogHMYE9J5X1tm+cvjjZuI +MJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678663905; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fhdKUD0TAzd/uf+JAXT2IFzkYdIwo6ITZjySQ+D1PHE=; b=vJ6m8m5KPjU3rpyueSYClDkeNRVIFZJF36YEXSY1epRU2L/qp8FI8Hv21acYWgIBAU p8IytDs6UvRkDNgEYX4Dh8TFAfWkrEac6yKxeVZ52g4LLFMmVgDTfhCYuvnfvCwbFX7X /p617Mcn6Q5waXNw8S5691NBaa3lYXPOC0aHfxOm+Y3x5A8wW2PjK+N0NOw/udGeCfkA 3RnQcpNt/XQ8hokRqelBHomC0XiRJoMVUGidfoydh3g4OvH4itWBEvGcJIvbbkPWY7Om hAI4yyenkA8i68FN8WV3BoChhUdykvLrWqCe2f9MfiD+B5nEHG8bksdixFCdGEW9255o kTnQ== X-Gm-Message-State: AO0yUKWkXTh8+d7eV38g8qNGICy2nsKU5zw3WHKyvJP9PZ6cxK8Ckuks GU4kZnK97hjCwpU4w0A8FRY= X-Google-Smtp-Source: AK7set+nzU3s/+PxT8hDjsADugoTfEsghkmA9lYqthx06STAreKzJ43EtL1b8gNvii1ClfkTzC5WYQ== X-Received: by 2002:a17:907:7f12:b0:928:d4f6:6f7b with SMTP id qf18-20020a1709077f1200b00928d4f66f7bmr2138268ejc.66.1678663904834; Sun, 12 Mar 2023 16:31:44 -0700 (PDT) Received: from centennial.enunes.eu (ip-78-45-66-209.bb.vodafone.cz. [78.45.66.209]) by smtp.gmail.com with ESMTPSA id vv11-20020a170907a68b00b009226f644a07sm2009958ejc.139.2023.03.12.16.31.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Mar 2023 16:31:43 -0700 (PDT) From: Erico Nunes To: Qiang Yu , dri-devel@lists.freedesktop.org Subject: [PATCH 3/3] drm/lima: add show_fdinfo for drm usage stats Date: Mon, 13 Mar 2023 00:30:52 +0100 Message-Id: <20230312233052.21095-4-nunes.erico@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230312233052.21095-1-nunes.erico@gmail.com> References: <20230312233052.21095-1-nunes.erico@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Airlie , Erico Nunes , lima@lists.freedesktop.org, linux-kernel@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This exposes an accumulated active time per client via the fdinfo infrastructure per execution engine, following Documentation/gpu/drm-usage-stats.rst. In lima, the exposed execution engines are gp and pp. Signed-off-by: Erico Nunes --- drivers/gpu/drm/lima/lima_drv.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/lima/lima_drv.c b/drivers/gpu/drm/lima/lima_drv.c index d23c0b77a252..c044a31493a4 100644 --- a/drivers/gpu/drm/lima/lima_drv.c +++ b/drivers/gpu/drm/lima/lima_drv.c @@ -261,7 +261,36 @@ static const struct drm_ioctl_desc lima_drm_driver_ioctls[] = { DRM_IOCTL_DEF_DRV(LIMA_CTX_FREE, lima_ioctl_ctx_free, DRM_RENDER_ALLOW), }; -DEFINE_DRM_GEM_FOPS(lima_drm_driver_fops); +static void lima_drm_driver_show_fdinfo(struct seq_file *m, struct file *filp) +{ + struct drm_file *file = filp->private_data; + struct drm_device *dev = file->minor->dev; + struct lima_device *ldev = dev->dev_private; + struct lima_drm_priv *priv = file->driver_priv; + struct lima_ctx_mgr *ctx_mgr = &priv->ctx_mgr; + u64 usage[lima_pipe_num]; + + lima_ctx_mgr_usage(ctx_mgr, usage); + + /* + * For a description of the text output format used here, see + * Documentation/gpu/drm-usage-stats.rst. + */ + seq_printf(m, "drm-driver:\t%s\n", dev->driver->name); + seq_printf(m, "drm-client-id:\t%u\n", priv->id); + for (int i = 0; i < lima_pipe_num; i++) { + struct lima_sched_pipe *pipe = &ldev->pipe[i]; + struct drm_gpu_scheduler *sched = &pipe->base; + + seq_printf(m, "drm-engine-%s:\t%llu ns\n", sched->name, usage[i]); + } +} + +static const struct file_operations lima_drm_driver_fops = { + .owner = THIS_MODULE, + DRM_GEM_FOPS, + .show_fdinfo = lima_drm_driver_show_fdinfo, +}; /* * Changelog: