From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3AC47C433EF for ; Thu, 17 Mar 2022 09:59:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232141AbiCQKA1 (ORCPT ); Thu, 17 Mar 2022 06:00:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231425AbiCQKA0 (ORCPT ); Thu, 17 Mar 2022 06:00:26 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1C13D3725 for ; Thu, 17 Mar 2022 02:59:09 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id x15so6529229wru.13 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=ep48D0sEXAl+Nmi7Ybqq0A8MI/DqFu0SR3yblg7V7dQCc4lq3SuVhTum588DgX64/m wqDP+b2sbowbMw3FJPq0ngc3VwQdG07nhtPd0zlT6Tv25NHw6tdVvfl+fWxJZEFMX+wG zynxsY6xPsWZez4VuNjLeGmhpe1MsYhbtVHOaswIhxtpeq/i4autQ8705Y7zek08Ka2p rr745MYZN7//FnwMFAi+0AhG573byoH+7Mt/tYRtDe5EOAcdcyyz48sYZHxOe8mMUBul FLJFGcj3ZxGi7PtJ0wBwl6ol++wfdcndjqcUX0sSvsGaqq9o6WPg+i5XpWXl2AiB1HpC /1ZA== X-Gm-Message-State: AOAM531vFG6V9b+jTKnD5nWUNeqnlCFipJlXXVIBA7wfxRjCwyOz80RJ Uhmm2eC4aJZoK+3VKt92/nZfKw== X-Google-Smtp-Source: ABdhPJyVRbvMqP3RkZC3MlKGRoYqlAqtY6uzXCzQNDy205UCPIRTLqvSpNmTlOSJ5ttBBEhl2Snd4A== 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 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@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