From patchwork Thu Jun 27 15:47:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Lankhorst X-Patchwork-Id: 13714717 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 1DD1BC2BD09 for ; Thu, 27 Jun 2024 15:48:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 38D9D6B0096; Thu, 27 Jun 2024 11:48:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 33F296B0099; Thu, 27 Jun 2024 11:48:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 190FA6B009A; Thu, 27 Jun 2024 11:48:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id DEF6E6B0096 for ; Thu, 27 Jun 2024 11:48:11 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 94377A0B10 for ; Thu, 27 Jun 2024 15:48:11 +0000 (UTC) X-FDA: 82277099982.04.BA49817 Received: from mblankhorst.nl (lankhorst.se [141.105.120.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 09F7710000A for ; Thu, 27 Jun 2024 15:48:09 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; spf=none (imf14.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=1719503281; a=rsa-sha256; cv=none; b=hq6XwT4kbSHdoA0scXpy+dgoqiA5/1NQ9rJDwNJUyeh6mvrRglFZOlR1yIEZHQpaATrq1V Q3lFCaphX8PpL0ih6GPMOn6gEN/7nvbo0Ehz1f8wbkb32932NxZ9Cz3HHN0ooh0V+j+lvH iqLAZtajE3VC6+HIdZj/5wXOzUUcHOU= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; spf=none (imf14.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=1719503281; 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=ofPiDQ1ehYffKAtKWPwTW8iiyJRRsBbx21eivUic3V8=; b=Ii5aubNqQOFrCAh3xh8bvY2Wa1CylyhveKH7cmLTkXzgptgvN/Y4Tqv7s5769kNsX2v8uC e7UTII6QCBvRJ+sfPFVA0Q2kSKjHbN6KgRO74aNZpKa+K88GxX30ERnX306rNAvC7iHnpd IavOs/748AGFaDufXoeJM/966At3wes= 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 , Lucas De Marchi , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Rodrigo Vivi , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter Cc: Friedrich Vock , cgroups@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 4/6] drm/xe: Implement cgroup for vram Date: Thu, 27 Jun 2024 17:47:23 +0200 Message-ID: <20240627154754.74828-5-maarten.lankhorst@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240627154754.74828-1-maarten.lankhorst@linux.intel.com> References: <20240627154754.74828-1-maarten.lankhorst@linux.intel.com> MIME-Version: 1.0 X-Stat-Signature: p66sp5rw5477sjigj1t1da3dq6meptdb X-Rspamd-Queue-Id: 09F7710000A X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1719503289-161652 X-HE-Meta: U2FsdGVkX196PFbb2wA5g9TE0jOistHz8md37+RC9WaVukgAWmYMX8NnB8nSoqUyMrjXzZjO6T28uX5GcdZ3dD0iTSMBKZ+FtjtA/aCPCCuC5OY3w8NXbhHyHlMvjbp5ZIoLreThJAfmamL5MXwEGbAyVWIGWD9gwB2kZH/3jRSsCRdVMocqeHqSkY7LiD+y4RlXG+02HR8/O9lLcbG18Pc/Xki05OLTQmig7MBK4XBzMzTN+VYc6C73+uo9GeLG96f2vphSmOcLB8ahJZmio8k8u5+/7FLtnM13NPmcxFeqZyMdqYXcYvqh4wRXtkTK9eMtkW6n0C73+RYc75MOWjk8Z+SsZOSGx7ENTiCHkqwoKfwfc9T18AK0/+v4vrH9RfhWnlFMoLsQrT9Dslztz0xZTYBnUjGTXyuzRu+3oo1kZFwbnLzmFJEM9dK1CNJvPy1op9E1VKgHXdGHAq48/FgCc9v4QF8+w4d0yVC+4O8p6bxHnjex+9h42daMI9s9HdKFX3K6xHcPQnf0Nou4g0DlOC6VC/HyCjH3UK4GaR+6xWCOj29idGq2MI82XjXzqaRJ9CfXiplTaqn+Ghf1zBFmaX3TnELuFcblox/4skF1lPckkO2F/NyempovPLfy/wDP0K7+whMZ/hWZ/Pp/mwd+BFVRP+CgSAtcINz5ikBv7TnlACd7+Glxkl7juYhiC4DTpwXcofnnRFWp/KpWjIaQbQQfTRUYKNNbzUU+imwGKgvi6Kujms3iK5cbw9rbFSY94fmKDWITEC+qnswC3E5XYRDz1tm3AxdSKxgtTGpZo6uED0Xj0gBUrzqbB1d8/jv2mPJFdnwA9jzHrEkhpEdjopvNqtGBlXG9M7bpozmBYoMHYo5DYUBOGaxpna220yIc+J7Kpj/xdiyy15c1ukR9DqXN5BHp75GT6ltO9B1HMieir/+t3hFycty6l9dYanUIDdMRa/hJepE1Jnw d2ACrWiM tdbVulpECwwlGcK2RXJEqjQjosYClbVU9JtrVKuvDmVcat07ZnXcFz6rgdcTVOpA0ZS7Hp1mU9eRC98FCqk8ml0y16rXdRUrd4XKKQufB/PRy8fm3E1ODSwiss+TWpr8z8IgIAhU0Zjoz/vfmJcwgKd3EocL4ir0Y8IFLWHA6onVpW3iXGcsmQptIxVCl0xSJXk0aiNZXCOsXZfv4yVEntzXFNQ/dJBKoIGlFSLaiTIAPQ48/K0r0mOjDXi1IiT4yq60dnvfaxk2VFgk= 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. 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 5ef9b50a20d0..6e630d67b13a 100644 --- a/drivers/gpu/drm/xe/xe_device.c +++ b/drivers/gpu/drm/xe/xe_device.c @@ -616,6 +616,10 @@ int xe_device_probe(struct xe_device *xe) /* Allocate and map stolen after potential VRAM resize */ xe_ttm_stolen_mgr_init(xe); + err = drmmcg_register_device(&xe->drm, &xe->cg); + if (err) + goto err_irq_shutdown; + /* * 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 2e62450d86e1..6b60837d9090 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 @@ -216,6 +217,9 @@ struct xe_device { /** @devcoredump: device coredump */ struct xe_devcoredump devcoredump; + /** @cg: drm cgroup bookkeeping */ + struct drmcgroup_device cg; + /** @info: device info */ struct intel_device_info { /** @info.graphics_name: graphics IP name */ diff --git a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c index fe3779fdba2c..9a625b69fc52 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);