From patchwork Thu Jul 8 17:37:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 12365911 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D71FC07E99 for ; Thu, 8 Jul 2021 17:38:22 +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 D2BD461879 for ; Thu, 8 Jul 2021 17:38:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D2BD461879 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 560B26E949; Thu, 8 Jul 2021 17:38:12 +0000 (UTC) Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by gabe.freedesktop.org (Postfix) with ESMTPS id 080E26E949 for ; Thu, 8 Jul 2021 17:38:11 +0000 (UTC) Received: by mail-wr1-x435.google.com with SMTP id p8so8565438wrr.1 for ; Thu, 08 Jul 2021 10:38:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4V6pxp76MaEudx/IEK54W+rky4iXy/miG07jgmRH7DY=; b=BrRyknKgZV88ecMd94XiTUvwrdcF0uLLV6KBOjYoFXh1VuGj/8QahnhkFG4boL11gc GbkImyM9EaNR/hFZVGGQMl4i8i9ZpHHQE92NlVugO0ICg1P/HA3rEOAIq3bIO1y0+Gv+ 2TrCxbD4EOn129DwOalT6Q4Z6kfQ1/gn4e+8k= 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=4V6pxp76MaEudx/IEK54W+rky4iXy/miG07jgmRH7DY=; b=HlT8qEuJ4uqcAxnr4hy1VOBs0RSMTauKowFvb6mZHd/5hlrgYqUM72cFWYrHKl+BMm RDSS4eSMEx5FoEGDsxY+2mD/oefAdj/apj4YPvRTrsZ55RmnsyYqjWwmVA3+T+cY1hww Eu/R8Ovp2IIqbiseVL7X5pqVxbJMeTeaJyF9UNi/EDAvDtC4ity7Fkxv8wiFg6rUDRhg lxUHQse4SU4tmrSOWyQo3RD/+joEIFfQWAAPRrFcn9tEXYH1Kdts4KXrxP/cFrV13Snn +6uIRGABTTNA7xf2LEAxmwyhDs3zBaSZB8xTAIURnuqwm2h4xwnDYrFn3ru1nULT1Xn+ 8QVA== X-Gm-Message-State: AOAM533dDFf+Y4k2GRzsnTWwpZIAGNbRUXjWXFvpMSRhEZIRgBqGrZmT ISIwtzXE0Ymk1tLIkBzZjiz7FA== X-Google-Smtp-Source: ABdhPJxHYVh0KxReMYig08Pr0SYBUWnkEnvrgb57hPZUNr7/myKklgUeEQiVEXOTmXmKCBxKM8EriQ== X-Received: by 2002:a5d:634e:: with SMTP id b14mr35294595wrw.96.1625765889739; Thu, 08 Jul 2021 10:38:09 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id l4sm2521853wme.26.2021.07.08.10.38.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jul 2021 10:38:09 -0700 (PDT) From: Daniel Vetter To: DRI Development Date: Thu, 8 Jul 2021 19:37:37 +0200 Message-Id: <20210708173754.3877540-4-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210708173754.3877540-1-daniel.vetter@ffwll.ch> References: <20210708173754.3877540-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH v3 03/20] drm/sched: Barriers are needed for entity->last_scheduled X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrey Grodzovsky , Daniel Vetter , Intel Graphics Development , Steven Price , Daniel Vetter , Lee Jones , =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" It might be good enough on x86 with just READ_ONCE, but the write side should then at least be WRITE_ONCE because x86 has total store order. It's definitely not enough on arm. Fix this proplery, which means - explain the need for the barrier in both places - point at the other side in each comment Also pull out the !sched_list case as the first check, so that the code flow is clearer. While at it sprinkle some comments around because it was very non-obvious to me what's actually going on here and why. Note that we really need full barriers here, at first I thought store-release and load-acquire on ->last_scheduled would be enough, but we actually requiring ordering between that and the queue state. Signed-off-by: Daniel Vetter Cc: "Christian König" Cc: Steven Price Cc: Daniel Vetter Cc: Andrey Grodzovsky Cc: Lee Jones Cc: Boris Brezillon --- drivers/gpu/drm/scheduler/sched_entity.c | 27 ++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c index 64d398166644..4e1124ed80e0 100644 --- a/drivers/gpu/drm/scheduler/sched_entity.c +++ b/drivers/gpu/drm/scheduler/sched_entity.c @@ -439,8 +439,16 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity) dma_fence_set_error(&sched_job->s_fence->finished, -ECANCELED); dma_fence_put(entity->last_scheduled); + entity->last_scheduled = dma_fence_get(&sched_job->s_fence->finished); + /* + * if the queue is empty we allow drm_sched_job_arm() to locklessly + * access ->last_scheduled. This only works if we set the pointer before + * we dequeue and if we a write barrier here. + */ + smp_wmb(); + spsc_queue_pop(&entity->job_queue); return sched_job; } @@ -459,10 +467,25 @@ void drm_sched_entity_select_rq(struct drm_sched_entity *entity) struct drm_gpu_scheduler *sched; struct drm_sched_rq *rq; - if (spsc_queue_count(&entity->job_queue) || !entity->sched_list) + /* single possible engine and already selected */ + if (!entity->sched_list) + return; + + /* queue non-empty, stay on the same engine */ + if (spsc_queue_count(&entity->job_queue)) return; - fence = READ_ONCE(entity->last_scheduled); + fence = entity->last_scheduled; + + /* + * Only when the queue is empty are we guaranteed the the scheduler + * thread cannot change ->last_scheduled. To enforce ordering we need + * a read barrier here. See drm_sched_entity_pop_job() for the other + * side. + */ + smp_rmb(); + + /* stay on the same engine if the previous job hasn't finished */ if (fence && !dma_fence_is_signaled(fence)) return;