Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1932537imm; Thu, 7 Jun 2018 02:40:12 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJlCt4Q5lTOHH0gDNGUc4xqQNtnD7ZTIDbdRgUFz3zI9JO5LijWSPRKd9SnLfZAH1sxFDwc X-Received: by 2002:a17:902:aa84:: with SMTP id d4-v6mr1286017plr.352.1528364412946; Thu, 07 Jun 2018 02:40:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528364412; cv=none; d=google.com; s=arc-20160816; b=dGvwZc90iex7/S8Z3Kp6fS4PIZScNG6J5kW0eVPJ2hlC24veXBdcLZhwVqfObHL0NQ DlqqRX+2ipS0OVkA376Rlx+5rf/YpnbhW3AQpxMQDsS0c0bZ7w1FcyeHvqeWaFr8Ol8P gVrUuZkNbd0oXjqRysEPnJEzx2cRyGwAfJV8icxt8SaCkP5fQxkAOThjZLx6bEx008C/ tWZ5fNMUJ/srIE1AWYwPCHKCIOsPWdpvFjAnza9ASk3T0u5JTpOVdmcoUb0/5MZ8qMRn AYZLkwfdbDGitDhWI6NDow4lgaFQBojciOyD7w3BSHD0pGUE2SBeT0QYzH2MHOEM6dPP ailQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=/FDfsejbOmCnaRdOOAbZGKkWIqpnxcbE5+Y1OBQYFT4=; b=bKgnA+LaH8pjz9p7KT0gI3ziQd9fxlNfCxYbKlwjjt+YaHOK8x7eKIdmqc4M1dSR5f bhJASJ8f02NOiE0CRFmGbIJWPSzHDEl9z/3QlWH/bQNUbMVpv7GfscJYglvwWe/ejRBO WtPjdvCm8W4t+2ng+0rEvz22A+JepSaJ/DIFEJ9FMwqcV9qGPJoYNFdwlFdj32HtfRKe QQfau4wY3wQS1u/RlIPDI/Km5E/tBwjfIkBKwQ+MhzTdBUft4kc9RFN5Cji76MS0/lHb aCcJPhHqhv97zD/fAlfB7+I5WFB2FZ48PbY9LjYO8ZpSP2KamynAsvaHdzpteFiqNcOM GSnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=QF+TvzlR; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i8-v6si15827516pgf.649.2018.06.07.02.39.57; Thu, 07 Jun 2018 02:40:12 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=QF+TvzlR; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753510AbeFGJjc (ORCPT + 99 others); Thu, 7 Jun 2018 05:39:32 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:60902 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753095AbeFGJja (ORCPT ); Thu, 7 Jun 2018 05:39:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=/FDfsejbOmCnaRdOOAbZGKkWIqpnxcbE5+Y1OBQYFT4=; b=QF+TvzlRna4mxZBm3FWO68xyH Ofws5i5st5UZXGfjI1p05btLfE9obLPNibyE+IUO3+WlPFBeLXDvzpurQCVEFAFPfSLGa0fNKmgQg o4SRfop9tVSySQGmf0leVHd4+MAOOMBSZa7aupCYD7S11vtQ3PH4PEGXnLU3hq4ijzuKe1ZH64ZCb +R4SgTpwBHmEaXSQntgb6Y4ZxolFHc2E9C6I8b5a+/wieRcoreib3nSti09vsO7I5clD0LTflDsWY z2d6S4FPRNSCu/CigNvgDHiL+bmLupJsXqRi97n8M2F2FEU7Pj+3KEKccujZlzaZzkOOzssD8SsMA Yk0peSXEQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fQrOC-0003H1-R1; Thu, 07 Jun 2018 09:39:29 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 53A57201EA7A5; Thu, 7 Jun 2018 11:39:27 +0200 (CEST) Date: Thu, 7 Jun 2018 11:39:27 +0200 From: Peter Zijlstra To: Daniel Lezcano Cc: Viresh Kumar , rjw@rjwysocki.net, linux-kernel@vger.kernel.org, Eduardo Valentin , Javi Merino , Leo Yan , Kevin Wangtao , Vincent Guittot , Rui Zhang , Daniel Thompson , "open list:POWER MANAGEMENT CORE" Subject: Re: [PATCH V5] powercap/drivers/idle_injection: Add an idle injection framework Message-ID: <20180607093927.GE12235@hirez.programming.kicks-ass.net> References: <20180606122357.GN12258@hirez.programming.kicks-ass.net> <22f5cf0b-049e-7938-55f6-4b4b154f8389@linaro.org> <20180606150203.GE12180@hirez.programming.kicks-ass.net> <20180607083229.GJ12198@hirez.programming.kicks-ass.net> <20180607084251.rv2tg3kgz4aohlpd@vireshk-i7> <9996fb40-c7aa-db61-5445-52c146f44d85@linaro.org> <20180607084921.toctrooftl6y7kkx@vireshk-i7> <20180607093201.GL12198@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180607093201.GL12198@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 07, 2018 at 11:32:01AM +0200, Peter Zijlstra wrote: > On Thu, Jun 07, 2018 at 11:09:13AM +0200, Daniel Lezcano wrote: > > On 07/06/2018 10:49, Viresh Kumar wrote: > > > On 07-06-18, 10:46, Daniel Lezcano wrote: > > >> Yes, correct. > > >> > > >> But if we don't care about who wins to store to value, is there a risk > > >> of scramble variable if we just assign a value ? > > > > > > Normally no, as the compiler wouldn't screw it up badly. But there is no rule > > > which stops the compiler from doing this: > > > > > > idle_duration_ms = 5; > > > idle_duration_ms = -5; > > > idle_duration_ms = 0; > > > idle_duration_ms = ; > > > > > > So we *must* use READ/WRITE_ONCE() to make sure garbage values aren't seen by > > > readers. > > > > Ok understood. Why would a compiler do this kind of things ? > > I think the above can happen when the compiler uses the variable as a > scratch pad -- very rare I would say. > > In general a compiler needs to proof that doing this makes no observable > difference ("as-if" rule). And since it is a regular variable it can > assume data-race-free and do the above (or something like that). Because > if there is a data-race it is UB and it can still do whatever it > pleases. > > And here I think the point is that regular variables are considered only > in the context of a single linear execution context. Locks are assumed > to bound observability. > > And here the "volatile" and "_atomic" type specifiers again tell the > compiler something 'special' is going on and you should not muck with > things. Also, I think, more likely: if (cond) X = 5; else X = 4; is allowed to be transformed into: X = 4; if (cond) X = 5; as long as cond doesn't involve a sequence point of sorts (think function call). For the single execution context case, this transformation is valid, but it is not in the threaded case. But then we go back to the assumption that regular variables are data-race-free.