From patchwork Wed Aug 10 21:24:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Paul X-Patchwork-Id: 9274181 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 37B556022E for ; Wed, 10 Aug 2016 21:24:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2546E27E22 for ; Wed, 10 Aug 2016 21:24:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A1C6283E9; Wed, 10 Aug 2016 21:24:30 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 C42E227E22 for ; Wed, 10 Aug 2016 21:24:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DD5676E884; Wed, 10 Aug 2016 21:24:28 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qk0-x22e.google.com (mail-qk0-x22e.google.com [IPv6:2607:f8b0:400d:c09::22e]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2CCA96E884 for ; Wed, 10 Aug 2016 21:24:27 +0000 (UTC) Received: by mail-qk0-x22e.google.com with SMTP id t7so56959990qkh.0 for ; Wed, 10 Aug 2016 14:24:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Xc0DWyS2LDUWnDT/xCvOy98YtU1jV8vXmIWipfduMRs=; b=aAh0S7XChL5ICuey5dwP7K4pSKoq613zaFtbGBkYQIwI2xb88JqR9TeDJqnca5nQHe RB/iV9vuDwB0zLfdgkfoqxzQNHYrAlt7pn5MPc5h1uE6xBAneTh2mbIPWvO6EeUBa8eP loJIYb/IV7bfZel63BTW6y0C439uJChL7oYj4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Xc0DWyS2LDUWnDT/xCvOy98YtU1jV8vXmIWipfduMRs=; b=Ny1HQ2JHOQkHB0oJJBCpWMaFUkmlON6Yb2viuq6Upejbc2gteJbRWDcTFb6n7s0jr/ 2nrs9D4dMVEMdfDKMLiMtP5wxaxPzR/tyR5LSMb3pH6qzpVkfvJaNBbjTd3hfapQ58Kn IQlU+P3LHQszROvsVmQsBNDZ3O/63jix+GPALOkP26xHPA+Iif6A6GnR7R8sTRKnlKqg cHLFDsMgAU3x/0zRdFmMs4ymvnWTBf+FFfoQse13aFMziMHT7m2oCeMcwZvZ9WhKY1vL sWT+Cc6BcArnqmjgRKplWQIKtSz3McHLO2WA2/0l72/Bh9U+TmNAIwfoY4837o0u+Ayg ySdg== X-Gm-Message-State: AEkoouseanX+QdIHMRYSRnMxqgRWcfGylhnCl+cbU/Xi3jCKUSeyridI4p0uGqOovNL+9o+m X-Received: by 10.55.103.145 with SMTP id b139mr6940839qkc.15.1470864266299; Wed, 10 Aug 2016 14:24:26 -0700 (PDT) Received: from boxwood.roam.corp.google.com (cpe-75-189-128-87.nc.res.rr.com. [75.189.128.87]) by smtp.gmail.com with ESMTPSA id l32sm24452678qta.23.2016.08.10.14.24.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Aug 2016 14:24:25 -0700 (PDT) From: Sean Paul To: mark.yao@rock-chips.com, dri-devel@lists.freedesktop.org, ykk@rock-chips.com Subject: [PATCH 2/6] drm/rockchip: Change state_mutex to spinlock Date: Wed, 10 Aug 2016 17:24:15 -0400 Message-Id: <1470864258-22680-3-git-send-email-seanpaul@chromium.org> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1470864258-22680-1-git-send-email-seanpaul@chromium.org> References: <1470864258-22680-1-git-send-email-seanpaul@chromium.org> Cc: marcheu@chromium.org, dianders@chromium.org, linux-rockchip@lists.infradead.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP So we can change the state while holding another spinlock (such as vblank_lock). Also add some locking around the flush function to ensure there are no races. Signed-off-by: Sean Paul --- drivers/gpu/drm/rockchip/rockchip_drm_psr.c | 54 +++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_psr.c b/drivers/gpu/drm/rockchip/rockchip_drm_psr.c index 6a51851..1fe271b 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_psr.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_psr.c @@ -29,7 +29,7 @@ enum psr_state { struct psr_drv { struct list_head list; enum psr_state state; - struct mutex state_mutex; + spinlock_t lock; struct timer_list flush_timer; @@ -55,16 +55,33 @@ out: return psr; } -static void psr_set_state(struct psr_drv *psr, enum psr_state state) +static void psr_set_state_locked(struct psr_drv *psr, enum psr_state state) { - mutex_lock(&psr->state_mutex); + /* + * Allowed finite state machine: + * + * PSR_ENABLE < = = = = = > PSR_FLUSH + * | ^ | + * | | | + * v | | + * PSR_DISABLE < - - - - - - - - - + */ + + /* Forbid no state change */ + if (state == psr->state) + return; - if (psr->state == state) { - mutex_unlock(&psr->state_mutex); + /* Forbid DISABLE change to FLUSH */ + if (state == PSR_FLUSH && psr->state == PSR_DISABLE) return; - } psr->state = state; + + /* Allow but no need hardware change, just need assign the state */ + if (state == PSR_DISABLE && psr->state == PSR_FLUSH) + return; + + /* Refact to hardware state change */ switch (state) { case PSR_ENABLE: psr->set(psr->encoder, true); @@ -74,19 +91,30 @@ static void psr_set_state(struct psr_drv *psr, enum psr_state state) case PSR_FLUSH: psr->set(psr->encoder, false); break; - }; + } +} - mutex_unlock(&psr->state_mutex); +static void psr_set_state(struct psr_drv *psr, enum psr_state state) +{ + unsigned long flags; + + spin_lock_irqsave(&psr->lock, flags); + psr_set_state_locked(psr, state); + spin_unlock_irqrestore(&psr->lock, flags); } static void psr_flush_handler(unsigned long data) { struct psr_drv *psr = (struct psr_drv *)data; + unsigned long flags; - if (!psr || psr->state != PSR_FLUSH) + if (!psr) return; - psr_set_state(psr, PSR_ENABLE); + spin_lock_irqsave(&psr->lock, flags); + if (psr->state == PSR_FLUSH) + psr_set_state_locked(psr, PSR_ENABLE); + spin_unlock_irqrestore(&psr->lock, flags); } /** @@ -147,9 +175,6 @@ void rockchip_drm_psr_flush(struct drm_device *dev) spin_lock_irqsave(&drm_drv->psr_list_lock, flags); list_for_each_entry(psr, &drm_drv->psr_list, list) { - if (psr->state == PSR_DISABLE) - continue; - mod_timer(&psr->flush_timer, round_jiffies_up(jiffies + PSR_FLUSH_TIMEOUT)); @@ -182,8 +207,7 @@ int rockchip_drm_psr_register(struct drm_encoder *encoder, return -ENOMEM; setup_timer(&psr->flush_timer, psr_flush_handler, (unsigned long)psr); - - mutex_init(&psr->state_mutex); + spin_lock_init(&psr->lock); psr->state = PSR_DISABLE; psr->encoder = encoder;