From patchwork Wed Apr 12 22:42:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 82697 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp643624vqo; Wed, 12 Apr 2023 15:46:57 -0700 (PDT) X-Google-Smtp-Source: AKy350bJ2HEfn9mbzZykLChfcItvHFf2G7d8n+9XWfLrnobjhqxD77m/4fv4nMRdbzBctybWmJxt X-Received: by 2002:a17:90b:10f:b0:244:af48:c4f3 with SMTP id p15-20020a17090b010f00b00244af48c4f3mr4151847pjz.7.1681339617345; Wed, 12 Apr 2023 15:46:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681339617; cv=none; d=google.com; s=arc-20160816; b=RM/03GfuX1iTzPooheXxB5ue43gdM7jpyZKCkClxHZ84VyUKQE1sUKDVTgJuNtK8aZ 1GgnOjWwQYbZJA3q9X6JJaH/9NzIrmxlKxkM/ZbPG5x7sgm/1bPYMQH9Umiw2NdXKxCi hohegUjQX3dvCYr2SM/RCxypD20tIvpGf2TXatHHhidA3MkQcf+fs8PDVGFtQ1V0WxZQ EPKfgUNTn3cjwM8a9VJm9xDav/e5KetsXIHoto6MYgLcdBITzNaz4x16aGJNop7YW1Y8 LHMLBpvOVmjnsa34TaOItEF5/Ip3H8w+be/j7Cbjiiu1Gy4LfYHhyzyMI5gTwVircKZM 7jJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/p/qDE2ikX+16GISXMOf5Sx657qFQJnEhjHYRNC2x2w=; b=SxXcl5RXltxT23nf4kYh8eC03MTuVRvMABeEPLQhk/sCBRUjlBTFaXoMHrQQ3yufP4 1ZVfR5Sci2heoAylZ36PmFIVct6cuuC9z0JGbAuVTN0WO6M5xayuXQHjdZ7ciBbSI6zn SSI87mjLLEK1cQF4IO81YrMUcNEvZ8SemdIFo9gM0AUm2YwnM/ua+TTa89ph2B151yri 360ZDyysk/G2au2++GaSqyxlsTWfRE4UcfWLTds1wka05A46VjmU1G7i5fFI+xUvj8Fk F+bDk8grGM9HMDdi615i2/wo26rWbKe0kdtcLaVGOEgNdFhVYzKrGjFk9d7nrk8nrA/+ O36Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=l4NSCNVB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h3-20020a17090ac38300b00246f9af56e6si172368pjt.76.2023.04.12.15.46.44; Wed, 12 Apr 2023 15:46:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=l4NSCNVB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229628AbjDLWnZ (ORCPT + 99 others); Wed, 12 Apr 2023 18:43:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229553AbjDLWnY (ORCPT ); Wed, 12 Apr 2023 18:43:24 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09D6B65B3; Wed, 12 Apr 2023 15:43:23 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id pc4-20020a17090b3b8400b0024676052044so13296732pjb.1; Wed, 12 Apr 2023 15:43:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681339402; 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=/p/qDE2ikX+16GISXMOf5Sx657qFQJnEhjHYRNC2x2w=; b=l4NSCNVBJ9Ay1odXd9M9YvurdYkrA4QQ8XIRYugfEVRjK1SiCvU60Ff89JKg+FqyIn U0QLFE+z+lHrl14haFZmuYAVNGQIoxw/hrNA6dknnmbd9sZ4wWdAlqPtz3HAUEtouKF2 /LwdtqJL2YU11YrrMJI/+qOlp0+wJ/1r24weHBT9AR6aTIa4qO+7Nwq/NGsGTH0VD3vt kW+kqp2ZXUGf/Xb02D+cRtpFiUOwPa8CHEs2A2MJv1nvQutZvSxHGL46wUljAVdPrt02 mBm1p3Eync8pH3zkqFzDsCJ9TxHsgYHFrsPe/gnq2ygMTWTchdlIl4v8/wmsJ/3L5eWV WYDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681339402; 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=/p/qDE2ikX+16GISXMOf5Sx657qFQJnEhjHYRNC2x2w=; b=aQ56aYmmV06T2vsqh6J50rkFg0ZVA5AJm2OfNnolSNdA9HcW5s5ldCbN9EbEeGjnWD pLP58V39WBN7CjQxt11oTk5+or5QozrubqUZOs4kGZMJx7s1PjnEhKD7U8fvqgDuyPR9 mC2nsH1jCaN6SlRinF8Nmn0jx+wOIDGthcOcCj5N/7PEK78s3jDnUNxlV4qxUq6ces8i ivULMaalEy4Zc6VHUI5Zfy/aLcx4XUGYa8uC2DHgyLKpOZSvQfLNJA7+y4eLamOEJHCt m6vfpnY1GhFVu2o34f/guBijzOvS2/VSUqgtBiesRSuHk7M16/JQlXNVQVmb0T+bN5g1 bnoQ== X-Gm-Message-State: AAQBX9d9hYZEQZQ+K0wPZPtnd10JraEqZpTOtk3eqKzkSozus4ZnX9m1 VVv2IAATrLubX1KSyl3+qpE= X-Received: by 2002:a17:903:7c6:b0:1a6:52f9:d4c7 with SMTP id ko6-20020a17090307c600b001a652f9d4c7mr370020plb.60.1681339402470; Wed, 12 Apr 2023 15:43:22 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id m7-20020a1709026bc700b0019a5aa7eab0sm102772plt.54.2023.04.12.15.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 15:43:22 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, Boris Brezillon , Tvrtko Ursulin , Christopher Healy , Emil Velikov , =?utf-8?q?Christian_K=C3=B6nig?= , Daniel Vetter , Rob Clark , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , linux-doc@vger.kernel.org (open list:DOCUMENTATION), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v4 1/6] drm: Add common fdinfo helper Date: Wed, 12 Apr 2023 15:42:53 -0700 Message-Id: <20230412224311.23511-2-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230412224311.23511-1-robdclark@gmail.com> References: <20230412224311.23511-1-robdclark@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763012371045315512?= X-GMAIL-MSGID: =?utf-8?q?1763012371045315512?= From: Rob Clark Handle a bit of the boiler-plate in a single case, and make it easier to add some core tracked stats. v2: Update drm-usage-stats.rst, 64b client-id, rename drm_show_fdinfo Reviewed-by: Daniel Vetter Signed-off-by: Rob Clark --- Documentation/gpu/drm-usage-stats.rst | 10 +++++++- drivers/gpu/drm/drm_file.c | 35 +++++++++++++++++++++++++++ include/drm/drm_drv.h | 7 ++++++ include/drm/drm_file.h | 4 +++ 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/Documentation/gpu/drm-usage-stats.rst b/Documentation/gpu/drm-usage-stats.rst index b46327356e80..2ab32c40e93c 100644 --- a/Documentation/gpu/drm-usage-stats.rst +++ b/Documentation/gpu/drm-usage-stats.rst @@ -126,7 +126,15 @@ percentage utilization of the engine, whereas drm-engine- only reflects time active without considering what frequency the engine is operating as a percentage of it's maximum frequency. +Implementation Details +====================== + +Drivers should use drm_show_fdinfo() in their `struct file_operations`, and +implement &drm_driver.show_fdinfo if they wish to provide any stats which +are not provided by drm_show_fdinfo(). But even driver specific stats should +be documented above and where possible, aligned with other drivers. + Driver specific implementations -=============================== +------------------------------- :ref:`i915-usage-stats` diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c index a51ff8cee049..6d5bdd684ae2 100644 --- a/drivers/gpu/drm/drm_file.c +++ b/drivers/gpu/drm/drm_file.c @@ -148,6 +148,7 @@ bool drm_dev_needs_global_mutex(struct drm_device *dev) */ struct drm_file *drm_file_alloc(struct drm_minor *minor) { + static atomic64_t ident = ATOMIC_INIT(0); struct drm_device *dev = minor->dev; struct drm_file *file; int ret; @@ -156,6 +157,8 @@ struct drm_file *drm_file_alloc(struct drm_minor *minor) if (!file) return ERR_PTR(-ENOMEM); + /* Get a unique identifier for fdinfo: */ + file->client_id = atomic64_inc_return(&ident); file->pid = get_pid(task_pid(current)); file->minor = minor; @@ -868,6 +871,38 @@ void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) } EXPORT_SYMBOL(drm_send_event); +/** + * drm_show_fdinfo - helper for drm file fops + * @seq_file: output stream + * @f: the device file instance + * + * Helper to implement fdinfo, for userspace to query usage stats, etc, of a + * process using the GPU. See also &drm_driver.show_fdinfo. + * + * For text output format description please see Documentation/gpu/drm-usage-stats.rst + */ +void drm_show_fdinfo(struct seq_file *m, struct file *f) +{ + struct drm_file *file = f->private_data; + struct drm_device *dev = file->minor->dev; + struct drm_printer p = drm_seq_file_printer(m); + + drm_printf(&p, "drm-driver:\t%s\n", dev->driver->name); + drm_printf(&p, "drm-client-id:\t%llu\n", file->client_id); + + if (dev_is_pci(dev->dev)) { + struct pci_dev *pdev = to_pci_dev(dev->dev); + + drm_printf(&p, "drm-pdev:\t%04x:%02x:%02x.%d\n", + pci_domain_nr(pdev->bus), pdev->bus->number, + PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); + } + + if (dev->driver->show_fdinfo) + dev->driver->show_fdinfo(&p, file); +} +EXPORT_SYMBOL(drm_show_fdinfo); + /** * mock_drm_getfile - Create a new struct file for the drm device * @minor: drm minor to wrap (e.g. #drm_device.primary) diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h index 5b86bb7603e7..5edf2a13733b 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -401,6 +401,13 @@ struct drm_driver { struct drm_device *dev, uint32_t handle, uint64_t *offset); + /** + * @show_fdinfo: + * + * Print device specific fdinfo. See Documentation/gpu/drm-usage-stats.rst. + */ + void (*show_fdinfo)(struct drm_printer *p, struct drm_file *f); + /** @major: driver major number */ int major; /** @minor: driver minor number */ diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index 0d1f853092ab..6de6d0e9c634 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -258,6 +258,9 @@ struct drm_file { /** @pid: Process that opened this file. */ struct pid *pid; + /** @client_id: A unique id for fdinfo */ + u64 client_id; + /** @magic: Authentication magic, see @authenticated. */ drm_magic_t magic; @@ -437,6 +440,7 @@ void drm_send_event(struct drm_device *dev, struct drm_pending_event *e); void drm_send_event_timestamp_locked(struct drm_device *dev, struct drm_pending_event *e, ktime_t timestamp); +void drm_show_fdinfo(struct seq_file *m, struct file *f); struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags); From patchwork Wed Apr 12 22:42:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 82702 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp655691vqo; Wed, 12 Apr 2023 16:08:00 -0700 (PDT) X-Google-Smtp-Source: AKy350YljGDTsiDCfGAusICt5Q3BaZfKho6vAx7G+pno4lISfQtOEMxa7xya+7y+UJbDE0l/xrKs X-Received: by 2002:a17:906:4409:b0:94e:3d6f:9c0f with SMTP id x9-20020a170906440900b0094e3d6f9c0fmr525218ejo.55.1681340880300; Wed, 12 Apr 2023 16:08:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681340880; cv=none; d=google.com; s=arc-20160816; b=XA5tg5GHQxCFnRIL2ZGhzllWV6aYFLsVe3KohwgLl/7j25UcgpWlV/yh/HqaLhwkAy 5FznLkI0YJy5KOrCZdEL/4yyFTaqkGkryGG5Bq1ptvyI8bRWB1/vilxJ2bdXhWsPjVuh kkXf+xtjMZdlCmSXHc4GbKwQ0tVCfkUMOQHdyLRjlZH4shwxpbDLQPq+L8ehHmqjYInF WpxKYDmdYPPMFRV8KwNkcMekVOxydxv/7tJWbfdsvpU/c5KWNvCbEBNEKBx6ZyqfTUCY 0iqMvFTXp+KMK6S8pT6apL5boKoQ4tJEVTdP5/Xhj07htvmQBQRWpJJ/34OAsgWMcZWM 1YYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=03BOImDDTacTaal3DT5GaR4eYwI41SC6VasRh9AK1Vg=; b=nY6JPZ+Urt5l7REnjSOzfsANrW1TrYyRgQlFRcsgWxhEfZxt8eEB1r3wE8ynAN+aAH gGc9dLWtAvHL6Qi4BBR+sb2qd+IrK3IV9Ds5KflIuq44VAp+Mi0LJA4pJe77E6dZz0Zm Qgvqj5ej1zQxsPWGSHqG64apH5VssNNg78ND4wET+0oNjx6wSR8u2CZ05IefOxEHdnDu +85oCoj774K2Cv2duRlxI6DFqeh8jk4yfp4nfy0JSG+VgMekjawfKnijfPLTYNwBqxer jsLLLtOfDoOq+nmBIhZ1RMG37eiZ/oGm+e5ikQC/+HhFKgg2GZvEdOGHnFRwI7eoLMpi NuNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="I9yPnaR/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u3-20020aa7d983000000b00504a1554d56si80991eds.505.2023.04.12.16.07.36; Wed, 12 Apr 2023 16:08:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="I9yPnaR/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229708AbjDLWn3 (ORCPT + 99 others); Wed, 12 Apr 2023 18:43:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229621AbjDLWnZ (ORCPT ); Wed, 12 Apr 2023 18:43:25 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD0887AA7; Wed, 12 Apr 2023 15:43:24 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id lh8so57555plb.1; Wed, 12 Apr 2023 15:43:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681339404; 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=03BOImDDTacTaal3DT5GaR4eYwI41SC6VasRh9AK1Vg=; b=I9yPnaR/8MyqGS9rBIjdGiMt62y2Ap8jwYETy5y1Nq6+ytk2e+5UeiV/2yXHsY/WZ/ 7i0K1UiVvJXmXESWuFBorANBJ793EWNv/5b4GthU27FtimIESntsOgyokF4SEyrx100q NPMjSwhxJv++VTrsSY8ZH6LFBZYoSekF059fHEKlUfwxzjIzwmjV/Nolk51zmVtsZQV1 x04AWUYGNhq7WjooDmk51P9Wpm2zbyyjEmF6HhtRFexzls27PcNQR4dhac5XNZ4xBpDJ wIobQltTaRx2gVXyXdacy+coT0BatjUR8bwBkeHbFG96jvsJUuozrvf7hn0Y2IRspOdn z5Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681339404; 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=03BOImDDTacTaal3DT5GaR4eYwI41SC6VasRh9AK1Vg=; b=eTStqh9KW7QKHuhPT03RM6W/06Zy3JOMW2+ZAa7AXJZox7sledBewS8O46JgvWoINi 5vA919tD8ukSHlbWCV1QPaUhuOsjeRuPXF8sqT+f74vWC+6KDRgQaJdW539NoySndWoU ccXxXs4pqrjuoWZk4UHkuFdFf7D7+j34IAnEuMVd1q50bkEm2NwBuj1f3BmHKfGYq4zJ vZRNBmIHpcXIcloJOSbCtwJUq8bpe4qR6XyN3X2prRqs6FWYCQAFfgHO8Rh6B+678RLM hos9Ie/+JXJfn2ENBKRBSdQtdHrjsP35mcDDt0Ab2TRDoCcqFBci2SOVYI2oUnz+vIBp sJIg== X-Gm-Message-State: AAQBX9dWrhXIyRNqDtswY0WIlVb0p4kQpjvI+8QmHJjdFr+swxvvOfQM yUiH/zBK0CsWqY5voVv1vQY= X-Received: by 2002:a05:6a20:1b23:b0:ec:2b01:1069 with SMTP id ch35-20020a056a201b2300b000ec2b011069mr506383pzb.45.1681339404416; Wed, 12 Apr 2023 15:43:24 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id l35-20020a635723000000b0051815eae23esm101713pgb.27.2023.04.12.15.43.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 15:43:24 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, Boris Brezillon , Tvrtko Ursulin , Christopher Healy , Emil Velikov , =?utf-8?q?Christian_K=C3=B6nig?= , Daniel Vetter , Rob Clark , Rob Clark , Abhinav Kumar , Dmitry Baryshkov , Sean Paul , David Airlie , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v4 2/6] drm/msm: Switch to fdinfo helper Date: Wed, 12 Apr 2023 15:42:54 -0700 Message-Id: <20230412224311.23511-3-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230412224311.23511-1-robdclark@gmail.com> References: <20230412224311.23511-1-robdclark@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763013694977440968?= X-GMAIL-MSGID: =?utf-8?q?1763013694977440968?= From: Rob Clark Signed-off-by: Rob Clark Reviewed-by: Dmitry Baryshkov --- drivers/gpu/drm/msm/msm_drv.c | 11 +++++------ drivers/gpu/drm/msm/msm_gpu.c | 2 -- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c index 5a10d28de9dd..3d73b98d6a9c 100644 --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -1043,23 +1043,21 @@ static const struct drm_ioctl_desc msm_ioctls[] = { DRM_IOCTL_DEF_DRV(MSM_SUBMITQUEUE_QUERY, msm_ioctl_submitqueue_query, DRM_RENDER_ALLOW), }; -static void msm_fop_show_fdinfo(struct seq_file *m, struct file *f) +static void msm_show_fdinfo(struct drm_printer *p, struct drm_file *file) { - struct drm_file *file = f->private_data; struct drm_device *dev = file->minor->dev; struct msm_drm_private *priv = dev->dev_private; - struct drm_printer p = drm_seq_file_printer(m); if (!priv->gpu) return; - msm_gpu_show_fdinfo(priv->gpu, file->driver_priv, &p); + msm_gpu_show_fdinfo(priv->gpu, file->driver_priv, p); } static const struct file_operations fops = { .owner = THIS_MODULE, DRM_GEM_FOPS, - .show_fdinfo = msm_fop_show_fdinfo, + .show_fdinfo = drm_show_fdinfo, }; static const struct drm_driver msm_driver = { @@ -1070,7 +1068,7 @@ static const struct drm_driver msm_driver = { DRIVER_SYNCOBJ_TIMELINE | DRIVER_SYNCOBJ, .open = msm_open, - .postclose = msm_postclose, + .postclose = msm_postclose, .lastclose = drm_fb_helper_lastclose, .dumb_create = msm_gem_dumb_create, .dumb_map_offset = msm_gem_dumb_map_offset, @@ -1081,6 +1079,7 @@ static const struct drm_driver msm_driver = { #ifdef CONFIG_DEBUG_FS .debugfs_init = msm_debugfs_init, #endif + .show_fdinfo = msm_show_fdinfo, .ioctls = msm_ioctls, .num_ioctls = ARRAY_SIZE(msm_ioctls), .fops = &fops, diff --git a/drivers/gpu/drm/msm/msm_gpu.c b/drivers/gpu/drm/msm/msm_gpu.c index 26ebda40be4f..c403912d13ab 100644 --- a/drivers/gpu/drm/msm/msm_gpu.c +++ b/drivers/gpu/drm/msm/msm_gpu.c @@ -151,8 +151,6 @@ int msm_gpu_pm_suspend(struct msm_gpu *gpu) void msm_gpu_show_fdinfo(struct msm_gpu *gpu, struct msm_file_private *ctx, struct drm_printer *p) { - drm_printf(p, "drm-driver:\t%s\n", gpu->dev->driver->name); - drm_printf(p, "drm-client-id:\t%u\n", ctx->seqno); drm_printf(p, "drm-engine-gpu:\t%llu ns\n", ctx->elapsed_ns); drm_printf(p, "drm-cycles-gpu:\t%llu\n", ctx->cycles); drm_printf(p, "drm-maxfreq-gpu:\t%u Hz\n", gpu->fast_rate); From patchwork Wed Apr 12 22:42:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 82699 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp647827vqo; Wed, 12 Apr 2023 15:55:09 -0700 (PDT) X-Google-Smtp-Source: AKy350Zz/j716NSSMcwGZXlaOULPM1mNr5TCyvuBMXCeWCGvHMsZVhicuzRa6pKCKD3WRd+Kf+jJ X-Received: by 2002:a17:903:22d0:b0:1a5:2fbd:d094 with SMTP id y16-20020a17090322d000b001a52fbdd094mr697284plg.9.1681340109699; Wed, 12 Apr 2023 15:55:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681340109; cv=none; d=google.com; s=arc-20160816; b=zgmDzFxENGlWgcZSx5gaB07Y5rpHVlNXTxrQJcQtrW1dcOM7TlayATyuDs9/3soAO2 9oF1WZhVfgwKr6I6RUj/8aBHAt25pupBOC/DQbarB+3HmTNdaR04WEqUs+8ILTxfpkhz OeV13sGQjOuevPTllPM+PRMxzXHZuJukLOivAFr7sjZ07Y3JsSOhrz0og2Okip+k7zN8 45aReCihp3oS0n/JWfwNfMU7mGJlwwoxYRM/1mwJmjMX1gBtpVktIo5NBRx/gSYbr/cu qLh3RBknzTIrV+AEG6TorUZtY+u+x59FuBFmqnm3Z8F2yMwI9MRVQ7oDCkTq2NwYd12D hNSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1+8Kg/kNPwcKOz+4LjRQVlRin3sixAOkoK4oz+w+/O4=; b=XOCP4xucQGTo4YrIn79m8vuJvN8TRo7Qoec3XAWcBG8Ey2wMpjVcmAcB+rjMVAGw2Z pHVBzQuoQfY/BS18UaK7FIzFt8cCW0IXwdFP8XIF++HOtaextYza7+X2RnacQNmz1uP4 ua5s4KRgb005SzftMVqLqw7LVxaujVyloEElKQ7uSILkNuqADpk6OVLqtEZn/LCSx0cS zTgwsXy4IFvXgigbjnEJiwDxl50vQpYCsvIuxp/5bvOd9lL5vgFh1tz3hX1A4cDbAPoR 9DXWcjtqaaAAEd/GbdKmnmGZ6FUjZK/MIZMntXr8sAzGAYG4mNf0greO6QKHyb/UM0Zo vicA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=KEZxSYnD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u10-20020a170902e5ca00b001a1eac2df75si264673plf.490.2023.04.12.15.54.57; Wed, 12 Apr 2023 15:55:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=KEZxSYnD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229804AbjDLWnh (ORCPT + 99 others); Wed, 12 Apr 2023 18:43:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229736AbjDLWne (ORCPT ); Wed, 12 Apr 2023 18:43:34 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C28E86AA; Wed, 12 Apr 2023 15:43:29 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id pm7-20020a17090b3c4700b00246f00dace2so5302615pjb.2; Wed, 12 Apr 2023 15:43:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681339409; 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=1+8Kg/kNPwcKOz+4LjRQVlRin3sixAOkoK4oz+w+/O4=; b=KEZxSYnDLqbxiIELLgGmH5WMU+InSNSVG5wcXAaTh3Y42Kai/vVgm+obE/d+VM5kMR 1/vISXdfNhzXOwnUEul+zynTB4OW412EM30TggX3KL2jCuWBfmKEJWRxpoBgniuRRXGE +9WhaPFXVY8A/la+25DwEiF/In4QQgD3CTHQ3MEqGuTKbfQYdc3pjJudcDec+VScpF3S 0f1cLJUa5c+ASLHFcKvB64i9fMZeUM1kkSHtsRcYKnpXIPe2aR8tRxGZurOhUc/NLL5K 1Q/HhLYVcmGzTjwJHT83E163fhcEodO8ZMjRkTBNPII/BwdYlQgkw9lW8xwybVynAVUm 5sSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681339409; 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=1+8Kg/kNPwcKOz+4LjRQVlRin3sixAOkoK4oz+w+/O4=; b=CtG1a3geP8O51Ta/inKslTUIr4v6ckIW0FsM6LZSDxPWydPFwRkl52wmxsC4CvsG5k q5R8oxNiqIb4JjNGCCyHloPmXNHUzgBl2eGF1GkprOBC3WtyfuAMRlNwZeHP77dPxSG5 0j32A2lt8xlm3LPS1eNmBcj3MMq1KunZdSrlgpgIveRpIVQC4yHld+/XYwJ6gtH9A+6c 84DvmkEgoECOHn3ewWNukI0WnDdNisKxEy1GCTg//1qsLydvMgqjLatPuGHRFeO+xIub uFX9tPkwh80UmVGqFNL5vPEyPz1cLLSoscN9AKCk0QrM4JEzb6oQrWIhEwKJnXpMZDl3 ONJQ== X-Gm-Message-State: AAQBX9f0g69O4URMWY4u3tZMcPNXBQSFWou/DVHmB9M9Cla+iEmgWWJb eqG3JYtL/Se1DJDWp5ULCxc= X-Received: by 2002:a17:90a:9316:b0:246:b617:c730 with SMTP id p22-20020a17090a931600b00246b617c730mr4167515pjo.39.1681339408823; Wed, 12 Apr 2023 15:43:28 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id jm10-20020a17090304ca00b001a55c2a42f6sm91859plb.158.2023.04.12.15.43.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 15:43:28 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, Boris Brezillon , Tvrtko Ursulin , Christopher Healy , Emil Velikov , =?utf-8?q?Christian_K=C3=B6nig?= , Daniel Vetter , Rob Clark , Alex Deucher , "Pan, Xinhui" , David Airlie , Evan Quan , Hawking Zhang , Mario Limonciello , YiPeng Chai , Guchun Chen , =?utf-8?q?Michel_D=C3=A4nzer?= , Shashank Sharma , Tvrtko Ursulin , Arunpravin Paneer Selvam , amd-gfx@lists.freedesktop.org (open list:RADEON and AMDGPU DRM DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v4 3/6] drm/amdgpu: Switch to fdinfo helper Date: Wed, 12 Apr 2023 15:42:55 -0700 Message-Id: <20230412224311.23511-4-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230412224311.23511-1-robdclark@gmail.com> References: <20230412224311.23511-1-robdclark@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763012886475745258?= X-GMAIL-MSGID: =?utf-8?q?1763012886475745258?= From: Rob Clark Signed-off-by: Rob Clark Reviewed-by: Christian König --- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c | 16 ++++++---------- drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.h | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c index f5ffca24def4..6c0e0c614b94 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c @@ -2752,7 +2752,7 @@ static const struct file_operations amdgpu_driver_kms_fops = { .compat_ioctl = amdgpu_kms_compat_ioctl, #endif #ifdef CONFIG_PROC_FS - .show_fdinfo = amdgpu_show_fdinfo + .show_fdinfo = drm_show_fdinfo, #endif }; @@ -2807,6 +2807,7 @@ static const struct drm_driver amdgpu_kms_driver = { .dumb_map_offset = amdgpu_mode_dumb_mmap, .fops = &amdgpu_driver_kms_fops, .release = &amdgpu_driver_release_kms, + .show_fdinfo = amdgpu_show_fdinfo, .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c index 99a7855ab1bc..c2fdd5e448d1 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c @@ -53,9 +53,8 @@ static const char *amdgpu_ip_name[AMDGPU_HW_IP_NUM] = { [AMDGPU_HW_IP_VCN_JPEG] = "jpeg", }; -void amdgpu_show_fdinfo(struct seq_file *m, struct file *f) +void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file) { - struct drm_file *file = f->private_data; struct amdgpu_device *adev = drm_to_adev(file->minor->dev); struct amdgpu_fpriv *fpriv = file->driver_priv; struct amdgpu_vm *vm = &fpriv->vm; @@ -86,18 +85,15 @@ void amdgpu_show_fdinfo(struct seq_file *m, struct file *f) * ****************************************************************** */ - seq_printf(m, "pasid:\t%u\n", fpriv->vm.pasid); - seq_printf(m, "drm-driver:\t%s\n", file->minor->dev->driver->name); - seq_printf(m, "drm-pdev:\t%04x:%02x:%02x.%d\n", domain, bus, dev, fn); - seq_printf(m, "drm-client-id:\t%Lu\n", vm->immediate.fence_context); - seq_printf(m, "drm-memory-vram:\t%llu KiB\n", vram_mem/1024UL); - seq_printf(m, "drm-memory-gtt: \t%llu KiB\n", gtt_mem/1024UL); - seq_printf(m, "drm-memory-cpu: \t%llu KiB\n", cpu_mem/1024UL); + drm_printf(p, "pasid:\t%u\n", fpriv->vm.pasid); + drm_printf(p, "drm-memory-vram:\t%llu KiB\n", vram_mem/1024UL); + drm_printf(p, "drm-memory-gtt: \t%llu KiB\n", gtt_mem/1024UL); + drm_printf(p, "drm-memory-cpu: \t%llu KiB\n", cpu_mem/1024UL); for (hw_ip = 0; hw_ip < AMDGPU_HW_IP_NUM; ++hw_ip) { if (!usage[hw_ip]) continue; - seq_printf(m, "drm-engine-%s:\t%Ld ns\n", amdgpu_ip_name[hw_ip], + drm_printf(p, "drm-engine-%s:\t%Ld ns\n", amdgpu_ip_name[hw_ip], ktime_to_ns(usage[hw_ip])); } } diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.h index e86834bfea1d..0398f5a159ef 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.h @@ -37,6 +37,6 @@ #include "amdgpu_ids.h" uint32_t amdgpu_get_ip_count(struct amdgpu_device *adev, int id); -void amdgpu_show_fdinfo(struct seq_file *m, struct file *f); +void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file); #endif From patchwork Wed Apr 12 22:42:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 82698 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp647509vqo; Wed, 12 Apr 2023 15:54:31 -0700 (PDT) X-Google-Smtp-Source: AKy350aFkCwRRUtMY8ZudEneuvFrimpxjsGZtVb5ZsyfFlm6fBph7fxPLhodyEHw2mgD5TlN/Q4D X-Received: by 2002:a17:90a:e38d:b0:23f:7625:49b6 with SMTP id b13-20020a17090ae38d00b0023f762549b6mr843659pjz.37.1681340071524; Wed, 12 Apr 2023 15:54:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681340071; cv=none; d=google.com; s=arc-20160816; b=ebu5hdqOLyDCZ+jJimblCC0OCW9cXrbGFGu8E7kkUrosPMdJcQI+ygmp8DOEtonskt dv0crHxC9lOJQnfp8lSXVZ9nkyqBAKh1LKQAHuj2BRW9O+ptX1dntpmeNkxaqIkGMw1t DrR7lKKHqEx74AUSpKwMh4Jedqf0X9hwsW2e1ZwK5QleA9olqBOqY+aWGRGuDDLKbMlo +gKajRhfUzqQx4pJZLaJBPndVghvGycvuHkhvqpQuP6NuHbKC4+DYQqACVl1ElkCGtaB MqY24y3C1mGhHhk9vyh+aeDtPmMTWNZ0ZofYNkm8P4KndkdDH23cCzkuDHKrU75E674i TFkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vkssoMCH0JBHP5vQQ5/soNqQdOvnZ6jaRR6/QM733LA=; b=qfOjkudAAX70Nc6+eJWZOZ9XcpbIfLUN7qUUToByPrB+wVB7/pEaVJj63J5br2cvBE i0NS5MM+GWtHV9LNLbjGTTsblpcibgSAJZqOSDaZJVfbu9zf2w3wnuxhWjv+RLYwM2i6 +t++B1f3BKKFyt4Y79IEcD3kV55+6QpwfKdwKlEAzEMtFpUZNNuQXVXTp/oNrPZEeN28 elGRHZELD7j4a/0yYS9AyW1oxIEOusZlhKU7VoHgR8XpGWRNsDYLBwQ0l+2rm8XNiqJq sARe4HRuLAyt01sZrIorgtyfFceMJj5k2y11+mOpZXWt5Eldi+rP7XMJ/GoofJb2lXua 3zqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=CN2Lu5bk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fw2-20020a17090b128200b0022c24bf1810si229402pjb.29.2023.04.12.15.54.18; Wed, 12 Apr 2023 15:54:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=CN2Lu5bk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229593AbjDLWoB (ORCPT + 99 others); Wed, 12 Apr 2023 18:44:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229773AbjDLWno (ORCPT ); Wed, 12 Apr 2023 18:43:44 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AACE8A5F; Wed, 12 Apr 2023 15:43:35 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1a661032878so2617885ad.2; Wed, 12 Apr 2023 15:43:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681339415; 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=vkssoMCH0JBHP5vQQ5/soNqQdOvnZ6jaRR6/QM733LA=; b=CN2Lu5bkY+MGZCbxwRhM4EnjEolwajayHfLudHbz9tBs33RQgILaEi5P6Qxw8qyguN xoWnK90QAZ9zgi3uJgybS58pTFgOPDC0i/Y6N/CC9/JxdBnW/Xko5eF5195pN+o96lOt B3t6MqVZRv401aFbp97LgzPPX3z/TcwK390iW3z2Gf8xXjmYrFOQ/B4oOjWKzqnHTa96 GN/9Aoqri3BO7s/4Byeu1KOHWVLYt/NMY37imHJ+YbzDNqT6SjvT1Ibylkrd6+wKdab4 3/7Ke0vXSk9PbKxS52tVBdr3grAT7reP701Rx6Wi78SSX9YiFQ/Ur9GJnzcZXFXOKmZK sFUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681339415; 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=vkssoMCH0JBHP5vQQ5/soNqQdOvnZ6jaRR6/QM733LA=; b=VtFqWePPpC7CIINakTi/QzNnll6Z77fYp0A8lWbymhjR6rTrRmnk4Mbpj6uJ4PE5SZ LgKljiWMLm7tvMN+lxyMyOY+4oMxEWrnIeBYvWp7Y16Fh1ngC0rek3OH5yIG67j9rFjU hc/omUkpF7USnWluz29YKXcwRpBOc6UjaVB0coV/XEA5FOtA379vsMShDux+CRxRwYUD KYoJbC0aUCwAU3DBk1f2LKFmeCBLZt4qs/9BzqIeivF3MtcxPWB9Fn4RdVKj1XcWJq32 YgZ7XEFKcKPJtcLhL8AnBlmTwq0j/9CEc4CQ67pmMbMHRWXT55BnyI5kTVR4aLDoIUWm ZKNw== X-Gm-Message-State: AAQBX9enJNpRuJTZsB/pRz11V7IDj3Gd9ysKf3G2nVX9zmDDR5jNyrLL ScRuwV/LM8MykagKh9L1SiE= X-Received: by 2002:a05:6a00:16c1:b0:636:4523:da93 with SMTP id l1-20020a056a0016c100b006364523da93mr529335pfc.12.1681339414895; Wed, 12 Apr 2023 15:43:34 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id w30-20020a63161e000000b00517f165d0a6sm114761pgl.4.2023.04.12.15.43.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 15:43:34 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, Boris Brezillon , Tvrtko Ursulin , Christopher Healy , Emil Velikov , =?utf-8?q?Christian_K=C3=B6nig?= , Daniel Vetter , Rob Clark , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , David Airlie , intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org (open list) Subject: [PATCH v4 4/6] drm/i915: Switch to fdinfo helper Date: Wed, 12 Apr 2023 15:42:56 -0700 Message-Id: <20230412224311.23511-5-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230412224311.23511-1-robdclark@gmail.com> References: <20230412224311.23511-1-robdclark@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763012846863571431?= X-GMAIL-MSGID: =?utf-8?q?1763012846863571431?= From: Rob Clark Signed-off-by: Rob Clark --- drivers/gpu/drm/i915/i915_driver.c | 3 ++- drivers/gpu/drm/i915/i915_drm_client.c | 18 +++++------------- drivers/gpu/drm/i915/i915_drm_client.h | 2 +- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_driver.c b/drivers/gpu/drm/i915/i915_driver.c index db7a86def7e2..0d91f85f8b97 100644 --- a/drivers/gpu/drm/i915/i915_driver.c +++ b/drivers/gpu/drm/i915/i915_driver.c @@ -1696,7 +1696,7 @@ static const struct file_operations i915_driver_fops = { .compat_ioctl = i915_ioc32_compat_ioctl, .llseek = noop_llseek, #ifdef CONFIG_PROC_FS - .show_fdinfo = i915_drm_client_fdinfo, + .show_fdinfo = drm_show_fdinfo, #endif }; @@ -1796,6 +1796,7 @@ static const struct drm_driver i915_drm_driver = { .open = i915_driver_open, .lastclose = i915_driver_lastclose, .postclose = i915_driver_postclose, + .show_fdinfo = i915_drm_client_fdinfo, .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c index b09d1d386574..4a77e5e47f79 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.c +++ b/drivers/gpu/drm/i915/i915_drm_client.c @@ -101,7 +101,7 @@ static u64 busy_add(struct i915_gem_context *ctx, unsigned int class) } static void -show_client_class(struct seq_file *m, +show_client_class(struct drm_printer *p, struct i915_drm_client *client, unsigned int class) { @@ -117,22 +117,20 @@ show_client_class(struct seq_file *m, rcu_read_unlock(); if (capacity) - seq_printf(m, "drm-engine-%s:\t%llu ns\n", + drm_printf(p, "drm-engine-%s:\t%llu ns\n", uabi_class_names[class], total); if (capacity > 1) - seq_printf(m, "drm-engine-capacity-%s:\t%u\n", + drm_printf(p, "drm-engine-capacity-%s:\t%u\n", uabi_class_names[class], capacity); } -void i915_drm_client_fdinfo(struct seq_file *m, struct file *f) +void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file) { - struct drm_file *file = f->private_data; struct drm_i915_file_private *file_priv = file->driver_priv; struct drm_i915_private *i915 = file_priv->dev_priv; struct i915_drm_client *client = file_priv->client; - struct pci_dev *pdev = to_pci_dev(i915->drm.dev); unsigned int i; /* @@ -141,12 +139,6 @@ void i915_drm_client_fdinfo(struct seq_file *m, struct file *f) * ****************************************************************** */ - seq_printf(m, "drm-driver:\t%s\n", i915->drm.driver->name); - seq_printf(m, "drm-pdev:\t%04x:%02x:%02x.%d\n", - pci_domain_nr(pdev->bus), pdev->bus->number, - PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); - seq_printf(m, "drm-client-id:\t%u\n", client->id); - /* * Temporarily skip showing client engine information with GuC submission till * fetching engine busyness is implemented in the GuC submission backend @@ -155,6 +147,6 @@ void i915_drm_client_fdinfo(struct seq_file *m, struct file *f) return; for (i = 0; i < ARRAY_SIZE(uabi_class_names); i++) - show_client_class(m, client, i); + show_client_class(p, client, i); } #endif diff --git a/drivers/gpu/drm/i915/i915_drm_client.h b/drivers/gpu/drm/i915/i915_drm_client.h index 69496af996d9..ef85fef45de5 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.h +++ b/drivers/gpu/drm/i915/i915_drm_client.h @@ -60,7 +60,7 @@ static inline void i915_drm_client_put(struct i915_drm_client *client) struct i915_drm_client *i915_drm_client_add(struct i915_drm_clients *clients); #ifdef CONFIG_PROC_FS -void i915_drm_client_fdinfo(struct seq_file *m, struct file *f); +void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file); #endif void i915_drm_clients_fini(struct i915_drm_clients *clients); From patchwork Wed Apr 12 22:42:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 82700 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp654517vqo; Wed, 12 Apr 2023 16:06:09 -0700 (PDT) X-Google-Smtp-Source: AKy350bAoszwIRAY6LcV0P4ApQhmsUCCCB3X2t/GA0ouxtta6Lttrs/bOf9rHfwZq9Nv8t26RBfa X-Received: by 2002:aa7:db50:0:b0:504:e176:8d22 with SMTP id n16-20020aa7db50000000b00504e1768d22mr430956edt.4.1681340769483; Wed, 12 Apr 2023 16:06:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681340769; cv=none; d=google.com; s=arc-20160816; b=QSqScxLk+uLolW+JO2kn2+GqHZtviN+AfwXTAyX/isM3SZmiT7vhgCkzhjsbWMFLmo Tbf6uMaQB9ezIf6wuOqnCHPlgCFymtMobcG1I62h2GrWBtD6adG5tq3z3bmiu84UnyyM XFIom689Qipna/S5DT7VzOG+E421WKawIfh/4rL8RvqwuKtCVp8jw3kSnCkwFKGzmC9e qG3N6snm/Ik6DNk6mMtESe3TxJzBy5yO1vxgTpJLhfbbbfX19WgHuBNve7ptuoinbgJW ifBekxOFuJDwcL5vlaJroJOfrdxXQK8pQQbER+9yjUPmHwCgD5AjxWmijyIboDZaDKBl n0lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=geumVPtdfdeonNbJRvQRqI8DZnvMBPVyWVWG9NtZCuE=; b=Hw5U1Pog5TzZiy/kGCP6W/PIXajSgmPlnxms4xE6wXJIpLFY8M0rAvOQItdP9gZfvw yxqjFO0BenV5BVdY/5RKw1HIvSMz+fPhFjlokmHyj2acsa48RtK352UCb7GpQPvfhTab n0YJmoBBEKx1NldexPcj39jp3vk2mFpRDuOPsec7yQmX9/9XGIn6Bnx/xgAKbk1bIeGT aMT9jsM8IC+KZNGVa6KlMLf4pPQVsMnMuFbY5Dtyi0JfeFJYqTafhCgW5QJs5Eld3KpM A9iWBWM6oTTWeFKqM71P7pq5u8eN1V9YhbJ+XnpCJ+23c/I33irh4TDQTbKK+d9CW0Dt EiVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=ATps2cQz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g14-20020a170906198e00b0094a4e970513si80514ejd.739.2023.04.12.16.05.41; Wed, 12 Apr 2023 16:06:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=ATps2cQz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229638AbjDLWoD (ORCPT + 99 others); Wed, 12 Apr 2023 18:44:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229897AbjDLWns (ORCPT ); Wed, 12 Apr 2023 18:43:48 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D76B7DB9; Wed, 12 Apr 2023 15:43:37 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-51870e745bfso782479a12.2; Wed, 12 Apr 2023 15:43:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681339417; 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=geumVPtdfdeonNbJRvQRqI8DZnvMBPVyWVWG9NtZCuE=; b=ATps2cQzsHjp2Awpl3uuwTjgh7vygigJUTrlBrNgwlzPytl1gYSdhpkH8e0PjnFWFU kAODEM4CPn0vunvQGMwPw7W57CANlRTN1eMEB4bs+TZCtsxhR3IPkrXpyzbPCWSW8tRl BdzHrm1X3RWXwDmNOOYE9+H/tAHvcxxdxVHEC8r0m5E/4zTcwnonBVaM4WMB9ry8c7Lv 6ENttFGk7zdFWXvyOm3iV4/XAKOvg8e+4NV3H6CViKepyJmEcq8Jghxkx56OoH+Qpiyr ZJhYOTLji+bvvBtrK+mNGoDMQiCoPlOdkOzceBZ6+s8tpxQBezB4/x93lIJCmhfpilrz lRtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681339417; 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=geumVPtdfdeonNbJRvQRqI8DZnvMBPVyWVWG9NtZCuE=; b=IOvZTU+JuYz0J/Slcv+1KfBGsmBVwKpFFV55N80epwu4O+dzNaP9D0Dkw1gm6jAY43 LdrASb92fo8pJ1d59BXYGIGlQi0Ckf0qYUPEAn2bWX82rX6LLSWrI9NbvXJP9UyKQwY8 J+t2x3qIxbK7PZ99EkQtyDr7/50pXrFegsMpdL6EmxTxXEd7roT6aj+UBVvZY/Y8gVL4 PEA0229lS92UWhkyV9R6PdVA9B1PQdzJXXeVzYkKqEh3ZmIF9Y0tsAfPM1vItwgd4c54 6VXFYV1LSP3cK281IcidtUTomTOAZKWwwtbyvH4fig2bYFEs4C4We6UeQ2PSvWLsKK/4 W00w== X-Gm-Message-State: AAQBX9d3U/NCzOTXmHycuF/LbGnKuaDNNOkbrN9EbdV7VgVA4lrwG8V3 +gi5ZFunpRrIEDJToTzqx+4= X-Received: by 2002:a05:6a00:244c:b0:63a:65a9:10db with SMTP id d12-20020a056a00244c00b0063a65a910dbmr634262pfj.7.1681339416832; Wed, 12 Apr 2023 15:43:36 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id t22-20020aa79396000000b00635d381b57csm7144133pfe.205.2023.04.12.15.43.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 15:43:36 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, Boris Brezillon , Tvrtko Ursulin , Christopher Healy , Emil Velikov , =?utf-8?q?Christian_K=C3=B6nig?= , Daniel Vetter , Rob Clark , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , linux-doc@vger.kernel.org (open list:DOCUMENTATION), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v4 5/6] drm: Add fdinfo memory stats Date: Wed, 12 Apr 2023 15:42:57 -0700 Message-Id: <20230412224311.23511-6-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230412224311.23511-1-robdclark@gmail.com> References: <20230412224311.23511-1-robdclark@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763013578746204679?= X-GMAIL-MSGID: =?utf-8?q?1763013578746204679?= From: Rob Clark Add support to dump GEM stats to fdinfo. v2: Fix typos, change size units to match docs, use div_u64 v3: Do it in core v4: more kerneldoc Signed-off-by: Rob Clark Reviewed-by: Emil Velikov Reviewed-by: Daniel Vetter Reviewed-by: Emil Velikov --- Documentation/gpu/drm-usage-stats.rst | 21 ++++++++ drivers/gpu/drm/drm_file.c | 76 +++++++++++++++++++++++++++ include/drm/drm_file.h | 1 + include/drm/drm_gem.h | 30 +++++++++++ 4 files changed, 128 insertions(+) diff --git a/Documentation/gpu/drm-usage-stats.rst b/Documentation/gpu/drm-usage-stats.rst index 2ab32c40e93c..80003e27e28e 100644 --- a/Documentation/gpu/drm-usage-stats.rst +++ b/Documentation/gpu/drm-usage-stats.rst @@ -105,6 +105,27 @@ object belong to this client, in the respective memory region. Default unit shall be bytes with optional unit specifiers of 'KiB' or 'MiB' indicating kibi- or mebi-bytes. +- drm-shared-memory: [KiB|MiB] + +The total size of buffers that are shared with another file (ie. have more +than a single handle). + +- drm-private-memory: [KiB|MiB] + +The total size of buffers that are not shared with another file. + +- drm-resident-memory: [KiB|MiB] + +The total size of buffers that are resident in system memory. + +- drm-purgeable-memory: [KiB|MiB] + +The total size of buffers that are purgeable. + +- drm-active-memory: [KiB|MiB] + +The total size of buffers that are active on one or more rings. + - drm-cycles- Engine identifier string must be the same as the one specified in the diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c index 6d5bdd684ae2..04a7ed7eba8e 100644 --- a/drivers/gpu/drm/drm_file.c +++ b/drivers/gpu/drm/drm_file.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include "drm_crtc_internal.h" @@ -871,6 +872,79 @@ void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) } EXPORT_SYMBOL(drm_send_event); +static void print_size(struct drm_printer *p, const char *stat, size_t sz) +{ + const char *units[] = {"", " KiB", " MiB"}; + unsigned u; + + for (u = 0; u < ARRAY_SIZE(units) - 1; u++) { + if (sz < SZ_1K) + break; + sz = div_u64(sz, SZ_1K); + } + + drm_printf(p, "%s:\t%zu%s\n", stat, sz, units[u]); +} + +static void print_memory_stats(struct drm_printer *p, struct drm_file *file) +{ + struct drm_gem_object *obj; + struct { + size_t shared; + size_t private; + size_t resident; + size_t purgeable; + size_t active; + } size = {0}; + bool has_status = false; + int id; + + spin_lock(&file->table_lock); + idr_for_each_entry (&file->object_idr, obj, id) { + enum drm_gem_object_status s = 0; + + if (obj->funcs && obj->funcs->status) { + s = obj->funcs->status(obj); + has_status = true; + } + + if (obj->handle_count > 1) { + size.shared += obj->size; + } else { + size.private += obj->size; + } + + if (s & DRM_GEM_OBJECT_RESIDENT) { + size.resident += obj->size; + } else { + /* If already purged or not yet backed by pages, don't + * count it as purgeable: + */ + s &= ~DRM_GEM_OBJECT_PURGEABLE; + } + + if (!dma_resv_test_signaled(obj->resv, dma_resv_usage_rw(true))) { + size.active += obj->size; + + /* If still active, don't count as purgeable: */ + s &= ~DRM_GEM_OBJECT_PURGEABLE; + } + + if (s & DRM_GEM_OBJECT_PURGEABLE) + size.purgeable += obj->size; + } + spin_unlock(&file->table_lock); + + print_size(p, "drm-shared-memory", size.shared); + print_size(p, "drm-private-memory", size.private); + print_size(p, "drm-active-memory", size.active); + + if (has_status) { + print_size(p, "drm-resident-memory", size.resident); + print_size(p, "drm-purgeable-memory", size.purgeable); + } +} + /** * drm_show_fdinfo - helper for drm file fops * @seq_file: output stream @@ -900,6 +974,8 @@ void drm_show_fdinfo(struct seq_file *m, struct file *f) if (dev->driver->show_fdinfo) dev->driver->show_fdinfo(&p, file); + + print_memory_stats(&p, file); } EXPORT_SYMBOL(drm_show_fdinfo); diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index 6de6d0e9c634..919284bb4f1d 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -41,6 +41,7 @@ struct dma_fence; struct drm_file; struct drm_device; +struct drm_printer; struct device; struct file; diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index 189fd618ca65..9ebd2820ad1f 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -42,6 +42,25 @@ struct iosys_map; struct drm_gem_object; +/** + * enum drm_gem_object_status - bitmask of object state for fdinfo reporting + * @DRM_GEM_OBJECT_RESIDENT: object is resident in memory (ie. not unpinned) + * @DRM_GEM_OBJECT_PURGEABLE: object marked as purgeable by userspace + * + * Bitmask of status used for fdinfo memory stats, see &drm_gem_object_funcs.status + * and drm_show_fdinfo(). Note that an object can DRM_GEM_OBJECT_PURGEABLE if + * it still active or not resident, in which case drm_show_fdinfo() will not + * account for it as purgeable. So drivers do not need to check if the buffer + * is idle and resident to return this bit. (Ie. userspace can mark a buffer + * as purgeable even while it is still busy on the GPU.. it does not _actually_ + * become puregeable until it becomes idle. The status gem object func does + * not need to consider this.) + */ +enum drm_gem_object_status { + DRM_GEM_OBJECT_RESIDENT = BIT(0), + DRM_GEM_OBJECT_PURGEABLE = BIT(1), +}; + /** * struct drm_gem_object_funcs - GEM object functions */ @@ -174,6 +193,17 @@ struct drm_gem_object_funcs { */ int (*evict)(struct drm_gem_object *obj); + /** + * @status: + * + * The optional status callback can return additional object state + * which determines which stats the object is counted against. The + * callback is called under table_lock. Racing against object status + * change is "harmless", and the callback can expect to not race + * against object destruction. + */ + enum drm_gem_object_status (*status)(struct drm_gem_object *obj); + /** * @vm_ops: * From patchwork Wed Apr 12 22:42:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 82704 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp656702vqo; Wed, 12 Apr 2023 16:09:41 -0700 (PDT) X-Google-Smtp-Source: AKy350ZEs6Z3xLs8rEaIp+1kQ5dgyO11QtZogCxoVuKB6+hCM8ipGKCzRM37qBg0C1bg2+8EPJNx X-Received: by 2002:aa7:c482:0:b0:505:75f:a2be with SMTP id m2-20020aa7c482000000b00505075fa2bemr318495edq.24.1681340980829; Wed, 12 Apr 2023 16:09:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681340980; cv=none; d=google.com; s=arc-20160816; b=MY0hqwd3zs/+7cpGsgoQiQ9fJIB95qXd4vHHugRNGvV09puf87c6zmHmA5PPVz2oRW 1E/UAmo3WYpV6lR5c+RApNB9c+hFIUBu0/DEXhviDRMkd4BOujVQDFwqbAhTzHUaVli7 +/zZIk3ZwfqaU+C5JbAD4gTzW8QNnrEzYpfPX9nsE5hry7MP0iGfEGkPef9e1MzLpOCD jW3iXRSYrhRZDR8ZrE1v3tshSYs5KDrENv0y/OfunsFQtQaRz6C6N+qjx4JOL2xlRbDC IR7s/2QnvHWA3mOkn3YPavuztaoKn02hx3+/mYnxd4nnXFozdhpuiLhj09XwBreOQn99 0EnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ayU9yxyS63GOBM6CjiiY8bjBwmD9ZnU8dUfgj0+el7c=; b=FVQcZf8mB6s6XGxjwbYLiCioI2MTl61THVzCmLjy6cvDlehNjxU34Hre2L0UuHE68M HchxakG7g7aWSQ4aO2umwH8lIW5XBFtKNN2it4kqCcWwXf3Cmz4oIy48eYcdJDBIUOJL 2LNf2i3SectdALz3VlrLKMMjmHD+7LQKFgJCWB2v5Xg0BXp+aonXHqMmjrENen2pi8w9 cArXjQ6D8I/mlO7m2TOZEEXrkjlSIkuBPRh70psjZNirLsm6uHfjVvisOeX8bSUqovtj zDZimPA6Z7Ib3Of8SNRVtdAllMN/E3geZOP6hDm59Wexflyq2GTFPAWPjrD6Vvxk0MqR UbzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=VfrlzRoN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d22-20020aa7d5d6000000b00504b1f83926si121267eds.202.2023.04.12.16.09.17; Wed, 12 Apr 2023 16:09:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=VfrlzRoN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229728AbjDLWoG (ORCPT + 99 others); Wed, 12 Apr 2023 18:44:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229931AbjDLWnv (ORCPT ); Wed, 12 Apr 2023 18:43:51 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5B488A54; Wed, 12 Apr 2023 15:43:39 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id cm18-20020a17090afa1200b0024713adf69dso702339pjb.3; Wed, 12 Apr 2023 15:43:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681339418; 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=ayU9yxyS63GOBM6CjiiY8bjBwmD9ZnU8dUfgj0+el7c=; b=VfrlzRoNCK4XsqcugPJpoWdrroAMxteTFc/L6PQaqDod7DJXTTC5ZBLFbKWLVQXpp5 RUxb3F3mYzwJrzNQTLRXXh9tB47WMMY4NE2xKUQ5mgqatwH0Z5mbhRxNqtFbgZrsIa9W wjCNuOGM/OGpJzmpIFik9KVsHBC6FROlCrPgABRalPKRP9i0BmoROJbW4WoE7LX+t70/ 2V4p47c/XDHyaMH0Gyo1OLT++OXCgld3H/afKxh8Piqwd2CwmEl1Zdzxl0qm63c/DOd0 TVKYKfRQZavdBmIUkh9XNUh3ARrZlrd9sc3yfsuhxkebSRWsTlZOWuqjy5r2PZ9e/ASb Eldg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681339418; 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=ayU9yxyS63GOBM6CjiiY8bjBwmD9ZnU8dUfgj0+el7c=; b=W8GGHusgIzfwiZyTnO4ZU4Mu7WiYQmUTi7/AI6q8VQicow0+41bc3+vMx86rovh4SC U8kTR4KZEP67Gq8EgyGOqZYSS3xbGsNPdSgNdQMyhv7BQWFpY5h6d2KsGy5YfKZkvvUu SD8FWYQrXuPYieu7g0f6TfuywDoFZ7iqrksVNI3/rCs6LCmLaHZw7bB8lczr4jXywawb SqB3abp1NWNNi38QelT6ZME1C6ZAuiDOyXeXw8AhZ0pcnKNYjA/EH3/OHNlpHsqNJl6H lgclF3iP4fErxyHB7bf1iDh+MenSGhmJxfqRJ5S0cxt7ENJF3cf8/Jd5tvRFwUaP/vUa fuPw== X-Gm-Message-State: AAQBX9cEGx/UeJC8YXqCUIaeRnoJVg0ZdeysqUrsbBQxBb37OJpaEQcO yW4hPAVcIkMutyhl3p0+VfUewQg01HQ= X-Received: by 2002:a17:90a:440d:b0:246:e9ab:aca5 with SMTP id s13-20020a17090a440d00b00246e9abaca5mr6823525pjg.18.1681339418302; Wed, 12 Apr 2023 15:43:38 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id m7-20020a1709026bc700b001a183ade911sm103481plt.56.2023.04.12.15.43.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 15:43:38 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, Boris Brezillon , Tvrtko Ursulin , Christopher Healy , Emil Velikov , =?utf-8?q?Christian_K=C3=B6nig?= , Daniel Vetter , Rob Clark , Rob Clark , Abhinav Kumar , Dmitry Baryshkov , Sean Paul , David Airlie , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v4 6/6] drm/msm: Add memory stats to fdinfo Date: Wed, 12 Apr 2023 15:42:58 -0700 Message-Id: <20230412224311.23511-7-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230412224311.23511-1-robdclark@gmail.com> References: <20230412224311.23511-1-robdclark@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763013800451951174?= X-GMAIL-MSGID: =?utf-8?q?1763013800451951174?= From: Rob Clark Use the new helper to export stats about memory usage. v2: Drop unintended hunk v3: Rebase Signed-off-by: Rob Clark Reviewed-by: Emil Velikov --- drivers/gpu/drm/msm/msm_gem.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c index db6c4e281d75..c32264234ea1 100644 --- a/drivers/gpu/drm/msm/msm_gem.c +++ b/drivers/gpu/drm/msm/msm_gem.c @@ -1096,6 +1096,20 @@ int msm_gem_new_handle(struct drm_device *dev, struct drm_file *file, return ret; } +static enum drm_gem_object_status msm_gem_status(struct drm_gem_object *obj) +{ + struct msm_gem_object *msm_obj = to_msm_bo(obj); + enum drm_gem_object_status status = 0; + + if (msm_obj->pages) + status |= DRM_GEM_OBJECT_RESIDENT; + + if (msm_obj->madv == MSM_MADV_DONTNEED) + status |= DRM_GEM_OBJECT_PURGEABLE; + + return status; +} + static const struct vm_operations_struct vm_ops = { .fault = msm_gem_fault, .open = drm_gem_vm_open, @@ -1110,6 +1124,7 @@ static const struct drm_gem_object_funcs msm_gem_object_funcs = { .vmap = msm_gem_prime_vmap, .vunmap = msm_gem_prime_vunmap, .mmap = msm_gem_object_mmap, + .status = msm_gem_status, .vm_ops = &vm_ops, };