From patchwork Thu Jan 12 16:56:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 42673 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4013250wrt; Thu, 12 Jan 2023 09:38:14 -0800 (PST) X-Google-Smtp-Source: AMrXdXteKBa6/HGGxpsLyqgLKaoGsjiAUi9wWnhqlBOUyTlJtAlP9mtYP2Gdj6K8k1h21T3wsmKv X-Received: by 2002:aa7:9796:0:b0:58a:66a8:edf5 with SMTP id o22-20020aa79796000000b0058a66a8edf5mr11501042pfp.3.1673545094380; Thu, 12 Jan 2023 09:38:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673545094; cv=none; d=google.com; s=arc-20160816; b=YaeKFw8/qSw1rOzpXHIPs5awYcG9dseFDg5Kp6u4np0yXsZl3cOA4o0SDnHCD4nwqK ENUQNdhE6iE8RQJs3ax+WnB6HrCwZU6cl2mgGwgCJgJDtjkJsNpVwY6LcXKuN2kmsMU4 z+OBHwU3aFDTYKmOvLXckVvnz28IexAdW3wd3izTgZ6suTGzdbDR3cQ1kZPcQwz/laDr Jk7e7E1ylGa1tLnX2LRjY2l5NU4ARh9ogO+uwKyPLyik9R5BKPXc7GR3oIia6/w+TyD9 AV2/2Evw/oySSMr6+YsgI4iXVIkT8rBphQyWP8ATViwFF90KWTlLvKXNlM7SKL+Zkgup py2A== 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=1jz1M7xOjkWvKh7JC8SglbFcNBMG+/84syQFCczswJQ=; b=SbJ71LYr4bcolwXu9ug1DMrxdcJGT9AlK9esZlxZF8ZTdkmhIfLtqgHdYzVWyOjJoM lymSXoSAyiJj2eDPV1OHO6Iz89HxjUlwalq7LV1HZ1RGXmkxOPJJhM3WST6b3/2uVZ6L n41Hx/VV5xlxXwLaAnwQXpW6mk7HJdIL5ZrL7QGm7vc60YjXKpVwI19oZyMYiqZd0Rau BYyD14TfsVFe5OqCAmQJwv1ioI8X/w5V357szzyLFRDEFh+LVGvxn5StiTJRed1nZ7IM 5TTbyDectI35CHQXDanZRyRpv3dje7cQemUtt6LT5OkcBMHxyg6STgLbkdvqKAZWG9T7 FCRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gr5YodDu; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x19-20020aa78f13000000b0056ea2b1b0fesi17908384pfr.119.2023.01.12.09.38.01; Thu, 12 Jan 2023 09:38:14 -0800 (PST) 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=gr5YodDu; 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 S231246AbjALRg6 (ORCPT + 99 others); Thu, 12 Jan 2023 12:36:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229680AbjALRgN (ORCPT ); Thu, 12 Jan 2023 12:36:13 -0500 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5E466B58B; Thu, 12 Jan 2023 08:57:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673542675; x=1705078675; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5tUTxI03m+NTLtcglmz0tTkp8uvuUcMX2wFEFmhnCZQ=; b=gr5YodDuerwBQpE/UJU3gArgEwRoR95cUhGIrKTfPRJSbXAZ9VyJhKLK YSsxEtfU2ghk+8vtG/4Ix0bppiM0Qn0HpbnkUG2xF2DY3+1Q7XaAfp9tZ T5uMKPiKacYagxDw5C+ZtW4LcBYOViaHbAfQTSMJCS21tOhJnwo2NAmpN Ua9mvST6mLSveY9ZCjbLAv/IKrMMEXO6+7BlXGdNUP5FlorYsAPUhnTnC mC5rUS0OPDKa+++egBp9syE3IIWygKDNYBqrewZrrq+c1y5qcctMaxuge ZedOwQ2PhCjZ7s2bcTmjjNPOqj52XBvOagFo3A6W37vMyoXR+zvL196pg w==; X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="325016371" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="325016371" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:56:38 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="651232620" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="651232620" Received: from jacton-mobl.ger.corp.intel.com (HELO localhost.localdomain) ([10.213.195.171]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:56:34 -0800 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_Marchesin?= , "T . J . Mercier" , Kenny.Ho@amd.com, =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , Brian Welty , Tvrtko Ursulin Subject: [RFC 03/12] cgroup: Add the DRM cgroup controller Date: Thu, 12 Jan 2023 16:56:00 +0000 Message-Id: <20230112165609.1083270-4-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230112165609.1083270-1-tvrtko.ursulin@linux.intel.com> References: <20230112165609.1083270-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3.3 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_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_NONE 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?1754839221025335946?= X-GMAIL-MSGID: =?utf-8?q?1754839221025335946?= From: Tvrtko Ursulin Skeleton controller without any functionality. Signed-off-by: Tvrtko Ursulin --- include/linux/cgroup_drm.h | 9 ++++++ include/linux/cgroup_subsys.h | 4 +++ init/Kconfig | 7 +++++ kernel/cgroup/Makefile | 1 + kernel/cgroup/drm.c | 59 +++++++++++++++++++++++++++++++++++ 5 files changed, 80 insertions(+) create mode 100644 include/linux/cgroup_drm.h create mode 100644 kernel/cgroup/drm.c diff --git a/include/linux/cgroup_drm.h b/include/linux/cgroup_drm.h new file mode 100644 index 000000000000..bf8abc6b8ebf --- /dev/null +++ b/include/linux/cgroup_drm.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright © 2022 Intel Corporation + */ + +#ifndef _CGROUP_DRM_H +#define _CGROUP_DRM_H + +#endif /* _CGROUP_DRM_H */ diff --git a/include/linux/cgroup_subsys.h b/include/linux/cgroup_subsys.h index 445235487230..49460494a010 100644 --- a/include/linux/cgroup_subsys.h +++ b/include/linux/cgroup_subsys.h @@ -65,6 +65,10 @@ SUBSYS(rdma) SUBSYS(misc) #endif +#if IS_ENABLED(CONFIG_CGROUP_DRM) +SUBSYS(drm) +#endif + /* * The following subsystems are not supported on the default hierarchy. */ diff --git a/init/Kconfig b/init/Kconfig index 7e5c3ddc341d..c5ace0d57007 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1089,6 +1089,13 @@ config CGROUP_RDMA Attaching processes with active RDMA resources to the cgroup hierarchy is allowed even if can cross the hierarchy's limit. +config CGROUP_DRM + bool "DRM controller" + help + Provides the DRM subsystem controller. + + ... + config CGROUP_FREEZER bool "Freezer controller" help diff --git a/kernel/cgroup/Makefile b/kernel/cgroup/Makefile index 12f8457ad1f9..849bd2917477 100644 --- a/kernel/cgroup/Makefile +++ b/kernel/cgroup/Makefile @@ -6,4 +6,5 @@ obj-$(CONFIG_CGROUP_PIDS) += pids.o obj-$(CONFIG_CGROUP_RDMA) += rdma.o obj-$(CONFIG_CPUSETS) += cpuset.o obj-$(CONFIG_CGROUP_MISC) += misc.o +obj-$(CONFIG_CGROUP_DRM) += drm.o obj-$(CONFIG_CGROUP_DEBUG) += debug.o diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c new file mode 100644 index 000000000000..48a8d646a094 --- /dev/null +++ b/kernel/cgroup/drm.c @@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright © 2022 Intel Corporation + */ + +#include +#include +#include +#include + +struct drm_cgroup_state { + struct cgroup_subsys_state css; +}; + +struct drm_root_cgroup_state { + struct drm_cgroup_state drmcs; +}; + +static inline struct drm_cgroup_state * +css_to_drmcs(struct cgroup_subsys_state *css) +{ + return container_of(css, struct drm_cgroup_state, css); +} + +static struct drm_root_cgroup_state root_drmcs; + +static void drmcs_free(struct cgroup_subsys_state *css) +{ + if (css != &root_drmcs.drmcs.css) + kfree(css_to_drmcs(css)); +} + +static struct cgroup_subsys_state * +drmcs_alloc(struct cgroup_subsys_state *parent_css) +{ + struct drm_cgroup_state *drmcs; + + if (!parent_css) { + drmcs = &root_drmcs.drmcs; + } else { + drmcs = kzalloc(sizeof(*drmcs), GFP_KERNEL); + if (!drmcs) + return ERR_PTR(-ENOMEM); + } + + return &drmcs->css; +} + +struct cftype files[] = { + { } /* Zero entry terminates. */ +}; + +struct cgroup_subsys drm_cgrp_subsys = { + .css_alloc = drmcs_alloc, + .css_free = drmcs_free, + .early_init = false, + .legacy_cftypes = files, + .dfl_cftypes = files, +};