From patchwork Mon Jul 30 11:03:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 10548897 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5EA3D9093 for ; Mon, 30 Jul 2018 11:03:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C18E2837D for ; Mon, 30 Jul 2018 11:03:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 403DC29430; Mon, 30 Jul 2018 11:03:59 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 D17402837D for ; Mon, 30 Jul 2018 11:03:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A7E0089D89; Mon, 30 Jul 2018 11:03:56 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3155E89D89 for ; Mon, 30 Jul 2018 11:03:55 +0000 (UTC) Received: by mail-wr1-x442.google.com with SMTP id h9-v6so12414420wro.3 for ; Mon, 30 Jul 2018 04:03:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=UUSvRGqCpfNftdcpeSHNdVLo2KAcRPCqr3kr26itY14=; b=JdxAkdWj9quvzbI4LTXfpaX/6DiITlS9VD32DpaU23vDrNgtmcVAoS5YHEB/0HoWPv L87eOH58Nusxz0opKAygTpPmX8pCrElw7jsSB7WL9q5Uyq7uewhXVlx8R1fz/NvH7HvD 6Tmqu35ZorRJp7y1r3URHR1jugJAA2nG+7teAoF2UuHHYpDMSKEr8Td/nfBcbun/LkTT UDhajtmwrw6e141DqTVz/EboUmbQlhRFz9Su7iYE8pSk8FNl9dsWPxYDxjACSFlsO7sE gg4g79hZ1SSPyc0Cuaxty42+gZNNyYEV2ui6RpxNkCOnksXKURZsX7dWg57F8DgLcXoJ c/6A== X-Gm-Message-State: AOUpUlEJIT0Kwjk6s/aNy/bU53dGB4gA1Iv4kErL7rKvKdafPWegnSQp fSTr1ksSV1ZAtboTjQCMJ3+DpL// X-Google-Smtp-Source: AAOMgpeATGxRugMg1f2Jz3k7tkuSS+N4Yy+B9h79/Jd68twMiy68cWK9Tpjdb56+68jgRBWdkblk1g== X-Received: by 2002:adf:9d46:: with SMTP id o6-v6mr17432617wre.51.1532948633647; Mon, 30 Jul 2018 04:03:53 -0700 (PDT) Received: from baker.fritz.box ([2a02:908:1257:4460:84be:eecf:8e75:4e06]) by smtp.gmail.com with ESMTPSA id j16-v6sm10620684wme.8.2018.07.30.04.03.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Jul 2018 04:03:53 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/2] drm/scheduler: only kill entity if last user is killed v2 Date: Mon, 30 Jul 2018 13:03:51 +0200 Message-Id: <20180730110352.2657-1-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 MIME-Version: 1.0 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: nayan26deshmukh@gmail.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Note which task is using the entity and only kill it if the last user of the entity is killed. This should prevent problems when entities are leaked to child processes. v2: add missing kernel doc Signed-off-by: Christian König Signed-off-by: Christian König <christian.koenig@amd.com>
--- drivers/gpu/drm/scheduler/gpu_scheduler.c | 6 +++++- include/drm/gpu_scheduler.h | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/scheduler/gpu_scheduler.c b/drivers/gpu/drm/scheduler/gpu_scheduler.c index 3f2fc5e8242a..f563e4fbb4b6 100644 --- a/drivers/gpu/drm/scheduler/gpu_scheduler.c +++ b/drivers/gpu/drm/scheduler/gpu_scheduler.c @@ -275,6 +275,7 @@ static void drm_sched_entity_kill_jobs_cb(struct dma_fence *f, long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) { struct drm_gpu_scheduler *sched; + struct task_struct *last_user; long ret = timeout; sched = entity->rq->sched; @@ -295,7 +296,9 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) /* For killed process disable any more IBs enqueue right now */ - if ((current->flags & PF_EXITING) && (current->exit_code == SIGKILL)) + last_user = cmpxchg(&entity->last_user, current->group_leader, NULL); + if ((!last_user || last_user == current->group_leader) && + (current->flags & PF_EXITING) && (current->exit_code == SIGKILL)) drm_sched_entity_set_rq(entity, NULL); return ret; @@ -541,6 +544,7 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job, trace_drm_sched_job(sched_job, entity); + WRITE_ONCE(entity->last_user, current->group_leader); first = spsc_queue_push(&entity->job_queue, &sched_job->queue_node); /* first job wakes up scheduler */ diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h index 091b9afcd184..21c648b0b2a1 100644 --- a/include/drm/gpu_scheduler.h +++ b/include/drm/gpu_scheduler.h @@ -66,6 +66,7 @@ enum drm_sched_priority { * @guilty: points to ctx's guilty. * @fini_status: contains the exit status in case the process was signalled. * @last_scheduled: points to the finished fence of the last scheduled job. + * @last_user: last group leader pushing a job into the entity. * * Entities will emit jobs in order to their corresponding hardware * ring, and the scheduler will alternate between entities based on @@ -85,6 +86,7 @@ struct drm_sched_entity { struct dma_fence_cb cb; atomic_t *guilty; struct dma_fence *last_scheduled; + struct task_struct *last_user; }; /** From patchwork Mon Jul 30 11:03:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 10548899 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D955D1751 for ; Mon, 30 Jul 2018 11:04:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C393F2837D for ; Mon, 30 Jul 2018 11:04:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B82B929430; Mon, 30 Jul 2018 11:04:03 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 6A50B283B2 for ; Mon, 30 Jul 2018 11:04:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E59996E08D; Mon, 30 Jul 2018 11:04:01 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by gabe.freedesktop.org (Postfix) with ESMTPS id D2FCD89D89 for ; Mon, 30 Jul 2018 11:03:55 +0000 (UTC) Received: by mail-wr1-x441.google.com with SMTP id h14-v6so12396789wrw.13 for ; Mon, 30 Jul 2018 04:03:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2QSZ83R/vBhJQcqPc6sok4d9pqflqYRkpdUIUEzWVRM=; b=rE3ZP7WQqu9LOhHHy8xpb5q/5wtlQKS0Sb+yavSEpOnNpaNx+aHvtbvukNZ9bbQ9Dp MKTiSN2WBNhfpRRGxoBvsX58yo5i3bMSHf5o2auhsD192uSSoj58v3dCpkAlUr27RWJ8 ip5v3MZtMXZqceM1V/bsbuUcT+J8PGIdBQW+8aojhNi9tVdYjUyBOE4POVF/k+iksJp/ z8hBLTXhtJwFQ37gE9xNtBnbnEeF+5Bn5PREncxWwK8D2ydXSDyJ2EBofj2YC0lI3tms ebByB+beuimQ7iFvB6C23mXyWCpUem8w27kJVVtWeQyFfDll1prsGrPlY0bUdXC82LMp uMLQ== X-Gm-Message-State: AOUpUlFlgZuStSKoHaFsGDYhrcV+9slLzXQAV2MSbBRG5bUKdOB6d0Vs nd4F5rutPsGfgxXtRbLmvYPZD+hh X-Google-Smtp-Source: AAOMgpeN+Be+rDPTHXhr2htInN7biYyG+WcSEf11by7+huyLzu48StkH2lf/dmv7HU0+N7tw+7L1RQ== X-Received: by 2002:adf:f689:: with SMTP id v9-v6mr16992584wrp.201.1532948634309; Mon, 30 Jul 2018 04:03:54 -0700 (PDT) Received: from baker.fritz.box ([2a02:908:1257:4460:84be:eecf:8e75:4e06]) by smtp.gmail.com with ESMTPSA id j16-v6sm10620684wme.8.2018.07.30.04.03.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Jul 2018 04:03:53 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/2] drm/scheduler: stop setting rq to NULL Date: Mon, 30 Jul 2018 13:03:52 +0200 Message-Id: <20180730110352.2657-2-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180730110352.2657-1-christian.koenig@amd.com> References: <20180730110352.2657-1-christian.koenig@amd.com> MIME-Version: 1.0 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: nayan26deshmukh@gmail.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP We removed the redundancy of having an extra scheduler field, so we can't set the rq to NULL any more or otherwise won't know which scheduler to use for the cleanup. Just remove the entity from the scheduling list instead. Signed-off-by: Christian König Acked-by: Nayan Deshmukh Signed-off-by: Christian König <christian.koenig@amd.com>
Good catch.
 
Acked-by: Nayan Deshmukh <nayan26deshmukh@gmail.com>
--- drivers/gpu/drm/scheduler/gpu_scheduler.c | 35 +++++++------------------------ 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/scheduler/gpu_scheduler.c b/drivers/gpu/drm/scheduler/gpu_scheduler.c index f563e4fbb4b6..1b733229201e 100644 --- a/drivers/gpu/drm/scheduler/gpu_scheduler.c +++ b/drivers/gpu/drm/scheduler/gpu_scheduler.c @@ -198,21 +198,6 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, } EXPORT_SYMBOL(drm_sched_entity_init); -/** - * drm_sched_entity_is_initialized - Query if entity is initialized - * - * @sched: Pointer to scheduler instance - * @entity: The pointer to a valid scheduler entity - * - * return true if entity is initialized, false otherwise -*/ -static bool drm_sched_entity_is_initialized(struct drm_gpu_scheduler *sched, - struct drm_sched_entity *entity) -{ - return entity->rq != NULL && - entity->rq->sched == sched; -} - /** * drm_sched_entity_is_idle - Check if entity is idle * @@ -224,7 +209,8 @@ static bool drm_sched_entity_is_idle(struct drm_sched_entity *entity) { rmb(); - if (!entity->rq || spsc_queue_peek(&entity->job_queue) == NULL) + if (list_empty(&entity->list) || + spsc_queue_peek(&entity->job_queue) == NULL) return true; return false; @@ -279,8 +265,6 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) long ret = timeout; sched = entity->rq->sched; - if (!drm_sched_entity_is_initialized(sched, entity)) - return ret; /** * The client will not queue more IBs during this fini, consume existing * queued IBs or discard them on SIGKILL @@ -299,7 +283,7 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) last_user = cmpxchg(&entity->last_user, current->group_leader, NULL); if ((!last_user || last_user == current->group_leader) && (current->flags & PF_EXITING) && (current->exit_code == SIGKILL)) - drm_sched_entity_set_rq(entity, NULL); + drm_sched_rq_remove_entity(entity->rq, entity); return ret; } @@ -320,7 +304,7 @@ void drm_sched_entity_fini(struct drm_sched_entity *entity) struct drm_gpu_scheduler *sched; sched = entity->rq->sched; - drm_sched_entity_set_rq(entity, NULL); + drm_sched_rq_remove_entity(entity->rq, entity); /* Consumption of existing IBs wasn't completed. Forcefully * remove them here. @@ -416,15 +400,12 @@ void drm_sched_entity_set_rq(struct drm_sched_entity *entity, if (entity->rq == rq) return; - spin_lock(&entity->rq_lock); - - if (entity->rq) - drm_sched_rq_remove_entity(entity->rq, entity); + BUG_ON(!rq); + spin_lock(&entity->rq_lock); + drm_sched_rq_remove_entity(entity->rq, entity); entity->rq = rq; - if (rq) - drm_sched_rq_add_entity(rq, entity); - + drm_sched_rq_add_entity(rq, entity); spin_unlock(&entity->rq_lock); } EXPORT_SYMBOL(drm_sched_entity_set_rq);