Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1646932pxp; Thu, 17 Mar 2022 13:31:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmwWo6tFSSG42gL1PRBzYdlyS4mdGHgB/H/AucL+65k353OJaGg9gQpb3f7IhLLO8gQiF1 X-Received: by 2002:a17:902:bd89:b0:14d:93b4:71a9 with SMTP id q9-20020a170902bd8900b0014d93b471a9mr6581620pls.98.1647549111746; Thu, 17 Mar 2022 13:31:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647549111; cv=none; d=google.com; s=arc-20160816; b=o+SHVblom6LYzdv2GGFqsVn3SD4itAdzNV4LJwqcGqwPh5dLkrDUizs+rQSLm/qE83 +f0XOgA5uNetAR6zSfurnyhmjBzu1nTEjJO3M+QtbxB0b6m+lOdFInLco8rKcws3Mc6j onarOrCFRTDz+uHZ+bGK3Kwc4EHe17kmXEQ/Cf+A0W1VuFS1RPTVZVMkN6diMLruPE8t oBAUSy+khhdgqrY0Yk5g+VfoqrcM7/Uy1k1LlbeQiwoCylDkS5gHIZ4HzYbpf2Ojo/IV nsqnAZ7+VVrV8dNeK/iBJ93fwkrdq4xFEjr6UfHyTGJVFctQfY3lyuCcgRWIvHPaOrCI B7ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature; bh=zUt2tWkZnzZmR22TBfzVAfjbYftNAG6kYb5PLZxCQe0=; b=JgoTdgVlmjTqvaiIP8+M8TtdSlFlVTiBbOAJbOuGSiiANzorIAMvyOKyy31BzicFN0 YNmC+2FKvO2FkdI4lEJsoz3ypEwPu0e+nno1VRd7ASXIHnNgCM/upzAgdwcHsDge3HAz IBvd+nr7buYxNvaJadHu60C9oPa6lZnLZswxZ+fNqjjY4lqa0WKujrZHpnuwxNPfjKmv kUw++xlOj0CHgkiiatZkS5SEDiuuuAXNuXduVw16ro6ncRYeNGvzJaTqYx4FsEefc/IJ 1nL7WUfK+LchaTI+gQSRvfVV+Z9AU/yNeBcDQ5gQHkCVVnzdDK34SZAwqPbkGjNDjnP7 jPPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b="jgPd4/lz"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id n18-20020a170902969200b00153b2d165a1si75757plp.425.2022.03.17.13.31.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 13:31:51 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b="jgPd4/lz"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7A2B12D41F8; Thu, 17 Mar 2022 13:06:24 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232129AbiCQKA1 (ORCPT + 99 others); Thu, 17 Mar 2022 06:00:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230232AbiCQKA0 (ORCPT ); Thu, 17 Mar 2022 06:00:26 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CFCBD3714 for ; Thu, 17 Mar 2022 02:59:09 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id r6so6581946wrr.2 for ; Thu, 17 Mar 2022 02:59:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=zUt2tWkZnzZmR22TBfzVAfjbYftNAG6kYb5PLZxCQe0=; b=jgPd4/lzC2G8C7BxbIVBbZg/T/CeFLTTtdnT7GDQIMkDTo3olfLtrfpc2XKCmFMmLN 1Ova22BUpr4EodnpmV4Us7t7xKvV6+Esqjh2hNtkN1dB9CtVfUXFClvd9PfYf7z22COq HvGTOMyMWbS0rIEfjLDuu2TOeyboi4LUHLuIY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=zUt2tWkZnzZmR22TBfzVAfjbYftNAG6kYb5PLZxCQe0=; b=rF0NuI4pByROVxCAocK9g2n3PvO4VGxeda6hxJRU8TLuDVzdJwuTMHDUpMDtbKQHBu fhkAh35XeXEVy3I7UhunpzAL8JfC9wyn7eb0h3DzU/F/Rg8qAf/asOBfBeH1/TnmQ4Yr opIuihxfpG6yktTxEPg7fmfhwBDx0zeNcIb4wvQQrgipC7yVTLp3jc1gMyxsucDc5QYb M/WsLhUQb9q5+lc7cYpmucL/or2g0jjOtFEjHyF7GojbJWIkUbLkCeV6RaiPGIhtiGH3 1wRdUU55AzhHcpWT0+SapnlrSFG7MODyfKKbc9t1Bfb81xWBZhluYxKNuW9wHsU5r/pJ yohA== X-Gm-Message-State: AOAM533zwsSaDK/umS44tVA9KYq+Hi+ogSMV6NT5woW3NCwa2nDJb3ON tcP5COBJEWJ0hNlT60A/d8trLQ== X-Received: by 2002:a05:6000:1688:b0:203:8efe:e0b0 with SMTP id y8-20020a056000168800b002038efee0b0mr3108580wrd.289.1647511148160; Thu, 17 Mar 2022 02:59:08 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id u7-20020a5d6da7000000b00203d9d1875bsm4016772wrs.73.2022.03.17.02.59.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 02:59:07 -0700 (PDT) Date: Thu, 17 Mar 2022 10:59:05 +0100 From: Daniel Vetter To: Rob Clark , Andrey Grodzovsky , Christian Koenig Cc: dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Rob Clark , Sean Paul , Abhinav Kumar , David Airlie , Daniel Vetter , Akhil P Oommen , Jonathan Marek , AngeloGioacchino Del Regno , Bjorn Andersson , Vladimir Lypak , open list Subject: Re: [PATCH 2/3] drm/msm/gpu: Park scheduler threads for system suspend Message-ID: Mail-Followup-To: Rob Clark , Andrey Grodzovsky , Christian Koenig , dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Rob Clark , Sean Paul , Abhinav Kumar , David Airlie , Akhil P Oommen , Jonathan Marek , AngeloGioacchino Del Regno , Bjorn Andersson , Vladimir Lypak , open list References: <20220310234611.424743-1-robdclark@gmail.com> <20220310234611.424743-3-robdclark@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220310234611.424743-3-robdclark@gmail.com> X-Operating-System: Linux phenom 5.10.0-8-amd64 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 10, 2022 at 03:46:05PM -0800, Rob Clark wrote: > From: Rob Clark > > In the system suspend path, we don't want to be racing with the > scheduler kthreads pushing additional queued up jobs to the hw > queue (ringbuffer). So park them first. While we are at it, > move the wait for active jobs to complete into the new system- > suspend path. > > Signed-off-by: Rob Clark > --- > drivers/gpu/drm/msm/adreno/adreno_device.c | 68 ++++++++++++++++++++-- > 1 file changed, 64 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpu/drm/msm/adreno/adreno_device.c b/drivers/gpu/drm/msm/adreno/adreno_device.c > index 8859834b51b8..0440a98988fc 100644 > --- a/drivers/gpu/drm/msm/adreno/adreno_device.c > +++ b/drivers/gpu/drm/msm/adreno/adreno_device.c > @@ -619,22 +619,82 @@ static int active_submits(struct msm_gpu *gpu) > static int adreno_runtime_suspend(struct device *dev) > { > struct msm_gpu *gpu = dev_to_gpu(dev); > - int remaining; > + > + /* > + * We should be holding a runpm ref, which will prevent > + * runtime suspend. In the system suspend path, we've > + * already waited for active jobs to complete. > + */ > + WARN_ON_ONCE(gpu->active_submits); > + > + return gpu->funcs->pm_suspend(gpu); > +} > + > +static void suspend_scheduler(struct msm_gpu *gpu) > +{ > + int i; > + > + /* > + * Shut down the scheduler before we force suspend, so that > + * suspend isn't racing with scheduler kthread feeding us > + * more work. > + * > + * Note, we just want to park the thread, and let any jobs > + * that are already on the hw queue complete normally, as > + * opposed to the drm_sched_stop() path used for handling > + * faulting/timed-out jobs. We can't really cancel any jobs > + * already on the hw queue without racing with the GPU. > + */ > + for (i = 0; i < gpu->nr_rings; i++) { > + struct drm_gpu_scheduler *sched = &gpu->rb[i]->sched; > + kthread_park(sched->thread); Shouldn't we have some proper interfaces for this? Also I'm kinda wondering how other drivers do this, feels like we should have a standard way. Finally not flushing out all in-flight requests sounds a bit like a bad idea for system suspend/resume since that's also the hibernation path, and that would mean your shrinker/page reclaim stops working. At least in full generality. Which ain't good for hibernation. Adding Christian and Andrey. -Daniel > + } > +} > + > +static void resume_scheduler(struct msm_gpu *gpu) > +{ > + int i; > + > + for (i = 0; i < gpu->nr_rings; i++) { > + struct drm_gpu_scheduler *sched = &gpu->rb[i]->sched; > + kthread_unpark(sched->thread); > + } > +} > + > +static int adreno_system_suspend(struct device *dev) > +{ > + struct msm_gpu *gpu = dev_to_gpu(dev); > + int remaining, ret; > + > + suspend_scheduler(gpu); > > remaining = wait_event_timeout(gpu->retire_event, > active_submits(gpu) == 0, > msecs_to_jiffies(1000)); > if (remaining == 0) { > dev_err(dev, "Timeout waiting for GPU to suspend\n"); > - return -EBUSY; > + ret = -EBUSY; > + goto out; > } > > - return gpu->funcs->pm_suspend(gpu); > + ret = pm_runtime_force_suspend(dev); > +out: > + if (ret) > + resume_scheduler(gpu); > + > + return ret; > } > + > +static int adreno_system_resume(struct device *dev) > +{ > + resume_scheduler(dev_to_gpu(dev)); > + return pm_runtime_force_resume(dev); > +} > + > #endif > > static const struct dev_pm_ops adreno_pm_ops = { > - SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume) > + SET_SYSTEM_SLEEP_PM_OPS(adreno_system_suspend, adreno_system_resume) > SET_RUNTIME_PM_OPS(adreno_runtime_suspend, adreno_runtime_resume, NULL) > }; > > -- > 2.35.1 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch