From patchwork Thu Oct 21 03:10:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 12573665 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 399ACC433FE for ; Thu, 21 Oct 2021 03:10:44 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 075F361090 for ; Thu, 21 Oct 2021 03:10:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 075F361090 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3BED66EA5D; Thu, 21 Oct 2021 03:10:35 +0000 (UTC) Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by gabe.freedesktop.org (Postfix) with ESMTPS id 92CB26E3D8 for ; Thu, 21 Oct 2021 03:10:31 +0000 (UTC) Received: by mail-pf1-x433.google.com with SMTP id f11so4620170pfc.12 for ; Wed, 20 Oct 2021 20:10:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=35kmIfN/EN6HlYQAf9OBmO1Wo6icnsDK3CGRODRZcFs=; b=UUeH1LXb6bN3bLuXh0yc5nlGW/kyMa8fv56ZqoMpRtyPIbXmyfdDg1uFwBbtNbZatN yoY6Go0sEHgri4SrjsUiVHdVC1417EOn1t3zJMooWxqV1thLlfh8NvR12v6Bo8GNry0W 3ZW6eB+DszzCn7p1dkYJ4HYrvSSm1SXMd/GrU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=35kmIfN/EN6HlYQAf9OBmO1Wo6icnsDK3CGRODRZcFs=; b=oE5rfvDoMwJx1+307yaMC+iI4ZMBFVYn5WaDPzb6XzUZAo2KCfgnhOlqzEL4ESpZaB CimR0b4NTb8v2oEKxhkuKEg7gqlf31XEcLRbgvmMq74yLzhn0CLj2lsBIucXSR+FhGs4 AVuuge527+OCcc7+5PYU9vdpW9ogWb+eTZMYoZbwXlp+lejRAO2dJzlAjKPJAzsdC8hW YaFZxlnsZTYeCFJZVpNvtNjIw6pb9UTGCv3TQpuRS0GjOkajW1aTa1f+tMxxp+cA7UX/ 37VUfv8UkqECS9u3yN1Q+BVB5VEHs6KLnaVseZp2q5zWmd2UpdiQLJQyqiGgiYiVuEoy Za3Q== X-Gm-Message-State: AOAM531DcljJ400+tWdupyku/sqcFXEJ1AuIE02h5cKOJI/uAFVq4SYz rtz5DuVsd9oF65MmV4NKFE1hcDmtKY72JA== X-Google-Smtp-Source: ABdhPJyuQs6FWqZJYUVEK9sEdqreefpCYOKDlBOtGfqhMfYK/hwgGFwhqjNkc7Y/joAW9+8XfGOSYg== X-Received: by 2002:a05:6a00:10c2:b0:44d:d761:48d4 with SMTP id d2-20020a056a0010c200b0044dd76148d4mr3152633pfu.0.1634785830815; Wed, 20 Oct 2021 20:10:30 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:21a4:fcf9:f5bb:f740]) by smtp.gmail.com with ESMTPSA id z1sm4016255pfh.150.2021.10.20.20.10.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:10:30 -0700 (PDT) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Cc: kaleshsingh@google.com, daniel@ffwll.ch, rostedt@goodmis.org Subject: [RFC PATCH 1/8] tracing/gpu: modify gpu_mem_total Date: Wed, 20 Oct 2021 20:10:20 -0700 Message-Id: <20211021031027.537-2-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20211021031027.537-1-gurchetansingh@chromium.org> References: <20211021031027.537-1-gurchetansingh@chromium.org> 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The existing gpu_mem_total tracepoint [1] is not currently used by any in-tree consumers, we should add some. In addition, there's a desire to report imported memory via the counters too [2]. To do this, we'll have to redefine the event to: a) Change 'pid' to 'ctx_id' The reason is DRM subsystem is created with GEM objects, DRM devices and DRM files in mind. A GEM object is associated with DRM device, and it may be shared between one or more DRM files. Per-instance (or "context") counters make more sense than per-process counters for DRM. For GPUs that per process counters (kgsl), this change is backwards compatible. b) add an "import_mem_total" field We're just appending a field, so no problem here. Change "size" to "mem_total" as well (name changes are backwards compatible). [1] https://lore.kernel.org/r/20200302234840.57188-1-zzyiwei@google.com/ [2] https://www.spinics.net/lists/kernel/msg4062769.html Signed-off-by: Gurchetan Singh --- include/trace/events/gpu_mem.h | 61 ++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/include/trace/events/gpu_mem.h b/include/trace/events/gpu_mem.h index 26d871f96e94..198b87f50356 100644 --- a/include/trace/events/gpu_mem.h +++ b/include/trace/events/gpu_mem.h @@ -14,41 +14,66 @@ #include /* - * The gpu_memory_total event indicates that there's an update to either the - * global or process total gpu memory counters. + * The gpu_mem_total event indicates that there's an update to local or + * global gpu memory counters. * - * This event should be emitted whenever the kernel device driver allocates, - * frees, imports, unimports memory in the GPU addressable space. + * This event should be emitted whenever a GPU device (ctx_id == 0): * - * @gpu_id: This is the gpu id. + * 1) allocates memory. + * 2) frees memory. + * 3) imports memory from an external exporter. * - * @pid: Put 0 for global total, while positive pid for process total. + * OR when a GPU device instance (ctx_id != 0): * - * @size: Size of the allocation in bytes. + * 1) allocates or acquires a reference to memory from another instance. + * 2) frees or releases a reference to memory from another instance. + * 3) imports memory from another GPU device instance. * + * When ctx_id == 0, both mem_total and import_mem_total total counters + * represent a global total. When ctx_id == 0, these counters represent + * an instance specifical total. + * + * Note allocation does not necessarily mean backing the memory with pages. + * + * @gpu_id: unique ID of the GPU. + * + * @ctx_id: an ID for specific instance of the GPU device. + * + * @mem_total: - total size of memory known to a GPU device, including + * imports (ctx_id == 0) + * - total size of memory known to a GPU device instance + * (ctx_id != 0) + * + * @import_mem_total: - size of memory imported from outside GPU + * device (ctx_id == 0) + * - size of memory imported into GPU device instance. + * (ctx_id == 0) */ TRACE_EVENT(gpu_mem_total, - TP_PROTO(uint32_t gpu_id, uint32_t pid, uint64_t size), + TP_PROTO(u32 gpu_id, u32 ctx_id, u64 mem_total, u64 import_mem_total), - TP_ARGS(gpu_id, pid, size), + TP_ARGS(gpu_id, ctx_id, mem_total, import_mem_total), TP_STRUCT__entry( - __field(uint32_t, gpu_id) - __field(uint32_t, pid) - __field(uint64_t, size) + __field(u32, gpu_id) + __field(u32, ctx_id) + __field(u64, mem_total) + __field(u64, import_mem_total) ), TP_fast_assign( __entry->gpu_id = gpu_id; - __entry->pid = pid; - __entry->size = size; + __entry->ctx_id = ctx_id; + __entry->mem_total = mem_total; + __entry->import_mem_total = import_mem_total; ), - TP_printk("gpu_id=%u pid=%u size=%llu", - __entry->gpu_id, - __entry->pid, - __entry->size) + TP_printk("gpu_id=%u, ctx_id=%u, mem total=%llu, mem import total=%llu", + __entry->gpu_id, + __entry->ctx_id, + __entry->mem_total, + __entry->import_mem_total) ); #endif /* _TRACE_GPU_MEM_H */ From patchwork Thu Oct 21 03:10:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 12573675 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 707B6C433F5 for ; Thu, 21 Oct 2021 03:10:56 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 42E0E61090 for ; Thu, 21 Oct 2021 03:10:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 42E0E61090 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 68C936EA6F; Thu, 21 Oct 2021 03:10:53 +0000 (UTC) Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by gabe.freedesktop.org (Postfix) with ESMTPS id 801DA6E3FE for ; Thu, 21 Oct 2021 03:10:32 +0000 (UTC) Received: by mail-pg1-x534.google.com with SMTP id 75so24328241pga.3 for ; Wed, 20 Oct 2021 20:10:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5lnP0JIeU4WMucvckNmAZdbJm3u8WDteMovU1BGERnM=; b=E//A4FRGDS7HjyUGx/gcxMA93ObKb3gM6+7KSphrVWWxfVe7X9tNE9k+zJKNfmavmn M2QTERS9yo6+3TvXZ0xJWlXvnB7M/yePVKyDjQhA3sbCNQY1nZtYKVvSPFmpswAftgQP BZWA7iSKd6tC8jvL5Njln0qmJxq+Qi8yLgeTc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5lnP0JIeU4WMucvckNmAZdbJm3u8WDteMovU1BGERnM=; b=maSY57t3gbCCw0IuXMIZshD2BfQGxOQ+BMk7oLi+CbKjwhAcoxNaSaH60JvAjluJ2s zIjITBHkxb/P5VayFHYXMfzHlRoLcJjFILoNjqUgVm5nwbrOyioNdPwqVkIQu7oRFkYv ucvvlKkFRefYr+Fafy9d4DdTA19oR3zWk/LDNj6OxX/oJTUKuwbWrrZ7h3lF90ouO6NY 1TNCR2rAOMqAEpW6KJuFVFQGoba5gLTUKob3zgZYYmrzqKYG00Dd5g406rWIGXi3a1D1 wl3L3LzrcKxsA5R3gQ+149wF1T6lf03/UKnwGn6+h25SbDSMwXLRF5K5w5BWzIw7SFdR Gi7Q== X-Gm-Message-State: AOAM531tOQms/w5nVmaghp37L+mG8seQUipPNzG/jxl/CYlOIuSL2xXY G1YEQuMemOKPpVtHbMAQS10oMYIaYYWwWg== X-Google-Smtp-Source: ABdhPJzjbsvYYjtVrmd637dUd6fTIMg3GhWX9z4hoW+81AVBL6mANQKgqaTzKhgKDvPbX8Ayq1zubw== X-Received: by 2002:a05:6a00:190d:b0:46d:516c:4ed9 with SMTP id y13-20020a056a00190d00b0046d516c4ed9mr924403pfi.57.1634785831636; Wed, 20 Oct 2021 20:10:31 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:21a4:fcf9:f5bb:f740]) by smtp.gmail.com with ESMTPSA id z1sm4016255pfh.150.2021.10.20.20.10.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:10:31 -0700 (PDT) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Cc: kaleshsingh@google.com, daniel@ffwll.ch, rostedt@goodmis.org Subject: [RFC PATCH 2/8] drm: add new tracepoint fields to drm_device and drm_file Date: Wed, 20 Oct 2021 20:10:21 -0700 Message-Id: <20211021031027.537-3-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20211021031027.537-1-gurchetansingh@chromium.org> References: <20211021031027.537-1-gurchetansingh@chromium.org> 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" For struct drm_device, add: - mem_total - import_mem_total For struct drm_file, add: - mem_instance - import_mem_instance Signed-off-by: Gurchetan Singh --- include/drm/drm_device.h | 16 ++++++++++++++++ include/drm/drm_file.h | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/drm/drm_device.h b/include/drm/drm_device.h index 604b1d1b2d72..35a96bda5320 100644 --- a/include/drm/drm_device.h +++ b/include/drm/drm_device.h @@ -298,6 +298,22 @@ struct drm_device { */ struct drm_fb_helper *fb_helper; + /** + * @mem_total: + * + * The total size of all GEM objects known to this DRM device. Used + * with `gpu_mem_total` tracepoint. + */ + atomic64_t mem_total; + + /** + * @import_mem_total: + * + * The total size of all GEM objects imported into this DRM device from + * external exporters. Used with `gpu_mem_total` tracepoint. + */ + atomic64_t import_mem_total; + /* Everything below here is for legacy driver, never use! */ /* private: */ #if IS_ENABLED(CONFIG_DRM_LEGACY) diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index a3acb7ac3550..a5b9befcf1db 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -362,6 +362,22 @@ struct drm_file { */ struct drm_prime_file_private prime; + /** + * @mem_instance: + * + * The total size of all GEM objects known into this instance of the DRM + * device. Used with `gpu_mem_instance` tracepoint. + */ + atomic64_t mem_instance; + + /** + * @import_mem_instance: + * + * The total size of all GEM objects imported into this instance of the + * DRM device. Used with `gpu_mem_instance` tracepoint. + */ + atomic64_t import_mem_instance; + /* private: */ #if IS_ENABLED(CONFIG_DRM_LEGACY) unsigned long lock_count; /* DRI1 legacy lock count */ From patchwork Thu Oct 21 03:10:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 12573663 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 441BBC433FE for ; Thu, 21 Oct 2021 03:10:40 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 0F00761090 for ; Thu, 21 Oct 2021 03:10:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0F00761090 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6AE1C6EA32; Thu, 21 Oct 2021 03:10:34 +0000 (UTC) Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by gabe.freedesktop.org (Postfix) with ESMTPS id 71C096EA32 for ; Thu, 21 Oct 2021 03:10:33 +0000 (UTC) Received: by mail-pf1-x42d.google.com with SMTP id q19so4648938pfl.4 for ; Wed, 20 Oct 2021 20:10:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iomAEfnd3OwzO0h9BQWpBoAtIo/GmoHhZ2/ejzvPfUE=; b=QUESbRhj9yWZP2GZbuJp41+MMItocA8OGFUq1MqFPD1JNinO2aEvqkLAEH+poAK+CS Fygq9FmSbFDFK2h6tNHIHVLCa8W1rYABKZ+v4ywYw+G+A6zQWv/2W+S/w5yG0ji91xNi Z2LI68LbHK8EmPfMmCntG+06rG7hCP0Jq9Uks= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iomAEfnd3OwzO0h9BQWpBoAtIo/GmoHhZ2/ejzvPfUE=; b=M1jQaFvfb/Xx+RzrQvPzAg5/jJF+E11MrxeT411IGJs5xywjX/SSVgIO4j5okO+Hfk euWZk1bMSsH2mqTQlL1dZ5cRZlsXLjqAjS2Wx4mjLRw9wsJvlyCHGk0BBh+tq/fyo68a FWfjhXhZJOiJE6lAMzr/Sa5RZoGaqW0dZI+7xASp/8gxeaEoxAlHu4+1NzbMhArRsYWz FFTDSbh/MDGcNmyF952JNOOTmF3CbhjcMjtcd2STEXSCALtIWzFjH4facEAhsRtkEAhU hNVmdy0gC2Dc+05ord//GyWq8rr8RPpGZ1F3vUFgO1y7niWAKtzKXw8Ow5hd1r9nl75+ f3WA== X-Gm-Message-State: AOAM532Z/Cwm9m+gEiVz10sVhyMK4G4bTLZHVKm5fxTC3unww3viI8Ji BHG3kvMXC/68enfWeFCkVyNPQHScuIenIA== X-Google-Smtp-Source: ABdhPJy6EGR/lJDI6H7N7Ik5w2uYGZnmMeAecJMedmL2As8YLvhYj1exHxKmA8ouweXRpc0vMFUGjg== X-Received: by 2002:a62:1b8e:0:b0:44c:9318:f6e1 with SMTP id b136-20020a621b8e000000b0044c9318f6e1mr2717541pfb.84.1634785832724; Wed, 20 Oct 2021 20:10:32 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:21a4:fcf9:f5bb:f740]) by smtp.gmail.com with ESMTPSA id z1sm4016255pfh.150.2021.10.20.20.10.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:10:31 -0700 (PDT) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Cc: kaleshsingh@google.com, daniel@ffwll.ch, rostedt@goodmis.org Subject: [RFC PATCH 3/8] drm: add helper functions for gpu_mem_total and gpu_mem_instance Date: Wed, 20 Oct 2021 20:10:22 -0700 Message-Id: <20211021031027.537-4-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20211021031027.537-1-gurchetansingh@chromium.org> References: <20211021031027.537-1-gurchetansingh@chromium.org> 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" - Add helper functions for above tracepoints in the drm_gem.{h,c} files - Given more tracepoints, a drm_trace.* file may be started Signed-off-by: Gurchetan Singh --- drivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/drm_gem.c | 49 +++++++++++++++++++++++++++++++++++++++ include/drm/drm_gem.h | 7 ++++++ 3 files changed, 57 insertions(+) diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index b91f0ce8154c..cef8545df1c9 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -15,6 +15,7 @@ menuconfig DRM select I2C_ALGOBIT select DMA_SHARED_BUFFER select SYNC_FILE + select TRACE_GPU_MEM # gallium uses SYS_kcmp for os_same_file_description() to de-duplicate # device and dmabuf fd. Let's make sure that is available for our userspace. select KCMP diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 4dcdec6487bb..24a719b79400 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -49,6 +49,8 @@ #include #include +#include + #include "drm_internal.h" /** @file drm_gem.c @@ -138,6 +140,53 @@ int drm_gem_object_init(struct drm_device *dev, } EXPORT_SYMBOL(drm_gem_object_init); +/** + * drm_gem_trace_gpu_mem_total - emit a total memory trace event + * @dev: drm_device to emit trace event for + * @delta: size change + * @imported: whether the imported or total memory counter should be used + * + * Emits a `gpu_mem_total` trace event with given parameters. + */ +void +drm_gem_trace_gpu_mem_total(struct drm_device *dev, s64 delta, bool imported) +{ + if (imported) + atomic64_add(delta, &dev->import_mem_total); + else + atomic64_add(delta, &dev->mem_total); + + trace_gpu_mem_total(dev->primary->index, 0, + atomic64_read(&dev->mem_total), + atomic64_read(&dev->import_mem_total)); +} +EXPORT_SYMBOL(drm_gem_trace_gpu_mem_total); + +/** + * drm_gem_trace_gpu_mem_instance - emit a per instance memory trace event + * @dev: drm_device associated with DRM file + * @file: drm_file to emit event for + * @delta: size change + * @imported: whether the imported or total memory counter should be used + * + * Emits a `gpu_mem_instance` trace event with given parameters. + */ +void +drm_gem_trace_gpu_mem_instance(struct drm_device *dev, struct drm_file *file, + s64 delta, bool imported) +{ + if (imported) + atomic64_add(delta, &file->import_mem_instance); + else + atomic64_add(delta, &file->mem_instance); + + trace_gpu_mem_total(dev->primary->index, + file_inode(file->filp)->i_ino, + atomic64_read(&file->mem_instance), + atomic64_read(&file->import_mem_instance)); +} +EXPORT_SYMBOL(drm_gem_trace_gpu_mem_instance); + /** * drm_gem_private_object_init - initialize an allocated private GEM object * @dev: drm_device the object should be initialized for diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index 35e7f44c2a75..d61937cce222 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -342,6 +342,13 @@ struct drm_gem_object { void drm_gem_object_release(struct drm_gem_object *obj); void drm_gem_object_free(struct kref *kref); + +void drm_gem_trace_gpu_mem_total(struct drm_device *dev, s64 delta, + bool imported); +void drm_gem_trace_gpu_mem_instance(struct drm_device *dev, + struct drm_file *file, + s64 delta, bool imported); + int drm_gem_object_init(struct drm_device *dev, struct drm_gem_object *obj, size_t size); void drm_gem_private_object_init(struct drm_device *dev, From patchwork Thu Oct 21 03:10:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 12573673 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A058AC433EF for ; Thu, 21 Oct 2021 03:10:54 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 6762461090 for ; Thu, 21 Oct 2021 03:10:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6762461090 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 25EA16EA6A; Thu, 21 Oct 2021 03:10:51 +0000 (UTC) Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4F1AB6E3FE for ; Thu, 21 Oct 2021 03:10:34 +0000 (UTC) Received: by mail-pg1-x530.google.com with SMTP id s136so21069519pgs.4 for ; Wed, 20 Oct 2021 20:10:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XE9+2bVA7CccLIzhLAPheXBj2paWYoYmQA2qJZ5y+AY=; b=VZDYpu1r1e00Rtnm23pbOa6bSUWAA3ViJi/ot+9rcwGOAYPK8xNjUtHr0BPVusQhs8 T1pmhjglFKM+sVbYlULCyo59GxCWKq78+EeOCGviGn5yXemHsSLJKPfNwINwQn4ubTx9 Fjq9Oy7MkJ+cHu7V6rGL6ilGVlX2yryQKpQ1g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XE9+2bVA7CccLIzhLAPheXBj2paWYoYmQA2qJZ5y+AY=; b=V7c+J0o+i4ceeFOMUntYhMhnuzLhxQXk/QP27Fmz/0rRuSaPe5U+zJndWij9dZaifn 2NWKIAFdxWdI+D9ROAAXuuvsFKxU9rZh6R+N05ZJIUUIo9nUWp8SXZxdIbXkp7nlTRcs MVR4AzSHNuEupLAQTDrNobT6iNaghvQ+k8LEWsxqY7SZ5vqJ+kY40fpTORs8jKXrNn2J XrFfDJa1OCLIz2RinwvXTOG4XKI30TethF7xA7eMIvqGkn+W8PESB2BzSYaNy4k6fUR5 N0w+1tlN8gG2D4sErQj++Rvu+SMhyCBVcdh4H/Y9ATrJhSdxs0Jyjpek1uZIuT+XwSp5 kXxA== X-Gm-Message-State: AOAM531gQZPgwZ/5Jo/MSlPRj59V6WbIiU6QDkGgTBgVAVq6UypSgQlA 0SHkPmHURSBn+46poqnO9DPfZ/K+PlsRGQ== X-Google-Smtp-Source: ABdhPJzSuCRexaxR7mnbeSlSRjyqovNXqg2zqWcrvuXv61n3fpNqGPgPRQ37jAh9fFGXm2kvLdRGmQ== X-Received: by 2002:aa7:9258:0:b0:44d:4f03:6a7a with SMTP id 24-20020aa79258000000b0044d4f036a7amr2620572pfp.33.1634785833504; Wed, 20 Oct 2021 20:10:33 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:21a4:fcf9:f5bb:f740]) by smtp.gmail.com with ESMTPSA id z1sm4016255pfh.150.2021.10.20.20.10.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:10:33 -0700 (PDT) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Cc: kaleshsingh@google.com, daniel@ffwll.ch, rostedt@goodmis.org Subject: [RFC PATCH 4/8] drm: start using drm_gem_trace_gpu_mem_total Date: Wed, 20 Oct 2021 20:10:23 -0700 Message-Id: <20211021031027.537-5-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20211021031027.537-1-gurchetansingh@chromium.org> References: <20211021031027.537-1-gurchetansingh@chromium.org> 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" - drm_gem_private_object_init(..) increases the total memory counter. * All GEM objects (whether allocated or imported) seem to begin there. * If there's a better place/method, please do let me know. - drm_gem_object_free(..) decreases the total memory counter. Signed-off-by: Gurchetan Singh --- drivers/gpu/drm/drm_gem.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 24a719b79400..528d7b29dccf 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -213,6 +213,7 @@ void drm_gem_private_object_init(struct drm_device *dev, obj->resv = &obj->_resv; drm_vma_node_reset(&obj->vma_node); + drm_gem_trace_gpu_mem_total(dev, obj->size, false); } EXPORT_SYMBOL(drm_gem_private_object_init); @@ -1015,6 +1016,10 @@ drm_gem_object_free(struct kref *kref) struct drm_gem_object *obj = container_of(kref, struct drm_gem_object, refcount); + struct drm_device *dev = obj->dev; + + drm_gem_trace_gpu_mem_total(dev, -obj->size, false); + if (WARN_ON(!obj->funcs->free)) return; From patchwork Thu Oct 21 03:10:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 12573669 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1278FC433F5 for ; Thu, 21 Oct 2021 03:10:50 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id D6B87611CB for ; Thu, 21 Oct 2021 03:10:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D6B87611CB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5A9156EA65; Thu, 21 Oct 2021 03:10:41 +0000 (UTC) Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2448E6E3FE for ; Thu, 21 Oct 2021 03:10:35 +0000 (UTC) Received: by mail-pl1-x632.google.com with SMTP id v20so17505660plo.7 for ; Wed, 20 Oct 2021 20:10:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9TThp1HI4kpOvu/0H4PBMLArwdOhxuUAZO1JZOsPPQg=; b=jMQX1CMFe17DbcK4X1+9H2+7H9PUAFf267h3c519tPcIGA5xJapzyKFi57EeNVQ3Kz tOHu1uW1+yj7SHaBrFW6bjgV22rsExZ+7t2M9llWo92DfIZP0wZnXPll14ktcS08ckf3 Ui4ihs5JrCeSmS3eH5Nl4tfoRUaJy6XZKAAzc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9TThp1HI4kpOvu/0H4PBMLArwdOhxuUAZO1JZOsPPQg=; b=3JxaMRzejP4fFi+bFBMB+Q8JYBUBJ74fuuiePoA/XX/6jySYQfqqczi1dYse5vQIgJ bm2KKHZBqA6HUWyPWcYAbJjJhih7fj5P29RDaI/JJ/kEgMrL/2mWwEymsWZiQjayIZAM nBtI7YMc2S5pamFwqVztsp3GvyvsVR/Oh7oSjYXIuWx/F0C2AgnkxGvE0DDfFtwJdZhd 9VNLAAtJmr68h6NPMC8425SBe2Lt4d7eGxpKlDI27oQ81tCIrLxkIFFF72nJQCsZ1EfO 5/ISs9SUpNeMXWh5IxirZJWHIbaZGejC7uQApjZCxvde22Pqe7l8wYtvPTkqX7wfqy0M WAOw== X-Gm-Message-State: AOAM531+GpDgIpFBBwhYFYiCFhg6q929ARV0EoRbPAW8aO8lmLC40JzH kYu5DSTAFPh6B+0px1S0JzM6XpC6oHkZgg== X-Google-Smtp-Source: ABdhPJwjQC+qCihdnzdY1vNpbSK51KgkxFZVSGTlOO3vcnbR+OzHP2rYtlawrDqsb8r7WMaWxTk2PQ== X-Received: by 2002:a17:902:a613:b0:13d:d95c:c892 with SMTP id u19-20020a170902a61300b0013dd95cc892mr2861830plq.35.1634785834417; Wed, 20 Oct 2021 20:10:34 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:21a4:fcf9:f5bb:f740]) by smtp.gmail.com with ESMTPSA id z1sm4016255pfh.150.2021.10.20.20.10.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:10:33 -0700 (PDT) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Cc: kaleshsingh@google.com, daniel@ffwll.ch, rostedt@goodmis.org Subject: [RFC PATCH 5/8] drm: start using drm_gem_trace_gpu_mem_instance Date: Wed, 20 Oct 2021 20:10:24 -0700 Message-Id: <20211021031027.537-6-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20211021031027.537-1-gurchetansingh@chromium.org> References: <20211021031027.537-1-gurchetansingh@chromium.org> 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" - drm_gem_handle_create_tail(..) increases the per instance memory counter. - drm_gem_object_release_handle(..) decreases the per instance memory counter. Signed-off-by: Gurchetan Singh Reported-by: kernel test robot --- drivers/gpu/drm/drm_gem.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 528d7b29dccf..6f70419f2c90 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -298,6 +298,7 @@ drm_gem_object_release_handle(int id, void *ptr, void *data) { struct drm_file *file_priv = data; struct drm_gem_object *obj = ptr; + struct drm_device *dev = file_priv->minor->dev; if (obj->funcs->close) obj->funcs->close(obj, file_priv); @@ -305,6 +306,7 @@ drm_gem_object_release_handle(int id, void *ptr, void *data) drm_gem_remove_prime_handles(obj, file_priv); drm_vma_node_revoke(&obj->vma_node, file_priv); + drm_gem_trace_gpu_mem_instance(dev, file_priv, -obj->size, false); drm_gem_object_handle_put_unlocked(obj); return 0; @@ -447,6 +449,7 @@ drm_gem_handle_create_tail(struct drm_file *file_priv, goto err_revoke; } + drm_gem_trace_gpu_mem_instance(dev, file_priv, obj->size, false); *handlep = handle; return 0; From patchwork Thu Oct 21 03:10:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 12573667 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D9F8C433EF for ; Thu, 21 Oct 2021 03:10:47 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 400EF611CC for ; Thu, 21 Oct 2021 03:10:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 400EF611CC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C89C86E3FE; Thu, 21 Oct 2021 03:10:40 +0000 (UTC) Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by gabe.freedesktop.org (Postfix) with ESMTPS id 001BB6EA64 for ; Thu, 21 Oct 2021 03:10:35 +0000 (UTC) Received: by mail-pl1-x632.google.com with SMTP id g5so17533856plg.1 for ; Wed, 20 Oct 2021 20:10:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AwgsndVmfHw/6pjlQaZU2erZEw/1WQ3kWFjNXQQ/usw=; b=QVYUVNLV8P3IAQqTDiFZYwO/JJzXGzHLG/xlruYZIsaIlBJlkYg33OqiDiXDOEOnsA n139ls4Ep3AjqEsuyItWrReMJuqEIgGyUIQRqOxD6KEhlMHJ9bInipFm0kw/c8/+Hn5b DPsmpLV+GFeJiQCFA+2VyHMHHxQotgH6/cRHs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AwgsndVmfHw/6pjlQaZU2erZEw/1WQ3kWFjNXQQ/usw=; b=iHTV2Vnl7guspa8JYlJTD3H7PzbfbkukBKEj7o/NQoxbm+gpIMNUsn26vtcnaAkPzD jf2XB2t2K5iwMHpt+OThpONgbGho2wbLv1Sd46Xq6kSANxZYLhPJ34hmMMGqMit4xQNZ sHqlfkt2TlNwq1dmACPR3W77unhrOi+IFsGoLsPoVPbnhgDyG0IdX0Qrr664TNpnsjgx jlD8uFgtPMASlgmw17lCOSo+Zx5IzXbHD9uh6QrQI+PS777DkfRKNnje0InBE25I5Vq2 vT9/J7w+FR1Jduc8RXi3ffid0pS0x3M5SOjjQ0b5LYqmMJIpZ71Wpi6FejOi/vaL2LMn bP1g== X-Gm-Message-State: AOAM5320t2ZnfAxAZmuEpe308eiULixnAskAgr+1q3lpLQsjAn/ANUWY /PqDF72n7Y/GQLQKAMGNHsW3+biVbB9LXw== X-Google-Smtp-Source: ABdhPJxWw2WGryhCkcjWw7TZ74SSaUzjMVDMrpY7nz3ds0Uh6v2h9e6ucOwbBCeif9LFGnvHQbtCDA== X-Received: by 2002:a17:902:b40a:b0:13d:cbcd:2e64 with SMTP id x10-20020a170902b40a00b0013dcbcd2e64mr2882180plr.18.1634785835304; Wed, 20 Oct 2021 20:10:35 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:21a4:fcf9:f5bb:f740]) by smtp.gmail.com with ESMTPSA id z1sm4016255pfh.150.2021.10.20.20.10.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:10:34 -0700 (PDT) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Cc: kaleshsingh@google.com, daniel@ffwll.ch, rostedt@goodmis.org Subject: [RFC PATCH 6/8] drm: track real and fake imports in drm_prime_member Date: Wed, 20 Oct 2021 20:10:25 -0700 Message-Id: <20211021031027.537-7-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20211021031027.537-1-gurchetansingh@chromium.org> References: <20211021031027.537-1-gurchetansingh@chromium.org> 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Sometimes, an exported dma-buf is added to the import list. That messes up with trace point accounting, so track real vs. fake imports to correct this. Signed-off-by: Gurchetan Singh --- drivers/gpu/drm/drm_gem.c | 5 ++++- drivers/gpu/drm/drm_internal.h | 4 ++-- drivers/gpu/drm/drm_prime.c | 18 +++++++++++++----- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 6f70419f2c90..7637be0ceb74 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -226,8 +226,11 @@ drm_gem_remove_prime_handles(struct drm_gem_object *obj, struct drm_file *filp) */ mutex_lock(&filp->prime.lock); if (obj->dma_buf) { + struct drm_device *dev = filp->minor->dev; + bool removed_real_import = false; drm_prime_remove_buf_handle_locked(&filp->prime, - obj->dma_buf); + obj->dma_buf, + &removed_real_import); } mutex_unlock(&filp->prime.lock); } diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h index 17f3548c8ed2..40d572e46e2a 100644 --- a/drivers/gpu/drm/drm_internal.h +++ b/drivers/gpu/drm/drm_internal.h @@ -75,8 +75,8 @@ int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data, void drm_prime_init_file_private(struct drm_prime_file_private *prime_fpriv); void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv); void drm_prime_remove_buf_handle_locked(struct drm_prime_file_private *prime_fpriv, - struct dma_buf *dma_buf); - + struct dma_buf *dma_buf, + bool *removed_real_import); /* drm_drv.c */ struct drm_minor *drm_minor_acquire(unsigned int minor_id); void drm_minor_release(struct drm_minor *minor); diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index deb23dbec8b5..31f033ec8549 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -90,13 +90,15 @@ struct drm_prime_member { struct dma_buf *dma_buf; uint32_t handle; + bool fake_import; struct rb_node dmabuf_rb; struct rb_node handle_rb; }; static int drm_prime_add_buf_handle(struct drm_prime_file_private *prime_fpriv, - struct dma_buf *dma_buf, uint32_t handle) + struct dma_buf *dma_buf, uint32_t handle, + bool fake_import) { struct drm_prime_member *member; struct rb_node **p, *rb; @@ -108,6 +110,7 @@ static int drm_prime_add_buf_handle(struct drm_prime_file_private *prime_fpriv, get_dma_buf(dma_buf); member->dma_buf = dma_buf; member->handle = handle; + member->fake_import = fake_import; rb = NULL; p = &prime_fpriv->dmabufs.rb_node; @@ -188,9 +191,11 @@ static int drm_prime_lookup_buf_handle(struct drm_prime_file_private *prime_fpri } void drm_prime_remove_buf_handle_locked(struct drm_prime_file_private *prime_fpriv, - struct dma_buf *dma_buf) + struct dma_buf *dma_buf, + bool *removed_real_import) { struct rb_node *rb; + *removed_real_import = false; rb = prime_fpriv->dmabufs.rb_node; while (rb) { @@ -201,6 +206,9 @@ void drm_prime_remove_buf_handle_locked(struct drm_prime_file_private *prime_fpr rb_erase(&member->handle_rb, &prime_fpriv->handles); rb_erase(&member->dmabuf_rb, &prime_fpriv->dmabufs); + if (!member->fake_import) + *removed_real_import = true; + dma_buf_put(dma_buf); kfree(member); return; @@ -303,7 +311,6 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev, return PTR_ERR(dma_buf); mutex_lock(&file_priv->prime.lock); - ret = drm_prime_lookup_buf_handle(&file_priv->prime, dma_buf, handle); if (ret == 0) @@ -315,6 +322,7 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev, obj = dev->driver->gem_prime_import(dev, dma_buf); else obj = drm_gem_prime_import(dev, dma_buf); + if (IS_ERR(obj)) { ret = PTR_ERR(obj); goto out_unlock; @@ -334,7 +342,7 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev, goto out_put; ret = drm_prime_add_buf_handle(&file_priv->prime, - dma_buf, *handle); + dma_buf, *handle, false); mutex_unlock(&file_priv->prime.lock); if (ret) goto fail; @@ -473,7 +481,7 @@ int drm_gem_prime_handle_to_fd(struct drm_device *dev, * ioctl doesn't miss to remove this buffer handle from the cache. */ ret = drm_prime_add_buf_handle(&file_priv->prime, - dmabuf, handle); + dmabuf, handle, true); mutex_unlock(&dev->object_name_lock); if (ret) goto fail_put_dmabuf; From patchwork Thu Oct 21 03:10:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 12573671 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92765C433F5 for ; Thu, 21 Oct 2021 03:10:52 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 5CABA611CC for ; Thu, 21 Oct 2021 03:10:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5CABA611CC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 00BB96EA64; Thu, 21 Oct 2021 03:10:41 +0000 (UTC) Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by gabe.freedesktop.org (Postfix) with ESMTPS id C94A16EA64 for ; Thu, 21 Oct 2021 03:10:36 +0000 (UTC) Received: by mail-pf1-x430.google.com with SMTP id k26so4644128pfi.5 for ; Wed, 20 Oct 2021 20:10:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LfwENsRJQFvw6YG/rstNPj2wimv2P8a7Qj183UL5rSc=; b=Em6XK05tPSv3xVQhFgdWCyxtQaykaElUtClkkvToYV+qPGkvoumcWLNV5bCL5JWjZh H+8HqChvHTlvBDJQ7RvZjf9Z09kIPwIQMedoRiqHW06Yb6nmRxgo4+QJ35TsP1tDvcZy wH9YaXh8CTM308yB+5JOiIMcoGahNHYXuWxhg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LfwENsRJQFvw6YG/rstNPj2wimv2P8a7Qj183UL5rSc=; b=uOVZdFBFlw8YqIdKGhRNc9uzBhYsIGVrTBI8O3jsHlETyRnkU7kj+ULsQJYN9Gkjma J3Nsez4GdHGE1MTwpWTkvo60gp7BzKA+S0Etf/pXKxze3FQMcORLG3Rkzvom3YqXzHl5 c2uwdIX68HIHT6SWyRc9wr6WE+oSqceM4zkB/FJaGNMf/9g8bHnCP39d8Eq4PWx4HW0U e7zvLZToXrPK4Sw+N721KJgleghyb8l4E1OV8wRNKls6GmZHQWnd4jnvXBuVbpK+4USA JCYWyJ8khPmj0VwuXSNRmYrYyMt2Z/Vn1Gw/lX4xK8BFbzTT83fIxB6jQZEIOJhZHJUI 7mMw== X-Gm-Message-State: AOAM532b+eUh5SCd1ecp4sy5eD5ifB60ALuyPaK7po4uPO667pFzDeIj Q0hBDTBFt2819ceyk8rj8BhK9fHEuTAOrA== X-Google-Smtp-Source: ABdhPJz6Emk/d9nzgz9HUo+zk5QFiC4hGj0Obh6mBOVRt7XHXH59y6O1cO9cn2d+xTHaqBmaw3VA3A== X-Received: by 2002:a05:6a00:b95:b0:44c:7c8b:f762 with SMTP id g21-20020a056a000b9500b0044c7c8bf762mr2705822pfj.60.1634785836027; Wed, 20 Oct 2021 20:10:36 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:21a4:fcf9:f5bb:f740]) by smtp.gmail.com with ESMTPSA id z1sm4016255pfh.150.2021.10.20.20.10.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:10:35 -0700 (PDT) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Cc: kaleshsingh@google.com, daniel@ffwll.ch, rostedt@goodmis.org Subject: [RFC PATCH 7/8] drm: trace memory import per DRM file Date: Wed, 20 Oct 2021 20:10:26 -0700 Message-Id: <20211021031027.537-8-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20211021031027.537-1-gurchetansingh@chromium.org> References: <20211021031027.537-1-gurchetansingh@chromium.org> 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" - drm_gem_prime_fd_to_handle increases the per-instance imported memory counter - drm_gem_remove_prime_handles decreases the per-instance imported memory counter on non-fake imports. Signed-off-by: Gurchetan Singh --- drivers/gpu/drm/drm_gem.c | 3 +++ drivers/gpu/drm/drm_prime.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 7637be0ceb74..c07568ea8442 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -231,6 +231,9 @@ drm_gem_remove_prime_handles(struct drm_gem_object *obj, struct drm_file *filp) drm_prime_remove_buf_handle_locked(&filp->prime, obj->dma_buf, &removed_real_import); + if (removed_real_import) + drm_gem_trace_gpu_mem_instance(dev, filp, -obj->size, + true); } mutex_unlock(&filp->prime.lock); } diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index 31f033ec8549..1afcae0c4038 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -349,6 +349,8 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev, dma_buf_put(dma_buf); + drm_gem_trace_gpu_mem_instance(dev, file_priv, obj->size, true); + return 0; fail: From patchwork Thu Oct 21 03:10:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 12573677 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A574DC433EF for ; Thu, 21 Oct 2021 03:10:58 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 74C51611CB for ; Thu, 21 Oct 2021 03:10:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 74C51611CB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C66766EA73; Thu, 21 Oct 2021 03:10:53 +0000 (UTC) Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by gabe.freedesktop.org (Postfix) with ESMTPS id C72946E3FE for ; Thu, 21 Oct 2021 03:10:37 +0000 (UTC) Received: by mail-pj1-x1036.google.com with SMTP id q10-20020a17090a1b0a00b001a076a59640so4928318pjq.0 for ; Wed, 20 Oct 2021 20:10:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v1CzWrWFVukEInFcsIV8dpfWP+HgwJWws9TvsQtzZYQ=; b=LmiFPrPu2utQ93qeT47eDCtd/GvNiHZTSnwEo8dBBX1ckGPSWuHiq9Km+I5+pbayf4 TjReip323K18tz/JXLDBd78kETg6wDoMS/u2wZaNx6Nlfpnz8nnhrzvTB8RZgRBUtcSs X8ghCRGe25WuxXlFwFoiM+IHGD4ne0lrYTR88= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=v1CzWrWFVukEInFcsIV8dpfWP+HgwJWws9TvsQtzZYQ=; b=IvBG6w+D7cRqNbdV2qibL9tSEE79eDrs1qMrreT09A5QKtbkcy3GR7kUMf30ERuMZ0 xI1V947VgY7/SHNqpgeaVLGUUsQFOIX4GKptptESQ6ei4SvT50xQ8py/YXJtCDiaoqKC c2/Yv7O94O0ZJhWGyVDH5APoigQ09crE40wLgpQxWjZKgS2p23R2eR33TXZSQWKI2AsA 7T0qpiVQ2oH3Tz2X2Ync9+Ggm/Jn9Y2K9KzPuUn+f+F4TZR9R4qN+1SZdZPLQ/xZHsxv 90E13EPSEDMycd1Gjausu67yRLyPVxpWOySOq0LYKluEs4ey4jcfwd0udDcMlFomGGA8 tEzw== X-Gm-Message-State: AOAM533gJz5tvmhdbEusWCGc+Z1iR9smtLig3Uy/M8jraTXYUF/Qg997 bo4PAbK7KNyfLMrxhAmCRvTyYZWyRQLT0w== X-Google-Smtp-Source: ABdhPJxaeaICwlCneJFeg6r6/K+h2EZ/TerlwQu0koHctvBU2AlY2jqRNqefxcCSedeT59Do3wvWgw== X-Received: by 2002:a17:902:900c:b0:13f:974c:19b0 with SMTP id a12-20020a170902900c00b0013f974c19b0mr2885138plp.12.1634785837133; Wed, 20 Oct 2021 20:10:37 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:21a4:fcf9:f5bb:f740]) by smtp.gmail.com with ESMTPSA id z1sm4016255pfh.150.2021.10.20.20.10.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:10:36 -0700 (PDT) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Cc: kaleshsingh@google.com, daniel@ffwll.ch, rostedt@goodmis.org Subject: [RFC PATCH 8/8] drm: trace memory import per DRM device Date: Wed, 20 Oct 2021 20:10:27 -0700 Message-Id: <20211021031027.537-9-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20211021031027.537-1-gurchetansingh@chromium.org> References: <20211021031027.537-1-gurchetansingh@chromium.org> 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" - drm_gem_prime_import_dev increases the per-device import memory counter * Most drivers use it. * drivers that have a (*gem_prime_import) callback will need additional changes, which can be done if everyone likes the overall RFC. - drm_prime_gem_destroy decreases the per-device import memory counter. * All drivers seem to use it? Signed-off-by: Gurchetan Singh --- drivers/gpu/drm/drm_prime.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index 1afcae0c4038..c2057b7a63b4 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -955,6 +955,7 @@ struct drm_gem_object *drm_gem_prime_import_dev(struct drm_device *dev, obj->import_attach = attach; obj->resv = dma_buf->resv; + drm_gem_trace_gpu_mem_total(dev, obj->size, true); return obj; @@ -1055,6 +1056,7 @@ void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg) struct dma_buf_attachment *attach; struct dma_buf *dma_buf; + drm_gem_trace_gpu_mem_total(obj->dev, -obj->size, true); attach = obj->import_attach; if (sg) dma_buf_unmap_attachment(attach, sg, DMA_BIDIRECTIONAL);