Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp38249569rwd; Wed, 12 Jul 2023 05:21:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlGgW5lrO4loqUUOw5GF4gcWm6/z4CbZHY5D02rJ2L+GUn4B8j/CRSRkVhuOUyTN/03lI8ie X-Received: by 2002:a05:6a00:985:b0:682:4e4c:48bc with SMTP id u5-20020a056a00098500b006824e4c48bcmr24194260pfg.21.1689164466851; Wed, 12 Jul 2023 05:21:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689164466; cv=none; d=google.com; s=arc-20160816; b=RFXbz0shz3jg4l0+aaSPE5qx10cZ+6jrEFj9Vnw6pho2Zf93rajx4DbGkShCFi3DS1 jnT/BQS7AOgP39CB6HNC1F4WU4SIl/Sfi+NMmspN+tEUhgCPJwM5QVLR/cj0BA0iCyfD P5tTESj8ShhV+cWm6eMXAlivUosG7vVl6U+9IkEFbKzIXD18P/CKrYD9l/iESOBWg+xs xkWG/QpnuYbETm6dyoh0KrvA33eeu39ycFwtEoblzizV0VH97vyZjFPEjF0xzzauhBnE ouyWekgxI/3YtElBCAkwsFKyhcVVsxos2VeEk87NSbKt6F4x+ExuBSA67yxOOgKJkkjG b7wQ== 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=aFY5RFhOHVG7ho530tNcbJHK5vbzUXzR+KGrC3oH15U=; fh=91Cr6lgbg2/7euFz8b0d14nlr8472cxl6H+/rDwdiaU=; b=QZF8BV19fheqNYRgwag5S5zbqNndWVQQx7GO8urRBriTwxjZ8ErpEWa4dWX5Ln7xL1 fygby6mkdmXmEAuyZFZumaCvcMdF6MHhfjrb9Defp1mqfai8cDIPwPIUG5A5nDfTtRak YjTkqijn0HC3ZWjHhGBhMMUpijVaFFB5oq5DZK4frFLylaRppdLfju0aUIiWYuDqLLhH 8Uk5mdeGwJSwm2gTBb9Zu1M56B3+BLy0xcNJRUFkeMuZ0YK2U8R9+rYGp2WYc4nONztd RMA4n1ECVaIJiXXYavREZsCPo7VoO8yN6eX/5FZdp5Ws4DnvfEWBl2GoGb2U60G6roMi jB1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=AtNUt514; 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=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h15-20020a056a00218f00b0063d19a45a93si3167672pfi.280.2023.07.12.05.20.54; Wed, 12 Jul 2023 05:21:06 -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=@intel.com header.s=Intel header.b=AtNUt514; 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=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233387AbjGLLtZ (ORCPT + 99 others); Wed, 12 Jul 2023 07:49:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233395AbjGLLtB (ORCPT ); Wed, 12 Jul 2023 07:49:01 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B80391FEC; Wed, 12 Jul 2023 04:48:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689162495; x=1720698495; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XfUgp3jiW7e0qUQq7cL+ROu1HZblCNZEW5a5U/4B3Zw=; b=AtNUt514oaV7Qkjp45zIJ9ZxGUYeESbbIfJxx6VZVyFE8UuFPRuRXXxo 80F7iwxm2/FaIgIktUQ5VE9c4ewSa9ngZk2MkRh4fXFDm/a7Rp93UKdsf 0W9k5eMkqtl6HrU6hRYpX6AzE0NqlZGD8CcrrqMp3HM3PjApBkN0p2xmX J7/RaBd8shLNjc0Nic7aPF2PQI62w6bphs6px4tticFKf2YDxcQ4PORaP jEhUCCOtzUvmjELlYl4iTD5zXmb9TGThYwXFAdwXn8TdykGfu+2rGN3LT StHw28nwuo7OkME6yJoHFXOeACi+/tD7XEZPtP238dQ2U6/DbKqr0695N w==; X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="344469145" X-IronPort-AV: E=Sophos;i="6.01,199,1684825200"; d="scan'208";a="344469145" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2023 04:46:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="866094096" X-IronPort-AV: E=Sophos;i="6.01,199,1684825200"; d="scan'208";a="866094096" Received: from eamonnob-mobl1.ger.corp.intel.com (HELO localhost.localdomain) ([10.213.237.202]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2023 04:46:31 -0700 From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Tejun Heo , Johannes Weiner , Zefan Li , Dave Airlie , Daniel Vetter , Rob Clark , =?UTF-8?q?St=C3=A9phane=20Marchesin?= , "T . J . Mercier" , Kenny.Ho@amd.com, =?UTF-8?q?Christian=20K=C3=B6nig?= , Brian Welty , Tvrtko Ursulin , Aravind Iddamsetty , Rob Clark Subject: [PATCH 05/17] drm/i915: Implement fdinfo memory stats printing Date: Wed, 12 Jul 2023 12:45:53 +0100 Message-Id: <20230712114605.519432-6-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230712114605.519432-1-tvrtko.ursulin@linux.intel.com> References: <20230712114605.519432-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HK_RANDOM_ENVFROM,HK_RANDOM_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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 From: Tvrtko Ursulin Use the newly added drm_print_memory_stats helper to show memory utilisation of our objects in drm/driver specific fdinfo output. To collect the stats we walk the per memory regions object lists and accumulate object size into the respective drm_memory_stats categories. Objects with multiple possible placements are reported in multiple regions for total and shared sizes, while other categories are counted only for the currently active region. Signed-off-by: Tvrtko Ursulin Cc: Aravind Iddamsetty Cc: Rob Clark --- drivers/gpu/drm/i915/i915_drm_client.c | 85 ++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c index a61356012df8..9e7a6075ee25 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.c +++ b/drivers/gpu/drm/i915/i915_drm_client.c @@ -45,6 +45,89 @@ void __i915_drm_client_free(struct kref *kref) } #ifdef CONFIG_PROC_FS +static void +obj_meminfo(struct drm_i915_gem_object *obj, + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN]) +{ + struct intel_memory_region *mr; + u64 sz = obj->base.size; + enum intel_region_id id; + unsigned int i; + + /* Attribute size and shared to all possible memory regions. */ + for (i = 0; i < obj->mm.n_placements; i++) { + mr = obj->mm.placements[i]; + id = mr->id; + + if (obj->base.handle_count > 1) + stats[id].shared += sz; + else + stats[id].private += sz; + } + + /* Attribute other categories to only the current region. */ + mr = obj->mm.region; + if (mr) + id = mr->id; + else + id = INTEL_REGION_SMEM; + + if (!obj->mm.n_placements) { + if (obj->base.handle_count > 1) + stats[id].shared += sz; + else + stats[id].private += sz; + } + + if (i915_gem_object_has_pages(obj)) { + stats[id].resident += sz; + + if (!dma_resv_test_signaled(obj->base.resv, + dma_resv_usage_rw(true))) + stats[id].active += sz; + else if (i915_gem_object_is_shrinkable(obj) && + obj->mm.madv == I915_MADV_DONTNEED) + stats[id].purgeable += sz; + } +} + +static void show_meminfo(struct drm_printer *p, struct drm_file *file) +{ + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN] = {}; + struct drm_i915_file_private *fpriv = file->driver_priv; + struct i915_drm_client *client = fpriv->client; + struct drm_i915_private *i915 = fpriv->i915; + struct drm_i915_gem_object *obj; + struct intel_memory_region *mr; + struct list_head *pos; + unsigned int id; + + /* Public objects. */ + spin_lock(&file->table_lock); + idr_for_each_entry(&file->object_idr, obj, id) + obj_meminfo(obj, stats); + spin_unlock(&file->table_lock); + + /* Internal objects. */ + rcu_read_lock(); + list_for_each_rcu(pos, &client->objects_list) { + obj = i915_gem_object_get_rcu(list_entry(pos, typeof(*obj), + client_link)); + if (!obj) + continue; + obj_meminfo(obj, stats); + i915_gem_object_put(obj); + } + rcu_read_unlock(); + + for_each_memory_region(mr, i915, id) + drm_print_memory_stats(p, + &stats[id], + DRM_GEM_OBJECT_RESIDENT | + DRM_GEM_OBJECT_PURGEABLE, + mr->name); +} + static const char * const uabi_class_names[] = { [I915_ENGINE_CLASS_RENDER] = "render", [I915_ENGINE_CLASS_COPY] = "copy", @@ -106,6 +189,8 @@ void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file) * ****************************************************************** */ + show_meminfo(p, file); + if (GRAPHICS_VER(i915) < 8) return; -- 2.39.2