From patchwork Wed Oct 23 07:52:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Lankhorst X-Patchwork-Id: 13846617 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3F0CD2E026 for ; Wed, 23 Oct 2024 07:53:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 721166B0088; Wed, 23 Oct 2024 03:53:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6AA0C6B0089; Wed, 23 Oct 2024 03:53:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B1296B008C; Wed, 23 Oct 2024 03:53:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 1D7B96B0088 for ; Wed, 23 Oct 2024 03:53:09 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 07FFE16077B for ; Wed, 23 Oct 2024 07:52:49 +0000 (UTC) X-FDA: 82704100752.30.37EC2D0 Received: from mblankhorst.nl (lankhorst.se [141.105.120.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 3E1E7C001E for ; Wed, 23 Oct 2024 07:52:46 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; spf=none (imf22.hostedemail.com: domain of mlankhorst@mblankhorst.nl has no SPF policy when checking 141.105.120.124) smtp.mailfrom=mlankhorst@mblankhorst.nl; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=intel.com (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729669910; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ejpx4io7xkTkt6wdywiSczKdYJy3tk7mjiwA8WRzGUs=; b=NW2iPZo1J+tszO47k6D0kVL7dTOnv2IrXK/7LsYwtGDbRuqftGGc2u5/8dagVJrCVxvAES u/MHMY/vmmaGltpx0h7C7U5NJtSSpt/GNsjGelnSRGJuQ0tRcbZDh+fJaSF+PzoJalLN55 wd2Isr/LyV7P146vRBLX+36y/z7fQ/w= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; spf=none (imf22.hostedemail.com: domain of mlankhorst@mblankhorst.nl has no SPF policy when checking 141.105.120.124) smtp.mailfrom=mlankhorst@mblankhorst.nl; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=intel.com (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729669910; a=rsa-sha256; cv=none; b=qSTGFE4KbwUwOguDuU7jfTzvlL5ojm96gQsgXh4MbTvd/KLpvh67hWDYkYLmcnxB78dtlx IMRLTJgZTzv0uUdZ+BglNLDz79BgTYX5EQCGBnfQURDu1EIJPn4CabiZq8+yU1NkYxHzwO 80tZcG+MaqWJbQNAj+cTtJRxkYqdsxk= From: Maarten Lankhorst To: intel-xe@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Tejun Heo , Zefan Li , Johannes Weiner , Andrew Morton Cc: Friedrich Vock , cgroups@vger.kernel.org, linux-mm@kvack.org, Maxime Ripard , Maarten Lankhorst Subject: [PATCH 4/7] drm/xe: Implement cgroup for vram Date: Wed, 23 Oct 2024 09:52:57 +0200 Message-ID: <20241023075302.27194-5-maarten.lankhorst@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241023075302.27194-1-maarten.lankhorst@linux.intel.com> References: <20241023075302.27194-1-maarten.lankhorst@linux.intel.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 3E1E7C001E X-Stat-Signature: thyq68a8hhyyw561bsm73gf1um6qktyo X-HE-Tag: 1729669966-91516 X-HE-Meta: U2FsdGVkX1/JUBA4N2w+MheJiY1gJ++pFU4CZzgJ72WMe2PiaNXX2loST16pFhhfgGzWtl0VprF9TyJ8Z/UjO4oS5Zjhmn4ye/4oWWplvTJMmofNdMVdzUE6rZJRZgUMOaz/FxUjIUr4LPU6zoTov90pnw2BFVRCDnbd8wyIanzfAi3qBQdjsqptC+FpvLTTRLS/+Ah6UaDIirqyDWBXg1B2YQ5F+v8j0G0F8U1+z32TriBFr1PMywDnTGqq1wq6e1iK+0QVks/JerrAr8ESEl1VTSurELyDSXYObm3ubAy7x57sCexXa3fSI/WAVXg2ZR8pubTHx64U9kwrnHB+tS1xtgvC/MMq06XUZ44HevHkE8nU3vlMdM8Cszj9Cb6wYUXQjZFyQlYbJJmaKtztR9aKeTFx+YsX3mN9neTblfjcPUb3hV/KdXE2FIoLCrGadHm0LBWTngs5/tG78Vsy0sBWt5s6ODNbJ/DI2WC2Lk9VmMij4SFPMy95dscX4T21sdWmRoiA9NWMRWsmHDzwcqQcrRElZejaQjkjYjk/dcpjvpTqoorv/Gjm4PwtwCHKP0Ehst00msvxoOEBbB3adOtpbfGxlUzlfp2s8oJgJJthVndnG80D3lCwqWaQgB67XPculRMQ6dqvO3ycIV9lXtoO9KlqrIek6JNcq8K+q7MUhYj+o236ylAa0+2POQhgcrXwXzCBTd6GvETYLWi7xIwm2Bwkfr2NGI5TLXQPj/dBSSSRkpAqfrr6iVJZW+mxtbXVsFswh10mxCnbA6hildeZMeVF/Rl6hCgLmJFiM62BikoyJdxV1uaqojUmsrV/XHwikYP0Rgzy6vk1u2GQK3S9voW0nfbNzqtwaiiD2LvD5Kbvr5OYwgQGea6Iuz+wo+Gc6p5buk3gKwdJVVf1+cIuZCJZIvLwB9Pz1BBcthgd8MvKpXJ/0+aSGBzyyu01R0DGUyhj225zSFNKyDg OZcRl67V 4lHoKvvyDU3kDfvwz8LdtsQy4F13l8C9WPG7+dV/VKOeK26EZ0Kt9Nysl8IZTXDf2Xphk8+VES++HwT0UP/Tk57OeOK92hgwnMuEUfiEpV/PtfsvAoV6h6JlYfiwWyk9JJt20hNUK9EILqmJB5FgROJDjX//61JZeK5+dh/1Ibwvd59G5J7+bTdDzy8xe4yLGOf+500PIaFqJ/Od6uQQWSCueDxv+CcYs5ATrQtZvr/ZrqtgPq4QlA3lPD7Nw1t63E9j/ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add vram based cgroup eviction to Xe. Most hardware with VRAM uses TTM for its management, and can be similarly trivially enabled. Co-developed-by: Maxime Ripard Signed-off-by: Maxime Ripard Signed-off-by: Maarten Lankhorst --- drivers/gpu/drm/xe/xe_device.c | 4 ++++ drivers/gpu/drm/xe/xe_device_types.h | 4 ++++ drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 10 ++++++++++ 3 files changed, 18 insertions(+) diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c index 51bb9d875268f..cb4b2013eb808 100644 --- a/drivers/gpu/drm/xe/xe_device.c +++ b/drivers/gpu/drm/xe/xe_device.c @@ -726,6 +726,10 @@ int xe_device_probe(struct xe_device *xe) /* Allocate and map stolen after potential VRAM resize */ xe_ttm_stolen_mgr_init(xe); + err = drmm_cgroup_register_device(&xe->drm, &xe->cg); + if (err) + goto err; + /* * Now that GT is initialized (TTM in particular), * we can try to init display, and inherit the initial fb. diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h index 85bede4dd6461..0401b4fe6f645 100644 --- a/drivers/gpu/drm/xe/xe_device_types.h +++ b/drivers/gpu/drm/xe/xe_device_types.h @@ -7,6 +7,7 @@ #define _XE_DEVICE_TYPES_H_ #include +#include #include #include @@ -257,6 +258,9 @@ struct xe_device { /** @devcoredump: device coredump */ struct xe_devcoredump devcoredump; + /** @cg: device cgroup bookkeeping */ + struct dev_cgroup_device cg; + /** @info: device info */ struct intel_device_info { /** @info.platform_name: platform name */ diff --git a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c index 423b261ea7430..cb463be53f4bc 100644 --- a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c +++ b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c @@ -339,6 +339,16 @@ int __xe_ttm_vram_mgr_init(struct xe_device *xe, struct xe_ttm_vram_mgr *mgr, struct ttm_resource_manager *man = &mgr->manager; int err; + if (mem_type != XE_PL_STOLEN) { + int cgregion = xe->cg.num_regions++; + + xe->cg.regions[cgregion].size = size; + xe->cg.regions[cgregion].name = + mem_type == XE_PL_VRAM0 ? "vram0" : "vram1"; + man->cgdev = &xe->cg; + man->cgidx = cgregion; + } + man->func = &xe_ttm_vram_mgr_func; mgr->mem_type = mem_type; mutex_init(&mgr->lock);