From patchwork Thu Aug 29 06:05:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 11120373 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B82EA14D5 for ; Thu, 29 Aug 2019 06:05: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 9A97E23405 for ; Thu, 29 Aug 2019 06:05:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9A97E23405 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 91C0789F77; Thu, 29 Aug 2019 06:05:47 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM02-CY1-obe.outbound.protection.outlook.com (mail-eopbgr760052.outbound.protection.outlook.com [40.107.76.52]) by gabe.freedesktop.org (Postfix) with ESMTPS id C21F189C8D; Thu, 29 Aug 2019 06:05:45 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KJQR3P6n2DB47SQcCQJWKgvD0foToBUrBqol451/uhxWVLBiNvRhTD+cShp469jC+1jJr1quc+a/ujvk+e4nM9WkJxJwKwjW0RK0lMPZ7dNW7i7XLCS4g+aaZkEosFWX7AUoDcRA2i2Sc2Y+fjJO7at3bZiMDKxzLx9xigKMPOn69Q7bQahgdrKM9zUYG2caYVVLIatExMGGaDQaM4u6iQUJKis8LfXo6iwut6cJqVjmAVDHEiQcrPYlXYc7+pFODUeUeIM1cJutCO9PyEmG0Q4MXOwhTLlPPHSDIJes5caKCz4N/kb258Qx57Vj3lLwUSlt2tDngEj1DA8mDyqP7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EDylsBT88o7NNWQhKnnCNGmH7Pj90ESfRt5IG8rGzKs=; b=JzSYGib96pScn9ovK0zsD7AuKsMZWNBfG7YvxoSdOhJMyCkqbU414O3oIGjJqRz4RuOQ751MLIe0If05wHFZQ6aHW5D6wiYJO2PaVtew2T9zliWX1T4f95GuShHPhVWWwgcXHGaXCSk2W643uUaDuF74mXc1gPZOZqYIaFLcAQhqGsHnxMG3EdNfaDhRMACoBH+76o7t/yyzySZ02dc65WOrsi3WU9tThoLcfdlEqesN2GhTMqlf1krpOPxtTeXgRPHrod/yll1deo5A4NqKhnnTZMWJWdXD+mIDOFezGbeDt8LFF7fWcS49oQJa/iJu4Tgw7rfH9lpeVONhR39zMw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none (sender ip is 165.204.84.17) smtp.rcpttodomain=cray.com smtp.mailfrom=amd.com; dmarc=permerror action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from CH2PR12CA0005.namprd12.prod.outlook.com (2603:10b6:610:57::15) by BN7PR12MB2707.namprd12.prod.outlook.com (2603:10b6:408:2f::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.20; Thu, 29 Aug 2019 06:05:43 +0000 Received: from CO1NAM03FT045.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::200) by CH2PR12CA0005.outlook.office365.com (2603:10b6:610:57::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2220.18 via Frontend Transport; Thu, 29 Aug 2019 06:05:43 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV01.amd.com (165.204.84.17) by CO1NAM03FT045.mail.protection.outlook.com (10.152.81.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2220.16 via Frontend Transport; Thu, 29 Aug 2019 06:05:42 +0000 Received: from kho-5039A.amd.com (10.180.168.240) by SATLEXCHOV01.amd.com (10.181.40.71) with Microsoft SMTP Server id 14.3.389.1; Thu, 29 Aug 2019 01:05:41 -0500 From: Kenny Ho To: , , , , , , , , , , , Subject: [PATCH RFC v4 01/16] drm: Add drm_minor_for_each Date: Thu, 29 Aug 2019 02:05:18 -0400 Message-ID: <20190829060533.32315-2-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829060533.32315-1-Kenny.Ho@amd.com> References: <20190829060533.32315-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(4636009)(136003)(346002)(376002)(39860400002)(396003)(2980300002)(428003)(189003)(199004)(1076003)(6666004)(356004)(14444005)(50226002)(70586007)(5660300002)(446003)(426003)(76176011)(53416004)(51416003)(7696005)(305945005)(50466002)(478600001)(48376002)(86362001)(81166006)(81156014)(2201001)(8676002)(36756003)(8936002)(2870700001)(47776003)(2906002)(70206006)(336012)(110136005)(26005)(486006)(186003)(126002)(476003)(2616005)(11346002)(53936002)(316002)(4326008)(921003)(83996005)(1121003)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:BN7PR12MB2707; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; MX:1; A:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 97bacf29-fa3f-4cd0-e6eb-08d72c46ecee X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328); SRVR:BN7PR12MB2707; X-MS-TrafficTypeDiagnostic: BN7PR12MB2707: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3173; X-Forefront-PRVS: 0144B30E41 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: we+OnEohfE4nnBrZKjoZVMhoKQiOwrBfXKbkgRlIVGrNOOCqKr9OUq6IziPEeDea5DI3xZ4AF6fOolyXGGFUSjf73z+TIkQtALl5Zd9vtthEAq9aeVVriSZkQf8vJiQ4H/G/4Gzc9Z4JlvOSVMiswiqpyNcpCnvXqh4v7MTeYkFtvxjrUIMsGH8I10vwiTprr1aMK0EF2OZ6VDdEqX9lGYMOPF1i/wlFavGIsTgORdBr5iKbLAqNA69IXqUzA3xbP2mWmwfTX/yDeKT35xb/2fMbevEtUOZ5j1MYDCT9avDJt4TJ4QCAyr28ptEOWFqZBaan95w3RPOssdpVvJiunkI1J+dwawzK8FgI4XxMZ2NYsN0ncOdXmmexV/Cox+b2GAYTrntt2650GO/CB4ev5gKcPm4hBI1FLmFf0bxNyiM= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2019 06:05:42.7419 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 97bacf29-fa3f-4cd0-e6eb-08d72c46ecee X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR12MB2707 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EDylsBT88o7NNWQhKnnCNGmH7Pj90ESfRt5IG8rGzKs=; b=EIS246rBjUHgDzjtmeD3q5CfYwr1c4tbSJ29PYyA9al1OFUnASliG2jy8h/NiPP0dXv3+P0C7GUMqzZgY9yTgd4X/xxFlafBwnNjKoqY4c+RSBNOz6JOjRFwuPiZrAe8+cMzLY+NCYJY7LawZaH3QUe8VvTSD+rsdcv1QkcZb20= X-Mailman-Original-Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; cray.com; dkim=none (message not signed) header.d=none;cray.com; dmarc=permerror action=none header.from=amd.com; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kenny Ho Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To allow other subsystems to iterate through all stored DRM minors and act upon them. Also exposes drm_minor_acquire and drm_minor_release for other subsystem to handle drm_minor. DRM cgroup controller is the initial consumer of this new features. Change-Id: I7c4b67ce6b31f06d1037b03435386ff5b8144ca5 Signed-off-by: Kenny Ho --- drivers/gpu/drm/drm_drv.c | 19 +++++++++++++++++++ drivers/gpu/drm/drm_internal.h | 4 ---- include/drm/drm_drv.h | 4 ++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 862621494a93..000cddabd970 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -254,11 +254,13 @@ struct drm_minor *drm_minor_acquire(unsigned int minor_id) return minor; } +EXPORT_SYMBOL(drm_minor_acquire); void drm_minor_release(struct drm_minor *minor) { drm_dev_put(minor->dev); } +EXPORT_SYMBOL(drm_minor_release); /** * DOC: driver instance overview @@ -1078,6 +1080,23 @@ int drm_dev_set_unique(struct drm_device *dev, const char *name) } EXPORT_SYMBOL(drm_dev_set_unique); +/** + * drm_minor_for_each - Iterate through all stored DRM minors + * @fn: Function to be called for each pointer. + * @data: Data passed to callback function. + * + * The callback function will be called for each @drm_minor entry, passing + * the minor, the entry and @data. + * + * If @fn returns anything other than %0, the iteration stops and that + * value is returned from this function. + */ +int drm_minor_for_each(int (*fn)(int id, void *p, void *data), void *data) +{ + return idr_for_each(&drm_minors_idr, fn, data); +} +EXPORT_SYMBOL(drm_minor_for_each); + /* * DRM Core * The DRM core module initializes all global DRM objects and makes them diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h index e19ac7ca602d..6bfad76f8e78 100644 --- a/drivers/gpu/drm/drm_internal.h +++ b/drivers/gpu/drm/drm_internal.h @@ -54,10 +54,6 @@ 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); -/* drm_drv.c */ -struct drm_minor *drm_minor_acquire(unsigned int minor_id); -void drm_minor_release(struct drm_minor *minor); - /* drm_vblank.c */ void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe); void drm_vblank_cleanup(struct drm_device *dev); diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h index 68ca736c548d..24f8d054c570 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -799,5 +799,9 @@ static inline bool drm_drv_uses_atomic_modeset(struct drm_device *dev) int drm_dev_set_unique(struct drm_device *dev, const char *name); +int drm_minor_for_each(int (*fn)(int id, void *p, void *data), void *data); + +struct drm_minor *drm_minor_acquire(unsigned int minor_id); +void drm_minor_release(struct drm_minor *minor); #endif From patchwork Thu Aug 29 06:05:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 11120375 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7B27314DE for ; Thu, 29 Aug 2019 06:05:57 +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 6474A233A1 for ; Thu, 29 Aug 2019 06:05:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6474A233A1 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AFCCD89F85; Thu, 29 Aug 2019 06:05:48 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-eopbgr790087.outbound.protection.outlook.com [40.107.79.87]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6A61489F82; Thu, 29 Aug 2019 06:05:47 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YOOnm65+8DVPzLNgLBopgvAcbKfSblTKWX3+6e8qFKcVEa3Qjdw+yJaFvjPcNApWuWvKahl6l89xJv3Wu3Ipu6R3WH8q4VJRe7asX0GUw6/E4K38kCKIOuPMF9FODPqHj3UR3V2WGQ5A4nK7U8pB2jDBvE58tnsZJ4/tnGYPTQKXvjju2DHQQSdxVMPVX5m4k8GRVicfPj69WipF/56LDZzemx5yTRyVUyPq2YuwLofFW/DkXHQiqcI4INLBsRqDmWL4/l7IUCtYZEGXjk9ATq0jul6/I7ZP/hHVWCh/6NBe9qB+eH3+9+32wyrpz7vztGky9cJtUq4i6ILqmGMS6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=s6EPMox26fU5F2yp9AcfPra6fm+DXi302zWJUO9/tUM=; b=Y4/QAdTMqcZcaWOG8AxWXLRLc1qJnPhIkHlI/ycqtJrVY0BdfLZtqbejheSms6oXfqpdCB+BYabRqWsP6m/zoPxB7PJIcZS2meDEpvm0yQ5u9rABzMgiLfRZK+iHAzQcWCZy0EtXwW5a+9KsVkr9sos1EnAREpLGh7+49/IQiiBt5nSPpOpp068mLpLBz+/xlZl2Ba7l7VLGG0e3fCekrQ5NwSTaFvLbmKQfpvpXhtPT58YS3ie+byyinkOwzn2eCsHbtZzMPQvW1pxMW6kiwdmEkNsY2J8LmTO0XBkVlCvwEwJ956KcHUoANgMFntKb6FoCACX8hpYet0f0ONu2IA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none (sender ip is 165.204.84.17) smtp.rcpttodomain=cray.com smtp.mailfrom=amd.com; dmarc=permerror action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from CH2PR12CA0005.namprd12.prod.outlook.com (2603:10b6:610:57::15) by BN6PR12MB1267.namprd12.prod.outlook.com (2603:10b6:404:17::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.20; Thu, 29 Aug 2019 06:05:44 +0000 Received: from CO1NAM03FT045.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::200) by CH2PR12CA0005.outlook.office365.com (2603:10b6:610:57::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2220.18 via Frontend Transport; Thu, 29 Aug 2019 06:05:44 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV01.amd.com (165.204.84.17) by CO1NAM03FT045.mail.protection.outlook.com (10.152.81.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2220.16 via Frontend Transport; Thu, 29 Aug 2019 06:05:44 +0000 Received: from kho-5039A.amd.com (10.180.168.240) by SATLEXCHOV01.amd.com (10.181.40.71) with Microsoft SMTP Server id 14.3.389.1; Thu, 29 Aug 2019 01:05:42 -0500 From: Kenny Ho To: , , , , , , , , , , , Subject: [PATCH RFC v4 02/16] cgroup: Introduce cgroup for drm subsystem Date: Thu, 29 Aug 2019 02:05:19 -0400 Message-ID: <20190829060533.32315-3-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829060533.32315-1-Kenny.Ho@amd.com> References: <20190829060533.32315-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(4636009)(376002)(39860400002)(346002)(136003)(396003)(2980300002)(428003)(199004)(189003)(5660300002)(86362001)(47776003)(6666004)(356004)(1076003)(478600001)(2201001)(2870700001)(2906002)(316002)(70206006)(70586007)(50466002)(110136005)(48376002)(53416004)(426003)(36756003)(4326008)(305945005)(53936002)(8936002)(8676002)(81156014)(186003)(51416003)(2616005)(11346002)(446003)(476003)(76176011)(5024004)(14444005)(7696005)(126002)(486006)(81166006)(50226002)(336012)(26005)(921003)(1121003)(2101003)(83996005); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR12MB1267; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: caf341a5-4743-4ef4-28f8-08d72c46edc3 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328); SRVR:BN6PR12MB1267; X-MS-TrafficTypeDiagnostic: BN6PR12MB1267: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-Forefront-PRVS: 0144B30E41 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: Is/OMQpFy8pXu8KcjTArZldv4Mepd09Di21K+1ZZUrYFaLZsNuhyelAmGqu2ykIjMd1C69MRUZEdDGdwzBy4M5LCkRZBVcByyzHTHc4erqEhhDplPuPRHHpuZu0zLbhsacZdAmK72BECH10jMuVcXqvr61dmYuTkVMCRPBp39mtel+FFs2y8PQGMnBtZWKDPrwxYx6X7XXQPwdIk+E8A5yBCMiEVJ5HFVzfVGoz3/+Bx+a6ZIltSmZdp2Ino2SoBoTSQd7hIEnIfI4NEfuqWYrk2KEb7J6j5AdTd/37rRUePlxRSubCR/Guk9oRRwvCf22yAP6lUs9LMskDCAqOfc17QVfxmCyowP7cprFguhYtboCQoSewjRLTczGrZYKzctrJrbuAnIvl4q+a1A0J5OQgfMeMV//7ua9hsVtxlprg= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2019 06:05:44.1292 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: caf341a5-4743-4ef4-28f8-08d72c46edc3 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1267 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=s6EPMox26fU5F2yp9AcfPra6fm+DXi302zWJUO9/tUM=; b=DIgzN0K2bhawl7vChxfradlfciqZ6J/8jD8900FSQAicN0F0nOZY3Coo5B6M+iHKZf4O9jjb1nQipqvK56BJwaM/wWGBDL9b+bzgnrNTG2unukKc9rCbpvsXr7incVH+ZeEutYfiPdKh/NcTO/wIX7AjQnhbA/ey31ABYtfk1UM= X-Mailman-Original-Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; cray.com; dkim=none (message not signed) header.d=none;cray.com; dmarc=permerror action=none header.from=amd.com; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kenny Ho Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" With the increased importance of machine learning, data science and other cloud-based applications, GPUs are already in production use in data centers today. Existing GPU resource management is very coarse grain, however, as sysadmins are only able to distribute workload on a per-GPU basis. An alternative is to use GPU virtualization (with or without SRIOV) but it generally acts on the entire GPU instead of the specific resources in a GPU. With a drm cgroup controller, we can enable alternate, fine-grain, sub-GPU resource management (in addition to what may be available via GPU virtualization.) Change-Id: I6830d3990f63f0c13abeba29b1d330cf28882831 Signed-off-by: Kenny Ho --- Documentation/admin-guide/cgroup-v2.rst | 18 ++++- Documentation/cgroup-v1/drm.rst | 1 + include/linux/cgroup_drm.h | 92 +++++++++++++++++++++++++ include/linux/cgroup_subsys.h | 4 ++ init/Kconfig | 5 ++ kernel/cgroup/Makefile | 1 + kernel/cgroup/drm.c | 42 +++++++++++ 7 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 Documentation/cgroup-v1/drm.rst create mode 100644 include/linux/cgroup_drm.h create mode 100644 kernel/cgroup/drm.c diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 88e746074252..2936423a3fd5 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -61,8 +61,10 @@ v1 is available under Documentation/cgroup-v1/. 5-6. Device 5-7. RDMA 5-7-1. RDMA Interface Files - 5-8. Misc - 5-8-1. perf_event + 5-8. DRM + 5-8-1. DRM Interface Files + 5-9. Misc + 5-9-1. perf_event 5-N. Non-normative information 5-N-1. CPU controller root cgroup process behaviour 5-N-2. IO controller root cgroup process behaviour @@ -1889,6 +1891,18 @@ RDMA Interface Files ocrdma1 hca_handle=1 hca_object=23 +DRM +--- + +The "drm" controller regulates the distribution and accounting of +of DRM (Direct Rendering Manager) and GPU-related resources. + +DRM Interface Files +~~~~~~~~~~~~~~~~~~~~ + +TODO + + Misc ---- diff --git a/Documentation/cgroup-v1/drm.rst b/Documentation/cgroup-v1/drm.rst new file mode 100644 index 000000000000..5f5658e1f5ed --- /dev/null +++ b/Documentation/cgroup-v1/drm.rst @@ -0,0 +1 @@ +Please see ../cgroup-v2.rst for details diff --git a/include/linux/cgroup_drm.h b/include/linux/cgroup_drm.h new file mode 100644 index 000000000000..971166f9dd78 --- /dev/null +++ b/include/linux/cgroup_drm.h @@ -0,0 +1,92 @@ +/* SPDX-License-Identifier: MIT + * Copyright 2019 Advanced Micro Devices, Inc. + */ +#ifndef _CGROUP_DRM_H +#define _CGROUP_DRM_H + +#ifdef CONFIG_CGROUP_DRM + +#include + +/** + * The DRM cgroup controller data structure. + */ +struct drmcg { + struct cgroup_subsys_state css; +}; + +/** + * css_to_drmcg - get the corresponding drmcg ref from a cgroup_subsys_state + * @css: the target cgroup_subsys_state + * + * Return: DRM cgroup that contains the @css + */ +static inline struct drmcg *css_to_drmcg(struct cgroup_subsys_state *css) +{ + return css ? container_of(css, struct drmcg, css) : NULL; +} + +/** + * drmcg_get - get the drmcg reference that a task belongs to + * @task: the target task + * + * This increase the reference count of the css that the @task belongs to + * + * Return: reference to the DRM cgroup the task belongs to + */ +static inline struct drmcg *drmcg_get(struct task_struct *task) +{ + return css_to_drmcg(task_get_css(task, drm_cgrp_id)); +} + +/** + * drmcg_put - put a drmcg reference + * @drmcg: the target drmcg + * + * Put a reference obtained via drmcg_get + */ +static inline void drmcg_put(struct drmcg *drmcg) +{ + if (drmcg) + css_put(&drmcg->css); +} + +/** + * drmcg_parent - find the parent of a drm cgroup + * @cg: the target drmcg + * + * This does not increase the reference count of the parent cgroup + * + * Return: parent DRM cgroup of @cg + */ +static inline struct drmcg *drmcg_parent(struct drmcg *cg) +{ + return css_to_drmcg(cg->css.parent); +} + +#else /* CONFIG_CGROUP_DRM */ + +struct drmcg { +}; + +static inline struct drmcg *css_to_drmcg(struct cgroup_subsys_state *css) +{ + return NULL; +} + +static inline struct drmcg *drmcg_get(struct task_struct *task) +{ + return NULL; +} + +static inline void drmcg_put(struct drmcg *drmcg) +{ +} + +static inline struct drmcg *drmcg_parent(struct drmcg *cg) +{ + return NULL; +} + +#endif /* CONFIG_CGROUP_DRM */ +#endif /* _CGROUP_DRM_H */ diff --git a/include/linux/cgroup_subsys.h b/include/linux/cgroup_subsys.h index acb77dcff3b4..ddedad809e8b 100644 --- a/include/linux/cgroup_subsys.h +++ b/include/linux/cgroup_subsys.h @@ -61,6 +61,10 @@ SUBSYS(pids) SUBSYS(rdma) #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 8b9ffe236e4f..01d3453f6e04 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -876,6 +876,11 @@ 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 (EXPERIMENTAL)" + help + Provides accounting and enforcement of resources in the DRM subsystem. + config CGROUP_FREEZER bool "Freezer controller" help diff --git a/kernel/cgroup/Makefile b/kernel/cgroup/Makefile index 5d7a76bfbbb7..31f186f58121 100644 --- a/kernel/cgroup/Makefile +++ b/kernel/cgroup/Makefile @@ -4,5 +4,6 @@ obj-y := cgroup.o rstat.o namespace.o cgroup-v1.o freezer.o obj-$(CONFIG_CGROUP_FREEZER) += legacy_freezer.o obj-$(CONFIG_CGROUP_PIDS) += pids.o obj-$(CONFIG_CGROUP_RDMA) += rdma.o +obj-$(CONFIG_CGROUP_DRM) += drm.o obj-$(CONFIG_CPUSETS) += cpuset.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..e97861b3cb30 --- /dev/null +++ b/kernel/cgroup/drm.c @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: MIT +// Copyright 2019 Advanced Micro Devices, Inc. +#include +#include +#include + +static struct drmcg *root_drmcg __read_mostly; + +static void drmcg_css_free(struct cgroup_subsys_state *css) +{ + struct drmcg *drmcg = css_to_drmcg(css); + + kfree(drmcg); +} + +static struct cgroup_subsys_state * +drmcg_css_alloc(struct cgroup_subsys_state *parent_css) +{ + struct drmcg *parent = css_to_drmcg(parent_css); + struct drmcg *drmcg; + + drmcg = kzalloc(sizeof(struct drmcg), GFP_KERNEL); + if (!drmcg) + return ERR_PTR(-ENOMEM); + + if (!parent) + root_drmcg = drmcg; + + return &drmcg->css; +} + +struct cftype files[] = { + { } /* terminate */ +}; + +struct cgroup_subsys drm_cgrp_subsys = { + .css_alloc = drmcg_css_alloc, + .css_free = drmcg_css_free, + .early_init = false, + .legacy_cftypes = files, + .dfl_cftypes = files, +}; From patchwork Thu Aug 29 06:05:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 11120385 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B2B6C14DE for ; Thu, 29 Aug 2019 06:06:13 +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 9BD9A20828 for ; Thu, 29 Aug 2019 06:06:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9BD9A20828 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3194A89FCA; Thu, 29 Aug 2019 06:06:02 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM04-SN1-obe.outbound.protection.outlook.com (mail-eopbgr700045.outbound.protection.outlook.com [40.107.70.45]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3166F89F82; Thu, 29 Aug 2019 06:05:48 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XbM2WRs5ttAz78pAfNQ0P0VTlRgZ1/WsFdlPqYU59XbqZLCNwhHazGd81a208k7nzRvfvF3HVEl76Clt8phSqtJvpjW/Mvitx026lzXakeOm6pYOgkH37pGYqVhG8VZryEO3NrXa8AFfBhVSMAkWYKXVHhGSyt7wI7cUYP6eQ45XtyaFW2uauhrNP/73gI9UuLvg7q6ZLXiMEap8XDZ5syAYqDg0L0KA3koKOlcA7V6WsDnR36+g1r1PXmVwLRx4C/ikCoNzfF+D2GHJWvCSopl7d9YcCBaXte10lHpGvR5AqlLC9Sg8aTsMlAawoAyHIADXSPtHKUuf6hzIQVs1/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NiGfUj8lkzJ3n79e6BUomcC2im3IgVaCAfZ0em4K9D8=; b=ZjOLopLwh88IcqEhrliRwCXAY8Oso0OJBqvMmKNP/v0LsLULPFMwNRRmvzLez09gs1U9ZQm7eD7jPj+oGSeYGsDEU8V2Ps0vxoLw4hri/D5NIq/A6u7649LM9xjdu4oqIDLd8/39V2X5bZ8nZwpZgF7jEuyeyaevoqaQd3g29EI4n/ETBBjaJnPbYWZRat9+HEzgCbt6l7mDqiAmPF7emlld2c7qla0JwrLVvN/USEKcvtNKLlu9ai6i9uKcxl7dc6cGv8Jz/D9rAKUd6VFNnq+eYI0W1PlJvE+v8Mj3LrxyXKRYQD7g5wkgDKnIQe1CgIzskQDToEFS/hh1U+2Nqw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none (sender ip is 165.204.84.17) smtp.rcpttodomain=cray.com smtp.mailfrom=amd.com; dmarc=permerror action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from CH2PR12CA0015.namprd12.prod.outlook.com (2603:10b6:610:57::25) by SN6PR12MB2717.namprd12.prod.outlook.com (2603:10b6:805:70::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.20; Thu, 29 Aug 2019 06:05:46 +0000 Received: from CO1NAM03FT045.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::202) by CH2PR12CA0015.outlook.office365.com (2603:10b6:610:57::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2220.18 via Frontend Transport; Thu, 29 Aug 2019 06:05:45 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV01.amd.com (165.204.84.17) by CO1NAM03FT045.mail.protection.outlook.com (10.152.81.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2220.16 via Frontend Transport; Thu, 29 Aug 2019 06:05:45 +0000 Received: from kho-5039A.amd.com (10.180.168.240) by SATLEXCHOV01.amd.com (10.181.40.71) with Microsoft SMTP Server id 14.3.389.1; Thu, 29 Aug 2019 01:05:43 -0500 From: Kenny Ho To: , , , , , , , , , , , Subject: [PATCH RFC v4 03/16] drm, cgroup: Initialize drmcg properties Date: Thu, 29 Aug 2019 02:05:20 -0400 Message-ID: <20190829060533.32315-4-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829060533.32315-1-Kenny.Ho@amd.com> References: <20190829060533.32315-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(4636009)(136003)(396003)(346002)(376002)(39860400002)(2980300002)(428003)(189003)(199004)(446003)(186003)(2616005)(486006)(11346002)(14444005)(336012)(47776003)(2201001)(7696005)(76176011)(51416003)(86362001)(305945005)(476003)(126002)(4326008)(426003)(26005)(1076003)(2906002)(50226002)(356004)(6666004)(53416004)(36756003)(8676002)(478600001)(81166006)(53936002)(81156014)(5660300002)(2870700001)(8936002)(70206006)(110136005)(48376002)(316002)(70586007)(50466002)(921003)(1121003)(83996005)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:SN6PR12MB2717; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; MX:1; A:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 025f64c5-f4e2-4352-6e51-08d72c46ee75 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328); SRVR:SN6PR12MB2717; X-MS-TrafficTypeDiagnostic: SN6PR12MB2717: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1107; X-Forefront-PRVS: 0144B30E41 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: ae3ZS0U59ft24Xab2IS6lz3xxMxUxvKQO6r80983KE0Cv+6IcXReai3gTT45vWyRRlQpiNwZisNksgY07+uPCcp+rSh9/xSW7T0F4Xjqe6YTM73Jv2g4K9T5MIqTivTweMdGgDk9zk6fNx/UMxbbfNBwfTP23oHZ/TTKvR0gMZq8dCQRCzMYLxyFnIH0ksvGarTP0X69rXYn42Mc0esN6xuNZNXLScVU2BSO0lkL6by7aZcKJeRg9uw0Y7cKsu60SvKtYMFUoELQKhckvikcN+FW6gb73iq/1JSAGpDjTjwph4UcyZXVsw1jw1T4qW4XcBkBWs/ZkRL+fulWR7/SfzSPo1SFdd5gA5iqmKWqir3Hep8td949cTn0AjW53c198ogfl2b4l7etTTr6fz3l6C5wbVAr9kUi6GhEEs2Ii5k= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2019 06:05:45.2968 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 025f64c5-f4e2-4352-6e51-08d72c46ee75 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2717 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NiGfUj8lkzJ3n79e6BUomcC2im3IgVaCAfZ0em4K9D8=; b=F/85A8BHfYyS56NNQGmsnJiRuymDFnEkRRnIlR2at9P/ddHTF36pJ3QIv/Dt2oo65OGFs5x3KtCxzSwI6CpNPeK0sUjayLPvx2uhSJDs3ivetA4yeuSnTZLeo5mwfRT3jF7e2fRBaZaRUFsiQUTnbxwnxHYDbRdlm+9bepu/aWE= X-Mailman-Original-Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; cray.com; dkim=none (message not signed) header.d=none;cray.com; dmarc=permerror action=none header.from=amd.com; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kenny Ho Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" drmcg initialization involves allocating a per cgroup, per device data structure and setting the defaults. There are two entry points for drmcg init: 1) When struct drmcg is created via css_alloc, initialization is done for each device 2) When DRM devices are created after drmcgs are created a) Per device drmcg data structure is allocated at the beginning of DRM device creation such that drmcg can begin tracking usage statistics b) At the end of DRM device creation, drmcg_device_update is called in case device specific defaults need to be applied. Entry point #2 usually applies to the root cgroup since it can be created before DRM devices are available. The drmcg controller will go through all existing drm cgroups and initialize them with the new device accordingly. Change-Id: I908ee6975ea0585e4c30eafde4599f87094d8c65 Signed-off-by: Kenny Ho --- drivers/gpu/drm/drm_drv.c | 7 +++ include/drm/drm_cgroup.h | 27 ++++++++ include/drm/drm_device.h | 7 +++ include/drm/drm_drv.h | 9 +++ include/linux/cgroup_drm.h | 13 ++++ kernel/cgroup/drm.c | 123 +++++++++++++++++++++++++++++++++++++ 6 files changed, 186 insertions(+) create mode 100644 include/drm/drm_cgroup.h diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 000cddabd970..94265eba68ca 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -37,6 +37,7 @@ #include #include #include +#include #include "drm_crtc_internal.h" #include "drm_legacy.h" @@ -672,6 +673,7 @@ int drm_dev_init(struct drm_device *dev, mutex_init(&dev->filelist_mutex); mutex_init(&dev->clientlist_mutex); mutex_init(&dev->master_mutex); + mutex_init(&dev->drmcg_mutex); dev->anon_inode = drm_fs_inode_new(); if (IS_ERR(dev->anon_inode)) { @@ -708,6 +710,7 @@ int drm_dev_init(struct drm_device *dev, if (ret) goto err_setunique; + drmcg_device_early_init(dev); return 0; err_setunique: @@ -722,6 +725,7 @@ int drm_dev_init(struct drm_device *dev, drm_fs_inode_free(dev->anon_inode); err_free: put_device(dev->dev); + mutex_destroy(&dev->drmcg_mutex); mutex_destroy(&dev->master_mutex); mutex_destroy(&dev->clientlist_mutex); mutex_destroy(&dev->filelist_mutex); @@ -798,6 +802,7 @@ void drm_dev_fini(struct drm_device *dev) put_device(dev->dev); + mutex_destroy(&dev->drmcg_mutex); mutex_destroy(&dev->master_mutex); mutex_destroy(&dev->clientlist_mutex); mutex_destroy(&dev->filelist_mutex); @@ -1008,6 +1013,8 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags) dev->dev ? dev_name(dev->dev) : "virtual device", dev->primary->index); + drmcg_device_update(dev); + goto out_unlock; err_minors: diff --git a/include/drm/drm_cgroup.h b/include/drm/drm_cgroup.h new file mode 100644 index 000000000000..bef9f9245924 --- /dev/null +++ b/include/drm/drm_cgroup.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: MIT + * Copyright 2019 Advanced Micro Devices, Inc. + */ +#ifndef __DRM_CGROUP_H__ +#define __DRM_CGROUP_H__ + +/** + * Per DRM device properties for DRM cgroup controller for the purpose + * of storing per device defaults + */ +struct drmcg_props { +}; + +#ifdef CONFIG_CGROUP_DRM + +void drmcg_device_update(struct drm_device *device); +void drmcg_device_early_init(struct drm_device *device); +#else +static inline void drmcg_device_update(struct drm_device *device) +{ +} + +static inline void drmcg_device_early_init(struct drm_device *device) +{ +} +#endif /* CONFIG_CGROUP_DRM */ +#endif /* __DRM_CGROUP_H__ */ diff --git a/include/drm/drm_device.h b/include/drm/drm_device.h index 7f9ef709b2b6..5d7d779a5083 100644 --- a/include/drm/drm_device.h +++ b/include/drm/drm_device.h @@ -8,6 +8,7 @@ #include #include +#include struct drm_driver; struct drm_minor; @@ -304,6 +305,12 @@ struct drm_device { */ struct drm_fb_helper *fb_helper; + /** \name DRM Cgroup */ + /*@{ */ + struct mutex drmcg_mutex; + struct drmcg_props drmcg_props; + /*@} */ + /* Everything below here is for legacy driver, never use! */ /* private: */ #if IS_ENABLED(CONFIG_DRM_LEGACY) diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h index 24f8d054c570..c8a37a08d98d 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -660,6 +660,15 @@ struct drm_driver { struct drm_device *dev, uint32_t handle); + /** + * @drmcg_custom_init + * + * Optional callback used to initialize drm cgroup per device properties + * such as resource limit defaults. + */ + void (*drmcg_custom_init)(struct drm_device *dev, + struct drmcg_props *props); + /** * @gem_vm_ops: Driver private ops for this object */ diff --git a/include/linux/cgroup_drm.h b/include/linux/cgroup_drm.h index 971166f9dd78..4ecd44f2ac27 100644 --- a/include/linux/cgroup_drm.h +++ b/include/linux/cgroup_drm.h @@ -6,13 +6,26 @@ #ifdef CONFIG_CGROUP_DRM +#include #include +#include + +/* limit defined per the way drm_minor_alloc operates */ +#define MAX_DRM_DEV (64 * DRM_MINOR_RENDER) + +/** + * Per DRM cgroup, per device resources (such as statistics and limits) + */ +struct drmcg_device_resource { + /* for per device stats */ +}; /** * The DRM cgroup controller data structure. */ struct drmcg { struct cgroup_subsys_state css; + struct drmcg_device_resource *dev_resources[MAX_DRM_DEV]; }; /** diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c index e97861b3cb30..135fdcdc4b51 100644 --- a/kernel/cgroup/drm.c +++ b/kernel/cgroup/drm.c @@ -1,28 +1,103 @@ // SPDX-License-Identifier: MIT // Copyright 2019 Advanced Micro Devices, Inc. +#include #include #include +#include +#include +#include #include +#include +#include +#include +#include +#include + +/* global mutex for drmcg across all devices */ +static DEFINE_MUTEX(drmcg_mutex); static struct drmcg *root_drmcg __read_mostly; +static int drmcg_css_free_fn(int id, void *ptr, void *data) +{ + struct drm_minor *minor = ptr; + struct drmcg *drmcg = data; + + if (minor->type != DRM_MINOR_PRIMARY) + return 0; + + kfree(drmcg->dev_resources[minor->index]); + + return 0; +} + static void drmcg_css_free(struct cgroup_subsys_state *css) { struct drmcg *drmcg = css_to_drmcg(css); + drm_minor_for_each(&drmcg_css_free_fn, drmcg); + kfree(drmcg); } +static inline int init_drmcg_single(struct drmcg *drmcg, struct drm_device *dev) +{ + int minor = dev->primary->index; + struct drmcg_device_resource *ddr = drmcg->dev_resources[minor]; + + if (ddr == NULL) { + ddr = kzalloc(sizeof(struct drmcg_device_resource), + GFP_KERNEL); + + if (!ddr) + return -ENOMEM; + } + + mutex_lock(&dev->drmcg_mutex); + drmcg->dev_resources[minor] = ddr; + + /* set defaults here */ + + mutex_unlock(&dev->drmcg_mutex); + return 0; +} + +static int init_drmcg_fn(int id, void *ptr, void *data) +{ + struct drm_minor *minor = ptr; + struct drmcg *drmcg = data; + + if (minor->type != DRM_MINOR_PRIMARY) + return 0; + + return init_drmcg_single(drmcg, minor->dev); +} + +static inline int init_drmcg(struct drmcg *drmcg, struct drm_device *dev) +{ + if (dev != NULL) + return init_drmcg_single(drmcg, dev); + + return drm_minor_for_each(&init_drmcg_fn, drmcg); +} + static struct cgroup_subsys_state * drmcg_css_alloc(struct cgroup_subsys_state *parent_css) { struct drmcg *parent = css_to_drmcg(parent_css); struct drmcg *drmcg; + int rc; drmcg = kzalloc(sizeof(struct drmcg), GFP_KERNEL); if (!drmcg) return ERR_PTR(-ENOMEM); + rc = init_drmcg(drmcg, NULL); + if (rc) { + drmcg_css_free(&drmcg->css); + return ERR_PTR(rc); + } + if (!parent) root_drmcg = drmcg; @@ -40,3 +115,51 @@ struct cgroup_subsys drm_cgrp_subsys = { .legacy_cftypes = files, .dfl_cftypes = files, }; + +static inline void drmcg_update_cg_tree(struct drm_device *dev) +{ + /* init cgroups created before registration (i.e. root cgroup) */ + if (root_drmcg != NULL) { + struct cgroup_subsys_state *pos; + struct drmcg *child; + + rcu_read_lock(); + css_for_each_descendant_pre(pos, &root_drmcg->css) { + child = css_to_drmcg(pos); + init_drmcg(child, dev); + } + rcu_read_unlock(); + } +} + +/** + * drmcg_device_update - update DRM cgroups defaults + * @dev: the target DRM device + * + * If @dev has a drmcg_custom_init for the DRM cgroup controller, it will be called + * to set device specific defaults and set the initial values for all existing + * cgroups created prior to @dev become available. + */ +void drmcg_device_update(struct drm_device *dev) +{ + if (dev->driver->drmcg_custom_init) + { + dev->driver->drmcg_custom_init(dev, &dev->drmcg_props); + + drmcg_update_cg_tree(dev); + } +} +EXPORT_SYMBOL(drmcg_device_update); + +/** + * drmcg_device_early_init - initialize device specific resources for DRM cgroups + * @dev: the target DRM device + * + * Allocate and initialize device specific resources for existing DRM cgroups. + * Typically only the root cgroup exists before the initialization of @dev. + */ +void drmcg_device_early_init(struct drm_device *dev) +{ + drmcg_update_cg_tree(dev); +} +EXPORT_SYMBOL(drmcg_device_early_init); From patchwork Thu Aug 29 06:05:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 11120377 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B141D14D5 for ; Thu, 29 Aug 2019 06:06:01 +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 3AA4A23404 for ; Thu, 29 Aug 2019 06:06:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3AA4A23404 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5FDEF89FA5; Thu, 29 Aug 2019 06:05:53 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-eopbgr790047.outbound.protection.outlook.com [40.107.79.47]) by gabe.freedesktop.org (Postfix) with ESMTPS id 33D7589F99; Thu, 29 Aug 2019 06:05:49 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mehXuf/EqzUZX6MVhNLUjSCEKz3DKqk222a7KINoWhQXx8mCrDwYpIFdixke/I+9ALjaXuyuQytoAdmuQST8fyBsqlgtbeBSDpz3yQOKQ1hA2eoi0EztBG7n4M769+Q+D4vLP8AG/XnvMq5BHiBhZJ43Qnq4uNQ9KMdbMR+a75r/Ct3G+6Unt2zgtOCxfxTYIZaQdMXMSvkWGNMPEemWcIAZcmMKlblZbQygPyweKP5K5gb9q8BNt6jETSa8XmgdrmyHOHTqk65yiFgqNSZiJ81g6iYw4O4fUBmUOQftfsCrQa5TwX7SUqXFvdzqD/siQgWQpy/EJHzxiszIVcwn8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RRyHhzF2uLSJ6aT6RZhce1jet+jmyq43CdAF0JtrtH4=; b=MbYEri5rSeqYytu0bmiIeXwB96cK5bO7q+Cw33hk1X0N8+ZATRpIY6Jw1rG6QY3lJLAyAKi5+VXNM1OymxHZ5tvh4bDQQkaQPmc5pC9If/27sNnwfT07hjpBVAb12NkF3s+u9Uv6YtUNeizhocmAfgCZC2x4ymgc7E7WM+h9RdIE51TN1IZyIJudLqIkceprz4hfBgALYPdsxM4/SGBCJhcTiEXYepKcbcSZW5XDrieByqzVy0SlXNVZclsvTL/WuSVPzLvzUDcLnJxN/PQZ1ZmYvpFs858jefVqOCbwleS14ptNvsgcsBA13jlojPFBqPQy9Et+toAkye9WOfP1kg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none (sender ip is 165.204.84.17) smtp.rcpttodomain=cray.com smtp.mailfrom=amd.com; dmarc=permerror action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from CH2PR12CA0005.namprd12.prod.outlook.com (2603:10b6:610:57::15) by BN6PR12MB1267.namprd12.prod.outlook.com (2603:10b6:404:17::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.20; Thu, 29 Aug 2019 06:05:47 +0000 Received: from CO1NAM03FT045.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::200) by CH2PR12CA0005.outlook.office365.com (2603:10b6:610:57::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2220.18 via Frontend Transport; Thu, 29 Aug 2019 06:05:47 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV01.amd.com (165.204.84.17) by CO1NAM03FT045.mail.protection.outlook.com (10.152.81.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2220.16 via Frontend Transport; Thu, 29 Aug 2019 06:05:46 +0000 Received: from kho-5039A.amd.com (10.180.168.240) by SATLEXCHOV01.amd.com (10.181.40.71) with Microsoft SMTP Server id 14.3.389.1; Thu, 29 Aug 2019 01:05:44 -0500 From: Kenny Ho To: , , , , , , , , , , , Subject: [PATCH RFC v4 04/16] drm, cgroup: Add total GEM buffer allocation stats Date: Thu, 29 Aug 2019 02:05:21 -0400 Message-ID: <20190829060533.32315-5-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829060533.32315-1-Kenny.Ho@amd.com> References: <20190829060533.32315-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(4636009)(376002)(39860400002)(346002)(136003)(396003)(2980300002)(428003)(199004)(189003)(5660300002)(86362001)(47776003)(6666004)(356004)(30864003)(1076003)(478600001)(2201001)(2870700001)(2906002)(316002)(70206006)(70586007)(50466002)(110136005)(48376002)(53416004)(426003)(36756003)(4326008)(305945005)(53936002)(8936002)(8676002)(81156014)(186003)(51416003)(2616005)(11346002)(446003)(476003)(76176011)(14444005)(7696005)(126002)(486006)(81166006)(50226002)(336012)(26005)(921003)(1121003)(2101003)(83996005); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR12MB1267; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dd245b17-da3e-4103-db9a-08d72c46ef65 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328); SRVR:BN6PR12MB1267; X-MS-TrafficTypeDiagnostic: BN6PR12MB1267: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-Forefront-PRVS: 0144B30E41 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: WVUb01NJ6EipNhyM+dH+tyIL7TKIGcz77bREr3F6tdG/9+iQazYZ05a4PJ0k69dzlUGWTbwQOAJqOdo/crGgSKn7i89BUBWZKcZ4enxqTa9Uc9cHndgGtK2WjTol8Gwa/0O2N9V3KMJZiOVuPL/mL9s/bVeTQh4nhDAAgx6jTbfjXtrnEc2Rb+QrZHJpNEjqLtdY5ZORIJA8Tg5Q5I/Aob4wn0yATJyDv7y5YRHBg71U0uaXqFuor6RMxl7NuYqGAAy8gTCuvIsUKgWIe6c8Q8i+KECNRb8DU6iiKbipu7tt6KoQUAbxbZxLQ6wRXBK+KlDB/d3HG+2zOj6ei2tiqoV5QUW+lRtGdHMP8xXCLrtD/vNgCg/JV9Imfy4AYTNXYnG/5mGL4D214169I3NXbdNo7x66hitIh9y6S7pPE/4= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2019 06:05:46.7233 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dd245b17-da3e-4103-db9a-08d72c46ef65 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1267 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RRyHhzF2uLSJ6aT6RZhce1jet+jmyq43CdAF0JtrtH4=; b=nBRPt5jwdem5DaTUn0zHT+1v+xg9h/uVLGGkBYEnX5PH1Vwwmi7EU1yIVL13Kbs0i1kjmoZ605lHyFyMrK2WQSzueUb/ibe16m6lPyT6kZF6Ol/hXd4mb+K0g6KrvI/szxcThvzgqXmoAe3knWgxYl8aA0ds0uk1Oz0ac0ffXqI= X-Mailman-Original-Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; cray.com; dkim=none (message not signed) header.d=none;cray.com; dmarc=permerror action=none header.from=amd.com; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kenny Ho Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The drm resource being measured here is the GEM buffer objects. User applications allocate and free these buffers. In addition, a process can allocate a buffer and share it with another process. The consumer of a shared buffer can also outlive the allocator of the buffer. For the purpose of cgroup accounting and limiting, ownership of the buffer is deemed to be the cgroup for which the allocating process belongs to. There is one cgroup stats per drm device. Each allocation is charged to the owning cgroup as well as all its ancestors. Similar to the memory cgroup, migrating a process to a different cgroup does not move the GEM buffer usages that the process started while in previous cgroup, to the new cgroup. The following is an example to illustrate some of the operations. Given the following cgroup hierarchy (The letters are cgroup names with R being the root cgroup. The numbers in brackets are processes. The processes are placed with cgroup's 'No Internal Process Constraint' in mind, so no process is placed in cgroup B.) R (4, 5) ------ A (6) \ B ---- C (7,8) \ D (9) Here is a list of operation and the associated effect on the size track by the cgroups (for simplicity, each buffer is 1 unit in size.) == == == == == =================================================== R A B C D Ops == == == == == =================================================== 1 0 0 0 0 4 allocated a buffer 1 0 0 0 0 4 shared a buffer with 5 1 0 0 0 0 4 shared a buffer with 9 2 0 1 0 1 9 allocated a buffer 3 0 2 1 1 7 allocated a buffer 3 0 2 1 1 7 shared a buffer with 8 3 0 2 1 1 7 sharing with 9 3 0 2 1 1 7 release a buffer 3 0 2 1 1 7 migrate to cgroup D 3 0 2 1 1 9 release a buffer from 7 2 0 1 0 1 8 release a buffer from 7 (last ref to shared buf) == == == == == =================================================== drm.buffer.stats A read-only flat-keyed file which exists on all cgroups. Each entry is keyed by the drm device's major:minor. Total GEM buffer allocation in bytes. Change-Id: I9d662ec50d64bb40a37dbf47f018b2f3a1c033ad Signed-off-by: Kenny Ho --- Documentation/admin-guide/cgroup-v2.rst | 50 +++++++++- drivers/gpu/drm/drm_gem.c | 9 ++ include/drm/drm_cgroup.h | 16 +++ include/drm/drm_gem.h | 11 +++ include/linux/cgroup_drm.h | 6 ++ kernel/cgroup/drm.c | 126 ++++++++++++++++++++++++ 6 files changed, 217 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 2936423a3fd5..0e29d136e2f9 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -63,6 +63,7 @@ v1 is available under Documentation/cgroup-v1/. 5-7-1. RDMA Interface Files 5-8. DRM 5-8-1. DRM Interface Files + 5-8-2. GEM Buffer Ownership 5-9. Misc 5-9-1. perf_event 5-N. Non-normative information @@ -1900,7 +1901,54 @@ of DRM (Direct Rendering Manager) and GPU-related resources. DRM Interface Files ~~~~~~~~~~~~~~~~~~~~ -TODO + drm.buffer.stats + A read-only flat-keyed file which exists on all cgroups. Each + entry is keyed by the drm device's major:minor. + + Total GEM buffer allocation in bytes. + +GEM Buffer Ownership +~~~~~~~~~~~~~~~~~~~~ + +For the purpose of cgroup accounting and limiting, ownership of the +buffer is deemed to be the cgroup for which the allocating process +belongs to. There is one cgroup stats per drm device. Each allocation +is charged to the owning cgroup as well as all its ancestors. + +Similar to the memory cgroup, migrating a process to a different cgroup +does not move the GEM buffer usages that the process started while in +previous cgroup, to the new cgroup. + +The following is an example to illustrate some of the operations. Given +the following cgroup hierarchy (The letters are cgroup names with R +being the root cgroup. The numbers in brackets are processes. The +processes are placed with cgroup's 'No Internal Process Constraint' in +mind, so no process is placed in cgroup B.) + +R (4, 5) ------ A (6) + \ + B ---- C (7,8) + \ + D (9) + +Here is a list of operation and the associated effect on the size +track by the cgroups (for simplicity, each buffer is 1 unit in size.) + +== == == == == =================================================== +R A B C D Ops +== == == == == =================================================== +1 0 0 0 0 4 allocated a buffer +1 0 0 0 0 4 shared a buffer with 5 +1 0 0 0 0 4 shared a buffer with 9 +2 0 1 0 1 9 allocated a buffer +3 0 2 1 1 7 allocated a buffer +3 0 2 1 1 7 shared a buffer with 8 +3 0 2 1 1 7 sharing with 9 +3 0 2 1 1 7 release a buffer +3 0 2 1 1 7 migrate to cgroup D +3 0 2 1 1 9 release a buffer from 7 +2 0 1 0 1 8 release a buffer from 7 (last ref to shared buf) +== == == == == =================================================== Misc diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 50de138c89e0..517b71a6f4d4 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -38,10 +38,12 @@ #include #include #include +#include #include #include #include #include +#include #include "drm_internal.h" /** @file drm_gem.c @@ -159,6 +161,9 @@ void drm_gem_private_object_init(struct drm_device *dev, obj->resv = &obj->_resv; drm_vma_node_reset(&obj->vma_node); + + obj->drmcg = drmcg_get(current); + drmcg_chg_bo_alloc(obj->drmcg, dev, size); } EXPORT_SYMBOL(drm_gem_private_object_init); @@ -950,6 +955,10 @@ drm_gem_object_release(struct drm_gem_object *obj) fput(obj->filp); reservation_object_fini(&obj->_resv); + + drmcg_unchg_bo_alloc(obj->drmcg, obj->dev, obj->size); + drmcg_put(obj->drmcg); + drm_gem_free_mmap_offset(obj); } EXPORT_SYMBOL(drm_gem_object_release); diff --git a/include/drm/drm_cgroup.h b/include/drm/drm_cgroup.h index bef9f9245924..1fa37d1ad44c 100644 --- a/include/drm/drm_cgroup.h +++ b/include/drm/drm_cgroup.h @@ -4,6 +4,8 @@ #ifndef __DRM_CGROUP_H__ #define __DRM_CGROUP_H__ +#include + /** * Per DRM device properties for DRM cgroup controller for the purpose * of storing per device defaults @@ -15,6 +17,10 @@ struct drmcg_props { void drmcg_device_update(struct drm_device *device); void drmcg_device_early_init(struct drm_device *device); +void drmcg_chg_bo_alloc(struct drmcg *drmcg, struct drm_device *dev, + size_t size); +void drmcg_unchg_bo_alloc(struct drmcg *drmcg, struct drm_device *dev, + size_t size); #else static inline void drmcg_device_update(struct drm_device *device) { @@ -23,5 +29,15 @@ static inline void drmcg_device_update(struct drm_device *device) static inline void drmcg_device_early_init(struct drm_device *device) { } + +static inline void drmcg_chg_bo_alloc(struct drmcg *drmcg, + struct drm_device *dev, size_t size) +{ +} + +static inline void drmcg_unchg_bo_alloc(struct drmcg *drmcg, + struct drm_device *dev, size_t size) +{ +} #endif /* CONFIG_CGROUP_DRM */ #endif /* __DRM_CGROUP_H__ */ diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index 5047c7ee25f5..6047968bdd17 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -291,6 +291,17 @@ struct drm_gem_object { * */ const struct drm_gem_object_funcs *funcs; + + /** + * @drmcg: + * + * DRM cgroup this GEM object belongs to. + * + * This is used to track and limit the amount of GEM objects a user + * can allocate. Since GEM objects can be shared, this is also used + * to ensure GEM objects are only shared within the same cgroup. + */ + struct drmcg *drmcg; }; /** diff --git a/include/linux/cgroup_drm.h b/include/linux/cgroup_drm.h index 4ecd44f2ac27..1d8a7f2cdb4e 100644 --- a/include/linux/cgroup_drm.h +++ b/include/linux/cgroup_drm.h @@ -13,11 +13,17 @@ /* limit defined per the way drm_minor_alloc operates */ #define MAX_DRM_DEV (64 * DRM_MINOR_RENDER) +enum drmcg_res_type { + DRMCG_TYPE_BO_TOTAL, + __DRMCG_TYPE_LAST, +}; + /** * Per DRM cgroup, per device resources (such as statistics and limits) */ struct drmcg_device_resource { /* for per device stats */ + s64 bo_stats_total_allocated; }; /** diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c index 135fdcdc4b51..87ae9164d8d8 100644 --- a/kernel/cgroup/drm.c +++ b/kernel/cgroup/drm.c @@ -11,11 +11,24 @@ #include #include #include +#include #include /* global mutex for drmcg across all devices */ static DEFINE_MUTEX(drmcg_mutex); +#define DRMCG_CTF_PRIV_SIZE 3 +#define DRMCG_CTF_PRIV_MASK GENMASK((DRMCG_CTF_PRIV_SIZE - 1), 0) +#define DRMCG_CTF_PRIV(res_type, f_type) ((res_type) <<\ + DRMCG_CTF_PRIV_SIZE | (f_type)) +#define DRMCG_CTF_PRIV2RESTYPE(priv) ((priv) >> DRMCG_CTF_PRIV_SIZE) +#define DRMCG_CTF_PRIV2FTYPE(priv) ((priv) & DRMCG_CTF_PRIV_MASK) + + +enum drmcg_file_type { + DRMCG_FTYPE_STATS, +}; + static struct drmcg *root_drmcg __read_mostly; static int drmcg_css_free_fn(int id, void *ptr, void *data) @@ -104,7 +117,66 @@ drmcg_css_alloc(struct cgroup_subsys_state *parent_css) return &drmcg->css; } +static void drmcg_print_stats(struct drmcg_device_resource *ddr, + struct seq_file *sf, enum drmcg_res_type type) +{ + if (ddr == NULL) { + seq_puts(sf, "\n"); + return; + } + + switch (type) { + case DRMCG_TYPE_BO_TOTAL: + seq_printf(sf, "%lld\n", ddr->bo_stats_total_allocated); + break; + default: + seq_puts(sf, "\n"); + break; + } +} + +static int drmcg_seq_show_fn(int id, void *ptr, void *data) +{ + struct drm_minor *minor = ptr; + struct seq_file *sf = data; + struct drmcg *drmcg = css_to_drmcg(seq_css(sf)); + enum drmcg_file_type f_type = + DRMCG_CTF_PRIV2FTYPE(seq_cft(sf)->private); + enum drmcg_res_type type = + DRMCG_CTF_PRIV2RESTYPE(seq_cft(sf)->private); + struct drmcg_device_resource *ddr; + + if (minor->type != DRM_MINOR_PRIMARY) + return 0; + + ddr = drmcg->dev_resources[minor->index]; + + seq_printf(sf, "%d:%d ", DRM_MAJOR, minor->index); + + switch (f_type) { + case DRMCG_FTYPE_STATS: + drmcg_print_stats(ddr, sf, type); + break; + default: + seq_puts(sf, "\n"); + break; + } + + return 0; +} + +int drmcg_seq_show(struct seq_file *sf, void *v) +{ + return drm_minor_for_each(&drmcg_seq_show_fn, sf); +} + struct cftype files[] = { + { + .name = "buffer.total.stats", + .seq_show = drmcg_seq_show, + .private = DRMCG_CTF_PRIV(DRMCG_TYPE_BO_TOTAL, + DRMCG_FTYPE_STATS), + }, { } /* terminate */ }; @@ -163,3 +235,57 @@ void drmcg_device_early_init(struct drm_device *dev) drmcg_update_cg_tree(dev); } EXPORT_SYMBOL(drmcg_device_early_init); + +/** + * drmcg_chg_bo_alloc - charge GEM buffer usage for a device and cgroup + * @drmcg: the DRM cgroup to be charged to + * @dev: the device the usage should be charged to + * @size: size of the GEM buffer to be accounted for + * + * This function should be called when a new GEM buffer is allocated to account + * for the utilization. This should not be called when the buffer is shared ( + * the GEM buffer's reference count being incremented.) + */ +void drmcg_chg_bo_alloc(struct drmcg *drmcg, struct drm_device *dev, + size_t size) +{ + struct drmcg_device_resource *ddr; + int devIdx = dev->primary->index; + + if (drmcg == NULL) + return; + + mutex_lock(&dev->drmcg_mutex); + for ( ; drmcg != NULL; drmcg = drmcg_parent(drmcg)) { + ddr = drmcg->dev_resources[devIdx]; + + ddr->bo_stats_total_allocated += (s64)size; + } + mutex_unlock(&dev->drmcg_mutex); +} +EXPORT_SYMBOL(drmcg_chg_bo_alloc); + +/** + * drmcg_unchg_bo_alloc - + * @drmcg: the DRM cgroup to uncharge from + * @dev: the device the usage should be removed from + * @size: size of the GEM buffer to be accounted for + * + * This function should be called when the GEM buffer is about to be freed ( + * not simply when the GEM buffer's reference count is being decremented.) + */ +void drmcg_unchg_bo_alloc(struct drmcg *drmcg, struct drm_device *dev, + size_t size) +{ + int devIdx = dev->primary->index; + + if (drmcg == NULL) + return; + + mutex_lock(&dev->drmcg_mutex); + for ( ; drmcg != NULL; drmcg = drmcg_parent(drmcg)) + drmcg->dev_resources[devIdx]->bo_stats_total_allocated + -= (s64)size; + mutex_unlock(&dev->drmcg_mutex); +} +EXPORT_SYMBOL(drmcg_unchg_bo_alloc); From patchwork Thu Aug 29 06:05:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 11120379 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BF01614D5 for ; Thu, 29 Aug 2019 06:06:04 +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 A808D23405 for ; Thu, 29 Aug 2019 06:06:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A808D23405 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BC80F89FA7; Thu, 29 Aug 2019 06:05:54 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-eopbgr800084.outbound.protection.outlook.com [40.107.80.84]) by gabe.freedesktop.org (Postfix) with ESMTPS id 68EAF89F9F; Thu, 29 Aug 2019 06:05:50 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DBuRjwJCzGUUBJZCCQ74Iq/c6lhLLjrizY7gZPeOIw+emp/FOGtXMzxYRDTBnP/i1wYO5XWPxcNEvuThcOlDPmrOr658eBNO0K0Rynos9JXPszEpNqHolpMHXP3fKFjKVQsry1hOgdpbGp9vWNsLMMbeAxcPYAQP4D4oNbNplrkKSo4R1UJzmlPWpVzrabkAne0+8lzXsGfcz8A1CtX6Kp6pmbVDLmtpVKHoktwk5IxNP9I+TQUw3+MOjUC/QBuIulogXXTs50DqnK0YBQHMMPcoIkciHglQ8j90rwIDkppsWg/c7pv/CV2oMBIavVhOKj6CKaoPt8oynpvXP36Gpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xUTefRHhP4jPk7HjUkR/MCUopIKc0hLAEG/HgFFHU9k=; b=HHSUYJaynJcMpFJNf9Cr+QYZ21ioyqd7V/VTlmrJZ+AAnvl0hxmIcDRwYx+AN/vfdUwrzsEJQHvP43RiuTeC5p3/yDVwKjflXYLQCCcSmeK8yh5QRqDJTYOj2Ys7uvOJRDKmBqZbUUkAqQo5V0pwdxG/9+PPAyVyLtXURsz2Vq9+oez2Oly0cRmEapqpM9RZPBMGLpIKpWk/5vHQwmZvsWq/qC1wBwnhJfPfEXrRR0PwzEVy67dHO5b/86ahk+yYLjxGark1Fy1mUdxl/XcwV1VKCbT7LCBm9/LGJV9f4ZHlYBACLu6o2IcKnxBosTWwT1b/mj/P9RO4P0bYZNxAtw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none (sender ip is 165.204.84.17) smtp.rcpttodomain=cray.com smtp.mailfrom=amd.com; dmarc=permerror action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from CH2PR12CA0005.namprd12.prod.outlook.com (2603:10b6:610:57::15) by DM6PR12MB2715.namprd12.prod.outlook.com (2603:10b6:5:4a::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Thu, 29 Aug 2019 06:05:48 +0000 Received: from CO1NAM03FT045.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::200) by CH2PR12CA0005.outlook.office365.com (2603:10b6:610:57::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2220.18 via Frontend Transport; Thu, 29 Aug 2019 06:05:48 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV01.amd.com (165.204.84.17) by CO1NAM03FT045.mail.protection.outlook.com (10.152.81.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2220.16 via Frontend Transport; Thu, 29 Aug 2019 06:05:47 +0000 Received: from kho-5039A.amd.com (10.180.168.240) by SATLEXCHOV01.amd.com (10.181.40.71) with Microsoft SMTP Server id 14.3.389.1; Thu, 29 Aug 2019 01:05:45 -0500 From: Kenny Ho To: , , , , , , , , , , , Subject: [PATCH RFC v4 05/16] drm, cgroup: Add peak GEM buffer allocation stats Date: Thu, 29 Aug 2019 02:05:22 -0400 Message-ID: <20190829060533.32315-6-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829060533.32315-1-Kenny.Ho@amd.com> References: <20190829060533.32315-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(4636009)(136003)(39860400002)(346002)(376002)(396003)(2980300002)(428003)(199004)(189003)(6666004)(5660300002)(2870700001)(11346002)(478600001)(2201001)(86362001)(2616005)(1076003)(186003)(36756003)(26005)(70586007)(81166006)(336012)(476003)(126002)(356004)(81156014)(70206006)(47776003)(486006)(53936002)(76176011)(48376002)(305945005)(446003)(426003)(2906002)(4326008)(316002)(8936002)(51416003)(7696005)(53416004)(14444005)(50226002)(50466002)(8676002)(110136005)(921003)(83996005)(2101003)(1121003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM6PR12MB2715; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ca76ff9d-9db3-4111-832c-08d72c46f000 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328); SRVR:DM6PR12MB2715; X-MS-TrafficTypeDiagnostic: DM6PR12MB2715: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-Forefront-PRVS: 0144B30E41 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 0XM5WBzGTx5oyxJL4ThUvtNyfVdJQT+9HZj6FIfo9Lt+T2MGu8sERR+OMKA5rkx49ngJRhzijBAGVVzhEGelxnatHFzdSQPu2V5p5tvQr8ZE6tOXuZMhHvBEcivPcaz2dGCFv3hvuSKTcTU9/Z8TWAjzP2UF4wYOD7OMQjbfWjpqV5Ov8CSQUtxqj76Q6HjQ7rMNTDZ7U883movIFZcnKbcNzw5RuqFIPqNhrk8bMXNMcxBOnjhDBL63gZggut6o/fXCBj8tBHiINuwrCC9YHCN/40dTjrWVvEZGaA3gB8CekE6aRqkw33mZj8/BOaN0McmFrmuYglo6rkF9PmkflX1yPvaKam9X0+oH7tF/Ug27ECu//wFyoGTRcwff2ukJsYGsQptSYgHbFc8sWXKi77YA8DxN430CxbGiCxyEkf0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2019 06:05:47.8790 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ca76ff9d-9db3-4111-832c-08d72c46f000 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2715 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xUTefRHhP4jPk7HjUkR/MCUopIKc0hLAEG/HgFFHU9k=; b=jzN+mFFc+4qYtHsla0OEKe6D2wdCWUaDHzLWG1MacGiGMvwRFwfjAFZlCCdj7B8DxMvqJp425EksZ7z7zOgbBjzIs8icunjae/poGS6MbJ1gFUeOvgJ7cjshpAeimyC0P4KJVxY0UV17Z+qElRvQ8tQmXCgSjaUepAG4t0rv3xg= X-Mailman-Original-Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; cray.com; dkim=none (message not signed) header.d=none;cray.com; dmarc=permerror action=none header.from=amd.com; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kenny Ho Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" drm.buffer.peak.stats A read-only flat-keyed file which exists on all cgroups. Each entry is keyed by the drm device's major:minor. Largest (high water mark) GEM buffer allocated in bytes. Change-Id: I79e56222151a3d33a76a61ba0097fe93ebb3449f Signed-off-by: Kenny Ho --- Documentation/admin-guide/cgroup-v2.rst | 6 ++++++ include/linux/cgroup_drm.h | 3 +++ kernel/cgroup/drm.c | 12 ++++++++++++ 3 files changed, 21 insertions(+) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 0e29d136e2f9..8588a0ffc69d 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1907,6 +1907,12 @@ DRM Interface Files Total GEM buffer allocation in bytes. + drm.buffer.peak.stats + A read-only flat-keyed file which exists on all cgroups. Each + entry is keyed by the drm device's major:minor. + + Largest (high water mark) GEM buffer allocated in bytes. + GEM Buffer Ownership ~~~~~~~~~~~~~~~~~~~~ diff --git a/include/linux/cgroup_drm.h b/include/linux/cgroup_drm.h index 1d8a7f2cdb4e..974d390cfa4f 100644 --- a/include/linux/cgroup_drm.h +++ b/include/linux/cgroup_drm.h @@ -15,6 +15,7 @@ enum drmcg_res_type { DRMCG_TYPE_BO_TOTAL, + DRMCG_TYPE_BO_PEAK, __DRMCG_TYPE_LAST, }; @@ -24,6 +25,8 @@ enum drmcg_res_type { struct drmcg_device_resource { /* for per device stats */ s64 bo_stats_total_allocated; + + s64 bo_stats_peak_allocated; }; /** diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c index 87ae9164d8d8..0bf5b95668c4 100644 --- a/kernel/cgroup/drm.c +++ b/kernel/cgroup/drm.c @@ -129,6 +129,9 @@ static void drmcg_print_stats(struct drmcg_device_resource *ddr, case DRMCG_TYPE_BO_TOTAL: seq_printf(sf, "%lld\n", ddr->bo_stats_total_allocated); break; + case DRMCG_TYPE_BO_PEAK: + seq_printf(sf, "%lld\n", ddr->bo_stats_peak_allocated); + break; default: seq_puts(sf, "\n"); break; @@ -177,6 +180,12 @@ struct cftype files[] = { .private = DRMCG_CTF_PRIV(DRMCG_TYPE_BO_TOTAL, DRMCG_FTYPE_STATS), }, + { + .name = "buffer.peak.stats", + .seq_show = drmcg_seq_show, + .private = DRMCG_CTF_PRIV(DRMCG_TYPE_BO_PEAK, + DRMCG_FTYPE_STATS), + }, { } /* terminate */ }; @@ -260,6 +269,9 @@ void drmcg_chg_bo_alloc(struct drmcg *drmcg, struct drm_device *dev, ddr = drmcg->dev_resources[devIdx]; ddr->bo_stats_total_allocated += (s64)size; + + if (ddr->bo_stats_peak_allocated < (s64)size) + ddr->bo_stats_peak_allocated = (s64)size; } mutex_unlock(&dev->drmcg_mutex); } From patchwork Thu Aug 29 06:05:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 11120381 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 01FAC14D5 for ; Thu, 29 Aug 2019 06:06:09 +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 DDFE7233A1 for ; Thu, 29 Aug 2019 06:06:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DDFE7233A1 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5CD7189FA6; Thu, 29 Aug 2019 06:05:54 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-eopbgr740058.outbound.protection.outlook.com [40.107.74.58]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2270489FA5; Thu, 29 Aug 2019 06:05:52 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=im8NVAFjE1M5AsM98gB+adyJp2zh7aQj5WF5vZZUSemmfdy/7BaSkJ0RWpZAVOzDUS1DcZ7X7rEy2oM/iNpcGoyKUkwHa7z35FvtrZzUlrVfx60C+t//BDx972TOEoj4Q77K2QX5T5ifXgu7VMVWIRoIU5ihliaCUGl+OaKrs7tTIs+XB2JuOgSbV94tabRliQurPwTtVrBpVIRejK36FOyFi6JKVny4qo5V6SLzVAConQg1bVWORnnYLJXpMGnQHCOykIiKjTVXHb6FIwktHutbRvvFtxeXWOGrHZFlau/TXIj5DIbfW4QQjTaZVrS77VwaMDDetmDN7kE04v12Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VuU3MD5G/KwGyScm4WY/+nb67CVxHL9Q8cXeaMI9nno=; b=Bmv5uZbEwoz7K9RKYkfOnsFOWFR2NlnOmbGyR2Kc+sp/GOXTlXal5tBn/Kz2SZMs7LK6v1XZKGYWlanD/9ZJQ6co507ySfYL7fZGPn15mieih8nTQ/QQENKkGExmnk9Y4SlX1DJhWwC1id3CtyorKxnUvPp2goK/teW8S90kXzHODJTcCw1+cB0MJ6nm0WEeqB5XePjekeD2PsBqhPqJApFXpudhz3wLS1JTiosyEnyjgSah/YoIRQxh9TBcr63n+PRS74/u7bjFMkbTNix/Y56BUD+Wtmbu0rowoysbVrJ2S2uzne0gL3JsGbJ7CpDlouNjp7pYJcmKbfP7hN4tfw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none (sender ip is 165.204.84.17) smtp.rcpttodomain=cray.com smtp.mailfrom=amd.com; dmarc=permerror action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from CH2PR12CA0005.namprd12.prod.outlook.com (2603:10b6:610:57::15) by DM5PR12MB1274.namprd12.prod.outlook.com (2603:10b6:3:78::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2178.18; Thu, 29 Aug 2019 06:05:49 +0000 Received: from CO1NAM03FT045.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::200) by CH2PR12CA0005.outlook.office365.com (2603:10b6:610:57::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2220.18 via Frontend Transport; Thu, 29 Aug 2019 06:05:49 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV01.amd.com (165.204.84.17) by CO1NAM03FT045.mail.protection.outlook.com (10.152.81.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2220.16 via Frontend Transport; Thu, 29 Aug 2019 06:05:48 +0000 Received: from kho-5039A.amd.com (10.180.168.240) by SATLEXCHOV01.amd.com (10.181.40.71) with Microsoft SMTP Server id 14.3.389.1; Thu, 29 Aug 2019 01:05:45 -0500 From: Kenny Ho To: , , , , , , , , , , , Subject: [PATCH RFC v4 06/16] drm, cgroup: Add GEM buffer allocation count stats Date: Thu, 29 Aug 2019 02:05:23 -0400 Message-ID: <20190829060533.32315-7-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829060533.32315-1-Kenny.Ho@amd.com> References: <20190829060533.32315-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(4636009)(346002)(376002)(396003)(39860400002)(136003)(2980300002)(428003)(199004)(189003)(186003)(47776003)(81166006)(81156014)(26005)(2906002)(2870700001)(11346002)(53936002)(70206006)(316002)(476003)(8936002)(14444005)(6666004)(7696005)(51416003)(356004)(478600001)(76176011)(53416004)(305945005)(70586007)(50466002)(86362001)(486006)(48376002)(5660300002)(4326008)(126002)(2616005)(50226002)(446003)(110136005)(36756003)(1076003)(2201001)(336012)(426003)(8676002)(921003)(2101003)(1121003)(83996005); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB1274; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 32447f36-cf7d-44e3-ad31-08d72c46f09d X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328); SRVR:DM5PR12MB1274; X-MS-TrafficTypeDiagnostic: DM5PR12MB1274: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-Forefront-PRVS: 0144B30E41 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 5ATGvrApfPfk/JJjeEjh6ymii2NrqmC+wTZx8m9aoa9Li2SP+PVsRtPwXaEBWl1D7R488p/lDk/k6XZhUQjiDMaROaMjv3jv7N3swE5MHIDA1aTZ4oNSsQ3tGGPOUK+C/X69kiIHla/rUPMbCN00n1BtpAyOQcsBCSRMAU+NhyMSqx7O+c7AG0oPivdKDWmeNEstjZH6wwtIwo/bJAng3ruqhUdvQlLs40I3tZBDVxtckgEJNBpE8DMSKIHY16BIgH0Yv30pzv0fZdqOw6bCOHoJOgcUuiNOTUKKm0yZ1sZma5AriJJJ9B098wkBZzE7YUtXh55JLYmLaVGU8bzzYsH/w5u0K8qRrbj1FdxqTVQq3lAEi25simORrik10Hvx9qlyI66cZm/dj/7btDyYhCQ5WhuzPBORwj9WkQFHLb0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2019 06:05:48.9206 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 32447f36-cf7d-44e3-ad31-08d72c46f09d X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1274 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VuU3MD5G/KwGyScm4WY/+nb67CVxHL9Q8cXeaMI9nno=; b=v+w/3TNRyMI/pOQ27dHWhM92m0fPeo7cp/AoLkIkFjtIxANizkFrQRwdisrN/yYH/oPNGvnV6yjGJiIXlgxj6VU6d5hIfnGYV64/NyPf6AOIvuCNnH2d9SGuXGAr2Bli0SZqKacTP2sdRxYPgykPu7f+HMicL1KwMyjVYPi+MXA= X-Mailman-Original-Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; cray.com; dkim=none (message not signed) header.d=none;cray.com; dmarc=permerror action=none header.from=amd.com; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kenny Ho Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" drm.buffer.count.stats A read-only flat-keyed file which exists on all cgroups. Each entry is keyed by the drm device's major:minor. Total number of GEM buffer allocated. Change-Id: Id3e1809d5fee8562e47a7d2b961688956d844ec6 Signed-off-by: Kenny Ho --- Documentation/admin-guide/cgroup-v2.rst | 6 ++++++ include/linux/cgroup_drm.h | 3 +++ kernel/cgroup/drm.c | 22 +++++++++++++++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 8588a0ffc69d..4dc72339a9b6 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1913,6 +1913,12 @@ DRM Interface Files Largest (high water mark) GEM buffer allocated in bytes. + drm.buffer.count.stats + A read-only flat-keyed file which exists on all cgroups. Each + entry is keyed by the drm device's major:minor. + + Total number of GEM buffer allocated. + GEM Buffer Ownership ~~~~~~~~~~~~~~~~~~~~ diff --git a/include/linux/cgroup_drm.h b/include/linux/cgroup_drm.h index 974d390cfa4f..972f7aa975b5 100644 --- a/include/linux/cgroup_drm.h +++ b/include/linux/cgroup_drm.h @@ -16,6 +16,7 @@ enum drmcg_res_type { DRMCG_TYPE_BO_TOTAL, DRMCG_TYPE_BO_PEAK, + DRMCG_TYPE_BO_COUNT, __DRMCG_TYPE_LAST, }; @@ -27,6 +28,8 @@ struct drmcg_device_resource { s64 bo_stats_total_allocated; s64 bo_stats_peak_allocated; + + s64 bo_stats_count_allocated; }; /** diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c index 0bf5b95668c4..85e46ece4a82 100644 --- a/kernel/cgroup/drm.c +++ b/kernel/cgroup/drm.c @@ -132,6 +132,9 @@ static void drmcg_print_stats(struct drmcg_device_resource *ddr, case DRMCG_TYPE_BO_PEAK: seq_printf(sf, "%lld\n", ddr->bo_stats_peak_allocated); break; + case DRMCG_TYPE_BO_COUNT: + seq_printf(sf, "%lld\n", ddr->bo_stats_count_allocated); + break; default: seq_puts(sf, "\n"); break; @@ -186,6 +189,12 @@ struct cftype files[] = { .private = DRMCG_CTF_PRIV(DRMCG_TYPE_BO_PEAK, DRMCG_FTYPE_STATS), }, + { + .name = "buffer.count.stats", + .seq_show = drmcg_seq_show, + .private = DRMCG_CTF_PRIV(DRMCG_TYPE_BO_COUNT, + DRMCG_FTYPE_STATS), + }, { } /* terminate */ }; @@ -272,6 +281,8 @@ void drmcg_chg_bo_alloc(struct drmcg *drmcg, struct drm_device *dev, if (ddr->bo_stats_peak_allocated < (s64)size) ddr->bo_stats_peak_allocated = (s64)size; + + ddr->bo_stats_count_allocated++; } mutex_unlock(&dev->drmcg_mutex); } @@ -289,15 +300,20 @@ EXPORT_SYMBOL(drmcg_chg_bo_alloc); void drmcg_unchg_bo_alloc(struct drmcg *drmcg, struct drm_device *dev, size_t size) { + struct drmcg_device_resource *ddr; int devIdx = dev->primary->index; if (drmcg == NULL) return; mutex_lock(&dev->drmcg_mutex); - for ( ; drmcg != NULL; drmcg = drmcg_parent(drmcg)) - drmcg->dev_resources[devIdx]->bo_stats_total_allocated - -= (s64)size; + for ( ; drmcg != NULL; drmcg = drmcg_parent(drmcg)) { + ddr = drmcg->dev_resources[devIdx]; + + ddr->bo_stats_total_allocated -= (s64)size; + + ddr->bo_stats_count_allocated--; + } mutex_unlock(&dev->drmcg_mutex); } EXPORT_SYMBOL(drmcg_unchg_bo_alloc); From patchwork Thu Aug 29 06:05:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 11120389 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8A93714DE for ; Thu, 29 Aug 2019 06:06:17 +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 73E6020828 for ; Thu, 29 Aug 2019 06:06:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 73E6020828 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3E5CB89FC9; Thu, 29 Aug 2019 06:06:03 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM05-CO1-obe.outbound.protection.outlook.com (mail-eopbgr720083.outbound.protection.outlook.com [40.107.72.83]) by gabe.freedesktop.org (Postfix) with ESMTPS id 034CD89FA6; Thu, 29 Aug 2019 06:05:53 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Vaz14vo3Q6bPFP7zF8uqGICI6I+Q/jzLVu0emk2+9kFr11JngzfOfUDRg4GzjKDofAG5f+JRuNc04/RYeaezG50UlqNoPm/5v21gOTwknsnHhvVytJ94HGNTh4KWv6o+jjxXtqqlDJ9ELRsZttq3Z7XhqYhtRZx+s5eh/foWeLLz8S5aKWa8zmNFZ2xAN1zYgFRUA9UXuN/T9aKt3151ktl/o43y2g3dN2ydMBpYkUGaPJska97VLDlcBejsvx1IrNQ5gSDTwkz2DGqrkA3XVPTklWXo3P0j/yP10Ipfd5azXS+9XJez7By57uYbzcL441wGhRe+FLkVaGjqkZA+DQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CwhrrpfnjRvIn1W1p0TIz3hJIBNex6hm3VEN6TfrWdI=; b=JntC1zxX+J2FfdkzPCOeTqxQDbTJEQlr9OEjGbqY1MfcKcWWtnoILmB7xouLdcdScYG7hYzsGn7DiAs8Z8sJt/l5awyiNH4QOPlJ+1KVznP4JPuYBT+EEgCSC+//h3u80TeT2Rqd3aORYDZi5x9PD5G87MPVkUNDfJ13vxkdPuP6cecB/sjGv1Dv9HF9tHt2mBrN2CRNRfdzie20ZyV6D4Dl7xSdUr1qgmGQWRfY7/gdrLmYDp+EYNGACOmvKBH2Af0zLKpNXsxtrGQbVenSDb+CeChkIuRWxPcPphfDjSLzGqxUTgLs8tT8Ji5sKwoDWjTrThenY7UOl4mu+B2kPw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none (sender ip is 165.204.84.17) smtp.rcpttodomain=cray.com smtp.mailfrom=amd.com; dmarc=permerror action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from CH2PR12CA0005.namprd12.prod.outlook.com (2603:10b6:610:57::15) by CY4PR12MB1272.namprd12.prod.outlook.com (2603:10b6:903:3e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2178.16; Thu, 29 Aug 2019 06:05:51 +0000 Received: from CO1NAM03FT045.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::200) by CH2PR12CA0005.outlook.office365.com (2603:10b6:610:57::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2220.18 via Frontend Transport; Thu, 29 Aug 2019 06:05:50 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV01.amd.com (165.204.84.17) by CO1NAM03FT045.mail.protection.outlook.com (10.152.81.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2220.16 via Frontend Transport; Thu, 29 Aug 2019 06:05:50 +0000 Received: from kho-5039A.amd.com (10.180.168.240) by SATLEXCHOV01.amd.com (10.181.40.71) with Microsoft SMTP Server id 14.3.389.1; Thu, 29 Aug 2019 01:05:46 -0500 From: Kenny Ho To: , , , , , , , , , , , Subject: [PATCH RFC v4 07/16] drm, cgroup: Add total GEM buffer allocation limit Date: Thu, 29 Aug 2019 02:05:24 -0400 Message-ID: <20190829060533.32315-8-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829060533.32315-1-Kenny.Ho@amd.com> References: <20190829060533.32315-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(4636009)(376002)(136003)(346002)(396003)(39860400002)(2980300002)(428003)(199004)(189003)(47776003)(336012)(478600001)(30864003)(126002)(81166006)(5660300002)(70586007)(53416004)(70206006)(186003)(86362001)(305945005)(486006)(11346002)(446003)(426003)(76176011)(48376002)(50466002)(36756003)(2906002)(476003)(2616005)(8676002)(7696005)(1076003)(14444005)(50226002)(2870700001)(26005)(356004)(51416003)(4326008)(6666004)(316002)(110136005)(2201001)(53936002)(81156014)(8936002)(921003)(2101003)(83996005)(1121003); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR12MB1272; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 534f0e73-4cf3-4450-5871-08d72c46f16a X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328); SRVR:CY4PR12MB1272; X-MS-TrafficTypeDiagnostic: CY4PR12MB1272: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-Forefront-PRVS: 0144B30E41 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: JYFNtGPowROq6GC7cP3zlUzpxK0oLEJR7Gt7Ruy07/TriY38vDkZ0rtwwAtFjdtIQljt2BULQq5ktXTRv2lgoczFTXlUrcSUja3Q2W/kDzgYNPY2iwDMfRbN5zBw74pPQLRVZ2Qg6rcBl2jW2xKxNdqoGvo8s3L9NNTNXTbmtJM2k0cItzEah+vdgLlATUKKdsFzkNZaKpmjgs809FGLDq9IBYFlgiF8FIXdoCcsvMS+DZQMk7KNxq2XcMOsA6dn9DanYcPlsVvosMviY0zYVqJxQg7EVb5jo+YtXhQFXF4jqermJj9b583xuVMGsbsyujhYjR8kL9F9CTtEsIDKtCDQoGSqC67IcErmCSdigJF3iWgxjhT4NMI9D/63vFxzIUF1BWZ2zFVmGVjZNT2kMpBHgjAFbs+i1X1RT0v6/zs= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2019 06:05:50.2776 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 534f0e73-4cf3-4450-5871-08d72c46f16a X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1272 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CwhrrpfnjRvIn1W1p0TIz3hJIBNex6hm3VEN6TfrWdI=; b=liTNHPrtqrcLks7OIjXZM3b2T0kLSGtTvqF56hi69Xunots8APtgqkn4+anOejaEayR1oJfkJlhcfV4vFeptAl+S+m1MXkqwfjEW5txHmExH0ep0E+XfsjFONcPX6xUpOidchfhRwgd6Rnq4jliB0xf0igC1sa0xbIaqEMkW7GA= X-Mailman-Original-Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; cray.com; dkim=none (message not signed) header.d=none;cray.com; dmarc=permerror action=none header.from=amd.com; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kenny Ho Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The drm resource being limited here is the GEM buffer objects. User applications allocate and free these buffers. In addition, a process can allocate a buffer and share it with another process. The consumer of a shared buffer can also outlive the allocator of the buffer. For the purpose of cgroup accounting and limiting, ownership of the buffer is deemed to be the cgroup for which the allocating process belongs to. There is one cgroup limit per drm device. The limiting functionality is added to the previous stats collection function. The drm_gem_private_object_init is modified to have a return value to allow failure due to cgroup limit. The try_chg function only fails if the DRM cgroup properties has limit_enforced set to true for the DRM device. This is to allow the DRM cgroup controller to collect usage stats without enforcing the limits. drm.buffer.default A read-only flat-keyed file which exists on the root cgroup. Each entry is keyed by the drm device's major:minor. Default limits on the total GEM buffer allocation in bytes. drm.buffer.max A read-write flat-keyed file which exists on all cgroups. Each entry is keyed by the drm device's major:minor. Per device limits on the total GEM buffer allocation in byte. This is a hard limit. Attempts in allocating beyond the cgroup limit will result in ENOMEM. Shorthand understood by memparse (such as k, m, g) can be used. Set allocation limit for /dev/dri/card1 to 1GB echo "226:1 1g" > drm.buffer.total.max Set allocation limit for /dev/dri/card0 to 512MB echo "226:0 512m" > drm.buffer.total.max Change-Id: I96e0b7add4d331ed8bb267b3c9243d360c6e9903 Signed-off-by: Kenny Ho --- Documentation/admin-guide/cgroup-v2.rst | 21 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 8 + drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 6 +- drivers/gpu/drm/drm_gem.c | 11 +- include/drm/drm_cgroup.h | 7 +- include/drm/drm_gem.h | 2 +- include/linux/cgroup_drm.h | 1 + kernel/cgroup/drm.c | 221 ++++++++++++++++++++- 8 files changed, 260 insertions(+), 17 deletions(-) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 4dc72339a9b6..e8fac2684179 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1919,6 +1919,27 @@ DRM Interface Files Total number of GEM buffer allocated. + drm.buffer.default + A read-only flat-keyed file which exists on the root cgroup. + Each entry is keyed by the drm device's major:minor. + + Default limits on the total GEM buffer allocation in bytes. + + drm.buffer.max + A read-write flat-keyed file which exists on all cgroups. Each + entry is keyed by the drm device's major:minor. + + Per device limits on the total GEM buffer allocation in byte. + This is a hard limit. Attempts in allocating beyond the cgroup + limit will result in ENOMEM. Shorthand understood by memparse + (such as k, m, g) can be used. + + Set allocation limit for /dev/dri/card1 to 1GB + echo "226:1 1g" > drm.buffer.total.max + + Set allocation limit for /dev/dri/card0 to 512MB + echo "226:0 512m" > drm.buffer.total.max + GEM Buffer Ownership ~~~~~~~~~~~~~~~~~~~~ diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c index c0bbd3aa0558..163a4fbf0611 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c @@ -1395,6 +1395,12 @@ amdgpu_get_crtc_scanout_position(struct drm_device *dev, unsigned int pipe, stime, etime, mode); } +static void amdgpu_drmcg_custom_init(struct drm_device *dev, + struct drmcg_props *props) +{ + props->limit_enforced = true; +} + static struct drm_driver kms_driver = { .driver_features = DRIVER_USE_AGP | DRIVER_ATOMIC | @@ -1431,6 +1437,8 @@ static struct drm_driver kms_driver = { .gem_prime_vunmap = amdgpu_gem_prime_vunmap, .gem_prime_mmap = amdgpu_gem_prime_mmap, + .drmcg_custom_init = amdgpu_drmcg_custom_init, + .name = DRIVER_NAME, .desc = DRIVER_DESC, .date = DRIVER_DATE, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c index 989b7b55cb2e..b1bd66be3e1a 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "amdgpu.h" #include "amdgpu_trace.h" #include "amdgpu_amdkfd.h" @@ -454,7 +455,10 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, bo = kzalloc(sizeof(struct amdgpu_bo), GFP_KERNEL); if (bo == NULL) return -ENOMEM; - drm_gem_private_object_init(adev->ddev, &bo->gem_base, size); + if (!drm_gem_private_object_init(adev->ddev, &bo->gem_base, size)) { + kfree(bo); + return -ENOMEM; + } INIT_LIST_HEAD(&bo->shadow_list); bo->vm_bo = NULL; bo->preferred_domains = bp->preferred_domain ? bp->preferred_domain : diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 517b71a6f4d4..7887f153ab83 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -145,11 +145,17 @@ EXPORT_SYMBOL(drm_gem_object_init); * no GEM provided backing store. Instead the caller is responsible for * backing the object and handling it. */ -void drm_gem_private_object_init(struct drm_device *dev, +bool drm_gem_private_object_init(struct drm_device *dev, struct drm_gem_object *obj, size_t size) { BUG_ON((size & (PAGE_SIZE - 1)) != 0); + obj->drmcg = drmcg_get(current); + if (!drmcg_try_chg_bo_alloc(obj->drmcg, dev, size)) { + drmcg_put(obj->drmcg); + obj->drmcg = NULL; + return false; + } obj->dev = dev; obj->filp = NULL; @@ -162,8 +168,7 @@ void drm_gem_private_object_init(struct drm_device *dev, drm_vma_node_reset(&obj->vma_node); - obj->drmcg = drmcg_get(current); - drmcg_chg_bo_alloc(obj->drmcg, dev, size); + return true; } EXPORT_SYMBOL(drm_gem_private_object_init); diff --git a/include/drm/drm_cgroup.h b/include/drm/drm_cgroup.h index 1fa37d1ad44c..49c5d35ff6e1 100644 --- a/include/drm/drm_cgroup.h +++ b/include/drm/drm_cgroup.h @@ -11,13 +11,16 @@ * of storing per device defaults */ struct drmcg_props { + bool limit_enforced; + + s64 bo_limits_total_allocated_default; }; #ifdef CONFIG_CGROUP_DRM void drmcg_device_update(struct drm_device *device); void drmcg_device_early_init(struct drm_device *device); -void drmcg_chg_bo_alloc(struct drmcg *drmcg, struct drm_device *dev, +bool drmcg_try_chg_bo_alloc(struct drmcg *drmcg, struct drm_device *dev, size_t size); void drmcg_unchg_bo_alloc(struct drmcg *drmcg, struct drm_device *dev, size_t size); @@ -30,7 +33,7 @@ static inline void drmcg_device_early_init(struct drm_device *device) { } -static inline void drmcg_chg_bo_alloc(struct drmcg *drmcg, +static inline void drmcg_try_chg_bo_alloc(struct drmcg *drmcg, struct drm_device *dev, size_t size) { } diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index 6047968bdd17..2bf0c0962ddf 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -334,7 +334,7 @@ void drm_gem_object_release(struct drm_gem_object *obj); void drm_gem_object_free(struct kref *kref); 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, +bool drm_gem_private_object_init(struct drm_device *dev, struct drm_gem_object *obj, size_t size); void drm_gem_vm_open(struct vm_area_struct *vma); void drm_gem_vm_close(struct vm_area_struct *vma); diff --git a/include/linux/cgroup_drm.h b/include/linux/cgroup_drm.h index 972f7aa975b5..eb54e56f20ae 100644 --- a/include/linux/cgroup_drm.h +++ b/include/linux/cgroup_drm.h @@ -26,6 +26,7 @@ enum drmcg_res_type { struct drmcg_device_resource { /* for per device stats */ s64 bo_stats_total_allocated; + s64 bo_limits_total_allocated; s64 bo_stats_peak_allocated; diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c index 85e46ece4a82..7161fa40e156 100644 --- a/kernel/cgroup/drm.c +++ b/kernel/cgroup/drm.c @@ -27,6 +27,8 @@ static DEFINE_MUTEX(drmcg_mutex); enum drmcg_file_type { DRMCG_FTYPE_STATS, + DRMCG_FTYPE_LIMIT, + DRMCG_FTYPE_DEFAULT, }; static struct drmcg *root_drmcg __read_mostly; @@ -70,6 +72,8 @@ static inline int init_drmcg_single(struct drmcg *drmcg, struct drm_device *dev) drmcg->dev_resources[minor] = ddr; /* set defaults here */ + ddr->bo_limits_total_allocated = + dev->drmcg_props.bo_limits_total_allocated_default; mutex_unlock(&dev->drmcg_mutex); return 0; @@ -141,6 +145,38 @@ static void drmcg_print_stats(struct drmcg_device_resource *ddr, } } +static void drmcg_print_limits(struct drmcg_device_resource *ddr, + struct seq_file *sf, enum drmcg_res_type type) +{ + if (ddr == NULL) { + seq_puts(sf, "\n"); + return; + } + + switch (type) { + case DRMCG_TYPE_BO_TOTAL: + seq_printf(sf, "%lld\n", ddr->bo_limits_total_allocated); + break; + default: + seq_puts(sf, "\n"); + break; + } +} + +static void drmcg_print_default(struct drmcg_props *props, + struct seq_file *sf, enum drmcg_res_type type) +{ + switch (type) { + case DRMCG_TYPE_BO_TOTAL: + seq_printf(sf, "%lld\n", + props->bo_limits_total_allocated_default); + break; + default: + seq_puts(sf, "\n"); + break; + } +} + static int drmcg_seq_show_fn(int id, void *ptr, void *data) { struct drm_minor *minor = ptr; @@ -163,6 +199,12 @@ static int drmcg_seq_show_fn(int id, void *ptr, void *data) case DRMCG_FTYPE_STATS: drmcg_print_stats(ddr, sf, type); break; + case DRMCG_FTYPE_LIMIT: + drmcg_print_limits(ddr, sf, type); + break; + case DRMCG_FTYPE_DEFAULT: + drmcg_print_default(&minor->dev->drmcg_props, sf, type); + break; default: seq_puts(sf, "\n"); break; @@ -176,6 +218,124 @@ int drmcg_seq_show(struct seq_file *sf, void *v) return drm_minor_for_each(&drmcg_seq_show_fn, sf); } +static void drmcg_pr_cft_err(const struct drmcg *drmcg, + int rc, const char *cft_name, int minor) +{ + pr_err("drmcg: error parsing %s, minor %d, rc %d ", + cft_name, minor, rc); + pr_cont_cgroup_name(drmcg->css.cgroup); + pr_cont("\n"); +} + +static int drmcg_process_limit_s64_val(char *sval, bool is_mem, + s64 def_val, s64 max_val, s64 *ret_val) +{ + int rc = strcmp("max", sval); + + + if (!rc) + *ret_val = max_val; + else { + rc = strcmp("default", sval); + + if (!rc) + *ret_val = def_val; + } + + if (rc) { + if (is_mem) { + *ret_val = memparse(sval, NULL); + rc = 0; + } else { + rc = kstrtoll(sval, 0, ret_val); + } + } + + if (*ret_val > max_val) + rc = -EINVAL; + + return rc; +} + +static void drmcg_value_apply(struct drm_device *dev, s64 *dst, s64 val) +{ + mutex_lock(&dev->drmcg_mutex); + *dst = val; + mutex_unlock(&dev->drmcg_mutex); +} + +static ssize_t drmcg_limit_write(struct kernfs_open_file *of, char *buf, + size_t nbytes, loff_t off) +{ + struct drmcg *drmcg = css_to_drmcg(of_css(of)); + struct drmcg *parent = drmcg_parent(drmcg); + enum drmcg_res_type type = + DRMCG_CTF_PRIV2RESTYPE(of_cft(of)->private); + char *cft_name = of_cft(of)->name; + char *limits = strstrip(buf); + struct drmcg_device_resource *ddr; + struct drmcg_props *props; + struct drm_minor *dm; + char *line; + char sattr[256]; + s64 val; + s64 p_max; + int rc; + int minor; + + while (limits != NULL) { + line = strsep(&limits, "\n"); + + if (sscanf(line, + __stringify(DRM_MAJOR)":%u %255[^\t\n]", + &minor, sattr) != 2) { + pr_err("drmcg: error parsing %s ", cft_name); + pr_cont_cgroup_name(drmcg->css.cgroup); + pr_cont("\n"); + + continue; + } + + dm = drm_minor_acquire(minor); + if (IS_ERR(dm)) { + pr_err("drmcg: invalid minor %d for %s ", + minor, cft_name); + pr_cont_cgroup_name(drmcg->css.cgroup); + pr_cont("\n"); + + continue; + } + + ddr = drmcg->dev_resources[minor]; + props = &dm->dev->drmcg_props; + switch (type) { + case DRMCG_TYPE_BO_TOTAL: + p_max = parent == NULL ? S64_MAX : + parent->dev_resources[minor]-> + bo_limits_total_allocated; + + rc = drmcg_process_limit_s64_val(sattr, true, + props->bo_limits_total_allocated_default, + p_max, + &val); + + if (rc || val < 0) { + drmcg_pr_cft_err(drmcg, rc, cft_name, minor); + break; + } + + drmcg_value_apply(dm->dev, + &ddr->bo_limits_total_allocated, val); + break; + default: + break; + } + drm_dev_put(dm->dev); /* release from drm_minor_acquire */ + } + + return nbytes; +} + struct cftype files[] = { { .name = "buffer.total.stats", @@ -183,6 +343,20 @@ struct cftype files[] = { .private = DRMCG_CTF_PRIV(DRMCG_TYPE_BO_TOTAL, DRMCG_FTYPE_STATS), }, + { + .name = "buffer.total.default", + .seq_show = drmcg_seq_show, + .flags = CFTYPE_ONLY_ON_ROOT, + .private = DRMCG_CTF_PRIV(DRMCG_TYPE_BO_TOTAL, + DRMCG_FTYPE_DEFAULT), + }, + { + .name = "buffer.total.max", + .write = drmcg_limit_write, + .seq_show = drmcg_seq_show, + .private = DRMCG_CTF_PRIV(DRMCG_TYPE_BO_TOTAL, + DRMCG_FTYPE_LIMIT), + }, { .name = "buffer.peak.stats", .seq_show = drmcg_seq_show, @@ -250,12 +424,16 @@ EXPORT_SYMBOL(drmcg_device_update); */ void drmcg_device_early_init(struct drm_device *dev) { + dev->drmcg_props.limit_enforced = false; + + dev->drmcg_props.bo_limits_total_allocated_default = S64_MAX; + drmcg_update_cg_tree(dev); } EXPORT_SYMBOL(drmcg_device_early_init); /** - * drmcg_chg_bo_alloc - charge GEM buffer usage for a device and cgroup + * drmcg_try_chg_bo_alloc - charge GEM buffer usage for a device and cgroup * @drmcg: the DRM cgroup to be charged to * @dev: the device the usage should be charged to * @size: size of the GEM buffer to be accounted for @@ -264,29 +442,52 @@ EXPORT_SYMBOL(drmcg_device_early_init); * for the utilization. This should not be called when the buffer is shared ( * the GEM buffer's reference count being incremented.) */ -void drmcg_chg_bo_alloc(struct drmcg *drmcg, struct drm_device *dev, +bool drmcg_try_chg_bo_alloc(struct drmcg *drmcg, struct drm_device *dev, size_t size) { struct drmcg_device_resource *ddr; int devIdx = dev->primary->index; + struct drmcg_props *props = &dev->drmcg_props; + struct drmcg *drmcg_cur = drmcg; + bool result = true; + s64 delta = 0; if (drmcg == NULL) - return; + return true; mutex_lock(&dev->drmcg_mutex); - for ( ; drmcg != NULL; drmcg = drmcg_parent(drmcg)) { - ddr = drmcg->dev_resources[devIdx]; + if (props->limit_enforced) { + for ( ; drmcg != NULL; drmcg = drmcg_parent(drmcg)) { + ddr = drmcg->dev_resources[devIdx]; + delta = ddr->bo_limits_total_allocated - + ddr->bo_stats_total_allocated; + + if (delta <= 0 || size > delta) { + result = false; + break; + } + } + } + + drmcg = drmcg_cur; + + if (result || !props->limit_enforced) { + for ( ; drmcg != NULL; drmcg = drmcg_parent(drmcg)) { + ddr = drmcg->dev_resources[devIdx]; - ddr->bo_stats_total_allocated += (s64)size; + ddr->bo_stats_total_allocated += (s64)size; - if (ddr->bo_stats_peak_allocated < (s64)size) - ddr->bo_stats_peak_allocated = (s64)size; + if (ddr->bo_stats_peak_allocated < (s64)size) + ddr->bo_stats_peak_allocated = (s64)size; - ddr->bo_stats_count_allocated++; + ddr->bo_stats_count_allocated++; + } } mutex_unlock(&dev->drmcg_mutex); + + return result; } -EXPORT_SYMBOL(drmcg_chg_bo_alloc); +EXPORT_SYMBOL(drmcg_try_chg_bo_alloc); /** * drmcg_unchg_bo_alloc - From patchwork Thu Aug 29 06:05:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 11120383 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 29AEB14DE for ; Thu, 29 Aug 2019 06:06:12 +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 12E9220828 for ; Thu, 29 Aug 2019 06:06:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 12E9220828 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4F8D889FCE; Thu, 29 Aug 2019 06:06:02 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM04-BN3-obe.outbound.protection.outlook.com (mail-eopbgr680063.outbound.protection.outlook.com [40.107.68.63]) by gabe.freedesktop.org (Postfix) with ESMTPS id C757689FA9; Thu, 29 Aug 2019 06:05:54 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XuozhqWmwnYWnN1XJHVe3I+JhFLq4hjA1BEDJ8fhf08e0EowDiXcORAOSKONovsVc5YidLPai6aRXwAyDn33At3BNL5qvqG+ZiPUdk/FsdgViKxMGmr8R0o+yQmt0XK9QyziK4BiNFuq/XzBy979dgRJPoDGD/BhwxRxwurGY5rW/4R12747VFQlhVgjPQ7wcyhvlkgB+maTfyZOwFqEqmTSwmYbXAGMBbd2UFO5nC2FbJ4LeOtYtOQgzIDlCAogULNm7Y0aX59dYlAmE6A+aD91SEdZrcdd/8qqQjKu0/hGcuevZUSFAV2LLwiIcPluQiVdQ8VxgIz7W546JBdjGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SKhzoLgZxeM7iusXzsHrw8m/DlzNrtrmWedO5N3GvHw=; b=LxNlaprt9kvrXjATWz2PogezDh4OaKlAiqWkYiX2Uf3n1jqGaPnU7WRTkP+Hg07lgpPaQPd/Ed0ikgaxrhvNxAnBFgmc4LlqKmHvTwF5P9Fdws3T3WBK4EVr4ChlZoPg+hsdiSuO+TBNYRa0ZfDJNSccZEn3S1uRHlXFhtFmLoRWa2ycBwSx96QMASkSOJJUCyPbWH1xzVHx+oaTbng7HQ/lVCMZx/k0826DQrSdTlIoqrRQY9VVL3s9BGN8CuvV9l4Vz5Xh+i0AF8mGtKhueG0iz5CJz6XVc2h5P5jVfm4IhjIdAJ4RAr0EA0nQhJUD+dSMMAhhaqaG8LqWQBOEsQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none (sender ip is 165.204.84.17) smtp.rcpttodomain=cray.com smtp.mailfrom=amd.com; dmarc=permerror action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from CH2PR12CA0005.namprd12.prod.outlook.com (2603:10b6:610:57::15) by SN6PR12MB2719.namprd12.prod.outlook.com (2603:10b6:805:70::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.19; Thu, 29 Aug 2019 06:05:52 +0000 Received: from CO1NAM03FT045.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::200) by CH2PR12CA0005.outlook.office365.com (2603:10b6:610:57::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2220.18 via Frontend Transport; Thu, 29 Aug 2019 06:05:51 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV01.amd.com (165.204.84.17) by CO1NAM03FT045.mail.protection.outlook.com (10.152.81.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2220.16 via Frontend Transport; Thu, 29 Aug 2019 06:05:51 +0000 Received: from kho-5039A.amd.com (10.180.168.240) by SATLEXCHOV01.amd.com (10.181.40.71) with Microsoft SMTP Server id 14.3.389.1; Thu, 29 Aug 2019 01:05:47 -0500 From: Kenny Ho To: , , , , , , , , , , , Subject: [PATCH RFC v4 08/16] drm, cgroup: Add peak GEM buffer allocation limit Date: Thu, 29 Aug 2019 02:05:25 -0400 Message-ID: <20190829060533.32315-9-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829060533.32315-1-Kenny.Ho@amd.com> References: <20190829060533.32315-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(4636009)(396003)(136003)(39860400002)(346002)(376002)(2980300002)(428003)(189003)(199004)(486006)(476003)(2616005)(126002)(426003)(478600001)(11346002)(356004)(6666004)(8936002)(50226002)(110136005)(305945005)(336012)(26005)(53936002)(186003)(50466002)(446003)(5660300002)(51416003)(2870700001)(7696005)(2906002)(76176011)(81166006)(81156014)(8676002)(36756003)(1076003)(4326008)(70586007)(70206006)(14444005)(48376002)(86362001)(2201001)(53416004)(316002)(47776003)(921003)(2101003)(83996005)(1121003); DIR:OUT; SFP:1101; SCL:1; SRVR:SN6PR12MB2719; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; MX:1; A:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 64e18461-bd51-4153-1b2a-08d72c46f224 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328); SRVR:SN6PR12MB2719; X-MS-TrafficTypeDiagnostic: SN6PR12MB2719: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-Forefront-PRVS: 0144B30E41 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: jZjWmcrUS2GdN6TRCVLVzIreA6NP7lm5mt8y1jfliOmjcEw9oModdR0xODpy8vdJQACDvz2xaxwDTM6sPkbKrNwuPLT2d/SuiIk8tY7PGtnUEYJWhlJiCSzv2ktS55dVcrJJwJ4Q57Bt62z9Us99AJixDF896GRTM4I1/VqYLENxvMFNXoiXEOyjVqsS5CXaFCLNkbKR4f8oFm642NAj9B4pdoLZ/jskjvCgU9U/LNcwkvFBAOlbkPC+8IYeXmlfybYh1rSSPP8lc3LFTCVRnsowja/rL70Ex7Wlsjfnrm9SZ2Ost3N62SOUWksiLdu7vI1J+eG5ESDdoQgiEKj1n3Y2Bg+UVSuQ1Ymr1/tisnsa5t0CTtP/ZrKFMbp/OQaCI1fOcNj6+DYblx5fdggkv4P/B0x3DFCSZw3iREsAKY4= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2019 06:05:51.4757 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 64e18461-bd51-4153-1b2a-08d72c46f224 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2719 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SKhzoLgZxeM7iusXzsHrw8m/DlzNrtrmWedO5N3GvHw=; b=jlX0t/NMX3p+u0eG62Ai64Re9Pag5VLEWHabMyCRlNmlk/uBTGiQYfYrATfQ/IbTeXi8nEM8liZE9UYEWPhu+I7ZwWeQo9C2J5hhR920I8N667yUKmIxGvO88oquGJZapZ6YMxroq7bxI+NddEDZ+cpfJ0H4X4x4daehuBfBGds= X-Mailman-Original-Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; cray.com; dkim=none (message not signed) header.d=none;cray.com; dmarc=permerror action=none header.from=amd.com; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kenny Ho Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" drm.buffer.peak.default A read-only flat-keyed file which exists on the root cgroup. Each entry is keyed by the drm device's major:minor. Default limits on the largest GEM buffer allocation in bytes. drm.buffer.peak.max A read-write flat-keyed file which exists on all cgroups. Each entry is keyed by the drm device's major:minor. Per device limits on the largest GEM buffer allocation in bytes. This is a hard limit. Attempts in allocating beyond the cgroup limit will result in ENOMEM. Shorthand understood by memparse (such as k, m, g) can be used. Set largest allocation for /dev/dri/card1 to 4MB echo "226:1 4m" > drm.buffer.peak.max Change-Id: I0830d56775568e1cf215b56cc892d5e7945e9f25 Signed-off-by: Kenny Ho --- Documentation/admin-guide/cgroup-v2.rst | 18 ++++++++++ include/drm/drm_cgroup.h | 1 + include/linux/cgroup_drm.h | 1 + kernel/cgroup/drm.c | 48 +++++++++++++++++++++++++ 4 files changed, 68 insertions(+) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index e8fac2684179..87a195133eaa 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1940,6 +1940,24 @@ DRM Interface Files Set allocation limit for /dev/dri/card0 to 512MB echo "226:0 512m" > drm.buffer.total.max + drm.buffer.peak.default + A read-only flat-keyed file which exists on the root cgroup. + Each entry is keyed by the drm device's major:minor. + + Default limits on the largest GEM buffer allocation in bytes. + + drm.buffer.peak.max + A read-write flat-keyed file which exists on all cgroups. Each + entry is keyed by the drm device's major:minor. + + Per device limits on the largest GEM buffer allocation in bytes. + This is a hard limit. Attempts in allocating beyond the cgroup + limit will result in ENOMEM. Shorthand understood by memparse + (such as k, m, g) can be used. + + Set largest allocation for /dev/dri/card1 to 4MB + echo "226:1 4m" > drm.buffer.peak.max + GEM Buffer Ownership ~~~~~~~~~~~~~~~~~~~~ diff --git a/include/drm/drm_cgroup.h b/include/drm/drm_cgroup.h index 49c5d35ff6e1..d61b90beded5 100644 --- a/include/drm/drm_cgroup.h +++ b/include/drm/drm_cgroup.h @@ -14,6 +14,7 @@ struct drmcg_props { bool limit_enforced; s64 bo_limits_total_allocated_default; + s64 bo_limits_peak_allocated_default; }; #ifdef CONFIG_CGROUP_DRM diff --git a/include/linux/cgroup_drm.h b/include/linux/cgroup_drm.h index eb54e56f20ae..87a2566c9fdd 100644 --- a/include/linux/cgroup_drm.h +++ b/include/linux/cgroup_drm.h @@ -29,6 +29,7 @@ struct drmcg_device_resource { s64 bo_limits_total_allocated; s64 bo_stats_peak_allocated; + s64 bo_limits_peak_allocated; s64 bo_stats_count_allocated; }; diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c index 7161fa40e156..2f54bff291e5 100644 --- a/kernel/cgroup/drm.c +++ b/kernel/cgroup/drm.c @@ -75,6 +75,9 @@ static inline int init_drmcg_single(struct drmcg *drmcg, struct drm_device *dev) ddr->bo_limits_total_allocated = dev->drmcg_props.bo_limits_total_allocated_default; + ddr->bo_limits_peak_allocated = + dev->drmcg_props.bo_limits_peak_allocated_default; + mutex_unlock(&dev->drmcg_mutex); return 0; } @@ -157,6 +160,9 @@ static void drmcg_print_limits(struct drmcg_device_resource *ddr, case DRMCG_TYPE_BO_TOTAL: seq_printf(sf, "%lld\n", ddr->bo_limits_total_allocated); break; + case DRMCG_TYPE_BO_PEAK: + seq_printf(sf, "%lld\n", ddr->bo_limits_peak_allocated); + break; default: seq_puts(sf, "\n"); break; @@ -171,6 +177,10 @@ static void drmcg_print_default(struct drmcg_props *props, seq_printf(sf, "%lld\n", props->bo_limits_total_allocated_default); break; + case DRMCG_TYPE_BO_PEAK: + seq_printf(sf, "%lld\n", + props->bo_limits_peak_allocated_default); + break; default: seq_puts(sf, "\n"); break; @@ -327,6 +337,24 @@ static ssize_t drmcg_limit_write(struct kernfs_open_file *of, char *buf, drmcg_value_apply(dm->dev, &ddr->bo_limits_total_allocated, val); break; + case DRMCG_TYPE_BO_PEAK: + p_max = parent == NULL ? S64_MAX : + parent->dev_resources[minor]-> + bo_limits_peak_allocated; + + rc = drmcg_process_limit_s64_val(sattr, true, + props->bo_limits_peak_allocated_default, + p_max, + &val); + + if (rc || val < 0) { + drmcg_pr_cft_err(drmcg, rc, cft_name, minor); + break; + } + + drmcg_value_apply(dm->dev, + &ddr->bo_limits_peak_allocated, val); + break; default: break; } @@ -363,6 +391,20 @@ struct cftype files[] = { .private = DRMCG_CTF_PRIV(DRMCG_TYPE_BO_PEAK, DRMCG_FTYPE_STATS), }, + { + .name = "buffer.peak.default", + .seq_show = drmcg_seq_show, + .flags = CFTYPE_ONLY_ON_ROOT, + .private = DRMCG_CTF_PRIV(DRMCG_TYPE_BO_PEAK, + DRMCG_FTYPE_DEFAULT), + }, + { + .name = "buffer.peak.max", + .write = drmcg_limit_write, + .seq_show = drmcg_seq_show, + .private = DRMCG_CTF_PRIV(DRMCG_TYPE_BO_PEAK, + DRMCG_FTYPE_LIMIT), + }, { .name = "buffer.count.stats", .seq_show = drmcg_seq_show, @@ -427,6 +469,7 @@ void drmcg_device_early_init(struct drm_device *dev) dev->drmcg_props.limit_enforced = false; dev->drmcg_props.bo_limits_total_allocated_default = S64_MAX; + dev->drmcg_props.bo_limits_peak_allocated_default = S64_MAX; drmcg_update_cg_tree(dev); } @@ -466,6 +509,11 @@ bool drmcg_try_chg_bo_alloc(struct drmcg *drmcg, struct drm_device *dev, result = false; break; } + + if (ddr->bo_limits_peak_allocated < size) { + result = false; + break; + } } } From patchwork Thu Aug 29 06:05:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 11120395 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0495314D5 for ; Thu, 29 Aug 2019 06:06:26 +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 E15A3233A1 for ; Thu, 29 Aug 2019 06:06:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E15A3233A1 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 70ADA89FC3; Thu, 29 Aug 2019 06:06:05 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM05-CO1-obe.outbound.protection.outlook.com (mail-eopbgr720041.outbound.protection.outlook.com [40.107.72.41]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5826789FC3; Thu, 29 Aug 2019 06:06:00 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jhTmVvyIu1nB6KwyY3OBwKOayGU2m7RWZdISg6lxhN/JJYljvIGitMrkNV2zbY1EcrTr3HMArEetnyo+6NiKfQHiGRFVk3BptqL7H8x1au4YFEgcuTxuMRD14P2PWary6C10U/Q981LTM0VXyTacn05F6uW0dOhFA1ct41jqk14kUlGqXraiGFtsmq7wT4J3CDg64TRULIE9mJS/iNy3OqK8/hnb2+8zIyDRTZREuha8/Xw01j66V/bRmwGMo2yJMNccnu/J7BYhKEkMVkiMirzeY9zlsFELtA/bAaGckF8gqD/AsrG3dLgNUuZnK1KousEtO95VfkeF8mvkOMVQJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dKzfvEyoQivPmWaSxM7+Za14b0lSX5ghR9kEEatplRI=; b=oGCJkcmBalLtxa4IZLKgj7jdMSv64fgHf9LNABbbXcV3VNM7ZJcBGNjcmzfaB+W2V0GuFH/aOrRK/zlaO8oIKABTHuDBQWco2XJSp/8zNj6dpOdGYJqXkYbTBn/svRftShFeCY+TxY5soGDW2N7FF+2Eu8jYZNkYGtM4/5aNxD+i+80fAlDktQrch/8phn41MZmbDyQD8KeDgzC4saSoQwNZgQkYux74Q/JlLuKtlukVvtCsGLjvKE8sDSuy8hnoB+dCzvZK87TaOQ00CrkTLG/fLXxSYFipdho/5zR4ixSQS8r4iS1v6kyr3jcdFymdfCpM+JPfW/wbhOEEnN2qxA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none (sender ip is 165.204.84.17) smtp.rcpttodomain=cray.com smtp.mailfrom=amd.com; dmarc=permerror action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from CH2PR12CA0005.namprd12.prod.outlook.com (2603:10b6:610:57::15) by MWHPR12MB1279.namprd12.prod.outlook.com (2603:10b6:300:d::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2220.16; Thu, 29 Aug 2019 06:05:54 +0000 Received: from CO1NAM03FT045.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::200) by CH2PR12CA0005.outlook.office365.com (2603:10b6:610:57::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2220.18 via Frontend Transport; Thu, 29 Aug 2019 06:05:54 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV01.amd.com (165.204.84.17) by CO1NAM03FT045.mail.protection.outlook.com (10.152.81.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2220.16 via Frontend Transport; Thu, 29 Aug 2019 06:05:53 +0000 Received: from kho-5039A.amd.com (10.180.168.240) by SATLEXCHOV01.amd.com (10.181.40.71) with Microsoft SMTP Server id 14.3.389.1; Thu, 29 Aug 2019 01:05:48 -0500 From: Kenny Ho To: , , , , , , , , , , , Subject: [PATCH RFC v4 09/16] drm, cgroup: Add TTM buffer allocation stats Date: Thu, 29 Aug 2019 02:05:26 -0400 Message-ID: <20190829060533.32315-10-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829060533.32315-1-Kenny.Ho@amd.com> References: <20190829060533.32315-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(4636009)(39860400002)(346002)(136003)(376002)(396003)(2980300002)(428003)(199004)(189003)(30864003)(47776003)(336012)(110136005)(5660300002)(81156014)(81166006)(86362001)(8676002)(53936002)(2870700001)(426003)(1076003)(486006)(70586007)(70206006)(2616005)(2201001)(446003)(476003)(126002)(7696005)(51416003)(11346002)(50466002)(48376002)(14444005)(186003)(4326008)(316002)(53416004)(36756003)(2906002)(76176011)(8936002)(356004)(6666004)(305945005)(26005)(478600001)(50226002)(921003)(83996005)(2101003)(1121003); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR12MB1279; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7b57e034-e76f-459b-ef0c-08d72c46f3ac X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328); SRVR:MWHPR12MB1279; X-MS-TrafficTypeDiagnostic: MWHPR12MB1279: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2582; X-Forefront-PRVS: 0144B30E41 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: ifLbnhZkj4CSISBRhk0Yho88KRt/p+YH3igEmblrvppJVf4KTH6dIGGtZxjRxZuN0SzU8UB+eh6g1a2X5G3uFnFz72DajykEwOyqaL3VVfoGduBQ7Sgz6YDKPAZE2qf+uYyzBKk8k083UIXlFxJXByVN7NOWUPEoh58dUJD/AuxgS5zL9dHdl7Dstbve8+LlKVmBNv9od9Qdg/6j2SmUEezk8KbdqdCcEA+7FcKwF2uowC/fS9uSrxfoXc5gGvAW8XmcWUT7g+X5TAExPoZvSA5ITfWXELD3xZo7e71df4tw2pXaHXOBTisg49ZfA3i1z3B4HnXwXuNNLzJojSpFijmTfp0PSgqEuaHwF0sYCEb3KC8kgq9tObSwS4ReNR2QWRe2UKM7NDUCgxqGkMuRqFqjR8TbOb3+1Ne1YlVI30Q= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2019 06:05:53.9313 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7b57e034-e76f-459b-ef0c-08d72c46f3ac X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1279 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dKzfvEyoQivPmWaSxM7+Za14b0lSX5ghR9kEEatplRI=; b=hXw/5uoqx60r93El6Pr3aMr6q92VXSAgfdQmtAwPMH6eSNabSfcMpJjMgYzqqGF72xwbp6Xx7erjCwdRcD6FR6ROQZYFsaHIr0rGZkvWdc5GADTPax2576KVztQj8CgPrJk1a/BTDFjRqnq463C5+JQ6jpJ2DbTGxHxjOFxJGg4= X-Mailman-Original-Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; cray.com; dkim=none (message not signed) header.d=none;cray.com; dmarc=permerror action=none header.from=amd.com; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kenny Ho Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The drm resource being measured is the TTM (Translation Table Manager) buffers. TTM manages different types of memory that a GPU might access. These memory types include dedicated Video RAM (VRAM) and host/system memory accessible through IOMMU (GART/GTT). TTM is currently used by multiple drm drivers (amd, ast, bochs, cirrus, hisilicon, maga200, nouveau, qxl, virtio, vmwgfx.) drm.memory.stats A read-only nested-keyed file which exists on all cgroups. Each entry is keyed by the drm device's major:minor. The following nested keys are defined. ====== ============================================= system Host/system memory tt Host memory used by the drm device (GTT/GART) vram Video RAM used by the drm device priv Other drm device, vendor specific memory ====== ============================================= Reading returns the following:: 226:0 system=0 tt=0 vram=0 priv=0 226:1 system=0 tt=9035776 vram=17768448 priv=16809984 226:2 system=0 tt=9035776 vram=17768448 priv=16809984 drm.memory.evict.stats A read-only flat-keyed file which exists on all cgroups. Each entry is keyed by the drm device's major:minor. Total number of evictions. Change-Id: Ice2c4cc845051229549bebeb6aa2d7d6153bdf6a Signed-off-by: Kenny Ho --- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 3 +- drivers/gpu/drm/ttm/ttm_bo.c | 30 +++++++ drivers/gpu/drm/ttm/ttm_bo_util.c | 4 + include/drm/drm_cgroup.h | 19 +++++ include/drm/ttm/ttm_bo_api.h | 2 + include/drm/ttm/ttm_bo_driver.h | 8 ++ include/linux/cgroup_drm.h | 6 ++ kernel/cgroup/drm.c | 108 ++++++++++++++++++++++++ 8 files changed, 179 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index cfcbbdc39656..463e015e8694 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -1720,8 +1720,9 @@ int amdgpu_ttm_init(struct amdgpu_device *adev) mutex_init(&adev->mman.gtt_window_lock); /* No others user of address space so set it to 0 */ - r = ttm_bo_device_init(&adev->mman.bdev, + r = ttm_bo_device_init_tmp(&adev->mman.bdev, &amdgpu_bo_driver, + adev->ddev, adev->ddev->anon_inode->i_mapping, adev->need_dma32); if (r) { diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 58c403eda04e..a0e9ce46baf3 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -42,6 +43,7 @@ #include #include #include +#include static void ttm_bo_global_kobj_release(struct kobject *kobj); @@ -151,6 +153,10 @@ static void ttm_bo_release_list(struct kref *list_kref) struct ttm_bo_device *bdev = bo->bdev; size_t acc_size = bo->acc_size; + if (bo->bdev->ddev != NULL) // TODO: remove after ddev initiazlied for all + drmcg_unchg_mem(bo); + drmcg_put(bo->drmcg); + BUG_ON(kref_read(&bo->list_kref)); BUG_ON(kref_read(&bo->kref)); BUG_ON(atomic_read(&bo->cpu_writers)); @@ -360,6 +366,8 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo, if (bo->mem.mem_type == TTM_PL_SYSTEM) { if (bdev->driver->move_notify) bdev->driver->move_notify(bo, evict, mem); + if (bo->bdev->ddev != NULL) // TODO: remove after ddev initiazlied for all + drmcg_mem_track_move(bo, evict, mem); bo->mem = *mem; mem->mm_node = NULL; goto moved; @@ -368,6 +376,8 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo, if (bdev->driver->move_notify) bdev->driver->move_notify(bo, evict, mem); + if (bo->bdev->ddev != NULL) // TODO: remove after ddev initiazlied for all + drmcg_mem_track_move(bo, evict, mem); if (!(old_man->flags & TTM_MEMTYPE_FLAG_FIXED) && !(new_man->flags & TTM_MEMTYPE_FLAG_FIXED)) @@ -381,6 +391,8 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo, if (bdev->driver->move_notify) { swap(*mem, bo->mem); bdev->driver->move_notify(bo, false, mem); + if (bo->bdev->ddev != NULL) // TODO: remove after ddev initiazlied for all + drmcg_mem_track_move(bo, evict, mem); swap(*mem, bo->mem); } @@ -1355,6 +1367,10 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev, WARN_ON(!locked); } + bo->drmcg = drmcg_get(current); + if (bo->bdev->ddev != NULL) // TODO: remove after ddev initiazlied for all + drmcg_chg_mem(bo); + if (likely(!ret)) ret = ttm_bo_validate(bo, placement, ctx); @@ -1747,6 +1763,20 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev, } EXPORT_SYMBOL(ttm_bo_device_init); +/* TODO merge with official function when implementation finalized*/ +int ttm_bo_device_init_tmp(struct ttm_bo_device *bdev, + struct ttm_bo_driver *driver, + struct drm_device *ddev, + struct address_space *mapping, + bool need_dma32) +{ + int ret = ttm_bo_device_init(bdev, driver, mapping, need_dma32); + + bdev->ddev = ddev; + return ret; +} +EXPORT_SYMBOL(ttm_bo_device_init_tmp); + /* * buffer object vm functions. */ diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c index 895d77d799e4..15acd2c0720e 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_util.c +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -522,6 +523,9 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo, ret = reservation_object_trylock(fbo->base.resv); WARN_ON(!ret); + if (bo->bdev->ddev != NULL) // TODO: remove after ddev initiazlied for all + drmcg_chg_mem(bo); + *new_obj = &fbo->base; return 0; } diff --git a/include/drm/drm_cgroup.h b/include/drm/drm_cgroup.h index d61b90beded5..7d63f73a5375 100644 --- a/include/drm/drm_cgroup.h +++ b/include/drm/drm_cgroup.h @@ -5,6 +5,7 @@ #define __DRM_CGROUP_H__ #include +#include /** * Per DRM device properties for DRM cgroup controller for the purpose @@ -25,6 +26,11 @@ bool drmcg_try_chg_bo_alloc(struct drmcg *drmcg, struct drm_device *dev, size_t size); void drmcg_unchg_bo_alloc(struct drmcg *drmcg, struct drm_device *dev, size_t size); +void drmcg_chg_mem(struct ttm_buffer_object *tbo); +void drmcg_unchg_mem(struct ttm_buffer_object *tbo); +void drmcg_mem_track_move(struct ttm_buffer_object *old_bo, bool evict, + struct ttm_mem_reg *new_mem); + #else static inline void drmcg_device_update(struct drm_device *device) { @@ -43,5 +49,18 @@ static inline void drmcg_unchg_bo_alloc(struct drmcg *drmcg, struct drm_device *dev, size_t size) { } + +static inline void drmcg_chg_mem(struct ttm_buffer_object *tbo) +{ +} + +static inline void drmcg_unchg_mem(struct ttm_buffer_object *tbo) +{ +} + +static inline void drmcg_mem_track_move(struct ttm_buffer_object *old_bo, + bool evict, struct ttm_mem_reg *new_mem) +{ +} #endif /* CONFIG_CGROUP_DRM */ #endif /* __DRM_CGROUP_H__ */ diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h index 49d9cdfc58f2..839936ab358c 100644 --- a/include/drm/ttm/ttm_bo_api.h +++ b/include/drm/ttm/ttm_bo_api.h @@ -128,6 +128,7 @@ struct ttm_tt; * struct ttm_buffer_object * * @bdev: Pointer to the buffer object device structure. + * @drmcg: DRM cgroup this object belongs to. * @type: The bo type. * @destroy: Destruction function. If NULL, kfree is used. * @num_pages: Actual number of pages. @@ -174,6 +175,7 @@ struct ttm_buffer_object { */ struct ttm_bo_device *bdev; + struct drmcg *drmcg; enum ttm_bo_type type; void (*destroy) (struct ttm_buffer_object *); unsigned long num_pages; diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h index c9b8ba492f24..e1a805d65b83 100644 --- a/include/drm/ttm/ttm_bo_driver.h +++ b/include/drm/ttm/ttm_bo_driver.h @@ -30,6 +30,7 @@ #ifndef _TTM_BO_DRIVER_H_ #define _TTM_BO_DRIVER_H_ +#include #include #include #include @@ -442,6 +443,7 @@ extern struct ttm_bo_global { * @driver: Pointer to a struct ttm_bo_driver struct setup by the driver. * @man: An array of mem_type_managers. * @vma_manager: Address space manager + * @ddev: Pointer to struct drm_device that this ttm_bo_device belongs to * lru_lock: Spinlock that protects the buffer+device lru lists and * ddestroy lists. * @dev_mapping: A pointer to the struct address_space representing the @@ -460,6 +462,7 @@ struct ttm_bo_device { struct ttm_bo_global *glob; struct ttm_bo_driver *driver; struct ttm_mem_type_manager man[TTM_NUM_MEM_TYPES]; + struct drm_device *ddev; /* * Protected by internal locks. @@ -598,6 +601,11 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev, struct address_space *mapping, bool need_dma32); +int ttm_bo_device_init_tmp(struct ttm_bo_device *bdev, + struct ttm_bo_driver *driver, + struct drm_device *ddev, + struct address_space *mapping, + bool need_dma32); /** * ttm_bo_unmap_virtual * diff --git a/include/linux/cgroup_drm.h b/include/linux/cgroup_drm.h index 87a2566c9fdd..4c2794c9333d 100644 --- a/include/linux/cgroup_drm.h +++ b/include/linux/cgroup_drm.h @@ -9,6 +9,7 @@ #include #include #include +#include /* limit defined per the way drm_minor_alloc operates */ #define MAX_DRM_DEV (64 * DRM_MINOR_RENDER) @@ -17,6 +18,8 @@ enum drmcg_res_type { DRMCG_TYPE_BO_TOTAL, DRMCG_TYPE_BO_PEAK, DRMCG_TYPE_BO_COUNT, + DRMCG_TYPE_MEM, + DRMCG_TYPE_MEM_EVICT, __DRMCG_TYPE_LAST, }; @@ -32,6 +35,9 @@ struct drmcg_device_resource { s64 bo_limits_peak_allocated; s64 bo_stats_count_allocated; + + s64 mem_stats[TTM_PL_PRIV+1]; + s64 mem_stats_evict; }; /** diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c index 2f54bff291e5..4960a8d1e8f4 100644 --- a/kernel/cgroup/drm.c +++ b/kernel/cgroup/drm.c @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include #include #include @@ -31,6 +33,13 @@ enum drmcg_file_type { DRMCG_FTYPE_DEFAULT, }; +static char const *ttm_placement_names[] = { + [TTM_PL_SYSTEM] = "system", + [TTM_PL_TT] = "tt", + [TTM_PL_VRAM] = "vram", + [TTM_PL_PRIV] = "priv", +}; + static struct drmcg *root_drmcg __read_mostly; static int drmcg_css_free_fn(int id, void *ptr, void *data) @@ -127,6 +136,7 @@ drmcg_css_alloc(struct cgroup_subsys_state *parent_css) static void drmcg_print_stats(struct drmcg_device_resource *ddr, struct seq_file *sf, enum drmcg_res_type type) { + int i; if (ddr == NULL) { seq_puts(sf, "\n"); return; @@ -142,6 +152,16 @@ static void drmcg_print_stats(struct drmcg_device_resource *ddr, case DRMCG_TYPE_BO_COUNT: seq_printf(sf, "%lld\n", ddr->bo_stats_count_allocated); break; + case DRMCG_TYPE_MEM: + for (i = 0; i <= TTM_PL_PRIV; i++) { + seq_printf(sf, "%s=%lld ", ttm_placement_names[i], + ddr->mem_stats[i]); + } + seq_puts(sf, "\n"); + break; + case DRMCG_TYPE_MEM_EVICT: + seq_printf(sf, "%lld\n", ddr->mem_stats_evict); + break; default: seq_puts(sf, "\n"); break; @@ -411,6 +431,18 @@ struct cftype files[] = { .private = DRMCG_CTF_PRIV(DRMCG_TYPE_BO_COUNT, DRMCG_FTYPE_STATS), }, + { + .name = "memory.stats", + .seq_show = drmcg_seq_show, + .private = DRMCG_CTF_PRIV(DRMCG_TYPE_MEM, + DRMCG_FTYPE_STATS), + }, + { + .name = "memory.evict.stats", + .seq_show = drmcg_seq_show, + .private = DRMCG_CTF_PRIV(DRMCG_TYPE_MEM_EVICT, + DRMCG_FTYPE_STATS), + }, { } /* terminate */ }; @@ -566,3 +598,79 @@ void drmcg_unchg_bo_alloc(struct drmcg *drmcg, struct drm_device *dev, mutex_unlock(&dev->drmcg_mutex); } EXPORT_SYMBOL(drmcg_unchg_bo_alloc); + +void drmcg_chg_mem(struct ttm_buffer_object *tbo) +{ + struct drm_device *dev = tbo->bdev->ddev; + struct drmcg *drmcg = tbo->drmcg; + int devIdx = dev->primary->index; + s64 size = (s64)(tbo->mem.size); + int mem_type = tbo->mem.mem_type; + struct drmcg_device_resource *ddr; + + if (drmcg == NULL) + return; + + mem_type = mem_type > TTM_PL_PRIV ? TTM_PL_PRIV : mem_type; + + mutex_lock(&dev->drmcg_mutex); + for ( ; drmcg != NULL; drmcg = drmcg_parent(drmcg)) { + ddr = drmcg->dev_resources[devIdx]; + ddr->mem_stats[mem_type] += size; + } + mutex_unlock(&dev->drmcg_mutex); +} +EXPORT_SYMBOL(drmcg_chg_mem); + +void drmcg_unchg_mem(struct ttm_buffer_object *tbo) +{ + struct drm_device *dev = tbo->bdev->ddev; + struct drmcg *drmcg = tbo->drmcg; + int devIdx = dev->primary->index; + s64 size = (s64)(tbo->mem.size); + int mem_type = tbo->mem.mem_type; + struct drmcg_device_resource *ddr; + + if (drmcg == NULL) + return; + + mem_type = mem_type > TTM_PL_PRIV ? TTM_PL_PRIV : mem_type; + + mutex_lock(&dev->drmcg_mutex); + for ( ; drmcg != NULL; drmcg = drmcg_parent(drmcg)) { + ddr = drmcg->dev_resources[devIdx]; + ddr->mem_stats[mem_type] -= size; + } + mutex_unlock(&dev->drmcg_mutex); +} +EXPORT_SYMBOL(drmcg_unchg_mem); + +void drmcg_mem_track_move(struct ttm_buffer_object *old_bo, bool evict, + struct ttm_mem_reg *new_mem) +{ + struct drm_device *dev = old_bo->bdev->ddev; + struct drmcg *drmcg = old_bo->drmcg; + s64 move_in_bytes = (s64)(old_bo->mem.size); + int devIdx = dev->primary->index; + int old_mem_type = old_bo->mem.mem_type; + int new_mem_type = new_mem->mem_type; + struct drmcg_device_resource *ddr; + + if (drmcg == NULL) + return; + + old_mem_type = old_mem_type > TTM_PL_PRIV ? TTM_PL_PRIV : old_mem_type; + new_mem_type = new_mem_type > TTM_PL_PRIV ? TTM_PL_PRIV : new_mem_type; + + mutex_lock(&dev->drmcg_mutex); + for ( ; drmcg != NULL; drmcg = drmcg_parent(drmcg)) { + ddr = drmcg->dev_resources[devIdx]; + ddr->mem_stats[old_mem_type] -= move_in_bytes; + ddr->mem_stats[new_mem_type] += move_in_bytes; + + if (evict) + ddr->mem_stats_evict++; + } + mutex_unlock(&dev->drmcg_mutex); +} +EXPORT_SYMBOL(drmcg_mem_track_move); From patchwork Thu Aug 29 06:05:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 11120387 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BB0BE14D5 for ; Thu, 29 Aug 2019 06:06:15 +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 A46DF20828 for ; Thu, 29 Aug 2019 06:06:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A46DF20828 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C8D7C89FC8; Thu, 29 Aug 2019 06:06:01 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM04-CO1-obe.outbound.protection.outlook.com (mail-co1nam04on0608.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe4d::608]) by gabe.freedesktop.org (Postfix) with ESMTPS id 731A689FA9; Thu, 29 Aug 2019 06:05:58 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P60zMQj+bQj4QjvRocDDnveHdK+D9t82WtmwIXh9jWdhL384CiVfc8DZCIl5kC9OGSXD63Pl1crwRzDPTEGsGN+yGNmrSBV05afPsb+F3voP9Cb07x7c54GShNekQVuv19noCMUb2X4wqvYGSonkmYpl2vPc9YLetQV4s5BO2jF2nHHCKweuqURsDhTSmuBkgIYoml5UX6XyONvEgtBn9JRg5UhOkMA7xNm1oYCHFySw79D7WmsHYdWF2lrHWh78cpa8+iqCp740V501iqol4w+dC2ezf34KpDRbWJCAvBbvEeRe5XltyXzYQlU9jJO4rXPj+u1Bk06vLgEylwNL9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cSYRmemse+JptUHNNHUIBq5v/9pLXrIRh71iG7WhWWk=; b=QiCITqSXNfFVlMCFf4MJhf7QGo6u5hEzA2+hb+YkPPOS/csxAT2QPSvYhrZa+99zm8eDW9/o2qwhbvP0xdc/uMjnJK1R1BrzbfTtyZLMUWtzVY73xWepbcdcw8oExdcjKgXy47u1k/a/McMWCjQyjDLME3gk0ROyOVI+gMtDSnsQcbmjCbrAqGJHE+9xfzU47XrnAnArrSE5t6TuurzuAa4YE+g1tLuA0YovGPESv4ay+ft+2smQQggctycCq3kB2++IpMK8iWv7OPLxR+2EqOSoBAij4qqqpAgfJBgIp5lVMXqVO8XxC8sxy9YGQLkL8hOo6q57owpzAIgjuDOFXw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none (sender ip is 165.204.84.17) smtp.rcpttodomain=cray.com smtp.mailfrom=amd.com; dmarc=permerror action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from CH2PR12CA0011.namprd12.prod.outlook.com (2603:10b6:610:57::21) by BYAPR12MB2712.namprd12.prod.outlook.com (2603:10b6:a03:68::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Thu, 29 Aug 2019 06:05:56 +0000 Received: from CO1NAM03FT045.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::208) by CH2PR12CA0011.outlook.office365.com (2603:10b6:610:57::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2220.18 via Frontend Transport; Thu, 29 Aug 2019 06:05:55 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV01.amd.com (165.204.84.17) by CO1NAM03FT045.mail.protection.outlook.com (10.152.81.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2220.16 via Frontend Transport; Thu, 29 Aug 2019 06:05:55 +0000 Received: from kho-5039A.amd.com (10.180.168.240) by SATLEXCHOV01.amd.com (10.181.40.71) with Microsoft SMTP Server id 14.3.389.1; Thu, 29 Aug 2019 01:05:48 -0500 From: Kenny Ho To: , , , , , , , , , , , Subject: [PATCH RFC v4 10/16] drm, cgroup: Add TTM buffer peak usage stats Date: Thu, 29 Aug 2019 02:05:27 -0400 Message-ID: <20190829060533.32315-11-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829060533.32315-1-Kenny.Ho@amd.com> References: <20190829060533.32315-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(4636009)(376002)(136003)(396003)(346002)(39860400002)(2980300002)(428003)(189003)(199004)(126002)(2906002)(476003)(446003)(11346002)(2616005)(486006)(478600001)(305945005)(426003)(50466002)(336012)(8936002)(48376002)(70206006)(2870700001)(50226002)(81166006)(81156014)(186003)(26005)(8676002)(14444005)(53936002)(70586007)(2201001)(316002)(110136005)(4326008)(1076003)(86362001)(47776003)(76176011)(5660300002)(7696005)(51416003)(6666004)(356004)(53416004)(36756003)(921003)(1121003)(83996005)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR12MB2712; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; MX:1; A:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b54cefe8-ef75-4b19-6c00-08d72c46f466 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328); SRVR:BYAPR12MB2712; X-MS-TrafficTypeDiagnostic: BYAPR12MB2712: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-Forefront-PRVS: 0144B30E41 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: oUHkZpezSqzK6Stn8Fg7f7GgTkTE5ieEf3SQ9YCqWy/5UfHXn5MYm2Ch6tWkt6eNMLw5D22rM7WzO52WcCP3e/6Z/s3kQCR+lLkyBqheTMYIIH7jwFSjWrDde3M87IUwTu+lmnKgMJcQZHnbhh+xmKl9a2gDpIm2odUnX7tXD2E7VCDezSR87lfUWUbY1ivoj4zVciXaVfI2XiY/U51E8TfYU3qdKBxA5HIGY5dFhDo+++4QvCB6Wki/ROJlO2emcuH9AhEiYiz6mIONSVdtJi63mNbgt36qGOcfV4P/kg72wC/vprIHD0sYMpSlodsFRDbpSDKh8/taKOZxJ5rPf1xlYkW5LAYbyahIr/Ed93VMQf9A5w3E3K0MLyZP9mKHkt6EuoSB3v+FTj1usWkUj9NlWw7woVpNK9P2KqpTLtw= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2019 06:05:55.1880 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b54cefe8-ef75-4b19-6c00-08d72c46f466 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB2712 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cSYRmemse+JptUHNNHUIBq5v/9pLXrIRh71iG7WhWWk=; b=MPsxzYwkwNnhTYZP1Ai5kIvOhvqJWMi4TD8pv1ehjhNtrDJ1AX6T2EseXMD5wkLagQSV421/0XKHQqmY49DWybnSL7nOf7qh6U/rCDgB7V/NmPNHEpcTPoNzLFJ9AygP2To6yd/aDZEZy+N8JrIfoh1cmwQLS5e6m8HHxuHpcaw= X-Mailman-Original-Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; cray.com; dkim=none (message not signed) header.d=none;cray.com; dmarc=permerror action=none header.from=amd.com; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kenny Ho Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" drm.memory.peak.stats A read-only nested-keyed file which exists on all cgroups. Each entry is keyed by the drm device's major:minor. The following nested keys are defined. ====== ============================================== system Peak host memory used tt Peak host memory used by the device (GTT/GART) vram Peak Video RAM used by the drm device priv Other drm device specific memory peak usage ====== ============================================== Reading returns the following:: 226:0 system=0 tt=0 vram=0 priv=0 226:1 system=0 tt=9035776 vram=17768448 priv=16809984 226:2 system=0 tt=9035776 vram=17768448 priv=16809984 Change-Id: I986e44533848f66411465bdd52105e78105a709a Signed-off-by: Kenny Ho --- include/linux/cgroup_drm.h | 2 ++ kernel/cgroup/drm.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/linux/cgroup_drm.h b/include/linux/cgroup_drm.h index 4c2794c9333d..9579e2a0b71d 100644 --- a/include/linux/cgroup_drm.h +++ b/include/linux/cgroup_drm.h @@ -20,6 +20,7 @@ enum drmcg_res_type { DRMCG_TYPE_BO_COUNT, DRMCG_TYPE_MEM, DRMCG_TYPE_MEM_EVICT, + DRMCG_TYPE_MEM_PEAK, __DRMCG_TYPE_LAST, }; @@ -37,6 +38,7 @@ struct drmcg_device_resource { s64 bo_stats_count_allocated; s64 mem_stats[TTM_PL_PRIV+1]; + s64 mem_peaks[TTM_PL_PRIV+1]; s64 mem_stats_evict; }; diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c index 4960a8d1e8f4..899dc44722c3 100644 --- a/kernel/cgroup/drm.c +++ b/kernel/cgroup/drm.c @@ -162,6 +162,13 @@ static void drmcg_print_stats(struct drmcg_device_resource *ddr, case DRMCG_TYPE_MEM_EVICT: seq_printf(sf, "%lld\n", ddr->mem_stats_evict); break; + case DRMCG_TYPE_MEM_PEAK: + for (i = 0; i <= TTM_PL_PRIV; i++) { + seq_printf(sf, "%s=%lld ", ttm_placement_names[i], + ddr->mem_peaks[i]); + } + seq_puts(sf, "\n"); + break; default: seq_puts(sf, "\n"); break; @@ -443,6 +450,12 @@ struct cftype files[] = { .private = DRMCG_CTF_PRIV(DRMCG_TYPE_MEM_EVICT, DRMCG_FTYPE_STATS), }, + { + .name = "memory.peaks.stats", + .seq_show = drmcg_seq_show, + .private = DRMCG_CTF_PRIV(DRMCG_TYPE_MEM_PEAK, + DRMCG_FTYPE_STATS), + }, { } /* terminate */ }; @@ -617,6 +630,8 @@ void drmcg_chg_mem(struct ttm_buffer_object *tbo) for ( ; drmcg != NULL; drmcg = drmcg_parent(drmcg)) { ddr = drmcg->dev_resources[devIdx]; ddr->mem_stats[mem_type] += size; + ddr->mem_peaks[mem_type] = max(ddr->mem_peaks[mem_type], + ddr->mem_stats[mem_type]); } mutex_unlock(&dev->drmcg_mutex); } @@ -668,6 +683,10 @@ void drmcg_mem_track_move(struct ttm_buffer_object *old_bo, bool evict, ddr->mem_stats[old_mem_type] -= move_in_bytes; ddr->mem_stats[new_mem_type] += move_in_bytes; + ddr->mem_peaks[new_mem_type] = max( + ddr->mem_peaks[new_mem_type], + ddr->mem_stats[new_mem_type]); + if (evict) ddr->mem_stats_evict++; } From patchwork Thu Aug 29 06:05:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 11120399 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D166614DE for ; Thu, 29 Aug 2019 06:06:33 +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 BA85F23405 for ; Thu, 29 Aug 2019 06:06:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BA85F23405 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3B3AF6E029; Thu, 29 Aug 2019 06:06:20 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on060e.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe48::60e]) by gabe.freedesktop.org (Postfix) with ESMTPS id 502B389FC0; Thu, 29 Aug 2019 06:06:00 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Achh8SohtSDVEjT+ED4d2EfbhzLYZWiJEFZyRJ/cnczqpNsN2lYB0T3Fwx6OrWvFWyChMNWo524zvmFD5TTzRebn69In0YFfrniIu1cv9ilp//9Cq9FNOtnaHsEQqvQM5rW4mZaa57IMA6Fkvq1RGEbDnHnqOZrE4Lzv8odGUAmT8frBrfKUZysdhIiTzngTPi+K3HzSnlTngVVW2dobmcnmhgHuzIjlwykk/QrKFtHweeCE7FfYQaiXB82npY10l6HmlFUmcOblja+L8vvpLsk4X2HiY/aWvyFTVNqzmajV53+ANzdtL8seK1NJXDo/gWwGb0t6t6O9oKwb6zxqBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aByQ3g8rw8uK5GkiDzLLdxItnWnzAPBvty1600CQzyU=; b=Xuebz19k4eRgaaSeb4Vm9ctG3msggeAbzk7DzK1OFtQ0SiO5c9AOXsXMGNXtPFtNC81+8mLIEejLwffrGZPxVCnNXsxtk5KKUPPFXzTNgz5dQudszp0POsrvlfgA+uQm0/8zXe4jW8L3THg6FeBo7vP+ttr8/T5mxckiySQCw4Ajp3F8jybU9dHfzpWdhb/6F3dTrCW8+U/Xki8iI08JSxZUxR2Z11tSVpmF9hP3FwpUxW2B6Fhbzwh4YwDctSPaVT0h1mPfcU/AUZDh5bLq/WODYpvlZEAz/bw2sfa2pGSLck19zTQi7MUf/sbF86AzHD8KNZWQe7NsTr9JzySFPw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none (sender ip is 165.204.84.17) smtp.rcpttodomain=cray.com smtp.mailfrom=amd.com; dmarc=permerror action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from CH2PR12CA0005.namprd12.prod.outlook.com (2603:10b6:610:57::15) by BN6PR12MB1267.namprd12.prod.outlook.com (2603:10b6:404:17::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.20; Thu, 29 Aug 2019 06:05:57 +0000 Received: from CO1NAM03FT045.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::200) by CH2PR12CA0005.outlook.office365.com (2603:10b6:610:57::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2220.18 via Frontend Transport; Thu, 29 Aug 2019 06:05:57 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV01.amd.com (165.204.84.17) by CO1NAM03FT045.mail.protection.outlook.com (10.152.81.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2220.16 via Frontend Transport; Thu, 29 Aug 2019 06:05:56 +0000 Received: from kho-5039A.amd.com (10.180.168.240) by SATLEXCHOV01.amd.com (10.181.40.71) with Microsoft SMTP Server id 14.3.389.1; Thu, 29 Aug 2019 01:05:49 -0500 From: Kenny Ho To: , , , , , , , , , , , Subject: [PATCH RFC v4 11/16] drm, cgroup: Add per cgroup bw measure and control Date: Thu, 29 Aug 2019 02:05:28 -0400 Message-ID: <20190829060533.32315-12-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829060533.32315-1-Kenny.Ho@amd.com> References: <20190829060533.32315-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(1496009)(4636009)(376002)(39860400002)(346002)(136003)(396003)(2980300002)(428003)(199004)(189003)(5660300002)(86362001)(47776003)(6666004)(356004)(30864003)(1076003)(478600001)(2201001)(2870700001)(2906002)(316002)(70206006)(70586007)(50466002)(110136005)(48376002)(53416004)(426003)(36756003)(4326008)(305945005)(53936002)(8936002)(8676002)(81156014)(186003)(51416003)(2616005)(11346002)(446003)(476003)(76176011)(14444005)(7696005)(126002)(486006)(81166006)(50226002)(336012)(26005)(921003)(1121003)(2101003)(83996005); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR12MB1267; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c3ef719f-10be-4e09-4beb-08d72c46f565 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328); SRVR:BN6PR12MB1267; X-MS-TrafficTypeDiagnostic: BN6PR12MB1267: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1060; X-Forefront-PRVS: 0144B30E41 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: w9/3OEuu3j/B00+Rm+G2QSoRWoFYqt5/2S3fQxGb+HFNT5sR4FzAMpRoAf1NaqLDGLfOH933huFclguB0iTHWzBVYLFmb6py8IO9X/KUMMaR/1KkmOsvwuPpjLwajaNoRvz+eoDqZiPoFYlgtpnNS0iylTBxHC/lyZDXMgso9xYvBE0Mp8gKSMDNCLeZPzOBiqcx//U3gcVxY/Vcwjqf7Tmu7vqXlPI7im0AN/Tmt3/aPcw61one/EejchIDj/5zG2SXZEdLcMUcWPONeEeUIT/MburChUxxTDmolPAXqrbTKsI1pl7dgpb5yBoCobxCGilvndqhXB2w+jA3x/yoASCpAcefZXtM7n7bnUkF4o53CjP21/6wXCxxBjt5Hzapvh7JfWAXl5L9B4Xft8mWzJ1kl5Zl+yt0pH74wZ24wd0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2019 06:05:56.9470 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c3ef719f-10be-4e09-4beb-08d72c46f565 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1267 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aByQ3g8rw8uK5GkiDzLLdxItnWnzAPBvty1600CQzyU=; b=fm0xk+/KMRbUJZ/n2Ei5eVYogoXsm4ra2HIjxbraL1dL0xXnj2RD7U47UcT1DVw8vGnuMgEkDkiHyYMFdwPMyjal/ZmavhMc0mqCe+5vn2qmoK9/+Tc58sThycKA/hrymI8bscMlFpcG89NcpJy03UcIDsQ7qUAHPAjSUkb6kZw= X-Mailman-Original-Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; cray.com; dkim=none (message not signed) header.d=none;cray.com; dmarc=permerror action=none header.from=amd.com; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kenny Ho Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The bandwidth is measured by keeping track of the amount of bytes moved by ttm within a time period. We defined two type of bandwidth: burst and average. Average bandwidth is calculated by dividing the total amount of bytes moved within a cgroup by the lifetime of the cgroup. Burst bandwidth is similar except that the byte and time measurement is reset after a user configurable period. The bandwidth control is best effort since it is done on a per move basis instead of per byte. The bandwidth is limited by delaying the move of a buffer. The bandwidth limit can be exceeded when the next move is larger than the remaining allowance. drm.burst_bw_period_in_us A read-write flat-keyed file which exists on the root cgroup. Each entry is keyed by the drm device's major:minor. Length of a period use to measure burst bandwidth in us. One period per device. drm.burst_bw_period_in_us.default A read-only flat-keyed file which exists on the root cgroup. Each entry is keyed by the drm device's major:minor. Default length of a period in us (one per device.) drm.bandwidth.stats A read-only nested-keyed file which exists on all cgroups. Each entry is keyed by the drm device's major:minor. The following nested keys are defined. ================= ====================================== burst_byte_per_us Burst bandwidth avg_bytes_per_us Average bandwidth moved_byte Amount of byte moved within a period accum_us Amount of time accumulated in a period total_moved_byte Byte moved within the cgroup lifetime total_accum_us Cgroup lifetime in us byte_credit Available byte credit to limit avg bw ================= ====================================== Reading returns the following:: 226:1 burst_byte_per_us=23 avg_bytes_per_us=0 moved_byte=2244608 accum_us=95575 total_moved_byte=45899776 total_accum_us=201634590 byte_credit=13214278590464 226:2 burst_byte_per_us=10 avg_bytes_per_us=219 moved_byte=430080 accum_us=39350 total_moved_byte=65518026752 total_accum_us=298337721 byte_credit=9223372036854644735 drm.bandwidth.high A read-write nested-keyed file which exists on all cgroups. Each entry is keyed by the drm device's major:minor. The following nested keys are defined. ================ ======================================= bytes_in_period Burst limit per period in byte avg_bytes_per_us Average bandwidth limit in bytes per us ================ ======================================= Reading returns the following:: 226:1 bytes_in_period=9223372036854775807 avg_bytes_per_us=65536 226:2 bytes_in_period=9223372036854775807 avg_bytes_per_us=65536 drm.bandwidth.default A read-only nested-keyed file which exists on the root cgroup. Each entry is keyed by the drm device's major:minor. The following nested keys are defined. ================ ======================================== bytes_in_period Default burst limit per period in byte avg_bytes_per_us Default average bw limit in bytes per us ================ ======================================== Reading returns the following:: 226:1 bytes_in_period=9223372036854775807 avg_bytes_per_us=65536 226:2 bytes_in_period=9223372036854775807 avg_bytes_per_us=65536 Change-Id: Ie573491325ccc16535bb943e7857f43bd0962add Signed-off-by: Kenny Ho --- drivers/gpu/drm/ttm/ttm_bo.c | 7 + include/drm/drm_cgroup.h | 19 +++ include/linux/cgroup_drm.h | 16 ++ kernel/cgroup/drm.c | 319 ++++++++++++++++++++++++++++++++++- 4 files changed, 359 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index a0e9ce46baf3..32eee85f3641 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -1256,6 +1257,12 @@ int ttm_bo_validate(struct ttm_buffer_object *bo, * Check whether we need to move buffer. */ if (!ttm_bo_mem_compat(placement, &bo->mem, &new_flags)) { + unsigned int move_delay = drmcg_get_mem_bw_period_in_us(bo); + + move_delay /= 2000; /* check every half period in ms*/ + while (bo->bdev->ddev != NULL && !drmcg_mem_can_move(bo)) + msleep(move_delay); + ret = ttm_bo_move_buffer(bo, placement, ctx); if (ret) return ret; diff --git a/include/drm/drm_cgroup.h b/include/drm/drm_cgroup.h index 7d63f73a5375..9ce0d54e6bd8 100644 --- a/include/drm/drm_cgroup.h +++ b/include/drm/drm_cgroup.h @@ -16,6 +16,12 @@ struct drmcg_props { s64 bo_limits_total_allocated_default; s64 bo_limits_peak_allocated_default; + + s64 mem_bw_limits_period_in_us; + s64 mem_bw_limits_period_in_us_default; + + s64 mem_bw_bytes_in_period_default; + s64 mem_bw_avg_bytes_per_us_default; }; #ifdef CONFIG_CGROUP_DRM @@ -30,6 +36,8 @@ void drmcg_chg_mem(struct ttm_buffer_object *tbo); void drmcg_unchg_mem(struct ttm_buffer_object *tbo); void drmcg_mem_track_move(struct ttm_buffer_object *old_bo, bool evict, struct ttm_mem_reg *new_mem); +unsigned int drmcg_get_mem_bw_period_in_us(struct ttm_buffer_object *tbo); +bool drmcg_mem_can_move(struct ttm_buffer_object *tbo); #else static inline void drmcg_device_update(struct drm_device *device) @@ -62,5 +70,16 @@ static inline void drmcg_mem_track_move(struct ttm_buffer_object *old_bo, bool evict, struct ttm_mem_reg *new_mem) { } + +static inline unsigned int drmcg_get_mem_bw_period_in_us( + struct ttm_buffer_object *tbo) +{ + return 0; +} + +static inline bool drmcg_mem_can_move(struct ttm_buffer_object *tbo) +{ + return true; +} #endif /* CONFIG_CGROUP_DRM */ #endif /* __DRM_CGROUP_H__ */ diff --git a/include/linux/cgroup_drm.h b/include/linux/cgroup_drm.h index 9579e2a0b71d..27809a583bf2 100644 --- a/include/linux/cgroup_drm.h +++ b/include/linux/cgroup_drm.h @@ -14,6 +14,15 @@ /* limit defined per the way drm_minor_alloc operates */ #define MAX_DRM_DEV (64 * DRM_MINOR_RENDER) +enum drmcg_mem_bw_attr { + DRMCG_MEM_BW_ATTR_BYTE_MOVED, /* for calulating 'instantaneous' bw */ + DRMCG_MEM_BW_ATTR_ACCUM_US, /* for calulating 'instantaneous' bw */ + DRMCG_MEM_BW_ATTR_TOTAL_BYTE_MOVED, + DRMCG_MEM_BW_ATTR_TOTAL_ACCUM_US, + DRMCG_MEM_BW_ATTR_BYTE_CREDIT, + __DRMCG_MEM_BW_ATTR_LAST, +}; + enum drmcg_res_type { DRMCG_TYPE_BO_TOTAL, DRMCG_TYPE_BO_PEAK, @@ -21,6 +30,8 @@ enum drmcg_res_type { DRMCG_TYPE_MEM, DRMCG_TYPE_MEM_EVICT, DRMCG_TYPE_MEM_PEAK, + DRMCG_TYPE_BANDWIDTH, + DRMCG_TYPE_BANDWIDTH_PERIOD_BURST, __DRMCG_TYPE_LAST, }; @@ -40,6 +51,11 @@ struct drmcg_device_resource { s64 mem_stats[TTM_PL_PRIV+1]; s64 mem_peaks[TTM_PL_PRIV+1]; s64 mem_stats_evict; + + s64 mem_bw_stats_last_update_us; + s64 mem_bw_stats[__DRMCG_MEM_BW_ATTR_LAST]; + s64 mem_bw_limits_bytes_in_period; + s64 mem_bw_limits_avg_bytes_per_us; }; /** diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c index 899dc44722c3..ab962a277e58 100644 --- a/kernel/cgroup/drm.c +++ b/kernel/cgroup/drm.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +41,17 @@ static char const *ttm_placement_names[] = { [TTM_PL_PRIV] = "priv", }; +static char const *mem_bw_attr_names[] = { + [DRMCG_MEM_BW_ATTR_BYTE_MOVED] = "moved_byte", + [DRMCG_MEM_BW_ATTR_ACCUM_US] = "accum_us", + [DRMCG_MEM_BW_ATTR_TOTAL_BYTE_MOVED] = "total_moved_byte", + [DRMCG_MEM_BW_ATTR_TOTAL_ACCUM_US] = "total_accum_us", + [DRMCG_MEM_BW_ATTR_BYTE_CREDIT] = "byte_credit", +}; + +#define MEM_BW_LIMITS_NAME_AVG "avg_bytes_per_us" +#define MEM_BW_LIMITS_NAME_BURST "bytes_in_period" + static struct drmcg *root_drmcg __read_mostly; static int drmcg_css_free_fn(int id, void *ptr, void *data) @@ -75,6 +87,9 @@ static inline int init_drmcg_single(struct drmcg *drmcg, struct drm_device *dev) if (!ddr) return -ENOMEM; + + ddr->mem_bw_stats_last_update_us = ktime_to_us(ktime_get()); + ddr->mem_bw_stats[DRMCG_MEM_BW_ATTR_ACCUM_US] = 1; } mutex_lock(&dev->drmcg_mutex); @@ -87,6 +102,12 @@ static inline int init_drmcg_single(struct drmcg *drmcg, struct drm_device *dev) ddr->bo_limits_peak_allocated = dev->drmcg_props.bo_limits_peak_allocated_default; + ddr->mem_bw_limits_bytes_in_period = + dev->drmcg_props.mem_bw_bytes_in_period_default; + + ddr->mem_bw_limits_avg_bytes_per_us = + dev->drmcg_props.mem_bw_avg_bytes_per_us_default; + mutex_unlock(&dev->drmcg_mutex); return 0; } @@ -133,6 +154,26 @@ drmcg_css_alloc(struct cgroup_subsys_state *parent_css) return &drmcg->css; } +static inline void drmcg_mem_burst_bw_stats_reset(struct drm_device *dev) +{ + struct cgroup_subsys_state *pos; + struct drmcg *node; + struct drmcg_device_resource *ddr; + int devIdx; + + devIdx = dev->primary->index; + + rcu_read_lock(); + css_for_each_descendant_pre(pos, &root_drmcg->css) { + node = css_to_drmcg(pos); + ddr = node->dev_resources[devIdx]; + + ddr->mem_bw_stats[DRMCG_MEM_BW_ATTR_ACCUM_US] = 1; + ddr->mem_bw_stats[DRMCG_MEM_BW_ATTR_BYTE_MOVED] = 0; + } + rcu_read_unlock(); +} + static void drmcg_print_stats(struct drmcg_device_resource *ddr, struct seq_file *sf, enum drmcg_res_type type) { @@ -169,6 +210,31 @@ static void drmcg_print_stats(struct drmcg_device_resource *ddr, } seq_puts(sf, "\n"); break; + case DRMCG_TYPE_BANDWIDTH: + if (ddr->mem_bw_stats[DRMCG_MEM_BW_ATTR_ACCUM_US] == 0) + seq_puts(sf, "burst_byte_per_us=NaN "); + else + seq_printf(sf, "burst_byte_per_us=%lld ", + ddr->mem_bw_stats[ + DRMCG_MEM_BW_ATTR_BYTE_MOVED]/ + ddr->mem_bw_stats[ + DRMCG_MEM_BW_ATTR_ACCUM_US]); + + if (ddr->mem_bw_stats[DRMCG_MEM_BW_ATTR_TOTAL_ACCUM_US] == 0) + seq_puts(sf, "avg_bytes_per_us=NaN "); + else + seq_printf(sf, "avg_bytes_per_us=%lld ", + ddr->mem_bw_stats[ + DRMCG_MEM_BW_ATTR_TOTAL_BYTE_MOVED]/ + ddr->mem_bw_stats[ + DRMCG_MEM_BW_ATTR_TOTAL_ACCUM_US]); + + for (i = 0; i < __DRMCG_MEM_BW_ATTR_LAST; i++) { + seq_printf(sf, "%s=%lld ", mem_bw_attr_names[i], + ddr->mem_bw_stats[i]); + } + seq_puts(sf, "\n"); + break; default: seq_puts(sf, "\n"); break; @@ -176,7 +242,8 @@ static void drmcg_print_stats(struct drmcg_device_resource *ddr, } static void drmcg_print_limits(struct drmcg_device_resource *ddr, - struct seq_file *sf, enum drmcg_res_type type) + struct seq_file *sf, enum drmcg_res_type type, + struct drm_device *dev) { if (ddr == NULL) { seq_puts(sf, "\n"); @@ -190,6 +257,17 @@ static void drmcg_print_limits(struct drmcg_device_resource *ddr, case DRMCG_TYPE_BO_PEAK: seq_printf(sf, "%lld\n", ddr->bo_limits_peak_allocated); break; + case DRMCG_TYPE_BANDWIDTH_PERIOD_BURST: + seq_printf(sf, "%lld\n", + dev->drmcg_props.mem_bw_limits_period_in_us); + break; + case DRMCG_TYPE_BANDWIDTH: + seq_printf(sf, "%s=%lld %s=%lld\n", + MEM_BW_LIMITS_NAME_BURST, + ddr->mem_bw_limits_bytes_in_period, + MEM_BW_LIMITS_NAME_AVG, + ddr->mem_bw_limits_avg_bytes_per_us); + break; default: seq_puts(sf, "\n"); break; @@ -208,6 +286,17 @@ static void drmcg_print_default(struct drmcg_props *props, seq_printf(sf, "%lld\n", props->bo_limits_peak_allocated_default); break; + case DRMCG_TYPE_BANDWIDTH_PERIOD_BURST: + seq_printf(sf, "%lld\n", + props->mem_bw_limits_period_in_us_default); + break; + case DRMCG_TYPE_BANDWIDTH: + seq_printf(sf, "%s=%lld %s=%lld\n", + MEM_BW_LIMITS_NAME_BURST, + props->mem_bw_bytes_in_period_default, + MEM_BW_LIMITS_NAME_AVG, + props->mem_bw_avg_bytes_per_us_default); + break; default: seq_puts(sf, "\n"); break; @@ -237,7 +326,7 @@ static int drmcg_seq_show_fn(int id, void *ptr, void *data) drmcg_print_stats(ddr, sf, type); break; case DRMCG_FTYPE_LIMIT: - drmcg_print_limits(ddr, sf, type); + drmcg_print_limits(ddr, sf, type, minor->dev); break; case DRMCG_FTYPE_DEFAULT: drmcg_print_default(&minor->dev->drmcg_props, sf, type); @@ -301,6 +390,83 @@ static void drmcg_value_apply(struct drm_device *dev, s64 *dst, s64 val) mutex_unlock(&dev->drmcg_mutex); } +static void drmcg_nested_limit_parse(struct kernfs_open_file *of, + struct drm_device *dev, char *attrs) +{ + enum drmcg_res_type type = + DRMCG_CTF_PRIV2RESTYPE(of_cft(of)->private); + struct drmcg *drmcg = css_to_drmcg(of_css(of)); + struct drmcg *parent = drmcg_parent(drmcg); + struct drmcg_props *props = &dev->drmcg_props; + char *cft_name = of_cft(of)->name; + int minor = dev->primary->index; + char *nested = strstrip(attrs); + struct drmcg_device_resource *ddr = + drmcg->dev_resources[minor]; + char *attr; + char sname[256]; + char sval[256]; + s64 val; + s64 p_max; + int rc; + + while (nested != NULL) { + attr = strsep(&nested, " "); + + if (sscanf(attr, "%255[^=]=%255[^=]", sname, sval) != 2) + continue; + + switch (type) { + case DRMCG_TYPE_BANDWIDTH: + if (strncmp(sname, MEM_BW_LIMITS_NAME_BURST, 256) + == 0) { + p_max = parent == NULL ? S64_MAX : + parent->dev_resources[minor]-> + mem_bw_limits_bytes_in_period; + + rc = drmcg_process_limit_s64_val(sval, true, + props->mem_bw_bytes_in_period_default, + p_max, &val); + + if (rc || val < 0) { + drmcg_pr_cft_err(drmcg, rc, cft_name, + minor); + continue; + } + + drmcg_value_apply(dev, + &ddr->mem_bw_limits_bytes_in_period, + val); + continue; + } + + if (strncmp(sname, MEM_BW_LIMITS_NAME_AVG, 256) == 0) { + p_max = parent == NULL ? S64_MAX : + parent->dev_resources[minor]-> + mem_bw_limits_avg_bytes_per_us; + + rc = drmcg_process_limit_s64_val(sval, true, + props->mem_bw_avg_bytes_per_us_default, + p_max, &val); + + if (rc || val < 0) { + drmcg_pr_cft_err(drmcg, rc, cft_name, + minor); + continue; + } + + drmcg_value_apply(dev, + &ddr->mem_bw_limits_avg_bytes_per_us, + val); + continue; + } + break; /* DRMCG_TYPE_BANDWIDTH */ + default: + break; + } /* switch (type) */ + } +} + static ssize_t drmcg_limit_write(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off) { @@ -382,6 +548,25 @@ static ssize_t drmcg_limit_write(struct kernfs_open_file *of, char *buf, drmcg_value_apply(dm->dev, &ddr->bo_limits_peak_allocated, val); break; + case DRMCG_TYPE_BANDWIDTH_PERIOD_BURST: + rc = drmcg_process_limit_s64_val(sattr, false, + props->mem_bw_limits_period_in_us_default, + S64_MAX, + &val); + + if (rc || val < 2000) { + drmcg_pr_cft_err(drmcg, rc, cft_name, minor); + break; + } + + drmcg_value_apply(dm->dev, + &props->mem_bw_limits_period_in_us, + val); + drmcg_mem_burst_bw_stats_reset(dm->dev); + break; + case DRMCG_TYPE_BANDWIDTH: + drmcg_nested_limit_parse(of, dm->dev, sattr); + break; default: break; } @@ -456,6 +641,41 @@ struct cftype files[] = { .private = DRMCG_CTF_PRIV(DRMCG_TYPE_MEM_PEAK, DRMCG_FTYPE_STATS), }, + { + .name = "burst_bw_period_in_us", + .write = drmcg_limit_write, + .seq_show = drmcg_seq_show, + .flags = CFTYPE_ONLY_ON_ROOT, + .private = DRMCG_CTF_PRIV(DRMCG_TYPE_BANDWIDTH_PERIOD_BURST, + DRMCG_FTYPE_LIMIT), + }, + { + .name = "burst_bw_period_in_us.default", + .seq_show = drmcg_seq_show, + .flags = CFTYPE_ONLY_ON_ROOT, + .private = DRMCG_CTF_PRIV(DRMCG_TYPE_BANDWIDTH_PERIOD_BURST, + DRMCG_FTYPE_DEFAULT), + }, + { + .name = "bandwidth.stats", + .seq_show = drmcg_seq_show, + .private = DRMCG_CTF_PRIV(DRMCG_TYPE_BANDWIDTH, + DRMCG_FTYPE_STATS), + }, + { + .name = "bandwidth.high", + .write = drmcg_limit_write, + .seq_show = drmcg_seq_show, + .private = DRMCG_CTF_PRIV(DRMCG_TYPE_BANDWIDTH, + DRMCG_FTYPE_LIMIT), + }, + { + .name = "bandwidth.default", + .seq_show = drmcg_seq_show, + .flags = CFTYPE_ONLY_ON_ROOT, + .private = DRMCG_CTF_PRIV(DRMCG_TYPE_BANDWIDTH, + DRMCG_FTYPE_DEFAULT), + }, { } /* terminate */ }; @@ -515,6 +735,10 @@ void drmcg_device_early_init(struct drm_device *dev) dev->drmcg_props.bo_limits_total_allocated_default = S64_MAX; dev->drmcg_props.bo_limits_peak_allocated_default = S64_MAX; + dev->drmcg_props.mem_bw_limits_period_in_us_default = 200000; + dev->drmcg_props.mem_bw_limits_period_in_us = 200000; + dev->drmcg_props.mem_bw_bytes_in_period_default = S64_MAX; + dev->drmcg_props.mem_bw_avg_bytes_per_us_default = 65536; drmcg_update_cg_tree(dev); } @@ -660,6 +884,27 @@ void drmcg_unchg_mem(struct ttm_buffer_object *tbo) } EXPORT_SYMBOL(drmcg_unchg_mem); +static inline void drmcg_mem_bw_accum(s64 time_us, + struct drmcg_device_resource *ddr) +{ + s64 increment_us = time_us - ddr->mem_bw_stats_last_update_us; + s64 new_credit = ddr->mem_bw_limits_avg_bytes_per_us * increment_us; + + ddr->mem_bw_stats[DRMCG_MEM_BW_ATTR_ACCUM_US] + += increment_us; + ddr->mem_bw_stats[DRMCG_MEM_BW_ATTR_TOTAL_ACCUM_US] + += increment_us; + + if ((S64_MAX - new_credit) > + ddr->mem_bw_stats[DRMCG_MEM_BW_ATTR_BYTE_CREDIT]) + ddr->mem_bw_stats[DRMCG_MEM_BW_ATTR_BYTE_CREDIT] + += new_credit; + else + ddr->mem_bw_stats[DRMCG_MEM_BW_ATTR_BYTE_CREDIT] = S64_MAX; + + ddr->mem_bw_stats_last_update_us = time_us; +} + void drmcg_mem_track_move(struct ttm_buffer_object *old_bo, bool evict, struct ttm_mem_reg *new_mem) { @@ -669,6 +914,7 @@ void drmcg_mem_track_move(struct ttm_buffer_object *old_bo, bool evict, int devIdx = dev->primary->index; int old_mem_type = old_bo->mem.mem_type; int new_mem_type = new_mem->mem_type; + s64 time_us; struct drmcg_device_resource *ddr; if (drmcg == NULL) @@ -677,6 +923,14 @@ void drmcg_mem_track_move(struct ttm_buffer_object *old_bo, bool evict, old_mem_type = old_mem_type > TTM_PL_PRIV ? TTM_PL_PRIV : old_mem_type; new_mem_type = new_mem_type > TTM_PL_PRIV ? TTM_PL_PRIV : new_mem_type; + if (root_drmcg->dev_resources[devIdx] != NULL && + root_drmcg->dev_resources[devIdx]-> + mem_bw_stats[DRMCG_MEM_BW_ATTR_ACCUM_US] >= + dev->drmcg_props.mem_bw_limits_period_in_us) + drmcg_mem_burst_bw_stats_reset(dev); + + time_us = ktime_to_us(ktime_get()); + mutex_lock(&dev->drmcg_mutex); for ( ; drmcg != NULL; drmcg = drmcg_parent(drmcg)) { ddr = drmcg->dev_resources[devIdx]; @@ -689,7 +943,68 @@ void drmcg_mem_track_move(struct ttm_buffer_object *old_bo, bool evict, if (evict) ddr->mem_stats_evict++; + + drmcg_mem_bw_accum(time_us, ddr); + + ddr->mem_bw_stats[DRMCG_MEM_BW_ATTR_BYTE_MOVED] + += move_in_bytes; + ddr->mem_bw_stats[DRMCG_MEM_BW_ATTR_TOTAL_BYTE_MOVED] + += move_in_bytes; + + ddr->mem_bw_stats[DRMCG_MEM_BW_ATTR_BYTE_CREDIT] + -= move_in_bytes; } mutex_unlock(&dev->drmcg_mutex); } EXPORT_SYMBOL(drmcg_mem_track_move); + +unsigned int drmcg_get_mem_bw_period_in_us(struct ttm_buffer_object *tbo) +{ + struct drmcg_props *props; + + //TODO replace with BUG_ON + if (tbo->bdev->ddev == NULL) + return 0; + + props = &tbo->bdev->ddev->drmcg_props; + + return (unsigned int) props->mem_bw_limits_period_in_us; +} +EXPORT_SYMBOL(drmcg_get_mem_bw_period_in_us); + +bool drmcg_mem_can_move(struct ttm_buffer_object *tbo) +{ + struct drm_device *dev = tbo->bdev->ddev; + struct drmcg *drmcg = tbo->drmcg; + int devIdx = dev->primary->index; + s64 time_us; + struct drmcg_device_resource *ddr; + bool result = true; + + if (root_drmcg->dev_resources[devIdx] != NULL && + root_drmcg->dev_resources[devIdx]-> + mem_bw_stats[DRMCG_MEM_BW_ATTR_ACCUM_US] >= + dev->drmcg_props.mem_bw_limits_period_in_us) + drmcg_mem_burst_bw_stats_reset(dev); + + time_us = ktime_to_us(ktime_get()); + + mutex_lock(&dev->drmcg_mutex); + for ( ; drmcg != NULL; drmcg = drmcg_parent(drmcg)) { + ddr = drmcg->dev_resources[devIdx]; + + drmcg_mem_bw_accum(time_us, ddr); + + if (result && + (ddr->mem_bw_stats[DRMCG_MEM_BW_ATTR_BYTE_MOVED] + >= ddr->mem_bw_limits_bytes_in_period || + ddr->mem_bw_stats[DRMCG_MEM_BW_ATTR_BYTE_CREDIT] + <= 0)) { + result = false; + } + } + mutex_unlock(&dev->drmcg_mutex); + + return result; +} +EXPORT_SYMBOL(drmcg_mem_can_move); From patchwork Thu Aug 29 06:05:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 11120391 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EDFC614DE for ; Thu, 29 Aug 2019 06:06:19 +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 D6C9120828 for ; Thu, 29 Aug 2019 06:06:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D6C9120828 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CCDD089FD9; Thu, 29 Aug 2019 06:06:05 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM05-CO1-obe.outbound.protection.outlook.com (mail-eopbgr720041.outbound.protection.outlook.com [40.107.72.41]) by gabe.freedesktop.org (Postfix) with ESMTPS id C7A5289FC0; Thu, 29 Aug 2019 06:06:01 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yf92rdb0hBGvt0i/Af9xZ4koRw/6KHI+N7Ckw7CFn6NP6TChbQy84HJ9RzoSZRa1eilJIkIFKofyGncezdlIOoJzXHShse8CMLQxLTq9O9QaOGBNFlZqAizugpChAQ31/fnwA87MQFFRDaTAe7y6dooIrvO6R8J8f57kUErcFgwrNHTKZv3YQFx+LOIolt8Cbjtp4872VwzGWSu0tTfYWKlq1IEZI/rLmTsEwqVjjafG5YM6nIaRFbEqECTHSmCVfiQSx2ysLFcW7bHrjmlr6xIfijJluh7MJZ22I//VuXZ7ALtFUa1MDJ3esROqXdh/5oVCz9g+OldSLid2Sz0ayg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Zg7tXbM7Idim2K75amETOc2+muRuSenAneZKe+szmmc=; b=Wy7zen/RoC9yPd4cX5tFt9ORIxBH3QAVwA04BJ6CTpb4m9tGUE6Req0OJBKXCVRlLkREmOk6o2FBBB9Yhdrx0oVGg4cnJd/Lx3dVU9p7JkZcc33ucN3jMS3bD6LmcdHKE6k427M8i8DUL7hT4mNNWCBTpZDqYM35l2u1fRBmLRTWis8h6f+UpSuVCADBJTYbL0yhpjEfn60yvRNPGFjux+Gk4QvYzhK+655w3X20yrPcAqoXO94rj55ZPv/kjZL/dskJLiOAWUSxS6xd+Xof8TfUI8hAtXsgzbTY+1aqZZtBbJvWc0tDZvJSQb6651hpbJOsiwjWkigMhuF4fYKN3g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none (sender ip is 165.204.84.17) smtp.rcpttodomain=cray.com smtp.mailfrom=amd.com; dmarc=permerror action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from CH2PR12CA0005.namprd12.prod.outlook.com (2603:10b6:610:57::15) by MWHPR12MB1279.namprd12.prod.outlook.com (2603:10b6:300:d::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2220.16; Thu, 29 Aug 2019 06:05:58 +0000 Received: from CO1NAM03FT045.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::200) by CH2PR12CA0005.outlook.office365.com (2603:10b6:610:57::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2220.18 via Frontend Transport; Thu, 29 Aug 2019 06:05:58 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV01.amd.com (165.204.84.17) by CO1NAM03FT045.mail.protection.outlook.com (10.152.81.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2220.16 via Frontend Transport; Thu, 29 Aug 2019 06:05:57 +0000 Received: from kho-5039A.amd.com (10.180.168.240) by SATLEXCHOV01.amd.com (10.181.40.71) with Microsoft SMTP Server id 14.3.389.1; Thu, 29 Aug 2019 01:05:50 -0500 From: Kenny Ho To: , , , , , , , , , , , Subject: [PATCH RFC v4 12/16] drm, cgroup: Add soft VRAM limit Date: Thu, 29 Aug 2019 02:05:29 -0400 Message-ID: <20190829060533.32315-13-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829060533.32315-1-Kenny.Ho@amd.com> References: <20190829060533.32315-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(4636009)(39860400002)(346002)(136003)(376002)(396003)(2980300002)(428003)(199004)(189003)(47776003)(336012)(110136005)(5660300002)(81156014)(81166006)(86362001)(8676002)(53936002)(2870700001)(426003)(1076003)(486006)(70586007)(70206006)(2616005)(2201001)(446003)(476003)(126002)(7696005)(51416003)(11346002)(50466002)(48376002)(14444005)(186003)(4326008)(316002)(53416004)(36756003)(2906002)(76176011)(8936002)(356004)(6666004)(305945005)(26005)(478600001)(50226002)(921003)(83996005)(2101003)(1121003); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR12MB1279; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d49c2571-cf70-4fc6-7b28-08d72c46f5fd X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328); SRVR:MWHPR12MB1279; X-MS-TrafficTypeDiagnostic: MWHPR12MB1279: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:849; X-Forefront-PRVS: 0144B30E41 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: zb1H/lAmVMbsZa/bbYODf9OFwcsxXTsEd3ZMd2bD6HkJYJLbub8RIzCf3X/RMOGsS2MFf8g0W98vsjuqGcFFjylUAcjyyz5yKBG6AJ57T4gmBaOjr09BjTSICEEOy0gmwOnB9omvd2wj4d+1xGnL8imHWb+WC0VTSrGMZ1spmynK2Yn6QXklDbwI0Ytkrr9NphqmPwQbhg9/4YjPCMOFrO0fnBwGwoXx8yr1a48oP3xqz7/T0ySOVbADWTc0GG7c7TQ6iuQMcWIfX+Imn/hnT6eD9sowKw7kNT5UiPpQ33pIT/wxZ8Yt7+uQ2dzVN0UWW17DICwG2fHUSr+/0OMy4yrDbLqsag9PfY4f0zF3N0MVO7DWdmXAS9Nm1fwJ5PIwH6h9ArPrDFoxZNpRaAPm11Jnvt2LmK7CHUx2KTVJcXE= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2019 06:05:57.9474 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d49c2571-cf70-4fc6-7b28-08d72c46f5fd X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1279 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Zg7tXbM7Idim2K75amETOc2+muRuSenAneZKe+szmmc=; b=0QNqFTM+FHh2qwnrv3laThUB+9LVNQ3PcVxv4ClyrjNYikIYdKl/UTQVl6mio2X8dgERxvUZoF+hHMmQNHOjrqwLbq05lNmSt3Qe5hMc16WpbR3fFEwO+28PZDSD99tOx/lCIcxHptd1CZ61T139lkur5/sYN5dftfsi5g2DInY= X-Mailman-Original-Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; cray.com; dkim=none (message not signed) header.d=none;cray.com; dmarc=permerror action=none header.from=amd.com; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kenny Ho Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The drm resource being limited is the TTM (Translation Table Manager) buffers. TTM manages different types of memory that a GPU might access. These memory types include dedicated Video RAM (VRAM) and host/system memory accessible through IOMMU (GART/GTT). TTM is currently used by multiple drm drivers (amd, ast, bochs, cirrus, hisilicon, maga200, nouveau, qxl, virtio, vmwgfx.) TTM buffers belonging to drm cgroups under memory pressure will be selected to be evicted first. drm.memory.high A read-write nested-keyed file which exists on all cgroups. Each entry is keyed by the drm device's major:minor. The following nested keys are defined. ==== ============================================= vram Video RAM soft limit for a drm device in byte ==== ============================================= Reading returns the following:: 226:0 vram=0 226:1 vram=17768448 226:2 vram=17768448 drm.memory.default A read-only nested-keyed file which exists on the root cgroup. Each entry is keyed by the drm device's major:minor. The following nested keys are defined. ==== =============================== vram Video RAM default limit in byte ==== =============================== Reading returns the following:: 226:0 vram=0 226:1 vram=17768448 226:2 vram=17768448 Change-Id: I7988e28a453b53140b40a28c176239acbc81d491 Signed-off-by: Kenny Ho --- drivers/gpu/drm/ttm/ttm_bo.c | 7 ++ include/drm/drm_cgroup.h | 17 +++++ include/linux/cgroup_drm.h | 2 + kernel/cgroup/drm.c | 135 +++++++++++++++++++++++++++++++++++ 4 files changed, 161 insertions(+) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 32eee85f3641..d7e3d3128ebb 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -853,14 +853,21 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev, struct ttm_bo_global *glob = bdev->glob; struct ttm_mem_type_manager *man = &bdev->man[mem_type]; bool locked = false; + bool check_drmcg; unsigned i; int ret; + check_drmcg = drmcg_mem_pressure_scan(bdev, mem_type); + spin_lock(&glob->lru_lock); for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) { list_for_each_entry(bo, &man->lru[i], lru) { bool busy; + if (check_drmcg && + !drmcg_mem_should_evict(bo, mem_type)) + continue; + if (!ttm_bo_evict_swapout_allowable(bo, ctx, &locked, &busy)) { if (busy && !busy_bo && diff --git a/include/drm/drm_cgroup.h b/include/drm/drm_cgroup.h index 9ce0d54e6bd8..c11df388fdf2 100644 --- a/include/drm/drm_cgroup.h +++ b/include/drm/drm_cgroup.h @@ -6,6 +6,7 @@ #include #include +#include /** * Per DRM device properties for DRM cgroup controller for the purpose @@ -22,6 +23,8 @@ struct drmcg_props { s64 mem_bw_bytes_in_period_default; s64 mem_bw_avg_bytes_per_us_default; + + s64 mem_highs_default[TTM_PL_PRIV+1]; }; #ifdef CONFIG_CGROUP_DRM @@ -38,6 +41,8 @@ void drmcg_mem_track_move(struct ttm_buffer_object *old_bo, bool evict, struct ttm_mem_reg *new_mem); unsigned int drmcg_get_mem_bw_period_in_us(struct ttm_buffer_object *tbo); bool drmcg_mem_can_move(struct ttm_buffer_object *tbo); +bool drmcg_mem_pressure_scan(struct ttm_bo_device *bdev, unsigned int type); +bool drmcg_mem_should_evict(struct ttm_buffer_object *tbo, unsigned int type); #else static inline void drmcg_device_update(struct drm_device *device) @@ -81,5 +86,17 @@ static inline bool drmcg_mem_can_move(struct ttm_buffer_object *tbo) { return true; } + +static inline bool drmcg_mem_pressure_scan(struct ttm_bo_device *bdev, + unsigned int type) +{ + return false; +} + +static inline bool drmcg_mem_should_evict(struct ttm_buffer_object *tbo, + unsigned int type) +{ + return true; +} #endif /* CONFIG_CGROUP_DRM */ #endif /* __DRM_CGROUP_H__ */ diff --git a/include/linux/cgroup_drm.h b/include/linux/cgroup_drm.h index 27809a583bf2..c56cfe74d1a6 100644 --- a/include/linux/cgroup_drm.h +++ b/include/linux/cgroup_drm.h @@ -50,6 +50,8 @@ struct drmcg_device_resource { s64 mem_stats[TTM_PL_PRIV+1]; s64 mem_peaks[TTM_PL_PRIV+1]; + s64 mem_highs[TTM_PL_PRIV+1]; + bool mem_pressure[TTM_PL_PRIV+1]; s64 mem_stats_evict; s64 mem_bw_stats_last_update_us; diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c index ab962a277e58..04fb9a398740 100644 --- a/kernel/cgroup/drm.c +++ b/kernel/cgroup/drm.c @@ -80,6 +80,7 @@ static inline int init_drmcg_single(struct drmcg *drmcg, struct drm_device *dev) { int minor = dev->primary->index; struct drmcg_device_resource *ddr = drmcg->dev_resources[minor]; + int i; if (ddr == NULL) { ddr = kzalloc(sizeof(struct drmcg_device_resource), @@ -108,6 +109,12 @@ static inline int init_drmcg_single(struct drmcg *drmcg, struct drm_device *dev) ddr->mem_bw_limits_avg_bytes_per_us = dev->drmcg_props.mem_bw_avg_bytes_per_us_default; + ddr->mem_bw_limits_avg_bytes_per_us = + dev->drmcg_props.mem_bw_avg_bytes_per_us_default; + + for (i = 0; i <= TTM_PL_PRIV; i++) + ddr->mem_highs[i] = dev->drmcg_props.mem_highs_default[i]; + mutex_unlock(&dev->drmcg_mutex); return 0; } @@ -257,6 +264,11 @@ static void drmcg_print_limits(struct drmcg_device_resource *ddr, case DRMCG_TYPE_BO_PEAK: seq_printf(sf, "%lld\n", ddr->bo_limits_peak_allocated); break; + case DRMCG_TYPE_MEM: + seq_printf(sf, "%s=%lld\n", + ttm_placement_names[TTM_PL_VRAM], + ddr->mem_highs[TTM_PL_VRAM]); + break; case DRMCG_TYPE_BANDWIDTH_PERIOD_BURST: seq_printf(sf, "%lld\n", dev->drmcg_props.mem_bw_limits_period_in_us); @@ -286,6 +298,11 @@ static void drmcg_print_default(struct drmcg_props *props, seq_printf(sf, "%lld\n", props->bo_limits_peak_allocated_default); break; + case DRMCG_TYPE_MEM: + seq_printf(sf, "%s=%lld\n", + ttm_placement_names[TTM_PL_VRAM], + props->mem_highs_default[TTM_PL_VRAM]); + break; case DRMCG_TYPE_BANDWIDTH_PERIOD_BURST: seq_printf(sf, "%lld\n", props->mem_bw_limits_period_in_us_default); @@ -461,6 +478,29 @@ static void drmcg_nested_limit_parse(struct kernfs_open_file *of, continue; } break; /* DRMCG_TYPE_BANDWIDTH */ + case DRMCG_TYPE_MEM: + if (strncmp(sname, ttm_placement_names[TTM_PL_VRAM], + 256) == 0) { + p_max = parent == NULL ? S64_MAX : + parent->dev_resources[minor]-> + mem_highs[TTM_PL_VRAM]; + + rc = drmcg_process_limit_s64_val(sval, true, + props->mem_highs_default[TTM_PL_VRAM], + p_max, &val); + + if (rc || val < 0) { + drmcg_pr_cft_err(drmcg, rc, cft_name, + minor); + continue; + } + + drmcg_value_apply(dev, + &ddr->mem_highs[TTM_PL_VRAM], + val); + continue; + } + break; /* DRMCG_TYPE_MEM */ default: break; } /* switch (type) */ @@ -565,6 +605,7 @@ static ssize_t drmcg_limit_write(struct kernfs_open_file *of, char *buf, drmcg_mem_burst_bw_stats_reset(dm->dev); break; case DRMCG_TYPE_BANDWIDTH: + case DRMCG_TYPE_MEM: drmcg_nested_limit_parse(of, dm->dev, sattr); break; default: @@ -641,6 +682,20 @@ struct cftype files[] = { .private = DRMCG_CTF_PRIV(DRMCG_TYPE_MEM_PEAK, DRMCG_FTYPE_STATS), }, + { + .name = "memory.default", + .seq_show = drmcg_seq_show, + .flags = CFTYPE_ONLY_ON_ROOT, + .private = DRMCG_CTF_PRIV(DRMCG_TYPE_MEM, + DRMCG_FTYPE_DEFAULT), + }, + { + .name = "memory.high", + .write = drmcg_limit_write, + .seq_show = drmcg_seq_show, + .private = DRMCG_CTF_PRIV(DRMCG_TYPE_MEM, + DRMCG_FTYPE_LIMIT), + }, { .name = "burst_bw_period_in_us", .write = drmcg_limit_write, @@ -731,6 +786,8 @@ EXPORT_SYMBOL(drmcg_device_update); */ void drmcg_device_early_init(struct drm_device *dev) { + int i; + dev->drmcg_props.limit_enforced = false; dev->drmcg_props.bo_limits_total_allocated_default = S64_MAX; @@ -740,6 +797,9 @@ void drmcg_device_early_init(struct drm_device *dev) dev->drmcg_props.mem_bw_bytes_in_period_default = S64_MAX; dev->drmcg_props.mem_bw_avg_bytes_per_us_default = 65536; + for (i = 0; i <= TTM_PL_PRIV; i++) + dev->drmcg_props.mem_highs_default[i] = S64_MAX; + drmcg_update_cg_tree(dev); } EXPORT_SYMBOL(drmcg_device_early_init); @@ -1008,3 +1068,78 @@ bool drmcg_mem_can_move(struct ttm_buffer_object *tbo) return result; } EXPORT_SYMBOL(drmcg_mem_can_move); + +static inline void drmcg_mem_set_pressure(struct drmcg *drmcg, + int devIdx, unsigned int mem_type, bool pressure_val) +{ + struct drmcg_device_resource *ddr; + struct cgroup_subsys_state *pos; + struct drmcg *node; + + css_for_each_descendant_pre(pos, &drmcg->css) { + node = css_to_drmcg(pos); + ddr = node->dev_resources[devIdx]; + ddr->mem_pressure[mem_type] = pressure_val; + } +} + +static inline bool drmcg_mem_check(struct drmcg *drmcg, int devIdx, + unsigned int mem_type) +{ + struct drmcg_device_resource *ddr = drmcg->dev_resources[devIdx]; + + /* already under pressure, no need to check and set */ + if (ddr->mem_pressure[mem_type]) + return true; + + if (ddr->mem_stats[mem_type] >= ddr->mem_highs[mem_type]) { + drmcg_mem_set_pressure(drmcg, devIdx, mem_type, true); + return true; + } + + return false; +} + +bool drmcg_mem_pressure_scan(struct ttm_bo_device *bdev, unsigned int type) +{ + struct drm_device *dev = bdev->ddev; + struct cgroup_subsys_state *pos; + struct drmcg *node; + int devIdx; + bool result = false; + + //TODO replace with BUG_ON + if (dev == NULL || type != TTM_PL_VRAM) /* only vram limit for now */ + return false; + + devIdx = dev->primary->index; + + type = type > TTM_PL_PRIV ? TTM_PL_PRIV : type; + + rcu_read_lock(); + drmcg_mem_set_pressure(root_drmcg, devIdx, type, false); + + css_for_each_descendant_pre(pos, &root_drmcg->css) { + node = css_to_drmcg(pos); + result |= drmcg_mem_check(node, devIdx, type); + } + rcu_read_unlock(); + + return result; +} +EXPORT_SYMBOL(drmcg_mem_pressure_scan); + +bool drmcg_mem_should_evict(struct ttm_buffer_object *tbo, unsigned int type) +{ + struct drm_device *dev = tbo->bdev->ddev; + int devIdx; + + //TODO replace with BUG_ON + if (dev == NULL) + return true; + + devIdx = dev->primary->index; + + return tbo->drmcg->dev_resources[devIdx]->mem_pressure[type]; +} +EXPORT_SYMBOL(drmcg_mem_should_evict); From patchwork Thu Aug 29 06:05:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 11120403 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 98DFA14DE for ; Thu, 29 Aug 2019 06:06:38 +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 81E9B2341F for ; Thu, 29 Aug 2019 06:06:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 81E9B2341F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 87CAC6E030; Thu, 29 Aug 2019 06:06:27 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM04-CO1-obe.outbound.protection.outlook.com (mail-co1nam04on0615.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe4d::615]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7CFA589FD3; Thu, 29 Aug 2019 06:06:02 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GcJrligq6rLBD9DhQb607bxS8BZ+WpVnfcu/aSsV/8JSlnd65l+wWwqhC5hHDxnHAFMfAhwBwa+8qyY/6yCIdzIrRd90bvFPDaESe7ycAITDjfBFi0Nr+xNYFRYwOmgABGS3i35/An/uV9WPLEokwiuL9qjz9pXaI72PDPWwGaGqiZ8pFku+s9DYXRhpo3Q35XQmvgZjuNBgZlsK79pg1tulPkNWmMBFv+e2GwZNPax3HiVmWMo3XKC/KIbJF4Nn16JYqHNmfJIlyjiZvKsiR1xORcmwf1PHoGR5XKxDF9mILBr/e64X1ie6krCZhvC0Jynm7OEJckNgQ/4326h0ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IO2xv2gzU6vk63jLoZO3k7qrATQypyFZjz78wXseTdE=; b=KwB//Y+MSz3TDttwTca87m7OVSlsBcXYVHa1xERo8ipW7rBZss8WEHPHvB1EfjIrLbUVD8KCoMx1x/W5Xqcw0gMp49SAVh6Ekeiwh4yfDaSyYTYxBhchG98eJT0EzxKyP/HqlmMVaJehJK2cdPCuNm4vd1NknRCKptiNp8ZbmZ7S1gQUajrEgN72c71Tzq2UpazigA9QUUDzzP+6NmVmP35A6heheFIyJQi9TeTYkKIXszsiEI07doCAmZm0ckRk6WwxgZgNJU91I+6Rtvip1uOjOQ+PHRZtZWLw+mrnD4GT1tj1xiOvNTDazSpuyBCUGLiWw0BRc0WFQQkZrBrIOw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none (sender ip is 165.204.84.17) smtp.rcpttodomain=cray.com smtp.mailfrom=amd.com; dmarc=permerror action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from CH2PR12CA0011.namprd12.prod.outlook.com (2603:10b6:610:57::21) by BYAPR12MB2712.namprd12.prod.outlook.com (2603:10b6:a03:68::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Thu, 29 Aug 2019 06:06:00 +0000 Received: from CO1NAM03FT045.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::208) by CH2PR12CA0011.outlook.office365.com (2603:10b6:610:57::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2220.18 via Frontend Transport; Thu, 29 Aug 2019 06:05:59 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV01.amd.com (165.204.84.17) by CO1NAM03FT045.mail.protection.outlook.com (10.152.81.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2220.16 via Frontend Transport; Thu, 29 Aug 2019 06:05:59 +0000 Received: from kho-5039A.amd.com (10.180.168.240) by SATLEXCHOV01.amd.com (10.181.40.71) with Microsoft SMTP Server id 14.3.389.1; Thu, 29 Aug 2019 01:05:51 -0500 From: Kenny Ho To: , , , , , , , , , , , Subject: [PATCH RFC v4 13/16] drm, cgroup: Allow more aggressive memory reclaim Date: Thu, 29 Aug 2019 02:05:30 -0400 Message-ID: <20190829060533.32315-14-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829060533.32315-1-Kenny.Ho@amd.com> References: <20190829060533.32315-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(4636009)(376002)(136003)(396003)(346002)(39860400002)(2980300002)(428003)(189003)(199004)(126002)(2906002)(476003)(446003)(11346002)(2616005)(486006)(478600001)(305945005)(426003)(50466002)(336012)(8936002)(48376002)(70206006)(2870700001)(50226002)(81166006)(81156014)(186003)(26005)(8676002)(14444005)(53936002)(70586007)(2201001)(316002)(110136005)(4326008)(1076003)(86362001)(47776003)(76176011)(5660300002)(7696005)(51416003)(6666004)(356004)(53416004)(36756003)(921003)(1121003)(83996005)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR12MB2712; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; MX:1; A:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 95fa5cc6-0246-4803-3b6c-08d72c46f6ca X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328); SRVR:BYAPR12MB2712; X-MS-TrafficTypeDiagnostic: BYAPR12MB2712: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-Forefront-PRVS: 0144B30E41 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: /WRCUPaJn2Euda3fBQ5PWoBQHYjdmfZilm2hwrout1B6ENedVwUZpKNt5PkY/30ZecbD+jJ+qFf/pmll9OfH/UfCAcW4K5psWizKs91tX+Hrn55iWa8ROoyqcMS8aqlw2nH+XizWpkVgfizwZ8HZ3CoxDZXxvlzl7z97sJeAbdzJcnHBkcKsxGlBotWSwxyfrvX4o3r3IceJHHCY3QvvMt5h0ZKW7Au5Qq1ltVN7awyqNB/HwNI+uAFmJaGPX9XYtCWNWINPK0nEcYWXARFTx/ahmH5aIxCXs6ZGm23GtfWbCHKwg1gJBmAUQLN/JjwSrRHZzKOrSQ/JvvifpR+Hf4tY37b/aGIV7ReOLpIjOgdprQEHhq9OszSSlvkkaYzq4M29rikBh+pD0C6s4XMNSkJf7vG5+ernlLvJOOIZm1w= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2019 06:05:59.1572 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 95fa5cc6-0246-4803-3b6c-08d72c46f6ca X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB2712 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IO2xv2gzU6vk63jLoZO3k7qrATQypyFZjz78wXseTdE=; b=Ns2AhLarkMuARJWOnQKmvok/CxPEYyqYr078vD7aoK0qCyVG0N00VKwxkaYAYgkxhO8/Huu1/R1hROC4fKZYWLGJ3+IuZ1UckC4lb1jXDKyO24y5HIX/PORk6WYYWAd1bBd8X9MPTJlOsv/CRc7aDNkfTGOQfjBhPGisXii6New= X-Mailman-Original-Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; cray.com; dkim=none (message not signed) header.d=none;cray.com; dmarc=permerror action=none header.from=amd.com; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kenny Ho Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Allow DRM TTM memory manager to register a work_struct, such that, when a drmcgrp is under memory pressure, memory reclaiming can be triggered immediately. Change-Id: I25ac04e2db9c19ff12652b88ebff18b44b2706d8 Signed-off-by: Kenny Ho --- drivers/gpu/drm/ttm/ttm_bo.c | 49 +++++++++++++++++++++++++++++++++ include/drm/drm_cgroup.h | 16 +++++++++++ include/drm/ttm/ttm_bo_driver.h | 2 ++ kernel/cgroup/drm.c | 30 ++++++++++++++++++++ 4 files changed, 97 insertions(+) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index d7e3d3128ebb..72efae694b7e 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -1590,6 +1590,46 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type) } EXPORT_SYMBOL(ttm_bo_evict_mm); +static void ttm_bo_reclaim_wq(struct work_struct *work) +{ + struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false, + .flags = TTM_OPT_FLAG_FORCE_ALLOC + }; + struct ttm_mem_type_manager *man = + container_of(work, struct ttm_mem_type_manager, reclaim_wq); + struct ttm_bo_device *bdev = man->bdev; + struct dma_fence *fence; + int mem_type; + int ret; + + for (mem_type = 0; mem_type < TTM_NUM_MEM_TYPES; mem_type++) + if (&bdev->man[mem_type] == man) + break; + + WARN_ON(mem_type >= TTM_NUM_MEM_TYPES); + if (mem_type >= TTM_NUM_MEM_TYPES) + return; + + if (!drmcg_mem_pressure_scan(bdev, mem_type)) + return; + + ret = ttm_mem_evict_first(bdev, mem_type, NULL, &ctx, NULL); + if (ret) + return; + + spin_lock(&man->move_lock); + fence = dma_fence_get(man->move); + spin_unlock(&man->move_lock); + + if (fence) { + ret = dma_fence_wait(fence, false); + dma_fence_put(fence); + } + +} + int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type, unsigned long p_size) { @@ -1624,6 +1664,13 @@ int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type, INIT_LIST_HEAD(&man->lru[i]); man->move = NULL; + pr_err("drmcg %p type %d\n", bdev->ddev, type); + + if (type <= TTM_PL_VRAM) { + INIT_WORK(&man->reclaim_wq, ttm_bo_reclaim_wq); + drmcg_register_device_mm(bdev->ddev, type, &man->reclaim_wq); + } + return 0; } EXPORT_SYMBOL(ttm_bo_init_mm); @@ -1701,6 +1748,8 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev) man = &bdev->man[i]; if (man->has_type) { man->use_type = false; + drmcg_unregister_device_mm(bdev->ddev, i); + cancel_work_sync(&man->reclaim_wq); if ((i != TTM_PL_SYSTEM) && ttm_bo_clean_mm(bdev, i)) { ret = -EBUSY; pr_err("DRM memory manager type %d is not clean\n", diff --git a/include/drm/drm_cgroup.h b/include/drm/drm_cgroup.h index c11df388fdf2..6d9707e1eb72 100644 --- a/include/drm/drm_cgroup.h +++ b/include/drm/drm_cgroup.h @@ -5,6 +5,7 @@ #define __DRM_CGROUP_H__ #include +#include #include #include @@ -25,12 +26,17 @@ struct drmcg_props { s64 mem_bw_avg_bytes_per_us_default; s64 mem_highs_default[TTM_PL_PRIV+1]; + + struct work_struct *mem_reclaim_wq[TTM_PL_PRIV]; }; #ifdef CONFIG_CGROUP_DRM void drmcg_device_update(struct drm_device *device); void drmcg_device_early_init(struct drm_device *device); +void drmcg_register_device_mm(struct drm_device *dev, unsigned int type, + struct work_struct *wq); +void drmcg_unregister_device_mm(struct drm_device *dev, unsigned int type); bool drmcg_try_chg_bo_alloc(struct drmcg *drmcg, struct drm_device *dev, size_t size); void drmcg_unchg_bo_alloc(struct drmcg *drmcg, struct drm_device *dev, @@ -53,6 +59,16 @@ static inline void drmcg_device_early_init(struct drm_device *device) { } +static inline void drmcg_register_device_mm(struct drm_device *dev, + unsigned int type, struct work_struct *wq) +{ +} + +static inline void drmcg_unregister_device_mm(struct drm_device *dev, + unsigned int type) +{ +} + static inline void drmcg_try_chg_bo_alloc(struct drmcg *drmcg, struct drm_device *dev, size_t size) { diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h index e1a805d65b83..529cef92bcf6 100644 --- a/include/drm/ttm/ttm_bo_driver.h +++ b/include/drm/ttm/ttm_bo_driver.h @@ -205,6 +205,8 @@ struct ttm_mem_type_manager { * Protected by @move_lock. */ struct dma_fence *move; + + struct work_struct reclaim_wq; }; /** diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c index 04fb9a398740..0ea7f0619e25 100644 --- a/kernel/cgroup/drm.c +++ b/kernel/cgroup/drm.c @@ -804,6 +804,29 @@ void drmcg_device_early_init(struct drm_device *dev) } EXPORT_SYMBOL(drmcg_device_early_init); +void drmcg_register_device_mm(struct drm_device *dev, unsigned int type, + struct work_struct *wq) +{ + if (dev == NULL || type >= TTM_PL_PRIV) + return; + + mutex_lock(&drmcg_mutex); + dev->drmcg_props.mem_reclaim_wq[type] = wq; + mutex_unlock(&drmcg_mutex); +} +EXPORT_SYMBOL(drmcg_register_device_mm); + +void drmcg_unregister_device_mm(struct drm_device *dev, unsigned int type) +{ + if (dev == NULL || type >= TTM_PL_PRIV) + return; + + mutex_lock(&drmcg_mutex); + dev->drmcg_props.mem_reclaim_wq[type] = NULL; + mutex_unlock(&drmcg_mutex); +} +EXPORT_SYMBOL(drmcg_unregister_device_mm); + /** * drmcg_try_chg_bo_alloc - charge GEM buffer usage for a device and cgroup * @drmcg: the DRM cgroup to be charged to @@ -1013,6 +1036,13 @@ void drmcg_mem_track_move(struct ttm_buffer_object *old_bo, bool evict, ddr->mem_bw_stats[DRMCG_MEM_BW_ATTR_BYTE_CREDIT] -= move_in_bytes; + + if (dev->drmcg_props.mem_reclaim_wq[new_mem_type] + != NULL && + ddr->mem_stats[new_mem_type] > + ddr->mem_highs[new_mem_type]) + schedule_work(dev-> + drmcg_props.mem_reclaim_wq[new_mem_type]); } mutex_unlock(&dev->drmcg_mutex); } From patchwork Thu Aug 29 06:05:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 11120401 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9E3CC14D5 for ; Thu, 29 Aug 2019 06:06:35 +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 876AF23405 for ; Thu, 29 Aug 2019 06:06:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 876AF23405 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E7B6389F97; Thu, 29 Aug 2019 06:06:18 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0623.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe46::623]) by gabe.freedesktop.org (Postfix) with ESMTPS id 032B989FDD; Thu, 29 Aug 2019 06:06:06 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k8ZcEto80o7CO4llpG8AdgVpdT1QE5AIdyQJYFEiS0TMqusHz6PckhjMT3cOK0z8Ux7wt+PsvhL8NMIfDdt7LObLvyG2CwWvqslTBjGZJOQt9qPv/GxxA/nWeQ1pe2f0AztrX0Y3lTSwjJiwk1nejwIwl7NZBKasG7vuP6aBfddTqaP/ZFCeXoU/a8IPitnjDW/QbNvAJCdhA16V0peXyR/oWnUaCkX5HOoJy3sfPz7TqkOjCBlJXBIFppx2+VPPyno4pSo7Ik8JmWqLDV7EXjDQkxEIHIEm1rd2Xy1A+nhGg0PVspdtBzkapVJzPoyP/qei/PodJ5ONhSQACtByyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9ikXulXvozVVaCx939FypgkWNr6qLB3Y+IHRVJ4CTwE=; b=ZTSX2S1gKqqsVoqO+trWGAvFHvPMuEdHE3kAAHzpJCGmq04yPS9hEUqZE48TgHzXzxL+DyKoty6p4uTRHUWb4Xo4v0jPccQTMfmaw8rloESo8qIOvhd/HPp0Harqk6bVN1hWwiCXkgik9nNhGTHVstZ/YYhiosNyWprqucv4r8gVTs6uc7KS1hsfByJ00rvNgOk0XacFPUepuCf6XCXltGpBkwMjOX4KIf7Ag/JZUJz389BGi41OUSzGLWSDrlm9Tg1GsLnjXJNhGDUEKAEFHv4cHz6+gtT4L9DCearjO2O7vi9cUEt/73RncK7DbHgsi5CGg7/1hUKaQ1qmIpBy6w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none (sender ip is 165.204.84.17) smtp.rcpttodomain=cray.com smtp.mailfrom=amd.com; dmarc=permerror action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from CH2PR12CA0011.namprd12.prod.outlook.com (2603:10b6:610:57::21) by MWHPR12MB1280.namprd12.prod.outlook.com (2603:10b6:300:12::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2178.19; Thu, 29 Aug 2019 06:06:01 +0000 Received: from CO1NAM03FT045.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::208) by CH2PR12CA0011.outlook.office365.com (2603:10b6:610:57::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2220.18 via Frontend Transport; Thu, 29 Aug 2019 06:06:01 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV01.amd.com (165.204.84.17) by CO1NAM03FT045.mail.protection.outlook.com (10.152.81.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2220.16 via Frontend Transport; Thu, 29 Aug 2019 06:06:00 +0000 Received: from kho-5039A.amd.com (10.180.168.240) by SATLEXCHOV01.amd.com (10.181.40.71) with Microsoft SMTP Server id 14.3.389.1; Thu, 29 Aug 2019 01:05:52 -0500 From: Kenny Ho To: , , , , , , , , , , , Subject: [PATCH RFC v4 14/16] drm, cgroup: Introduce lgpu as DRM cgroup resource Date: Thu, 29 Aug 2019 02:05:31 -0400 Message-ID: <20190829060533.32315-15-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829060533.32315-1-Kenny.Ho@amd.com> References: <20190829060533.32315-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(979002)(4636009)(396003)(39860400002)(376002)(346002)(136003)(2980300002)(428003)(199004)(189003)(51416003)(76176011)(14444005)(5660300002)(53936002)(486006)(2906002)(4326008)(126002)(478600001)(2870700001)(7696005)(2616005)(86362001)(11346002)(1076003)(476003)(110136005)(2201001)(30864003)(26005)(47776003)(53416004)(36756003)(81156014)(8936002)(81166006)(8676002)(446003)(305945005)(70206006)(316002)(356004)(6666004)(50466002)(48376002)(336012)(426003)(70586007)(186003)(50226002)(921003)(2101003)(83996005)(1121003)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR12MB1280; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 728853de-7870-4644-1edd-08d72c46f7a3 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328); SRVR:MWHPR12MB1280; X-MS-TrafficTypeDiagnostic: MWHPR12MB1280: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1051; X-Forefront-PRVS: 0144B30E41 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: OQiAUAD/sew0X+5bSOOrWAiBbP81EZyenvO0dfezMW0Y0lU+ttNjKJbv1l9EYZhYSu+EMQPKOR/feJfQF4iVtKjxnFXkwlwDJ8nKlSMWvh/9At53Y2m49DTSjjIETjxwqiesOBC98W0oxoMUloaBGdtVXAMDlOecnRJ+lY5obzh9Mkv+H8F0uKb2PdsWDEWJG1ObUseXZtEZL1ktCQxawsjzU9SrL3OBFZLls2BucI2gRmsiwW0ofS/OGDv7dykq4v0txsb+iuK2R8C4/8OG7XLXSN9xpvrCjTiRSTdeDfnBpJsArCMAJnCPkMNWLnRJ6zM6L2dlDGydPrTIGVZjT7zv0er9/7+eedmnrcMD1CeqZyjepYC75zicEHgQJ56HFo5wv17S/QxXZTQGBbqizjIzO4+NP44PLK37OPj4yfI= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2019 06:06:00.6213 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 728853de-7870-4644-1edd-08d72c46f7a3 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1280 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9ikXulXvozVVaCx939FypgkWNr6qLB3Y+IHRVJ4CTwE=; b=4iy0hcSiV+Du/n5wqf9P3CYUtSIrR+0Zv5XONhWnq9l0fVAgl1/y4YJi9Ta+1h6zVfYiz3kOoeRQoK+/dDFReLLhXjGi+yfF5x9aRaYHjhUED9Y4cfgFg6ubMqRmYaWCFLikd7a389b3OIpA4V9UE2WfD6q0+tRc2ggXJv39Z4o= X-Mailman-Original-Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; cray.com; dkim=none (message not signed) header.d=none;cray.com; dmarc=permerror action=none header.from=amd.com; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kenny Ho Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" drm.lgpu A read-write nested-keyed file which exists on all cgroups. Each entry is keyed by the DRM device's major:minor. lgpu stands for logical GPU, it is an abstraction used to subdivide a physical DRM device for the purpose of resource management. The lgpu is a discrete quantity that is device specific (i.e. some DRM devices may have 64 lgpus while others may have 100 lgpus.) The lgpu is a single quantity with two representations denoted by the following nested keys. ===== ======================================== count Representing lgpu as anonymous resource list Representing lgpu as named resource ===== ======================================== For example: 226:0 count=256 list=0-255 226:1 count=4 list=0,2,4,6 226:2 count=32 list=32-63 lgpu is represented by a bitmap and uses the bitmap_parselist kernel function so the list key input format is a comma-separated list of decimal numbers and ranges. Consecutively set bits are shown as two hyphen-separated decimal numbers, the smallest and largest bit numbers set in the range. Optionally each range can be postfixed to denote that only parts of it should be set. The range will divided to groups of specific size. Syntax: range:used_size/group_size Example: 0-1023:2/256 ==> 0,1,256,257,512,513,768,769 The count key is the hamming weight / hweight of the bitmap. Both count and list accept the max and default keywords. Some DRM devices may only support lgpu as anonymous resources. In such case, the significance of the position of the set bits in list will be ignored. This lgpu resource supports the 'allocation' resource distribution model. Change-Id: I1afcacf356770930c7f925df043e51ad06ceb98e Signed-off-by: Kenny Ho Acked-by: Felix Kuehling --- Documentation/admin-guide/cgroup-v2.rst | 46 ++++++++ include/drm/drm_cgroup.h | 4 + include/linux/cgroup_drm.h | 6 ++ kernel/cgroup/drm.c | 135 ++++++++++++++++++++++++ 4 files changed, 191 insertions(+) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 87a195133eaa..57f18469bd76 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1958,6 +1958,52 @@ DRM Interface Files Set largest allocation for /dev/dri/card1 to 4MB echo "226:1 4m" > drm.buffer.peak.max + drm.lgpu + A read-write nested-keyed file which exists on all cgroups. + Each entry is keyed by the DRM device's major:minor. + + lgpu stands for logical GPU, it is an abstraction used to + subdivide a physical DRM device for the purpose of resource + management. + + The lgpu is a discrete quantity that is device specific (i.e. + some DRM devices may have 64 lgpus while others may have 100 + lgpus.) The lgpu is a single quantity with two representations + denoted by the following nested keys. + + ===== ======================================== + count Representing lgpu as anonymous resource + list Representing lgpu as named resource + ===== ======================================== + + For example: + 226:0 count=256 list=0-255 + 226:1 count=4 list=0,2,4,6 + 226:2 count=32 list=32-63 + + lgpu is represented by a bitmap and uses the bitmap_parselist + kernel function so the list key input format is a + comma-separated list of decimal numbers and ranges. + + Consecutively set bits are shown as two hyphen-separated decimal + numbers, the smallest and largest bit numbers set in the range. + Optionally each range can be postfixed to denote that only parts + of it should be set. The range will divided to groups of + specific size. + Syntax: range:used_size/group_size + Example: 0-1023:2/256 ==> 0,1,256,257,512,513,768,769 + + The count key is the hamming weight / hweight of the bitmap. + + Both count and list accept the max and default keywords. + + Some DRM devices may only support lgpu as anonymous resources. + In such case, the significance of the position of the set bits + in list will be ignored. + + This lgpu resource supports the 'allocation' resource + distribution model. + GEM Buffer Ownership ~~~~~~~~~~~~~~~~~~~~ diff --git a/include/drm/drm_cgroup.h b/include/drm/drm_cgroup.h index 6d9707e1eb72..a8d6be0b075b 100644 --- a/include/drm/drm_cgroup.h +++ b/include/drm/drm_cgroup.h @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -28,6 +29,9 @@ struct drmcg_props { s64 mem_highs_default[TTM_PL_PRIV+1]; struct work_struct *mem_reclaim_wq[TTM_PL_PRIV]; + + int lgpu_capacity; + DECLARE_BITMAP(lgpu_slots, MAX_DRMCG_LGPU_CAPACITY); }; #ifdef CONFIG_CGROUP_DRM diff --git a/include/linux/cgroup_drm.h b/include/linux/cgroup_drm.h index c56cfe74d1a6..7b1cfc4ce4c3 100644 --- a/include/linux/cgroup_drm.h +++ b/include/linux/cgroup_drm.h @@ -14,6 +14,8 @@ /* limit defined per the way drm_minor_alloc operates */ #define MAX_DRM_DEV (64 * DRM_MINOR_RENDER) +#define MAX_DRMCG_LGPU_CAPACITY 256 + enum drmcg_mem_bw_attr { DRMCG_MEM_BW_ATTR_BYTE_MOVED, /* for calulating 'instantaneous' bw */ DRMCG_MEM_BW_ATTR_ACCUM_US, /* for calulating 'instantaneous' bw */ @@ -32,6 +34,7 @@ enum drmcg_res_type { DRMCG_TYPE_MEM_PEAK, DRMCG_TYPE_BANDWIDTH, DRMCG_TYPE_BANDWIDTH_PERIOD_BURST, + DRMCG_TYPE_LGPU, __DRMCG_TYPE_LAST, }; @@ -58,6 +61,9 @@ struct drmcg_device_resource { s64 mem_bw_stats[__DRMCG_MEM_BW_ATTR_LAST]; s64 mem_bw_limits_bytes_in_period; s64 mem_bw_limits_avg_bytes_per_us; + + s64 lgpu_used; + DECLARE_BITMAP(lgpu_allocated, MAX_DRMCG_LGPU_CAPACITY); }; /** diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c index 0ea7f0619e25..18c4368e2c29 100644 --- a/kernel/cgroup/drm.c +++ b/kernel/cgroup/drm.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -52,6 +53,9 @@ static char const *mem_bw_attr_names[] = { #define MEM_BW_LIMITS_NAME_AVG "avg_bytes_per_us" #define MEM_BW_LIMITS_NAME_BURST "bytes_in_period" +#define LGPU_LIMITS_NAME_LIST "list" +#define LGPU_LIMITS_NAME_COUNT "count" + static struct drmcg *root_drmcg __read_mostly; static int drmcg_css_free_fn(int id, void *ptr, void *data) @@ -115,6 +119,10 @@ static inline int init_drmcg_single(struct drmcg *drmcg, struct drm_device *dev) for (i = 0; i <= TTM_PL_PRIV; i++) ddr->mem_highs[i] = dev->drmcg_props.mem_highs_default[i]; + bitmap_copy(ddr->lgpu_allocated, dev->drmcg_props.lgpu_slots, + MAX_DRMCG_LGPU_CAPACITY); + ddr->lgpu_used = bitmap_weight(ddr->lgpu_allocated, MAX_DRMCG_LGPU_CAPACITY); + mutex_unlock(&dev->drmcg_mutex); return 0; } @@ -280,6 +288,14 @@ static void drmcg_print_limits(struct drmcg_device_resource *ddr, MEM_BW_LIMITS_NAME_AVG, ddr->mem_bw_limits_avg_bytes_per_us); break; + case DRMCG_TYPE_LGPU: + seq_printf(sf, "%s=%lld %s=%*pbl\n", + LGPU_LIMITS_NAME_COUNT, + ddr->lgpu_used, + LGPU_LIMITS_NAME_LIST, + dev->drmcg_props.lgpu_capacity, + ddr->lgpu_allocated); + break; default: seq_puts(sf, "\n"); break; @@ -314,6 +330,15 @@ static void drmcg_print_default(struct drmcg_props *props, MEM_BW_LIMITS_NAME_AVG, props->mem_bw_avg_bytes_per_us_default); break; + case DRMCG_TYPE_LGPU: + seq_printf(sf, "%s=%d %s=%*pbl\n", + LGPU_LIMITS_NAME_COUNT, + bitmap_weight(props->lgpu_slots, + props->lgpu_capacity), + LGPU_LIMITS_NAME_LIST, + props->lgpu_capacity, + props->lgpu_slots); + break; default: seq_puts(sf, "\n"); break; @@ -407,9 +432,21 @@ static void drmcg_value_apply(struct drm_device *dev, s64 *dst, s64 val) mutex_unlock(&dev->drmcg_mutex); } +static void drmcg_lgpu_values_apply(struct drm_device *dev, + struct drmcg_device_resource *ddr, unsigned long *val) +{ + + mutex_lock(&dev->drmcg_mutex); + bitmap_copy(ddr->lgpu_allocated, val, MAX_DRMCG_LGPU_CAPACITY); + ddr->lgpu_used = bitmap_weight(ddr->lgpu_allocated, MAX_DRMCG_LGPU_CAPACITY); + mutex_unlock(&dev->drmcg_mutex); +} + static void drmcg_nested_limit_parse(struct kernfs_open_file *of, struct drm_device *dev, char *attrs) { + DECLARE_BITMAP(tmp_bitmap, MAX_DRMCG_LGPU_CAPACITY); + DECLARE_BITMAP(chk_bitmap, MAX_DRMCG_LGPU_CAPACITY); enum drmcg_res_type type = DRMCG_CTF_PRIV2RESTYPE(of_cft(of)->private); struct drmcg *drmcg = css_to_drmcg(of_css(of)); @@ -501,6 +538,83 @@ static void drmcg_nested_limit_parse(struct kernfs_open_file *of, continue; } break; /* DRMCG_TYPE_MEM */ + case DRMCG_TYPE_LGPU: + if (strncmp(sname, LGPU_LIMITS_NAME_LIST, 256) && + strncmp(sname, LGPU_LIMITS_NAME_COUNT, 256) ) + continue; + + if (!strcmp("max", sval) || + !strcmp("default", sval)) { + if (parent != NULL) + drmcg_lgpu_values_apply(dev, ddr, + parent->dev_resources[minor]-> + lgpu_allocated); + else + drmcg_lgpu_values_apply(dev, ddr, + props->lgpu_slots); + + continue; + } + + if (strncmp(sname, LGPU_LIMITS_NAME_COUNT, 256) == 0) { + p_max = parent == NULL ? props->lgpu_capacity: + bitmap_weight( + parent->dev_resources[minor]-> + lgpu_allocated, props->lgpu_capacity); + + rc = drmcg_process_limit_s64_val(sval, + false, p_max, p_max, &val); + + if (rc || val < 0) { + drmcg_pr_cft_err(drmcg, rc, cft_name, + minor); + continue; + } + + bitmap_zero(tmp_bitmap, + MAX_DRMCG_LGPU_CAPACITY); + bitmap_set(tmp_bitmap, 0, val); + } + + if (strncmp(sname, LGPU_LIMITS_NAME_LIST, 256) == 0) { + rc = bitmap_parselist(sval, tmp_bitmap, + MAX_DRMCG_LGPU_CAPACITY); + + if (rc) { + drmcg_pr_cft_err(drmcg, rc, cft_name, + minor); + continue; + } + + bitmap_andnot(chk_bitmap, tmp_bitmap, + props->lgpu_slots, + MAX_DRMCG_LGPU_CAPACITY); + + if (!bitmap_empty(chk_bitmap, + MAX_DRMCG_LGPU_CAPACITY)) { + drmcg_pr_cft_err(drmcg, 0, cft_name, + minor); + continue; + } + } + + + if (parent != NULL) { + bitmap_and(chk_bitmap, tmp_bitmap, + parent->dev_resources[minor]->lgpu_allocated, + props->lgpu_capacity); + + if (bitmap_empty(chk_bitmap, + props->lgpu_capacity)) { + drmcg_pr_cft_err(drmcg, 0, + cft_name, minor); + continue; + } + } + + drmcg_lgpu_values_apply(dev, ddr, tmp_bitmap); + + break; /* DRMCG_TYPE_LGPU */ default: break; } /* switch (type) */ @@ -606,6 +720,7 @@ static ssize_t drmcg_limit_write(struct kernfs_open_file *of, char *buf, break; case DRMCG_TYPE_BANDWIDTH: case DRMCG_TYPE_MEM: + case DRMCG_TYPE_LGPU: drmcg_nested_limit_parse(of, dm->dev, sattr); break; default: @@ -731,6 +846,20 @@ struct cftype files[] = { .private = DRMCG_CTF_PRIV(DRMCG_TYPE_BANDWIDTH, DRMCG_FTYPE_DEFAULT), }, + { + .name = "lgpu", + .seq_show = drmcg_seq_show, + .write = drmcg_limit_write, + .private = DRMCG_CTF_PRIV(DRMCG_TYPE_LGPU, + DRMCG_FTYPE_LIMIT), + }, + { + .name = "lgpu.default", + .seq_show = drmcg_seq_show, + .flags = CFTYPE_ONLY_ON_ROOT, + .private = DRMCG_CTF_PRIV(DRMCG_TYPE_LGPU, + DRMCG_FTYPE_DEFAULT), + }, { } /* terminate */ }; @@ -744,6 +873,10 @@ struct cgroup_subsys drm_cgrp_subsys = { static inline void drmcg_update_cg_tree(struct drm_device *dev) { + bitmap_zero(dev->drmcg_props.lgpu_slots, MAX_DRMCG_LGPU_CAPACITY); + bitmap_fill(dev->drmcg_props.lgpu_slots, + dev->drmcg_props.lgpu_capacity); + /* init cgroups created before registration (i.e. root cgroup) */ if (root_drmcg != NULL) { struct cgroup_subsys_state *pos; @@ -800,6 +933,8 @@ void drmcg_device_early_init(struct drm_device *dev) for (i = 0; i <= TTM_PL_PRIV; i++) dev->drmcg_props.mem_highs_default[i] = S64_MAX; + dev->drmcg_props.lgpu_capacity = MAX_DRMCG_LGPU_CAPACITY; + drmcg_update_cg_tree(dev); } EXPORT_SYMBOL(drmcg_device_early_init); From patchwork Thu Aug 29 06:05:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 11120405 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 41D9E14DE for ; Thu, 29 Aug 2019 06:06: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 2B06723407 for ; Thu, 29 Aug 2019 06:06:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2B06723407 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5E1CA89F6D; Thu, 29 Aug 2019 06:06:28 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM04-BN3-obe.outbound.protection.outlook.com (mail-eopbgr680078.outbound.protection.outlook.com [40.107.68.78]) by gabe.freedesktop.org (Postfix) with ESMTPS id 871DA89FCC; Thu, 29 Aug 2019 06:06:05 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=coyR3PhhGdQ289VT1xTyJr1eM4Q7ipslx1vH1JDbXnRw6UPnNEGiIMTdx0/Uzc8NJUHPmi4h77tl79hoBTUOJO6O0Yrae8cigKDkxAdEhu8JMhhOmILGGeRrg+l81rStPFNNQkcaOr+aDZL4WJHki+F2CLFV1Pmij6DUCc/amv/41VHJCFmgZhlSoGH2hdGO8dj3ZUCoqId9eRkh+pUmOWutkzbnxhLkXqyKpDgdnsGRct9/6XnDBuKUcFttol/2qYWgRfCiF2w+OpZuhWDs3irPr8S+V0pceQj95vae8TyVys1r9LEc1JOzJyDka3W/pbr3XgBej44lOTAmPQP99w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tHCdRB4lz61FKBEyUmCsgxLGy00PpWlSb12BZmjdJis=; b=NY0n9LhvvIMRtwDd1XAbI3uiAEQ0kWhyBWYHDWnc5yPm7VzqtotUWE1/LKU2urUliibhLfUI/WB5T465fLaG1pntLRXVtKEWuCNpEfzG7LXwdOE3oW8MKcVqaIKxiwHV3+H5BoZcIr+KooHOGdLAwF5VI2e/q0zgGBqqT87JgPh1JpxTv+f8Nu+Qy4Q/upe+FW8R6u/yUVSwy3w6tdf+o5AWCwOsrbc4AMuNlLxMREQmLy3evoFEpuohGzrO0hxku6SGnEFFH9iOZ4RUP6hmCct8jtprD99mqrdi3AunJJvU6eT7VNtxVMl2kUiYHxn8760xZ4yjHtHkuTIbRmQxaw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none (sender ip is 165.204.84.17) smtp.rcpttodomain=cray.com smtp.mailfrom=amd.com; dmarc=permerror action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from CH2PR12CA0005.namprd12.prod.outlook.com (2603:10b6:610:57::15) by SN6PR12MB2719.namprd12.prod.outlook.com (2603:10b6:805:70::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.19; Thu, 29 Aug 2019 06:06:03 +0000 Received: from CO1NAM03FT045.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::200) by CH2PR12CA0005.outlook.office365.com (2603:10b6:610:57::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2220.18 via Frontend Transport; Thu, 29 Aug 2019 06:06:02 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV01.amd.com (165.204.84.17) by CO1NAM03FT045.mail.protection.outlook.com (10.152.81.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2220.16 via Frontend Transport; Thu, 29 Aug 2019 06:06:02 +0000 Received: from kho-5039A.amd.com (10.180.168.240) by SATLEXCHOV01.amd.com (10.181.40.71) with Microsoft SMTP Server id 14.3.389.1; Thu, 29 Aug 2019 01:05:52 -0500 From: Kenny Ho To: , , , , , , , , , , , Subject: [PATCH RFC v4 15/16] drm, cgroup: add update trigger after limit change Date: Thu, 29 Aug 2019 02:05:32 -0400 Message-ID: <20190829060533.32315-16-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829060533.32315-1-Kenny.Ho@amd.com> References: <20190829060533.32315-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(4636009)(396003)(136003)(39860400002)(346002)(376002)(2980300002)(428003)(189003)(199004)(486006)(476003)(2616005)(126002)(426003)(478600001)(11346002)(356004)(6666004)(8936002)(50226002)(110136005)(305945005)(336012)(26005)(53936002)(186003)(50466002)(446003)(5660300002)(15650500001)(51416003)(2870700001)(7696005)(2906002)(76176011)(81166006)(81156014)(8676002)(36756003)(1076003)(4326008)(70586007)(5024004)(70206006)(14444005)(48376002)(86362001)(2201001)(53416004)(316002)(47776003)(921003)(2101003)(83996005)(1121003); DIR:OUT; SFP:1101; SCL:1; SRVR:SN6PR12MB2719; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; MX:1; A:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a1b87b45-2a42-4107-bde9-08d72c46f8a8 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328); SRVR:SN6PR12MB2719; X-MS-TrafficTypeDiagnostic: SN6PR12MB2719: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1332; X-Forefront-PRVS: 0144B30E41 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 1ND1aj3G7PS92B3emWO4t1VvMpq3pbGoTv7Du9foPdf8l39vpF6WH0EOLRWPR2Vg65v3H6Mqbfi7u+DQKWJBpuUC1IW8+rJ5G5d650vN+BlN0fRC1xyanHtFzAjPCuxnOfDvcovTXXMVUerMf2U7LFtXqRIxKQXVCZxxsl2xugwNIn0BZctQyqLla8iPN1yyI3qtwJiwi6vME7tEHGAccfnEs3MjkCu6yz2VjkjCiiLgt57GxL0p1BpdRoVI1bENQUhgteMcpE301gBny8w7rGBPgoSVVZz/JZaRRtL2QWBK3xlY+hLnAQ7fPYOjgN++rS9PNTLcMAim2+z/7pyLgFbC7T4E8rN7/22WBu6tN74qWJYqQaZ0Q+75E2vnPX4EbbQP5lCoF7ijrcXOpWfeBpRv8d7fJesg8KD3HuV/JWM= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2019 06:06:02.3166 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a1b87b45-2a42-4107-bde9-08d72c46f8a8 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2719 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tHCdRB4lz61FKBEyUmCsgxLGy00PpWlSb12BZmjdJis=; b=FJ9CEsUTHTD/c5M5pZrVBNiKuLyw9sbcWxOEpBEirse0l0Cr25+3m1lhDDVGAQgWlLxXYAk+7s/cYuFKwPn8F2u+HEe57hYsX+dcWtRjvAI1NIHCsYGeXwX/cY560Y/KalEekkK7L4cnggGJGgY0dh1hIkASoCSEGVtNeox7F7M= X-Mailman-Original-Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; cray.com; dkim=none (message not signed) header.d=none;cray.com; dmarc=permerror action=none header.from=amd.com; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kenny Ho Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Before this commit, drmcg limits are updated but enforcement is delayed until the next time the driver check against the new limit. While this is sufficient for certain resources, a more proactive enforcement may be needed for other resources. Introducing an optional drmcg_limit_updated callback for the DRM drivers. When defined, it will be called in two scenarios: 1) When limits are updated for a particular cgroup, the callback will be triggered for each task in the updated cgroup. 2) When a task is migrated from one cgroup to another, the callback will be triggered for each resource type for the migrated task. Change-Id: I68187a72818b855b5f295aefcb241cda8ab63b00 Signed-off-by: Kenny Ho --- include/drm/drm_drv.h | 10 ++++++++ kernel/cgroup/drm.c | 57 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h index c8a37a08d98d..7e588b874a27 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -669,6 +669,16 @@ struct drm_driver { void (*drmcg_custom_init)(struct drm_device *dev, struct drmcg_props *props); + /** + * @drmcg_limit_updated + * + * Optional callback + */ + void (*drmcg_limit_updated)(struct drm_device *dev, + struct task_struct *task,\ + struct drmcg_device_resource *ddr, + enum drmcg_res_type res_type); + /** * @gem_vm_ops: Driver private ops for this object */ diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c index 18c4368e2c29..99772e5d9ccc 100644 --- a/kernel/cgroup/drm.c +++ b/kernel/cgroup/drm.c @@ -621,6 +621,23 @@ static void drmcg_nested_limit_parse(struct kernfs_open_file *of, } } +static void drmcg_limit_updated(struct drm_device *dev, struct drmcg *drmcg, + enum drmcg_res_type res_type) +{ + struct drmcg_device_resource *ddr = + drmcg->dev_resources[dev->primary->index]; + struct css_task_iter it; + struct task_struct *task; + + css_task_iter_start(&drmcg->css.cgroup->self, + CSS_TASK_ITER_PROCS, &it); + while ((task = css_task_iter_next(&it))) { + dev->driver->drmcg_limit_updated(dev, task, + ddr, res_type); + } + css_task_iter_end(&it); +} + static ssize_t drmcg_limit_write(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off) { @@ -726,6 +743,10 @@ static ssize_t drmcg_limit_write(struct kernfs_open_file *of, char *buf, default: break; } + + if (dm->dev->driver->drmcg_limit_updated) + drmcg_limit_updated(dm->dev, drmcg, type); + drm_dev_put(dm->dev); /* release from drm_minor_acquire */ } @@ -863,9 +884,45 @@ struct cftype files[] = { { } /* terminate */ }; +static int drmcg_attach_fn(int id, void *ptr, void *data) +{ + struct drm_minor *minor = ptr; + struct task_struct *task = data; + struct drm_device *dev; + + if (minor->type != DRM_MINOR_PRIMARY) + return 0; + + dev = minor->dev; + + if (dev->driver->drmcg_limit_updated) { + struct drmcg *drmcg = drmcg_get(task); + struct drmcg_device_resource *ddr = + drmcg->dev_resources[minor->index]; + enum drmcg_res_type type; + + for (type = 0; type < __DRMCG_TYPE_LAST; type++) + dev->driver->drmcg_limit_updated(dev, task, ddr, type); + + drmcg_put(drmcg); + } + + return 0; +} + +static void drmcg_attach(struct cgroup_taskset *tset) +{ + struct task_struct *task; + struct cgroup_subsys_state *css; + + cgroup_taskset_for_each(task, css, tset) + drm_minor_for_each(&drmcg_attach_fn, task); +} + struct cgroup_subsys drm_cgrp_subsys = { .css_alloc = drmcg_css_alloc, .css_free = drmcg_css_free, + .attach = drmcg_attach, .early_init = false, .legacy_cftypes = files, .dfl_cftypes = files, From patchwork Thu Aug 29 06:05:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 11120397 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 484F314DE for ; Thu, 29 Aug 2019 06:06:32 +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 319BC23405 for ; Thu, 29 Aug 2019 06:06:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 319BC23405 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0069A89FBC; Thu, 29 Aug 2019 06:06:18 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM04-BN3-obe.outbound.protection.outlook.com (mail-eopbgr680067.outbound.protection.outlook.com [40.107.68.67]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0EC3B89FE8; Thu, 29 Aug 2019 06:06:07 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YCb5dBeod9oJlZ2bdI6k9CRkK4AOZmwZRNBeHqIrai/Imap8B9K2aSP2OE3kpiy4S+cxYW8cR8sUXJGcD8vs00Ns45w56wx8xG52GSpGYRGX2fEGwHFtri2DtV/jckUwZ9oXuzMQCWIeQkueitPgRMTTwg3wiPsrgLyqOtJloEHLwbVejgjViUvFxPxkfNOZ67pSVw19YPAGKLtKcf6l7Bza0b36peUhyunPdS5JB92m0dUvqylUlRIM0E9X56qDdWjcEd+6olMX/QsJtNsnbQ00zkXNfxgq3+EuVERSXiuC6+V4h/CqkVG4NHQjlYzlE/JGGRXCo8jqdvvHwdyJXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lIa2TlfOaEpLObifkD5JDIqeDLfDxJ6AINWi5bSAaGo=; b=ZjZtiD5rk4nMhZ6BnzSAW9TW/CEiXjUryBF/YQx1U43UQLPALIqkYvCecohSzstG+6xXqyT+qK+kH/cCO/u6UmZ1EpMvi859nMDwp+wM4xaUGYKK4Ea6VIQObWKxn/AOvmqTNkEZ+F9Mewp6+ZrinHCKOgbuTZLKeibM3zys8bPLOz21HbPe8mPSKNQBblxEpY1cty/oTS0MUhRZExWO382LAcgW7qaNWWm4PP6MuLmlx2r3Zy6q7wTGb4dDeDAn1TqPeleqZNIJdzDhJZLQAbvGEvnb2WQOEcEHEZB7CHvHhHLBDTUihfyVFwqx5I9p/t9mbCHoH6Yd2L9mCtJIsA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none (sender ip is 165.204.84.17) smtp.rcpttodomain=cray.com smtp.mailfrom=amd.com; dmarc=permerror action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from CH2PR12CA0005.namprd12.prod.outlook.com (2603:10b6:610:57::15) by BN6PR12MB1267.namprd12.prod.outlook.com (2603:10b6:404:17::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.20; Thu, 29 Aug 2019 06:06:04 +0000 Received: from CO1NAM03FT045.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::200) by CH2PR12CA0005.outlook.office365.com (2603:10b6:610:57::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2220.18 via Frontend Transport; Thu, 29 Aug 2019 06:06:04 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV01.amd.com (165.204.84.17) by CO1NAM03FT045.mail.protection.outlook.com (10.152.81.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2220.16 via Frontend Transport; Thu, 29 Aug 2019 06:06:03 +0000 Received: from kho-5039A.amd.com (10.180.168.240) by SATLEXCHOV01.amd.com (10.181.40.71) with Microsoft SMTP Server id 14.3.389.1; Thu, 29 Aug 2019 01:05:53 -0500 From: Kenny Ho To: , , , , , , , , , , , Subject: [PATCH RFC v4 16/16] drm/amdgpu: Integrate with DRM cgroup Date: Thu, 29 Aug 2019 02:05:33 -0400 Message-ID: <20190829060533.32315-17-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829060533.32315-1-Kenny.Ho@amd.com> References: <20190829060533.32315-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(1496009)(4636009)(376002)(39860400002)(346002)(136003)(396003)(2980300002)(428003)(199004)(189003)(5660300002)(86362001)(47776003)(6666004)(356004)(1076003)(478600001)(2201001)(2870700001)(2906002)(316002)(70206006)(70586007)(50466002)(110136005)(48376002)(53416004)(426003)(36756003)(4326008)(305945005)(53936002)(8936002)(8676002)(81156014)(186003)(51416003)(2616005)(11346002)(446003)(476003)(76176011)(14444005)(7696005)(126002)(486006)(81166006)(50226002)(336012)(26005)(921003)(1121003)(2101003)(83996005); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR12MB1267; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bd4e2dbb-9942-4172-8e08-08d72c46f95d X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328); SRVR:BN6PR12MB1267; X-MS-TrafficTypeDiagnostic: BN6PR12MB1267: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-Forefront-PRVS: 0144B30E41 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: EQVhlXOyUFvAWJGK27QD0WY1qdZ3vGuO+Wb3v4Sh5Oz5jEOBw2OwqxXNi4U8g/gS/k1/bclhuWBQEbXzhz8OKui1yJ7BBEqdB+vPKOzTjOLpuvmd1NR3EaqTDFa3MmTO4MCERqrv3APbtcnR9G21zz1dyUwXtJIpMbGTHVozmW3+JwUtyh6iPtxoGNnLImjAX+IPhAIyeGaDvy8b755mLxQA4DvcEHh6j6ZCTmXxIHVTHZfSGjvu7RFmZEaoUuHi5TkJMrAg2zoeyO/n6n/vRKYfcaGtYlf8xTo4QAtB10aC3+LfHE169HWv8woVIVEUg6dGEOSv/cLPJepTXHn1k41Q62dQCOhYO4JgQtRhiCwhWCIPhOlA6wzdorn3Psviuq5izqaL11dyctQwFe7Nr+dVqW7h4gqoSSwyAl1nTRs= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2019 06:06:03.4601 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bd4e2dbb-9942-4172-8e08-08d72c46f95d X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1267 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lIa2TlfOaEpLObifkD5JDIqeDLfDxJ6AINWi5bSAaGo=; b=gyUcqceHqU8fONALcrLqaWQqg/x96Sz77VauJmvTDyDrFwInWQkzveEIPmIs3NcrJYnuC2Xbpxg/+r4YM+bPxntZMs7D8b6jW1tgXM/Y0Au5GY3tNQclxMmJcL3DZvvFOf7hnyftyVxIWOVE0k+xSws6O6NDLNgpEE3Kr7hW1xg= X-Mailman-Original-Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; cray.com; dkim=none (message not signed) header.d=none;cray.com; dmarc=permerror action=none header.from=amd.com; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kenny Ho Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The number of logical gpu (lgpu) is defined to be the number of compute unit (CU) for a device. The lgpu allocation limit only applies to compute workload for the moment (enforced via kfd queue creation.) Any cu_mask update is validated against the availability of the compute unit as defined by the drmcg the kfd process belongs to. Change-Id: I69a57452c549173a1cd623c30dc57195b3b6563e Signed-off-by: Kenny Ho --- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 4 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 21 +++ drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 6 + drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 3 + .../amd/amdkfd/kfd_process_queue_manager.c | 140 ++++++++++++++++++ 5 files changed, 174 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h index 55cb1b2094fd..369915337213 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h @@ -198,6 +198,10 @@ uint8_t amdgpu_amdkfd_get_xgmi_hops_count(struct kgd_dev *dst, struct kgd_dev *s valid; \ }) +int amdgpu_amdkfd_update_cu_mask_for_process(struct task_struct *task, + struct amdgpu_device *adev, unsigned long *lgpu_bitmap, + unsigned int nbits); + /* GPUVM API */ int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev *kgd, unsigned int pasid, void **vm, void **process_info, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c index 163a4fbf0611..8abeffdd2e5b 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c @@ -1398,9 +1398,29 @@ amdgpu_get_crtc_scanout_position(struct drm_device *dev, unsigned int pipe, static void amdgpu_drmcg_custom_init(struct drm_device *dev, struct drmcg_props *props) { + struct amdgpu_device *adev = dev->dev_private; + + props->lgpu_capacity = adev->gfx.cu_info.number; + props->limit_enforced = true; } +static void amdgpu_drmcg_limit_updated(struct drm_device *dev, + struct task_struct *task, struct drmcg_device_resource *ddr, + enum drmcg_res_type res_type) +{ + struct amdgpu_device *adev = dev->dev_private; + + switch (res_type) { + case DRMCG_TYPE_LGPU: + amdgpu_amdkfd_update_cu_mask_for_process(task, adev, + ddr->lgpu_allocated, dev->drmcg_props.lgpu_capacity); + break; + default: + break; + } +} + static struct drm_driver kms_driver = { .driver_features = DRIVER_USE_AGP | DRIVER_ATOMIC | @@ -1438,6 +1458,7 @@ static struct drm_driver kms_driver = { .gem_prime_mmap = amdgpu_gem_prime_mmap, .drmcg_custom_init = amdgpu_drmcg_custom_init, + .drmcg_limit_updated = amdgpu_drmcg_limit_updated, .name = DRIVER_NAME, .desc = DRIVER_DESC, diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c index 138c70454e2b..fa765b803f97 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c @@ -450,6 +450,12 @@ static int kfd_ioctl_set_cu_mask(struct file *filp, struct kfd_process *p, return -EFAULT; } + if (!pqm_drmcg_lgpu_validate(p, args->queue_id, properties.cu_mask, cu_mask_size)) { + pr_debug("CU mask not permitted by DRM Cgroup"); + kfree(properties.cu_mask); + return -EACCES; + } + mutex_lock(&p->mutex); retval = pqm_set_cu_mask(&p->pqm, args->queue_id, &properties); diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h index 8b0eee5b3521..88881bec7550 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h +++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h @@ -1038,6 +1038,9 @@ int pqm_get_wave_state(struct process_queue_manager *pqm, u32 *ctl_stack_used_size, u32 *save_area_used_size); +bool pqm_drmcg_lgpu_validate(struct kfd_process *p, int qid, u32 *cu_mask, + unsigned int cu_mask_size); + int amdkfd_fence_wait_timeout(unsigned int *fence_addr, unsigned int fence_value, unsigned int timeout_ms); diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c index 7e6c3ee82f5b..a896de290307 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c @@ -23,9 +23,11 @@ #include #include +#include #include "kfd_device_queue_manager.h" #include "kfd_priv.h" #include "kfd_kernel_queue.h" +#include "amdgpu.h" #include "amdgpu_amdkfd.h" static inline struct process_queue_node *get_queue_by_qid( @@ -167,6 +169,7 @@ static int create_cp_queue(struct process_queue_manager *pqm, struct queue_properties *q_properties, struct file *f, unsigned int qid) { + struct drmcg *drmcg; int retval; /* Doorbell initialized in user space*/ @@ -180,6 +183,36 @@ static int create_cp_queue(struct process_queue_manager *pqm, if (retval != 0) return retval; + + drmcg = drmcg_get(pqm->process->lead_thread); + if (drmcg) { + struct amdgpu_device *adev; + struct drmcg_device_resource *ddr; + int mask_size; + u32 *mask; + + adev = (struct amdgpu_device *) dev->kgd; + + mask_size = adev->ddev->drmcg_props.lgpu_capacity; + mask = kzalloc(sizeof(u32) * round_up(mask_size, 32), + GFP_KERNEL); + + if (!mask) { + drmcg_put(drmcg); + uninit_queue(*q); + return -ENOMEM; + } + + ddr = drmcg->dev_resources[adev->ddev->primary->index]; + + bitmap_to_arr32(mask, ddr->lgpu_allocated, mask_size); + + (*q)->properties.cu_mask_count = mask_size; + (*q)->properties.cu_mask = mask; + + drmcg_put(drmcg); + } + (*q)->device = dev; (*q)->process = pqm->process; @@ -495,6 +528,113 @@ int pqm_get_wave_state(struct process_queue_manager *pqm, save_area_used_size); } +bool pqm_drmcg_lgpu_validate(struct kfd_process *p, int qid, u32 *cu_mask, + unsigned int cu_mask_size) +{ + DECLARE_BITMAP(curr_mask, MAX_DRMCG_LGPU_CAPACITY); + struct drmcg_device_resource *ddr; + struct process_queue_node *pqn; + struct amdgpu_device *adev; + struct drmcg *drmcg; + bool result; + + if (cu_mask_size > MAX_DRMCG_LGPU_CAPACITY) + return false; + + bitmap_from_arr32(curr_mask, cu_mask, cu_mask_size); + + pqn = get_queue_by_qid(&p->pqm, qid); + if (!pqn) + return false; + + adev = (struct amdgpu_device *)pqn->q->device->kgd; + + drmcg = drmcg_get(p->lead_thread); + ddr = drmcg->dev_resources[adev->ddev->primary->index]; + + if (bitmap_subset(curr_mask, ddr->lgpu_allocated, + MAX_DRMCG_LGPU_CAPACITY)) + result = true; + else + result = false; + + drmcg_put(drmcg); + + return result; +} + +int amdgpu_amdkfd_update_cu_mask_for_process(struct task_struct *task, + struct amdgpu_device *adev, unsigned long *lgpu_bm, + unsigned int lgpu_bm_size) +{ + struct kfd_dev *kdev = adev->kfd.dev; + struct process_queue_node *pqn; + struct kfd_process *kfdproc; + size_t size_in_bytes; + u32 *cu_mask; + int rc = 0; + + if ((lgpu_bm_size % 32) != 0) { + pr_warn("lgpu_bm_size %d must be a multiple of 32", + lgpu_bm_size); + return -EINVAL; + } + + kfdproc = kfd_get_process(task); + + if (IS_ERR(kfdproc)) + return -ESRCH; + + size_in_bytes = sizeof(u32) * round_up(lgpu_bm_size, 32); + + mutex_lock(&kfdproc->mutex); + list_for_each_entry(pqn, &kfdproc->pqm.queues, process_queue_list) { + if (pqn->q && pqn->q->device == kdev) { + /* update cu_mask accordingly */ + cu_mask = kzalloc(size_in_bytes, GFP_KERNEL); + if (!cu_mask) { + rc = -ENOMEM; + break; + } + + if (pqn->q->properties.cu_mask) { + DECLARE_BITMAP(curr_mask, + MAX_DRMCG_LGPU_CAPACITY); + + if (pqn->q->properties.cu_mask_count > + lgpu_bm_size) { + rc = -EINVAL; + kfree(cu_mask); + break; + } + + bitmap_from_arr32(curr_mask, + pqn->q->properties.cu_mask, + pqn->q->properties.cu_mask_count); + + bitmap_and(curr_mask, curr_mask, lgpu_bm, + lgpu_bm_size); + + bitmap_to_arr32(cu_mask, curr_mask, + lgpu_bm_size); + + kfree(curr_mask); + } else + bitmap_to_arr32(cu_mask, lgpu_bm, + lgpu_bm_size); + + pqn->q->properties.cu_mask = cu_mask; + pqn->q->properties.cu_mask_count = lgpu_bm_size; + + rc = pqn->q->device->dqm->ops.update_queue( + pqn->q->device->dqm, pqn->q); + } + } + mutex_unlock(&kfdproc->mutex); + + return rc; +} + #if defined(CONFIG_DEBUG_FS) int pqm_debugfs_mqds(struct seq_file *m, void *data)