From patchwork Wed Jul 20 07:36:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Paneer Selvam, Arunpravin" X-Patchwork-Id: 12923596 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 7D883C43334 for ; Wed, 20 Jul 2022 07:41:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6ECCB10F89D; Wed, 20 Jul 2022 07:41:06 +0000 (UTC) Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2078.outbound.protection.outlook.com [40.107.101.78]) by gabe.freedesktop.org (Postfix) with ESMTPS id 01CCF112DFE; Wed, 20 Jul 2022 07:41:01 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EX4RjaRurYs6MH1Nh4/7oJ66/kOtRP6qV5COCrm79IBPPVv0+JE9EK++GCrjk6zpCYuqIpFAZQ64RutU43/DrgX3o4zKSO/APZTQonlVJ6qyAbIrUux8ciWGsZWeHsgZH13W8y0eLXPWKo9a0vK2kHSSXD+5iO9NynxZFoni5Ru84OCB/ZM1U5OG9AM0t6+ZqA/8QxooEN/I7e6tXRRYg1JTWI+qx4o7ghJgTZ2H0/PwgNZ8eNxcrk5hvHh/Y4JRFFKR7GBZ9oMAr1PdupVh0b53wij+Z5XknLt/nPCQ5IRjog6q3xEe8ZiSW9kBAewaDEyQ9xBM+rct2P9fnVh+xg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7OPPj3QAAHn20AYoFGDi7yilZrCG8NFC7DOWFrAYBKg=; b=W9us5pTAgWxWsFizC9XFl+Di0huXawAtMFqJ5L/d4Ewa3rNv1pZqqe0xlAZlb0VzvJNrWTUdGSml+6VGQ9HsDMyYZLY7ubV1FyQX4Wqb3CkxTWjLBwu4neR8/Sv1vYGNQ0wkuTUo1O5Jau5Nae7wa2tzExU8PThQ9qF35UJuRlveNBF8U216gp4Z8sYEtYsqYvjKbysZG8RBt/gE8X5e3fsqJ+3FJix+JL/bPv0Hs9q7MyOjFBDz5crfXAV90gtaXODw41Vh9yqesz2FXvIcNlz5OMy4cyUyX0HAL5Q7uIbAmgXPnOp5dnsM3Nx1heKZlL2kJE8k7+fiPL7ZsNVVKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.freedesktop.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7OPPj3QAAHn20AYoFGDi7yilZrCG8NFC7DOWFrAYBKg=; b=3fuSlNZSH4PS9QAiEnQ0qIPV7SEA8JYfJ53Ssu66kWl/WRvwYCTw8hBhj+ttpVkmVOiKO3mPAn9JsDNA1Ioe1xdKq8IS2GjWJJABivIbXOD6mr0+1I03BxM22q0s3+cR791ukxNPZ1SUtzOiTolsorciTN6JUI/uPtBhXg2Ofi4= Received: from DM5PR08CA0040.namprd08.prod.outlook.com (2603:10b6:4:60::29) by MWHPR12MB1568.namprd12.prod.outlook.com (2603:10b6:301:e::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.20; Wed, 20 Jul 2022 07:40:58 +0000 Received: from DM6NAM11FT054.eop-nam11.prod.protection.outlook.com (2603:10b6:4:60:cafe::a5) by DM5PR08CA0040.outlook.office365.com (2603:10b6:4:60::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.19 via Frontend Transport; Wed, 20 Jul 2022 07:40:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT054.mail.protection.outlook.com (10.13.173.95) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5458.17 via Frontend Transport; Wed, 20 Jul 2022 07:40:57 +0000 Received: from amd-X570-AORUS-ELITE.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Wed, 20 Jul 2022 02:40:54 -0500 From: Arunpravin Paneer Selvam To: , , , Subject: [PATCH 1/4] drm/ttm: add new intersect callback to res mgr Date: Wed, 20 Jul 2022 00:36:03 -0700 Message-ID: <20220720073606.3885-1-Arunpravin.PaneerSelvam@amd.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2b6adc26-fd25-42d3-9bbc-08da6a232f8d X-MS-TrafficTypeDiagnostic: MWHPR12MB1568:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4LvSus88MGf++mju7nqN6n6Qe1P3Dw+7INdRq/o33nu6Z9MW6eFhhjwPzSypZooGGBVpouxjxZh2+59vfqV3TRXA0dl0U+WClpZJ4PdXJOD3KehGmOhe7mSPIz+pSPoi8n8+DQAApgfJp+8pGO5KWDfLH4SaahF3cmlYcQ50M2/Bn2OP70k8QYj0WzfPT47tllpvdok16laND9YNJ3pcjUektF3c8rCZBi9NeTaGXzgY0vtE663sCPt1syd7RMyNuh/88Hwri0NiqH39UHI8OgJZwZjJFcznCf7EXLrYRHJN5GDMokC9TE8gi2cMJn2SsJj/yrIbKTjNXZ9N52E35bqNBdAEDYyfXWI0tLjXKyrvUq4zPqgn+rRbtPMXl0WBJMRNOmm/Wn5eyYSdJ3JNYIHVcO1Ou20fXda9mwtMWK4di2y3xpWVfpHdb+PEClSMc1s/hloOAoPrtY6e/lJ8hJlwLJ6ns/yMudLC7WKca3b/1TG92kNiBhj/JQHeEygwcNbWiZWvDCV/tgPSSeQkmWL7n1nYG/CpkheBPadk/DosPoi/s5pGki/lMg9Fiec1na5EHoJTtfTIzcM9MikB9MqNhSqma0qLKjBQnZIFlFfwRJrxJnMLBFrPXPFXbtTUR2i6jlmWjeDPUg+LTbKuONW0ZOCeewkwEsbGf4K+t7F6aDK1Ahl4PfpD4JNKB0/UDdNNuXXPacK+j48vKLqn9/XTfjIEpoUCYyMFUtOk/+1gUtUYsDSRn/2xrbsyG/0GJ38BzXJjPUQWkRo26FMrjxwzaje+bPGFaBzs0b8hI3DKhQKU5cdvDyKn7CK/R0KF7WFQN6OB33mHdQgXqT4B8Q== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230016)(4636009)(346002)(39860400002)(376002)(136003)(396003)(36840700001)(40470700004)(46966006)(81166007)(82310400005)(7696005)(83380400001)(47076005)(26005)(426003)(6666004)(2906002)(41300700001)(336012)(1076003)(2616005)(478600001)(36756003)(16526019)(54906003)(40460700003)(186003)(40480700001)(110136005)(5660300002)(70206006)(316002)(82740400003)(86362001)(70586007)(356005)(8676002)(4326008)(36860700001)(8936002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2022 07:40:57.9462 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2b6adc26-fd25-42d3-9bbc-08da6a232f8d 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT054.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1568 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alexander.deucher@amd.com, Arunpravin Paneer Selvam , christian.koenig@amd.com, matthew.auld@intel.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" - This allows the resource manager to handle intersection of placement and resources. - Add callback function to amdgpu driver module fetching start offset from buddy allocator. Signed-off-by: Christian König Signed-off-by: Arunpravin Paneer Selvam --- drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c | 19 +++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 33 ++++++++++++++++++++ drivers/gpu/drm/ttm/ttm_range_manager.c | 17 ++++++++++ drivers/gpu/drm/ttm/ttm_resource.c | 28 +++++++++++++++++ include/drm/ttm/ttm_resource.h | 20 ++++++++++++ 5 files changed, 117 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c index 8c6b2284cf56..727c80134aa6 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c @@ -204,6 +204,24 @@ void amdgpu_gtt_mgr_recover(struct amdgpu_gtt_mgr *mgr) amdgpu_gart_invalidate_tlb(adev); } +/** + * amdgpu_gtt_mgr_intersect - test for intersection + * + * @man: Our manager object + * @res: The resource to test + * @place: The place for the new allocation + * @size: The size of the new allocation + * + * Simplified intersection test, only interesting if we need GART or not. + */ +static bool amdgpu_gtt_mgr_intersect(struct ttm_resource_manager *man, + struct ttm_resource *res, + const struct ttm_place *place, + size_t size) +{ + return !place->lpfn || amdgpu_gtt_mgr_has_gart_addr(res); +} + /** * amdgpu_gtt_mgr_debug - dump VRAM table * @@ -225,6 +243,7 @@ static void amdgpu_gtt_mgr_debug(struct ttm_resource_manager *man, static const struct ttm_resource_manager_func amdgpu_gtt_mgr_func = { .alloc = amdgpu_gtt_mgr_new, .free = amdgpu_gtt_mgr_del, + .intersect = amdgpu_gtt_mgr_intersect, .debug = amdgpu_gtt_mgr_debug }; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c index 28ec5f8ac1c1..ed0d10fe0b88 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c @@ -720,6 +720,38 @@ uint64_t amdgpu_vram_mgr_vis_usage(struct amdgpu_vram_mgr *mgr) return atomic64_read(&mgr->vis_usage); } +/** + * amdgpu_vram_mgr_intersect - test each drm buddy block for intersection + * + * @man: TTM memory type manager + * @res: The resource to test + * @place: The place to test against + * @size: Size of the new allocation + * + * Test each drm buddy block for intersection for eviction decision. + */ +static bool amdgpu_vram_mgr_intersect(struct ttm_resource_manager *man, + struct ttm_resource *res, + const struct ttm_place *place, + size_t size) +{ + struct amdgpu_vram_mgr_resource *mgr = to_amdgpu_vram_mgr_resource(res); + struct list_head *list = &mgr->blocks; + struct drm_buddy_block *block; + u32 num_pages = PFN_UP(size); + u32 start; + + /* Check each drm buddy block individually */ + list_for_each_entry(block, list, link) { + start = amdgpu_vram_mgr_block_start(block) >> PAGE_SHIFT; + if (start < place->fpfn || + (place->lpfn && (start + num_pages) > place->lpfn)) + return false; + } + + return true; +} + /** * amdgpu_vram_mgr_debug - dump VRAM table * @@ -753,6 +785,7 @@ static void amdgpu_vram_mgr_debug(struct ttm_resource_manager *man, static const struct ttm_resource_manager_func amdgpu_vram_mgr_func = { .alloc = amdgpu_vram_mgr_new, .free = amdgpu_vram_mgr_del, + .intersect = amdgpu_vram_mgr_intersect, .debug = amdgpu_vram_mgr_debug }; diff --git a/drivers/gpu/drm/ttm/ttm_range_manager.c b/drivers/gpu/drm/ttm/ttm_range_manager.c index d91666721dc6..bf5de1978ead 100644 --- a/drivers/gpu/drm/ttm/ttm_range_manager.c +++ b/drivers/gpu/drm/ttm/ttm_range_manager.c @@ -113,6 +113,22 @@ static void ttm_range_man_free(struct ttm_resource_manager *man, kfree(node); } +static bool ttm_range_man_intersect(struct ttm_resource_manager *man, + struct ttm_resource *res, + const struct ttm_place *place, + size_t size) +{ + struct drm_mm_node *node = &to_ttm_range_mgr_node(res)->mm_nodes[0]; + u32 num_pages = PFN_UP(size); + + /* Don't evict BOs outside of the requested placement range */ + if (place->fpfn >= (node->start + num_pages) || + (place->lpfn && place->lpfn <= node->start)) + return false; + + return true; +} + static void ttm_range_man_debug(struct ttm_resource_manager *man, struct drm_printer *printer) { @@ -126,6 +142,7 @@ static void ttm_range_man_debug(struct ttm_resource_manager *man, static const struct ttm_resource_manager_func ttm_range_manager_func = { .alloc = ttm_range_man_alloc, .free = ttm_range_man_free, + .intersect = ttm_range_man_intersect, .debug = ttm_range_man_debug }; diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c index 20f9adcc3235..84c21f92b422 100644 --- a/drivers/gpu/drm/ttm/ttm_resource.c +++ b/drivers/gpu/drm/ttm/ttm_resource.c @@ -253,6 +253,34 @@ void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource **res) } EXPORT_SYMBOL(ttm_resource_free); +/** + * ttm_resource_intersect - test for intersection + * + * @bdev: TTM device structure + * @res: The resource to test + * @place: The placement to test + * @size: How many bytes the new allocation needs. + * + * Test if @res intersects with @place and @size. Used for testing if evictions + * are valueable or not. + */ +bool ttm_resource_intersect(struct ttm_device *bdev, + struct ttm_resource *res, + const struct ttm_place *place, + size_t size) +{ + struct ttm_resource_manager *man; + + if (!res) + return false; + + man = ttm_manager_type(bdev, res->mem_type); + if (!place || !man->func->intersect) + return true; + + return man->func->intersect(man, res, place, size); +} + static bool ttm_resource_places_compat(struct ttm_resource *res, const struct ttm_place *places, unsigned num_placement) diff --git a/include/drm/ttm/ttm_resource.h b/include/drm/ttm/ttm_resource.h index ca89a48c2460..3f3ab2a8a69e 100644 --- a/include/drm/ttm/ttm_resource.h +++ b/include/drm/ttm/ttm_resource.h @@ -88,6 +88,22 @@ struct ttm_resource_manager_func { void (*free)(struct ttm_resource_manager *man, struct ttm_resource *res); + /** + * struct ttm_resource_manager_func member intersect + * + * @man: Pointer to a memory type manager. + * @res: Pointer to a struct ttm_resource to be checked. + * @place: Placement to check against. + * @size: Size of the check. + * + * Test if @res intersects with @place + @size. Used to judge if + * evictions are valueable or not. + */ + bool (*intersect)(struct ttm_resource_manager *man, + struct ttm_resource *res, + const struct ttm_place *place, + size_t size); + /** * struct ttm_resource_manager_func member debug * @@ -329,6 +345,10 @@ int ttm_resource_alloc(struct ttm_buffer_object *bo, const struct ttm_place *place, struct ttm_resource **res); void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource **res); +bool ttm_resource_intersect(struct ttm_device *bdev, + struct ttm_resource *res, + const struct ttm_place *place, + size_t size); bool ttm_resource_compat(struct ttm_resource *res, struct ttm_placement *placement); void ttm_resource_set_bo(struct ttm_resource *res, From patchwork Wed Jul 20 07:36:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Paneer Selvam, Arunpravin" X-Patchwork-Id: 12923598 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 220E8C43334 for ; Wed, 20 Jul 2022 07:41:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0160210EEFB; Wed, 20 Jul 2022 07:41:10 +0000 (UTC) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2083.outbound.protection.outlook.com [40.107.220.83]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5E87E10F32F; Wed, 20 Jul 2022 07:41:05 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lSNKfCe0eMACy4Mvzq58CyudSCP3/vZIrxzbQ9F9Tz46I5pR8RusFvth7uHL3tNONVwFjUQKQqtqNZIwQYMVMQj/74RgIEwTG2GpQhT/H8Vgj6tWDhj+GdkJz4jXCEraGeo70jPMzNOME36cddKSoU5uXbGN5hQg37/II4hrD3ZQ2V+rtTfocU3gbNyP6F537mtUUfRFrWND8MjNkgfWQpKx+FyEhU+yds3ksc6KN4gHJMnFy6uh3xkmck4SLOOtaRY54VMjReDZVvqpaux4awl6CyzAQ494iBaob+7X00yHSluBXHD79mcNPoS7axoc23qgpA33kP8LDYZenFVOtQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ByHo5yDs5s1Imb3nJc7NLGwDstL+YMUwak6J3JkGHLM=; b=cTEro17bMX2+Qj4eudoLftGwgEYmSVgYkUsuQ+kcNOSV+r/cqREEbCUtIPVyInlkk9QNMVBTHVWWb4don+NLCWQcpTjDkti/sHWPJazn6NVh/FmZ2LGBnCSmJkdBRGzHVzwyPEJa+vYwN1JTbK+lKqhuE5jRkrjgsNxJY1IxSR0ucawyzvzWjyIO6yT0F6RYm9MqPDCBL6hnIItvDEwN3FRVnltIjdHnflzI+9NQmYSeGNp6NoDkfVHm7VqYWSD+uwLQ2hfdPMOjnzNcThjTAA7A11kXf3aaS/SpclFM1MhDdmmIRv/YUtJ7o/hLTlGE1HsPSRhKxETcaSnw4OT1hA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.freedesktop.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ByHo5yDs5s1Imb3nJc7NLGwDstL+YMUwak6J3JkGHLM=; b=x9IBp8DFzpYR+yuGlyOKTHJ6KmFi1Ou9sGbSWXMenV1/laPSKCTaXOvMTjSNQyqE+B/y5Tq7M3zyZQGHViNahwOgGcjlf1dkOC3lm07+D0GcNE8WfzJai4uaGOnUJNQciYT//4BZ1hlDlUYwXHlXgnZZFfePnhmm+Czk2ENq9tI= Received: from DM6PR08CA0033.namprd08.prod.outlook.com (2603:10b6:5:80::46) by MWHPR12MB1405.namprd12.prod.outlook.com (2603:10b6:300:13::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.21; Wed, 20 Jul 2022 07:41:01 +0000 Received: from DM6NAM11FT014.eop-nam11.prod.protection.outlook.com (2603:10b6:5:80:cafe::a2) by DM6PR08CA0033.outlook.office365.com (2603:10b6:5:80::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.17 via Frontend Transport; Wed, 20 Jul 2022 07:41:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT014.mail.protection.outlook.com (10.13.173.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5458.17 via Frontend Transport; Wed, 20 Jul 2022 07:41:00 +0000 Received: from amd-X570-AORUS-ELITE.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Wed, 20 Jul 2022 02:40:57 -0500 From: Arunpravin Paneer Selvam To: , , , Subject: [PATCH 2/4] drm/i915: Add intersect callback function Date: Wed, 20 Jul 2022 00:36:04 -0700 Message-ID: <20220720073606.3885-2-Arunpravin.PaneerSelvam@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220720073606.3885-1-Arunpravin.PaneerSelvam@amd.com> References: <20220720073606.3885-1-Arunpravin.PaneerSelvam@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bbf8bd53-7ee9-428a-6fb2-08da6a23311c X-MS-TrafficTypeDiagnostic: MWHPR12MB1405:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bfTOKtfM3o0IIBVqpLbhE1oBLdNsR7DeNwdNEC/JN1pF9VcLxUonnt7X5D2AcDPzQNwy0WrbyT6t2HMptYWUGnLbf+u7ZU0+ISWmz1E2ElFx6Uf91g72dLInnhyFqHoD7NxyzNpmr3/CFQYGSJv7vjG/mAuKuK9W0Ms2VEYPycMfwUF0Pa+KNEDiKp4OHHySTh5kbtXhHuf86UVF2TE7fIDnyrhkhEYNtaCr8jTRQSsCmZbbd2qPFMv5nhlD2YtkunlDwRuf0BE7w7ucXSQEL1OLl3TGP9NuQclt4vHuCnYtvMIeepcmY6pQMK2iXXdVYBcOcn66nUugxGgJEeVUe6+5T+USr15g/c5lHD2DHlZQTUYsdymd9EpmSRaq3XGTyXGHm8sgqSIRqGBLKV100yv9lUri0zPS5SuJffC6I7mRwvE3QrhTFImC1shY7JmmJKlpDCuOc2T1FoZUir4agt9WlaMemhePnsYRhxvc/zcrK5/Kt6A3KC36ZQjO3MBLV3OuDlyxxywWnLAdwXlHXX+b8VUIDvS+ykZOeFlIiRwnHpOy35dM60ZPS2FQhTRoOtcq8ArYsigqmpVeqYldO5jIVM3mwA5bwwH+vZ/sjvAVvfpuC/0TErtSIxYzA7HWgAbvG9Wcdc4i7RPyqAI8Q36/4if/ngrws7txrl4+826qEcSUFTEHwb7EbP1BmpS0I+UdVEN6SEk+WRZYxNzoaO83rEhY3HJQ+wwjNOxdLd+CmJ/rTVzB5e49J78RI9Ju5VQATksT8kFDm8i/Mb575zXOtrySrDS/5pHHVqB7mdZX6V80kpam5x7+qwqc0ocYSisSy9P/u4KpJ65NVOXETA== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230016)(4636009)(39860400002)(346002)(376002)(396003)(136003)(40470700004)(46966006)(36840700001)(54906003)(110136005)(16526019)(6666004)(36860700001)(47076005)(41300700001)(4326008)(7696005)(316002)(1076003)(2616005)(186003)(8676002)(5660300002)(426003)(336012)(26005)(86362001)(36756003)(8936002)(70586007)(70206006)(356005)(2906002)(81166007)(83380400001)(478600001)(82310400005)(82740400003)(40460700003)(40480700001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2022 07:41:00.5599 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bbf8bd53-7ee9-428a-6fb2-08da6a23311c 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT014.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1405 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alexander.deucher@amd.com, Arunpravin Paneer Selvam , christian.koenig@amd.com, matthew.auld@intel.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add a new intersect callback function fetching start offset from backend drm buddy allocator. Signed-off-by: Christian König Signed-off-by: Arunpravin Paneer Selvam --- drivers/gpu/drm/i915/i915_ttm_buddy_manager.c | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c index a5109548abc0..30bb8ade67a9 100644 --- a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c +++ b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c @@ -178,6 +178,28 @@ static void i915_ttm_buddy_man_free(struct ttm_resource_manager *man, kfree(bman_res); } +static bool i915_ttm_buddy_man_intersect(struct ttm_resource_manager *man, + struct ttm_resource *res, + const struct ttm_place *place, + size_t size) +{ + struct i915_ttm_buddy_resource *bman_res = to_ttm_buddy_resource(res); + struct list_head *list = &bman_res->blocks; + struct drm_buddy_block *block; + u32 num_pages = PFN_UP(size); + u32 start; + + /* Check each drm buddy block individually */ + list_for_each_entry(block, list, link) { + start = drm_buddy_block_offset(block) >> PAGE_SHIFT; + if (start < place->fpfn || + (place->lpfn && (start + num_pages) > place->lpfn)) + return false; + } + + return true; +} + static void i915_ttm_buddy_man_debug(struct ttm_resource_manager *man, struct drm_printer *printer) { @@ -205,6 +227,7 @@ static void i915_ttm_buddy_man_debug(struct ttm_resource_manager *man, static const struct ttm_resource_manager_func i915_ttm_buddy_manager_func = { .alloc = i915_ttm_buddy_man_alloc, .free = i915_ttm_buddy_man_free, + .intersect = i915_ttm_buddy_man_intersect, .debug = i915_ttm_buddy_man_debug, }; From patchwork Wed Jul 20 07:36:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Paneer Selvam, Arunpravin" X-Patchwork-Id: 12923597 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 2DB19C43334 for ; Wed, 20 Jul 2022 07:41:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 019EA10F123; Wed, 20 Jul 2022 07:41:09 +0000 (UTC) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2083.outbound.protection.outlook.com [40.107.220.83]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8D5E710FAA0; Wed, 20 Jul 2022 07:41:05 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XZ2Yl0cbqu3qrsJT1DvkQvuBIgUJ0FS5gcRGtwwhixjGQlm4VERVlZuGnuadZCTwMU4E7r5cMVAEA7cTR8lbqrrcvWxNlecYj/ESjf9InjYi5el7hCPTy0C0AesWLWrBZi7IEdx/QsbozakFSLiQA6ME42gTbMXqtCS//Sv4tx4xfc8Vb30Andl2DzEvC/OWI80rMG52kDQhad1o1YqhbaTGVaAEEXzDDUXBEK0wqTkh6ZAjDocr1j3fm4CmMszWwkFfwWbAQa4/NbpKR/YQnhkv4QLmTlPCNvQkpxp+3Nx3A4kZjADSd+vUzO/p6AhL0wSIB0h1INxVPgRXiNorPw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1DurLB9Bv3nwQyfFdCzAS9Rw3FnvqJtVeioN2PKCUOg=; b=eTLV8uwHiAmtl1Qy36ot1R0eXIWNrNFl9hYaq5JD1CaMAZc2R4X84uJHutX2SyoWdzQpi0Vao/z2B0+TaiqUjXxL0UHQ2JtPi3G3rWf0TV+YoQWbObLpgg3rhoUJ6cFZhC/MCngFT3djrY1F7vXlzrNnbm1wYVFkWgaXKvB9RWLaqarCAU7urscYSZhJMcbR/zA1oNfsZ4ohZHxQp6YieWth0RvRYyb9Fk4479SVKd56+XYxjFld52q0E+vZB4QiQax7d2JPGafm/cvcdIt4rf1SpUe/E1Q/P4z7reia1Jx/h019SJhG8HQgXGVBqnBEpCqQem5icvX95xdUorxnhg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.freedesktop.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1DurLB9Bv3nwQyfFdCzAS9Rw3FnvqJtVeioN2PKCUOg=; b=SWwIbcAruovQ61gA5sCDOy98oD6tXL4CauWj18NkXLUSqBFrBwMkzmxvBBwYosr/kfNlwPL2xVmsAfrN6D9j2/mUDESQY5MazOfH5Q5ICXh2rPA66rcXg+B7RmMQCofmN4U961J1kgOAIWyDgAsWC+Uec2T08lq7fTuek3T0IPw= Received: from DM6PR08CA0033.namprd08.prod.outlook.com (2603:10b6:5:80::46) by MWHPR12MB1405.namprd12.prod.outlook.com (2603:10b6:300:13::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.21; Wed, 20 Jul 2022 07:41:04 +0000 Received: from DM6NAM11FT014.eop-nam11.prod.protection.outlook.com (2603:10b6:5:80:cafe::a2) by DM6PR08CA0033.outlook.office365.com (2603:10b6:5:80::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.17 via Frontend Transport; Wed, 20 Jul 2022 07:41:03 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT014.mail.protection.outlook.com (10.13.173.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5458.17 via Frontend Transport; Wed, 20 Jul 2022 07:41:03 +0000 Received: from amd-X570-AORUS-ELITE.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Wed, 20 Jul 2022 02:41:00 -0500 From: Arunpravin Paneer Selvam To: , , , Subject: [PATCH 3/4] drm/nouveau: Add intersect callback function Date: Wed, 20 Jul 2022 00:36:05 -0700 Message-ID: <20220720073606.3885-3-Arunpravin.PaneerSelvam@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220720073606.3885-1-Arunpravin.PaneerSelvam@amd.com> References: <20220720073606.3885-1-Arunpravin.PaneerSelvam@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fac8f165-943f-4f53-dc5b-08da6a233315 X-MS-TrafficTypeDiagnostic: MWHPR12MB1405:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZAlJoKoctne+E7GwddBDI6Kshh5QQ058KC7rigLscgUwrmIGpTvx6ePexkPE1SPuDQzMZ3s/L3O4UsUoGs58qPHOX879yr/c0PvXVMt2tFidR/6SzKuMwHaNm4XagC2225oW6sHijsO8JQ7M9oK31vMIXlLB0ItTDhVwShlHGec1GpWxX6UGFlkuWK11ywZru2PuUoBOo8dmFtM5p2mWWlsviMJAUY8e2WOvpGpekrwtSMwk85D+i4P8/aRywLVMr4KJFWjsWEeA/0a0iLjSe8X7owXicN+SgKjASevCNkVMYEkCBXL6Dj++rc0vZsSFCaMdVw6nsskt35thIPA4q18a780IL+5HzTdp49N1g0BjPHSWCM0YmVabRnFX7fTiS84k4IH0ouOjXIbh26I5H1d6plIeq/QpVz8rTBw06bG4SRhx3opy3qMsbZ+gMhcro99g7lQ0kBjXLDM9tfEi85lmchZPvqPxFYNhwWwkQ+kFJbf2Dd8tBfD21CUyU/L2g/Pc2WpA0SK2m/F6YEx9fhopUhkD9qJrMKPoLYbbOExFEN9dnRNArxk512xQ2sjHpubK+pMWCZ/ZukUF9/HfWyc0PiJ1FOzitTfs99akb3yglLDd7vG52vYVi77A8ypFUeBDKpLECkwL83gnOLaXgGj4y6TgNJKPy2TG+wzdkh7ANwY+Tmh2sUeJbcmE1PdHcp+nM78ZqELGglQKl29eTRF2p2L0jJVG3jGLndmp9D24REHgYFvp7JUmiPJAb8Ea/EbikMoszHhvbAcBYf+7nXbnxTtcYJticftWyzrk6iKZV5ppk8MMusQoC1GSKRA+1Mfj2XS5dZsACIzXKzbk+Q== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230016)(4636009)(39860400002)(346002)(376002)(396003)(136003)(40470700004)(46966006)(36840700001)(54906003)(110136005)(16526019)(36860700001)(47076005)(41300700001)(4326008)(7696005)(316002)(1076003)(2616005)(186003)(8676002)(5660300002)(426003)(336012)(26005)(86362001)(36756003)(8936002)(70586007)(70206006)(356005)(2906002)(81166007)(83380400001)(478600001)(82310400005)(82740400003)(40460700003)(40480700001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2022 07:41:03.8723 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fac8f165-943f-4f53-dc5b-08da6a233315 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT014.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1405 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alexander.deucher@amd.com, Arunpravin Paneer Selvam , christian.koenig@amd.com, matthew.auld@intel.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add a new intersect callback function fetching the start offset from struct ttm_resource. Signed-off-by: Christian König Signed-off-by: Arunpravin Paneer Selvam --- drivers/gpu/drm/nouveau/nouveau_mem.c | 15 +++++++++++++++ drivers/gpu/drm/nouveau/nouveau_mem.h | 3 +++ drivers/gpu/drm/nouveau/nouveau_ttm.c | 12 ++++++++++++ 3 files changed, 30 insertions(+) diff --git a/drivers/gpu/drm/nouveau/nouveau_mem.c b/drivers/gpu/drm/nouveau/nouveau_mem.c index 2e517cdc24c9..b8a773f03c32 100644 --- a/drivers/gpu/drm/nouveau/nouveau_mem.c +++ b/drivers/gpu/drm/nouveau/nouveau_mem.c @@ -187,3 +187,18 @@ nouveau_mem_new(struct nouveau_cli *cli, u8 kind, u8 comp, *res = &mem->base; return 0; } + +bool +nouveau_mem_intersect(struct ttm_resource *res, + const struct ttm_place *place, + size_t size) +{ + u32 num_pages = PFN_UP(size); + + /* Don't evict BOs outside of the requested placement range */ + if (place->fpfn >= (res->start + num_pages) || + (place->lpfn && place->lpfn <= res->start)) + return false; + + return true; +} diff --git a/drivers/gpu/drm/nouveau/nouveau_mem.h b/drivers/gpu/drm/nouveau/nouveau_mem.h index 325551eba5cd..349fefe48e3c 100644 --- a/drivers/gpu/drm/nouveau/nouveau_mem.h +++ b/drivers/gpu/drm/nouveau/nouveau_mem.h @@ -25,6 +25,9 @@ int nouveau_mem_new(struct nouveau_cli *, u8 kind, u8 comp, struct ttm_resource **); void nouveau_mem_del(struct ttm_resource_manager *man, struct ttm_resource *); +bool nouveau_mem_intersect(struct ttm_resource *res, + const struct ttm_place *place, + size_t size); int nouveau_mem_vram(struct ttm_resource *, bool contig, u8 page); int nouveau_mem_host(struct ttm_resource *, struct ttm_tt *); void nouveau_mem_fini(struct nouveau_mem *); diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c index 85f1f5a0fe5d..46afd57008dd 100644 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c @@ -42,6 +42,15 @@ nouveau_manager_del(struct ttm_resource_manager *man, nouveau_mem_del(man, reg); } +static bool +nouveau_manager_intersect(struct ttm_resource_manager *man, + struct ttm_resource *res, + const struct ttm_place *place, + size_t size) +{ + return nouveau_mem_intersect(res, place, size); +} + static int nouveau_vram_manager_new(struct ttm_resource_manager *man, struct ttm_buffer_object *bo, @@ -73,6 +82,7 @@ nouveau_vram_manager_new(struct ttm_resource_manager *man, const struct ttm_resource_manager_func nouveau_vram_manager = { .alloc = nouveau_vram_manager_new, .free = nouveau_manager_del, + .intersect = nouveau_manager_intersect, }; static int @@ -97,6 +107,7 @@ nouveau_gart_manager_new(struct ttm_resource_manager *man, const struct ttm_resource_manager_func nouveau_gart_manager = { .alloc = nouveau_gart_manager_new, .free = nouveau_manager_del, + .intersect = nouveau_manager_intersect, }; static int @@ -130,6 +141,7 @@ nv04_gart_manager_new(struct ttm_resource_manager *man, const struct ttm_resource_manager_func nv04_gart_manager = { .alloc = nv04_gart_manager_new, .free = nouveau_manager_del, + .intersect = nouveau_manager_intersect, }; static int From patchwork Wed Jul 20 07:36:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Paneer Selvam, Arunpravin" X-Patchwork-Id: 12923599 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id DA4BBC433EF for ; Wed, 20 Jul 2022 07:41:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5DBC9113A52; Wed, 20 Jul 2022 07:41:11 +0000 (UTC) Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1anam02on2084.outbound.protection.outlook.com [40.107.96.84]) by gabe.freedesktop.org (Postfix) with ESMTPS id BB01E10EEFB; Wed, 20 Jul 2022 07:41:08 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ip056n1/uI0orYh+Bd1F7+LpeqevK3clJOL+JmcW2EPgzvlOvMTEcbUxUWkjiPuAYn/uqRmqwtS4FMbY5KQzJ1yZNkGmg8qpHbk4+7W7ERDNASUZ+YnxrJ67l0TIEXMP5xRqoVie1aKlGWzjlNvuKwmCcftxm7JP3yYzv1f2gakLmKYF9fbkhp9n7UzKMuY/zof8Ou6wdTytObSVwIfhjVrWxQF3RJ+o6dbRf3HK1lq0gkMXx/mGGC+MIOZ+41fAtmGrdX06HE2pxye7AOrk7rLU5fCHnQ9bwFwBJJk5eIk79qTOMgy3uPF0x3S02LuLSveHOD1NCCbjdPDDn6ttQQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Q6p46eBl4vTsyEkyIWmxjuy18oI6FGeXiFibDW+O6K8=; b=jCVSKq+9g1zAQsnWe4kB62Yd90KgKn9Ukll8IqTCfKoZvAIKWqgXhCkSiHbwUsfu9MHPBqhkus52nDf7pd7w81S4dOh8sU3oxQ3GhAYzvXIDrGjtsOdgbzjCxPIEE42OKN8bGn5QaXVdLaynoXpCyYMiYtp0f/IJUvJPEmxfREe4Jv7SD0ijqEXKe7/GiAVImJ9TK1p8gtBMOyAgvfDRm5hSiMRawvTCbhTq6QjioWqhRP6+6sK8COFI9VUZqwZ5BZ4/LbX86O4bP3p+LYuxYItYrHgRNSNDAhVEp+rm9zSXzOzMDdKBk/aXvPWAmFEnfCTHIbRpxmYVKrQIKKhptQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.freedesktop.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Q6p46eBl4vTsyEkyIWmxjuy18oI6FGeXiFibDW+O6K8=; b=hcO2PCGpt3byBuu6odQokcgnZ5t8DuwYxZWwLAA66bchAjckil1wEELnQnE5VR0GJUAqekVQY8NfsVJW3E/ImUoOfSxOelWiMISlBeXNrW0hEpj/5yxNscCDCferzXFs3v8l3wtgstdqeU6C1XxNDqs7jw2mKOv1uvovflwiAnc= Received: from DM6PR08CA0008.namprd08.prod.outlook.com (2603:10b6:5:80::21) by BL0PR12MB4849.namprd12.prod.outlook.com (2603:10b6:208:1c2::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.14; Wed, 20 Jul 2022 07:41:06 +0000 Received: from DM6NAM11FT014.eop-nam11.prod.protection.outlook.com (2603:10b6:5:80:cafe::1a) by DM6PR08CA0008.outlook.office365.com (2603:10b6:5:80::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.17 via Frontend Transport; Wed, 20 Jul 2022 07:41:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT014.mail.protection.outlook.com (10.13.173.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5458.17 via Frontend Transport; Wed, 20 Jul 2022 07:41:05 +0000 Received: from amd-X570-AORUS-ELITE.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Wed, 20 Jul 2022 02:41:02 -0500 From: Arunpravin Paneer Selvam To: , , , Subject: [PATCH 4/4] drm/ttm: Switch to using the new intersect callback Date: Wed, 20 Jul 2022 00:36:06 -0700 Message-ID: <20220720073606.3885-4-Arunpravin.PaneerSelvam@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220720073606.3885-1-Arunpravin.PaneerSelvam@amd.com> References: <20220720073606.3885-1-Arunpravin.PaneerSelvam@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6037e17d-8639-4d87-cc8b-08da6a23342c X-MS-TrafficTypeDiagnostic: BL0PR12MB4849:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GH+U2G21avp7CYavPC6UEt0bQnsK15h63ho3w2gB8k6csfDEVWjBiCl6gIXjeqaLhWtN0+hfnlim3g6AcFsjri59jMIvDwRYIB+4y0C/AEVMrHR2xX2VJiW8gvdAKLktqUWQjZcUVtC0n0yQ3woxd7o+TrtbrBwsc70T3VRuQOOgS+Dkd/fN1gXj+TYSxW+MzRgQgfF6tR8lLXTlZZDgxlGM6zoE9EDSkvuNgCHw8KHXw7/TC1llfSonwl2lmOt9/39ldY6HLGujntEM+yTZ9NjY9qTmIGj3U51oYF+5+22C9pXr5Na0dODid1e5R431PSlDWeC8VNioQBFT01YXSVk0im8wBCdbgs4GlNEwkkfBDv/Bc/rj0h4xApZkgnGWHcqaSDRTlIO+r1y/wmymwzb3DeTZc+pqmK9fIylkoRx1QwGw3Dm8qV/o7nWVtNppvRgIkLmaBEm6if0RT+W6g8emAev/SQa1ZHC/lHqzwrZXBWmNv2vEO1+VbNYqtJLfQNpT2/MN4/LbLqR/7ILYkIkXoQozvTE6XfmsGqcewmEaFsBGo7LvJ3PdxX2JU8ePTXgKbTp+59pCB/DUhDkKQiOpb1FYtIB9BSCuavIWFNVNYyvIcpc/7H1UuDud6f3IXhIXn6BBk4G/zN5ec4jlNZ8FwMQYZhvRh5m51WbyI1dc6Yh1EfacvcyG+s6BJlnNU4qVriXsCSEQvXO8SgcvJd96L0eiIG43XiyK5jhn/jGJ9aBvnvCkPEphtjcmSpklDjy9kpXCKDK2xNJhcLCVRnKFFALXHxQrtPqwhGbtyvXhpYWCMka18PBskBfgnJCHQhWvsFslFHwA5fDskYruPw== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230016)(4636009)(136003)(346002)(39860400002)(376002)(396003)(46966006)(36840700001)(40470700004)(5660300002)(26005)(36860700001)(86362001)(8936002)(36756003)(1076003)(66574015)(426003)(47076005)(16526019)(336012)(356005)(2616005)(82740400003)(81166007)(186003)(83380400001)(110136005)(40460700003)(54906003)(478600001)(41300700001)(316002)(7696005)(40480700001)(8676002)(82310400005)(70586007)(70206006)(2906002)(4326008)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2022 07:41:05.6847 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6037e17d-8639-4d87-cc8b-08da6a23342c 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT014.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB4849 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alexander.deucher@amd.com, Arunpravin Paneer Selvam , christian.koenig@amd.com, matthew.auld@intel.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Use new intersect callback instead of having a generic placement range verification. Signed-off-by: Christian König Signed-off-by: Arunpravin Paneer Selvam --- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 45 +++++++------------------ drivers/gpu/drm/ttm/ttm_bo.c | 9 +++-- drivers/gpu/drm/ttm/ttm_resource.c | 5 +-- 3 files changed, 20 insertions(+), 39 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index 170935c294f5..7d25a10395c0 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -1328,11 +1328,12 @@ uint64_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm, static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, const struct ttm_place *place) { - unsigned long num_pages = bo->resource->num_pages; struct dma_resv_iter resv_cursor; - struct amdgpu_res_cursor cursor; struct dma_fence *f; + if (!amdgpu_bo_is_amdgpu_bo(bo)) + return ttm_bo_eviction_valuable(bo, place); + /* Swapout? */ if (bo->resource->mem_type == TTM_PL_SYSTEM) return true; @@ -1351,40 +1352,20 @@ static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, return false; } - switch (bo->resource->mem_type) { - case AMDGPU_PL_PREEMPT: - /* Preemptible BOs don't own system resources managed by the - * driver (pages, VRAM, GART space). They point to resources - * owned by someone else (e.g. pageable memory in user mode - * or a DMABuf). They are used in a preemptible context so we - * can guarantee no deadlocks and good QoS in case of MMU - * notifiers or DMABuf move notifiers from the resource owner. - */ + /* Preemptible BOs don't own system resources managed by the + * driver (pages, VRAM, GART space). They point to resources + * owned by someone else (e.g. pageable memory in user mode + * or a DMABuf). They are used in a preemptible context so we + * can guarantee no deadlocks and good QoS in case of MMU + * notifiers or DMABuf move notifiers from the resource owner. + */ + if (bo->resource->mem_type == AMDGPU_PL_PREEMPT) return false; - case TTM_PL_TT: - if (amdgpu_bo_is_amdgpu_bo(bo) && - amdgpu_bo_encrypted(ttm_to_amdgpu_bo(bo))) - return false; - return true; - case TTM_PL_VRAM: - /* Check each drm MM node individually */ - amdgpu_res_first(bo->resource, 0, (u64)num_pages << PAGE_SHIFT, - &cursor); - while (cursor.remaining) { - if (place->fpfn < PFN_DOWN(cursor.start + cursor.size) - && !(place->lpfn && - place->lpfn <= PFN_DOWN(cursor.start))) - return true; - - amdgpu_res_next(&cursor, cursor.size); - } + if (bo->resource->mem_type == TTM_PL_TT && + amdgpu_bo_encrypted(ttm_to_amdgpu_bo(bo))) return false; - default: - break; - } - return ttm_bo_eviction_valuable(bo, place); } diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index c1bd006a5525..03409409e43e 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -518,6 +518,9 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, const struct ttm_place *place) { + struct ttm_resource *res = bo->resource; + struct ttm_device *bdev = bo->bdev; + dma_resv_assert_held(bo->base.resv); if (bo->resource->mem_type == TTM_PL_SYSTEM) return true; @@ -525,11 +528,7 @@ bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, /* Don't evict this BO if it's outside of the * requested placement range */ - if (place->fpfn >= (bo->resource->start + bo->resource->num_pages) || - (place->lpfn && place->lpfn <= bo->resource->start)) - return false; - - return true; + return ttm_resource_intersect(bdev, res, place, bo->base.size); } EXPORT_SYMBOL(ttm_bo_eviction_valuable); diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c index 84c21f92b422..ff3e9058943c 100644 --- a/drivers/gpu/drm/ttm/ttm_resource.c +++ b/drivers/gpu/drm/ttm/ttm_resource.c @@ -285,6 +285,8 @@ static bool ttm_resource_places_compat(struct ttm_resource *res, const struct ttm_place *places, unsigned num_placement) { + struct ttm_buffer_object *bo = res->bo; + struct ttm_device *bdev = bo->bdev; unsigned i; if (res->placement & TTM_PL_FLAG_TEMPORARY) @@ -293,8 +295,7 @@ static bool ttm_resource_places_compat(struct ttm_resource *res, for (i = 0; i < num_placement; i++) { const struct ttm_place *heap = &places[i]; - if (res->start < heap->fpfn || (heap->lpfn && - (res->start + res->num_pages) > heap->lpfn)) + if (!ttm_resource_intersect(bdev, res, heap, bo->base.size)) continue; if ((res->mem_type == heap->mem_type) &&