Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4343684ybi; Tue, 30 Jul 2019 00:18:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqx3sPBEVuM0TCU60KEJeV3hgtkHZV0NXVv8tq8wlSkWMOKUstSwd7tCMmPUiclLhD6pL1+D X-Received: by 2002:aa7:97b7:: with SMTP id d23mr42022332pfq.203.1564471095418; Tue, 30 Jul 2019 00:18:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564471095; cv=none; d=google.com; s=arc-20160816; b=I6Bw6shgcF+sXHFdb5l1ptGRJO5/LSH0klfBR/Wns5sTAhChhv7oG0ctsNWUIuMOXM p8NH04/CRsYemeJ5yHhcIJJqdv6kw6UIKJuYBK8heZSdlPCUglLCvuWqkF8rHdq59WMQ Wxq+qLi3PB3xdG6tudiNoZe4DcfSX87QCi6S1/wjsqjqubOER7OvvbolrQ7H1WoW16r+ TuUKaSI7nuLcXsv/oJ5XpNWGIjhZ8gfQ/imbYprx4XFndmOgLVszdr3QE9mtOiNYfKY0 ve1NKpuJm2iRSYtmzHAKOu0o3piDCwlPZzCg1Gf6SSvYc0YpUVsdQZsWkZz9CkCjGJ9x qJdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:user-agent:cc:subject:to:from :references:in-reply-to:content-transfer-encoding:mime-version :message-id:dkim-signature; bh=Iq6W5b285KrUDE+rxE5CdrYmcMCWWImQEwlR0dFM2bE=; b=NPXSJSU3SsVxaueN5wJr+X0x76uPpMFmNiwYC1zJRMIIzNCUKfNLLDJhjHgX4alRvI 4BfU1icU4aanpRrcg5MUDCm+R5WudnMaiu1Et+lezr/XSfM8ycV9E7H4DEhnR1sOFT+s kZGRjQ55Gm9TK5rE/Vt10ISbI25ZoiHTdzbXqk2m9VRGCKP4ozysBeFowMFglrSwhhhB ho3utBvxJZV8qwxV1CQ5AzEix0Z/cesDkG2jxFgb9yg0OVr028yvvLhVjG45n1ui47gF T+xAsZbwCGWkks+gxzg+/0k/ibjnRR7ZvgLr5z8DZY97PnuHDUrybygGIwQuo01+IL+Z +T+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="f/yeuiND"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q25si26935615pgv.114.2019.07.30.00.18.00; Tue, 30 Jul 2019 00:18:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="f/yeuiND"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388382AbfG2U4P (ORCPT + 99 others); Mon, 29 Jul 2019 16:56:15 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:38743 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388360AbfG2U4P (ORCPT ); Mon, 29 Jul 2019 16:56:15 -0400 Received: by mail-pg1-f196.google.com with SMTP id f5so20025795pgu.5 for ; Mon, 29 Jul 2019 13:56:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=message-id:mime-version:content-transfer-encoding:in-reply-to :references:from:to:subject:cc:user-agent:date; bh=Iq6W5b285KrUDE+rxE5CdrYmcMCWWImQEwlR0dFM2bE=; b=f/yeuiNDbPrjXuT+RnwPpAsP/eViKYRpJZVzyM+Kngqn9apFLepG8/tWmQ0UEm/NAf aRlMlR3PHw4Ccfb/+nqMIrd66PNnGAsuRmhYTNOUgj/5ouxZgyKD7rOzPrSI4jrivIR9 sylL9kP0Oeu/CdzSZLM/BgzeeJdOUPJyexvGs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:mime-version :content-transfer-encoding:in-reply-to:references:from:to:subject:cc :user-agent:date; bh=Iq6W5b285KrUDE+rxE5CdrYmcMCWWImQEwlR0dFM2bE=; b=oM/YTr5xDcbbUSwLBBBBrMRJtvHKPqB2dkBYWBo4VnJ77YXhtZzr0DBj+PMjLOsWcd Y0fchNeBC/RW9cwdTEuC4yl5Yy266TSUFkM5bni4zw5Vgc5l5ALJC2ZVcXquD7REzsau CiQfFaxCDSLGr59qs3hRTd/rjlAeasrtVBnNZ/z7cLa+nX0X8sDr5SirGiIg6r8EPXW8 qvmw01ZFiZYlcSyGJfp/SK05wSuDziiu1AQ5+4A33vZMyigjsAJ6dR9yovy+8AyiQYSS 0VhoOT3PZiXMN6vWdFZnlHFzMrSwWShmCQtOqqGLwCLQ4A/5M6oCbnj+uzKZ1X/hzQSt Z3Nw== X-Gm-Message-State: APjAAAU9CmC4pK0Gp9iRyWYhRrZMR6WQIbWgEAWN7yoMw+j1RrYfLPe5 bLtxSW6RNEUxpogbFY/jTzicP2KQX4U= X-Received: by 2002:a63:2c8:: with SMTP id 191mr104332462pgc.139.1564433774298; Mon, 29 Jul 2019 13:56:14 -0700 (PDT) Received: from chromium.org ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id o24sm121273158pfp.135.2019.07.29.13.56.13 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 29 Jul 2019 13:56:13 -0700 (PDT) Message-ID: <5d3f5d6d.1c69fb81.4c1e2.5be6@mx.google.com> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <20190729190139.GH18620@codeaurora.org> References: <20190722215340.3071-1-ilina@codeaurora.org> <20190722215340.3071-2-ilina@codeaurora.org> <5d3769df.1c69fb81.55d03.aa33@mx.google.com> <20190724145251.GB18620@codeaurora.org> <5d38b38e.1c69fb81.e8e5d.035b@mx.google.com> <20190724203610.GE18620@codeaurora.org> <20190725151851.GG18620@codeaurora.org> <20190729190139.GH18620@codeaurora.org> From: Stephen Boyd To: Doug Anderson , Lina Iyer Subject: Re: [PATCH V2 2/4] drivers: qcom: rpmh-rsc: avoid locking in the interrupt handler Cc: Andy Gross , Bjorn Andersson , linux-arm-msm , "open list:ARM/QUALCOMM SUPPORT" , Rajendra Nayak , LKML , Linux PM , mkshah@codeaurora.org User-Agent: alot/0.8.1 Date: Mon, 29 Jul 2019 13:56:12 -0700 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Lina Iyer (2019-07-29 12:01:39) > On Thu, Jul 25 2019 at 09:44 -0600, Doug Anderson wrote: > >On Thu, Jul 25, 2019 at 8:18 AM Lina Iyer wrote: > >> > >> On Wed, Jul 24 2019 at 17:28 -0600, Doug Anderson wrote: > >> > > >> >Jumping in without reading all the context, but I saw this fly by and > >> >it seemed odd. If I'm way off base then please ignore... > >> > > >> >Can you give more details? Why are these drivers in atomic contexts? > >> >If they are in atomic contexts because they are running in the context > >> >of an interrupt then your next patch in the series isn't so correct. > >> > > >> >Also: when people submit requests in atomic context are they always > >> >submitting an asynchronous request? In that case we could > >> >(presumably) just use a spinlock to protect the queue of async > >> >requests and a mutex for everything else? > >> Yes, drivers only make async requests in interrupt contexts. > > > >So correct me if I'm off base, but you're saying that drivers make > >requests in interrupt contexts even after your whole series and that's > >why you're using spinlocks instead of mutexes. ...but then in patch > >#3 in your series you say: > > > >> Switch over from using _irqsave/_irqrestore variants since we no longer > >> race with a lock from the interrupt handler. > > > >Those seem like contradictions. What happens if someone is holding > >the lock, then an interrupt fires, then the interrupt routine wants to > >do an async request. Boom, right? > > > The interrupt routine is handled by the driver and only completes the > waiting object (for sync requests). No other requests can be made from > our interrupt handler. The question is more if an interrupt handler for some consumer driver can call into this code and make an async request. Is that possible? If so, the concern is that the driver's interrupt handler can run and try to grab the lock on a CPU that already holds the lock in a non-irq disabled context. This would lead to a deadlock while the CPU servicing the interrupt waits for the lock held by another task that's been interrupted. >=20 > >> They cannot > >> use the sync variants. The async and sync variants are streamlined into > >> the same code path. Hence the use of spinlocks instead of mutexes > >> through the critical path. > > > >I will perhaps defer to Stephen who was the one thinking that a mutex > >would be a big win here. ...but if a mutex truly is a big win then it > >doesn't seem like it'd be that hard to have a linked list (protected > >by a spinlock) and then some type of async worker that: > > > >1. Grab the spinlock, pops one element off the linked list, release the = spinlock > >2. Grab the mutex, send the one element, release the mutex > This would be a problem when the request is made from an irq handler. We > want to keep things simple and quick. >=20 Is the problem that you want to use RPMh code from deep within the idle thread? As part of some sort of CPU idle driver for qcom platforms? The way this discussion is going it sounds like nothing is standing in the way of a design that use a kthread to pump messages off a queue of messages that is protected by a spinlock. The kthread would be woken up by the sync or async write to continue to pump messages out until the queue is empty.