From patchwork Fri May 1 17:07:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 47895 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 92A1220553 for ; Fri, 1 May 2015 17:07:24 +0000 (UTC) Received: by wizk4 with SMTP id k4sf18831507wiz.2 for ; Fri, 01 May 2015 10:07:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=Tn7bjCzCquY4vM+6Eki7kqW5OJyhErzRy+F7dGc64kM=; b=Hfr9DEpUy2T4GI5HvALvdZd3WnjEtkjy+NqDRjhobRQ+vQO05tZCfAkWgfwrFYj795 w4ypDGxVA+91yhZJXa1yx5AXKN0memCydXQTCacTfCsvNgS6Ya10RU7IPCaKoWZz8jHi 6RJuMHLhuIutMy/XgHePE0E5gXnuTIL4cKI7zKOinLYTyfAAartIRU2nNvflmdxIyWx8 f2X8JP0potP8fJqijAvH/g01NyGe4MTdGu4k86LmOG8h8LpsLoMoLzXuDgtdE+4RG3I8 +ctQ8vMaegxZ4M8ekCcAFqwgWx2kDLvmmcl6ETLJi1UUbmtKoG9qw/5aP19ZYwmIdKo1 rTiA== X-Gm-Message-State: ALoCoQkgpWFtaL4bHTVWSHxDDf38jwuI/18fABEFPsh7N+J1lqbVYQxMOhe3gqUCLoZYnULBxkH+ X-Received: by 10.152.184.73 with SMTP id es9mr8978574lac.4.1430500043868; Fri, 01 May 2015 10:07:23 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.37.196 with SMTP id a4ls546444lak.30.gmail; Fri, 01 May 2015 10:07:23 -0700 (PDT) X-Received: by 10.112.234.163 with SMTP id uf3mr9107797lbc.9.1430500043690; Fri, 01 May 2015 10:07:23 -0700 (PDT) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id m3si4324727lah.93.2015.05.01.10.07.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 May 2015 10:07:23 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by layy10 with SMTP id y10so67869039lay.0 for ; Fri, 01 May 2015 10:07:23 -0700 (PDT) X-Received: by 10.112.219.70 with SMTP id pm6mr8776615lbc.41.1430500043579; Fri, 01 May 2015 10:07:23 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.67.65 with SMTP id l1csp395281lbt; Fri, 1 May 2015 10:07:22 -0700 (PDT) X-Received: by 10.70.134.231 with SMTP id pn7mr19553190pdb.97.1430500041761; Fri, 01 May 2015 10:07:21 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id il1si8678638pac.176.2015.05.01.10.07.20; Fri, 01 May 2015 10:07:21 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752178AbbEARHP (ORCPT + 28 others); Fri, 1 May 2015 13:07:15 -0400 Received: from mail-ie0-f172.google.com ([209.85.223.172]:36522 "EHLO mail-ie0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751298AbbEARHN (ORCPT ); Fri, 1 May 2015 13:07:13 -0400 Received: by iebrs15 with SMTP id rs15so93216782ieb.3 for ; Fri, 01 May 2015 10:07:12 -0700 (PDT) X-Received: by 10.107.132.223 with SMTP id o92mr13626566ioi.49.1430500032166; Fri, 01 May 2015 10:07:12 -0700 (PDT) Received: from localhost.localdomain (c-24-8-37-141.hsd1.co.comcast.net. [24.8.37.141]) by mx.google.com with ESMTPSA id n8sm3849973ioe.37.2015.05.01.10.07.11 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 May 2015 10:07:11 -0700 (PDT) From: Lina Iyer To: ohad@wizery.com, s-anna@ti.com, Bjorn.Andersson@sonymobile.com, agross@codeaurora.org Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, galak@codeaurora.org, jhugo@codeaurora.org, Lina Iyer Subject: [PATCH RFC] hwspinlock: Don't take software spinlock before hwspinlock Date: Fri, 1 May 2015 11:07:06 -0600 Message-Id: <1430500026-47990-1-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 2.1.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lina.iyer@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Some uses of the hwspinlock could be that one entity acquires the lock and the other entity releases the lock. This allows for a serialized traversal path from the locking entity to the other. For example, the cpuidle entry from Linux to the firmware to power down the core, can be serialized across the context switch by locking the hwspinlock in Linux and releasing it in the firmware. Do not force the caller of __hwspin_trylock() to acquire a kernel spinlock before acquiring the hwspinlock. Cc: Jeffrey Hugo Cc: Ohad Ben-Cohen Cc: Suman Anna Cc: Andy Gross Signed-off-by: Lina Iyer --- drivers/hwspinlock/hwspinlock_core.c | 56 ++++++++++++++++++++---------------- include/linux/hwspinlock.h | 1 + 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/drivers/hwspinlock/hwspinlock_core.c b/drivers/hwspinlock/hwspinlock_core.c index 461a0d7..bdc59f2 100644 --- a/drivers/hwspinlock/hwspinlock_core.c +++ b/drivers/hwspinlock/hwspinlock_core.c @@ -105,30 +105,34 @@ int __hwspin_trylock(struct hwspinlock *hwlock, int mode, unsigned long *flags) * problems with hwspinlock usage (e.g. scheduler checks like * 'scheduling while atomic' etc.) */ - if (mode == HWLOCK_IRQSTATE) - ret = spin_trylock_irqsave(&hwlock->lock, *flags); - else if (mode == HWLOCK_IRQ) - ret = spin_trylock_irq(&hwlock->lock); - else - ret = spin_trylock(&hwlock->lock); + if (mode != HWLOCK_NOLOCK) { + if (mode == HWLOCK_IRQSTATE) + ret = spin_trylock_irqsave(&hwlock->lock, *flags); + else if (mode == HWLOCK_IRQ) + ret = spin_trylock_irq(&hwlock->lock); + else + ret = spin_trylock(&hwlock->lock); - /* is lock already taken by another context on the local cpu ? */ - if (!ret) - return -EBUSY; + /* is lock already taken by another context on the local cpu? */ + if (!ret) + return -EBUSY; + } /* try to take the hwspinlock device */ ret = hwlock->bank->ops->trylock(hwlock); - /* if hwlock is already taken, undo spin_trylock_* and exit */ - if (!ret) { - if (mode == HWLOCK_IRQSTATE) - spin_unlock_irqrestore(&hwlock->lock, *flags); - else if (mode == HWLOCK_IRQ) - spin_unlock_irq(&hwlock->lock); - else - spin_unlock(&hwlock->lock); + if (mode != HWLOCK_NOLOCK) { + /* if hwlock is already taken, undo spin_trylock_* and exit */ + if (!ret) { + if (mode == HWLOCK_IRQSTATE) + spin_unlock_irqrestore(&hwlock->lock, *flags); + else if (mode == HWLOCK_IRQ) + spin_unlock_irq(&hwlock->lock); + else + spin_unlock(&hwlock->lock); - return -EBUSY; + return -EBUSY; + } } /* @@ -247,13 +251,15 @@ void __hwspin_unlock(struct hwspinlock *hwlock, int mode, unsigned long *flags) hwlock->bank->ops->unlock(hwlock); - /* Undo the spin_trylock{_irq, _irqsave} called while locking */ - if (mode == HWLOCK_IRQSTATE) - spin_unlock_irqrestore(&hwlock->lock, *flags); - else if (mode == HWLOCK_IRQ) - spin_unlock_irq(&hwlock->lock); - else - spin_unlock(&hwlock->lock); + if (mode != HWLOCK_NOLOCK) { + /* Undo the spin_trylock{_irq, _irqsave} called while locking */ + if (mode == HWLOCK_IRQSTATE) + spin_unlock_irqrestore(&hwlock->lock, *flags); + else if (mode == HWLOCK_IRQ) + spin_unlock_irq(&hwlock->lock); + else + spin_unlock(&hwlock->lock); + } } EXPORT_SYMBOL_GPL(__hwspin_unlock); diff --git a/include/linux/hwspinlock.h b/include/linux/hwspinlock.h index 3343298..219b333 100644 --- a/include/linux/hwspinlock.h +++ b/include/linux/hwspinlock.h @@ -24,6 +24,7 @@ /* hwspinlock mode argument */ #define HWLOCK_IRQSTATE 0x01 /* Disable interrupts, save state */ #define HWLOCK_IRQ 0x02 /* Disable interrupts, don't save state */ +#define HWLOCK_NOLOCK 0xFF /* Dont take any lock */ struct device; struct hwspinlock;