From patchwork Thu Jan 25 09:59:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunming Zhou X-Patchwork-Id: 10183817 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 67EFF60233 for ; Thu, 25 Jan 2018 09:59:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56D6B223A4 for ; Thu, 25 Jan 2018 09:59:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B6C628A6D; Thu, 25 Jan 2018 09:59:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 62B36223A4 for ; Thu, 25 Jan 2018 09:59:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 86CAB6E753; Thu, 25 Jan 2018 09:59:42 +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-dm3nam03on0067.outbound.protection.outlook.com [104.47.41.67]) by gabe.freedesktop.org (Postfix) with ESMTPS id 208DB6E753; Thu, 25 Jan 2018 09:59:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=MtYeaBogcKgNXNaZxY2G7/0VaA4YZJ+bQ34RkXxwPLg=; b=BM5PhHxi6pFS1xkhF8PpoQat3wGSYJi/4vh9OFA0M3lCQlQv6NIKbo5v3y4UiF0On4p9821ppIjJVEFu8GLEawvuTpLr+TX0J3jjoN2cpFvQgP/0LZCS2Mud9B4pXwhaiMEF2XGKHzv5bmFHZeDu+LrevfoNzdHDqt68eJumvPE= Received: from CY1PR1201CA0001.namprd12.prod.outlook.com (10.169.17.139) by CY4PR1201MB0054.namprd12.prod.outlook.com (10.172.77.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.428.17; Thu, 25 Jan 2018 09:59:39 +0000 Received: from BY2NAM03FT056.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e4a::203) by CY1PR1201CA0001.outlook.office365.com (2a01:111:e400:5b9a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.444.14 via Frontend Transport; Thu, 25 Jan 2018 09:59:39 +0000 Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=permerror action=none header.from=amd.com; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV02.amd.com (165.204.84.17) by BY2NAM03FT056.mail.protection.outlook.com (10.152.85.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.444.13 via Frontend Transport; Thu, 25 Jan 2018 09:59:38 +0000 Received: from zhoucm1.amd.com (10.34.1.3) by SATLEXCHOV02.amd.com (10.181.40.72) with Microsoft SMTP Server id 14.3.361.1; Thu, 25 Jan 2018 03:59:37 -0600 From: Chunming Zhou To: , Subject: [PATCH] [RFC]drm/ttm: fix scheduling balance Date: Thu, 25 Jan 2018 17:59:32 +0800 Message-ID: <20180125095932.30860-1-david1.zhou@amd.com> X-Mailer: git-send-email 2.14.1 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)(396003)(39860400002)(346002)(376002)(39380400002)(2980300002)(428003)(189003)(199004)(55674003)(53936002)(48376002)(50466002)(316002)(106466001)(5660300001)(6666003)(47776003)(110136005)(16586007)(54906003)(26005)(104016004)(186003)(7696005)(51416003)(2906002)(77096007)(36756003)(336011)(356003)(59450400001)(105586002)(1076002)(8936002)(305945005)(97736004)(4326008)(81166006)(72206003)(68736007)(81156014)(8676002)(478600001)(50226002)(450100002)(86362001)(53416004); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR1201MB0054; H:SATLEXCHOV02.amd.com; FPR:; SPF:None; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2NAM03FT056; 1:TDHwKxYnEYBHpPgXfl5GXQqvmHHSdC/3NZ8tRkfhv7AueIg3vkOErcdpg4tesfsnjsxA4kNqw9SYDMArXOtmrxObSDYrqiTbuMm8+GyRaqNNCca27RW8uSfoMlIwKzRL X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bf973376-6e18-4e38-b332-08d563da58f5 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060); SRVR:CY4PR1201MB0054; X-Microsoft-Exchange-Diagnostics: 1; CY4PR1201MB0054; 3:fp2/tIP61PEyozSr8ldyKEvffjIg5TFLitYJHy9B3PbbvQb+4vcCbxcIiBsBhALgFgA/8qYnR+hB6b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OJwiziqMa4eIZFSzfA7/xvukViiztKMkRwl7saAkdSKkDe2yZpFVtac8aoyZsCrkmhmtPu7Kh29wGzHh+qSYjlppFTTGG9S9MmYq/srjzyPiN8B0s3hYoWbOyIaHwJe7bmvVFV25eX+VdX3tF8CU9OK3wbMjCbeGjlkpkWFc77QXaBksvigx+sY0AgOkq6weIuZ96uNEGDCgWD6RfN1BvSYHSBiBkcYhpYxkeXwvqfJFZPPe/StnnauomAwuJ/Pv4zJgrKPoKNj/X0Vb4rA4FxQmyDFi6NGF7aOzlOcQwWugicE5uS9y2RxlCrcYeaAiDSMn0dBJ6+q5xtBDT9WR7h/D+0ZbRO4TP8cr+C5PTR54CsCwqaBPgzAoRwc8 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(5005006)(8121501046)(10201501046)(93006095)(93003095)(3231023)(2400081)(944501161)(3002001)(6055026)(6041288)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123558120)(6072148)(201708071742011); SRVR:CY4PR1201MB0054; BCL:0; PCL:0; RULEID:; SRVR:CY4PR1201MB0054; X-Microsoft-Exchange-Diagnostics: 1; CY4PR1201MB0054; 4:v/vBAv9SgNhCOqGyRGi1orU4xIC0UkX7ABOS8FdzmM3t1r5mgYMWaynd9DRIvFqIvtB3myE6AzMHli3T+o3TiebggsTPo60+FMiS2zlhNUxni4TTBj1FNtYNbw2vHDrOR4HdGrHhIR9QwpkUzEryXoD/QThxFWInMgHx32C2CTrX9iu9EotcPadhZZkGIkh+BWrOpkD4CV1S7VttaR/J4Ytl7gboip/XEujH+5L4zOpHXO0L7MBDf9YvM1N/TJEfs/Tn+XhjFhNk0ByR3u+H3f2mp5UqILUdxPXjnhh2S4KJ5lxK31D56m9/6EJBvwHc X-Forefront-PRVS: 0563F2E8B7 X-Microsoft-Exchange-Di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eqjAQMp8lkx9+Kcigj2DgT6J+VqPTDRv2fpJZ06+OvUl6hxqRSNkTQKkm9iVuJDaTAU3R3Qy4ROUBOV7creqQ/Cp3AJctK6pWrxL8EQg83Ymd1pMnAaQDUXByDycnzuVCf2nl0NqM8v/M89mPhbrlauR4ISrjkHUsDZBlJ9977y/Rej/zJtlbH00s/rEnE30sls4vgXv46kjtgyp3YEkqUWkR323rcu0kkCXwukmvuMUK7n SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY4PR1201MB0054; 20:57vZhEi2TMk5YHepnE6Wl0SBtQWIjtD5f/p9eqO91R3Fk/YgOM/EnOgHYjBoZNZTGYqv7XxGmIh7HTTdNTw35xoO5IO+o71g18S91fu8sWwMFlk8LUirRo6taHboojVvethnBjtEhCXkPdoXGBXqSuF3qaUQ9PqXO+tmuXGtjDOA3MF/movHmX3pXtg7GjhjVBiqtemXVlxKi/4pAMVMKmNdEFTRYI97qEtg+xvXF2uFUBpsIu5PzWwW5F/AKVbE X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jan 2018 09:59:38.6966 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bf973376-6e18-4e38-b332-08d563da58f5 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=[SATLEXCHOV02.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1201MB0054 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: christian.koenig@amd.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP there is a scheduling balance issue about get node like: a. process A allocates full memory and use it for submission. b. process B tries to allocates memory, will wait for process A BO idle in eviction. c. process A completes the job, process B eviction will put process A BO node, but in the meantime, process C is comming to allocate BO, whill directly get node successfully, and do submission, process B will again wait for process C BO idle. d. repeat the above setps, process B could be delayed much more. add a mutex to gerantee the allocation sequence for same domain. But there is a possibility that visible vram could be evicted to invisilbe, the tricky is they are same domain manager, so which needs a special handling. Change-Id: I260e8eb704f7b4788b071d3f641f21b242912256 Signed-off-by: Chunming Zhou --- drivers/gpu/drm/ttm/ttm_bo.c | 16 +++++++++++++++- include/drm/ttm/ttm_bo_api.h | 2 ++ include/drm/ttm/ttm_bo_driver.h | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index d33a6bb742a1..f465f1d38711 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -969,7 +969,11 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo, if (mem_type == TTM_PL_SYSTEM) break; + if (ctx->man != man) + mutex_lock(&man->node_mutex); ret = (*man->func->get_node)(man, bo, place, mem); + if (ctx->man != man) + mutex_unlock(&man->node_mutex); if (unlikely(ret)) return ret; @@ -991,6 +995,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo, for (i = 0; i < placement->num_busy_placement; ++i) { const struct ttm_place *place = &placement->busy_placement[i]; + struct ttm_operation_ctx busy_ctx; ret = ttm_mem_type_from_place(place, &mem_type); if (ret) @@ -1018,7 +1023,15 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo, return 0; } - ret = ttm_bo_mem_force_space(bo, mem_type, place, mem, ctx); + memcpy(&busy_ctx, ctx, sizeof(busy_ctx)); + if (ctx->man != man) { + mutex_lock(&man->node_mutex); + busy_ctx.man = man; + } + ret = ttm_bo_mem_force_space(bo, mem_type, place, mem, + &busy_ctx); + if (ctx->man != man) + mutex_unlock(&man->node_mutex); if (ret == 0 && mem->mm_node) { mem->placement = cur_flags; return 0; @@ -1449,6 +1462,7 @@ int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type, man->io_reserve_fastpath = true; man->use_io_reserve_lru = false; mutex_init(&man->io_reserve_mutex); + mutex_init(&man->node_mutex); spin_lock_init(&man->move_lock); INIT_LIST_HEAD(&man->io_reserve_lru); diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h index 2cd025c2abe7..b08629050215 100644 --- a/include/drm/ttm/ttm_bo_api.h +++ b/include/drm/ttm/ttm_bo_api.h @@ -265,6 +265,7 @@ struct ttm_bo_kmap_obj { * @no_wait_gpu: Return immediately if the GPU is busy. * @allow_reserved_eviction: Allow eviction of reserved BOs. * @resv: Reservation object to allow reserved evictions with. + * @man: record ctx is under man->node_mutex. * * Context for TTM operations like changing buffer placement or general memory * allocation. @@ -275,6 +276,7 @@ struct ttm_operation_ctx { bool allow_reserved_eviction; struct reservation_object *resv; uint64_t bytes_moved; + struct ttm_mem_type_manager *man; }; /** diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h index 9b417eb2df20..d85d6ee4f54d 100644 --- a/include/drm/ttm/ttm_bo_driver.h +++ b/include/drm/ttm/ttm_bo_driver.h @@ -288,6 +288,7 @@ struct ttm_mem_type_manager { uint32_t default_caching; const struct ttm_mem_type_manager_func *func; void *priv; + struct mutex node_mutex; struct mutex io_reserve_mutex; bool use_io_reserve_lru; bool io_reserve_fastpath;