Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1991764pxp; Thu, 10 Mar 2022 16:56:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJyFmGT8LjG79+QiXjquSZyQMJfJ9ADetu6Lu6/3hFcibC3F3ilK+U+h4h0OiZRxeT8fXwk6 X-Received: by 2002:a17:906:3117:b0:6cd:f81b:e295 with SMTP id 23-20020a170906311700b006cdf81be295mr6222870ejx.511.1646960200705; Thu, 10 Mar 2022 16:56:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646960200; cv=none; d=google.com; s=arc-20160816; b=EHKs7h1PwtrnLi3uGCjsgkja92TP99nDAUBcv0S8IuKBNKB+8I7xBmTKlYM9FR9BY2 2HcC05SEONDO293zVuFoJ8shwTDbx+Bv24ZJ7PVKcaLOS4WOvlrHA22tFoOVYQWPT+XM qNTX/dsNgNakYxB2q7WJpCWbxbBal6GXW498GNzfoeB0Hv88mnhTPi+PoSYT0g9M6WpO ze3co6tdbvatinCGBDQ3VE7QXVrhf+fxdP1DrXoUxjyxDM7T1A97gyckplMmgunD6m5E B+n8hveHWfFmnj4WmIGOuAyqkybaoLg43Yhcpg+eJt/3vkuiMfbQy3/vt1EIYgaUX3Vp /fLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=84Raz5JYKVeX/pUi+12Qa70UMUs/NibyW3b6HrH/7lY=; b=HDobpp6mCvpRi8YQW2YYfJbVJnnm3IZE4EA3c06kB5ivmFK+Kz/FiPiYEesq1K7EwH 8scv2dtrUns0R5t//wXpfVbrR1NxJaAwbn8Sy/7iAmetfnPA1/LEYh3Ng2rr5ucY23j/ tfcDVFIKD8KxfovGYqWHEPB/Va/21suMVobwT0xsJ26SG8MhK4Y0MLcOs31nQWEDSNHJ pqDq30dFporXnL4/j5NBbz98JkKwx8tGFCh2thMmbN/6ZHy/XvXYOLxceWSDFjATzowy D901rItoTeOWd3ELhABGZVB7Pa1DghORgGKjvrsREBrLmy7mYkL83Q0yoqPJg7TVuxU4 C+2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RIWCIMYL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qw35-20020a1709066a2300b006cf65c4495bsi3984599ejc.57.2022.03.10.16.56.16; Thu, 10 Mar 2022 16:56:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RIWCIMYL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344808AbiCJXqq (ORCPT + 99 others); Thu, 10 Mar 2022 18:46:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344840AbiCJXqm (ORCPT ); Thu, 10 Mar 2022 18:46:42 -0500 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A9A319E022; Thu, 10 Mar 2022 15:45:40 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id a5so6476659pfv.2; Thu, 10 Mar 2022 15:45:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=84Raz5JYKVeX/pUi+12Qa70UMUs/NibyW3b6HrH/7lY=; b=RIWCIMYLv6fAl3X5yNuGJ/ZhuuVr/0l9TPnu448skU2Fk/3Dd5CxT4a38n+h8IJrI0 mUL+urptgd7ItaeuQrx16YN3HcVwrGQ5V/P3uZvlhW/2MX2PNw2KgZ9dqjC6ewvNi9Gy ssv1VBfyC56RqCVv5L90TaEfFpRctyF+Vwm+Y74O4CCV02XokyiQbjoJF7mAwUUj/yfN d/SSBZ5edruXH+IARzrbune3t+cTVvPOSofeG4QygAfOAmyOTZSkrIDOokc8zIVHzR4M KdKwn5BULrZW408bbHXjNVZOhh0xJoP4mf5iaZEBbEYnSX6EatPviXdw0oKJMGRyVAC5 BgRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=84Raz5JYKVeX/pUi+12Qa70UMUs/NibyW3b6HrH/7lY=; b=21TRZO6tAG6D3XNUqdd+g5yzjxcL/Rr2z7oPuOG0B3Gy6btYzYnCHtIfKbPBjeSaJ/ mqVqQVaXnvnvDpbJHAd8ojgLPb8Eqm4YmAQtqUZ0JYANjIxIQUfgDs6j4VhnBWmyTD2Q HfYSCDEgXr8MyxjX7UtLWnl8ZhsMO/TWmSxxWDtb75hPN+jVXk8enDSfSB/AIFLxujpL d0xfRx3b5jG5ZVkvb6g7XK5Aea681CeJkTMqOQyPhZR5VOcnfRNttvYewxT9O5A/DobR FOtDcY/HoCo9qoZDuQY4bxmgVRjD4vdlGyxmDxiOYxxpXAIAWnKVYiSFvrKx4Hxk1Tf/ Nqmg== X-Gm-Message-State: AOAM532mGQd47eEC8vZpeLWMEWzWE8Ku1UB1QwKSm6UFUiKj1Mc03GcP ZHQOYNa0eLg+SifRG6/L36o= X-Received: by 2002:a63:28d:0:b0:365:8e16:5c19 with SMTP id 135-20020a63028d000000b003658e165c19mr6158756pgc.579.1646955939174; Thu, 10 Mar 2022 15:45:39 -0800 (PST) Received: from localhost ([2601:1c0:5200:a6:307:a401:7b76:c6e5]) by smtp.gmail.com with ESMTPSA id y7-20020aa78047000000b004f7299bf685sm7917827pfm.91.2022.03.10.15.45.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 15:45:38 -0800 (PST) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Rob Clark , Rob Clark , Sean Paul , Abhinav Kumar , David Airlie , Daniel Vetter , Akhil P Oommen , Jonathan Marek , AngeloGioacchino Del Regno , Bjorn Andersson , Vladimir Lypak , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 2/3] drm/msm/gpu: Park scheduler threads for system suspend Date: Thu, 10 Mar 2022 15:46:05 -0800 Message-Id: <20220310234611.424743-3-robdclark@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310234611.424743-1-robdclark@gmail.com> References: <20220310234611.424743-1-robdclark@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 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); + } +} + +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