Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp160014ybd; Tue, 25 Jun 2019 18:48:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqzzBgPwyPSDrq2kKRt6YDIQFAeoNIcFTkbfZV/LGYu+PMDFcw14FCh0iAHz0sZj5Ht9F7j4 X-Received: by 2002:a17:90a:22c6:: with SMTP id s64mr1177051pjc.5.1561513729816; Tue, 25 Jun 2019 18:48:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561513729; cv=none; d=google.com; s=arc-20160816; b=pO4L1sXTZNIzIE1ejrvbMCgneixV8sPpusaTT4n3qrLo2tVMtciOUKXLZTLgT/Yg7q 3uHX1oyjX54vufosDE2tb1iLAKp60Kgcc04KTRWX91wB+aMGzFchSYZxIa98sdE3mYng Wiw5xBs629w7pwukUKnFqwyh3AS0Gwc3FfsQ52rRLDbYwxcxfJ6aKFbM57ErjnbB5fT2 daQ8VAasxAXSkf8bKCHCTTjEouraAXFyKyW8aIELzMCfctKaZXe7EBRW2MECrjt6W6ua FfMwgGpx1rYuaRpaLWsUeNL/fqRCG/RxSMM4CbhXvLaIaU4GcK+8BVjTzdswEL6GDgZV tj+Q== 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; bh=7A4Dm+1oAsk+uZVQmN3o31RF/FXrm9afwX6wzcT3j2A=; b=wFpzZWDHmriiaE3ROdMa9PSXeK/dYyZbpKq5rceP52Ifm87vbhV8JjqJjyXuTvGa2f ghd1m9vF1/h2XbNzB3a6iUqAdktcrVAYwYpqmNZFwBe0fynLqExu8OjxKS0AQsYr+JUy RCsDwY6sgPGTmR7961L+wdemjtSU64r6yFtyyPIrEL230EQA1r/XvpApT/CxDumgaetU h33hGj6hbWhMI0CCT0crxuL4lfZjbpCPxqDaTyjyHXMFDSNjZr3lmMvLDuJIBahT9Di2 6dxc9SDuSYr/HQdcP71iYkF9IH2UBsq2mfD2Hv1NC8GCgso9lYJQNZGxbbT98osS57p/ l3sQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BL8S8Bzs; 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 p16si14591381pgm.11.2019.06.25.18.48.32; Tue, 25 Jun 2019 18:48:49 -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=@kernel.org header.s=default header.b=BL8S8Bzs; 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 S1726445AbfFZBsJ (ORCPT + 99 others); Tue, 25 Jun 2019 21:48:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:49104 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726401AbfFZBsJ (ORCPT ); Tue, 25 Jun 2019 21:48:09 -0400 Received: from localhost (li1825-44.members.linode.com [172.104.248.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BDC5C204EC; Wed, 26 Jun 2019 01:48:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561513688; bh=lhOKRprT7HVe0Z8Cz+OabL8qmzBmCh0WUg8YKiJg6kI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BL8S8BzsOC1JOHpaxjj/CTatmCr1mGi07Q7JwyCKDT+4+v22IeNWUhCXfpmspHgxG cUK/l3MuLXJTLFZSH+DOHSUmj+O8ZYqciueHRuR7ZoT3lqpr5xlAA+jyBRjKq7h60F V9Ii3OEqVpE7rxOOnaIqsvmncQprx25jWE1XQuvA= Date: Wed, 26 Jun 2019 09:46:33 +0800 From: Greg KH To: Tri Vo Cc: "Rafael J. Wysocki" , Viresh Kumar , "Rafael J. Wysocki" , Hridya Valsaraju , Sandeep Patil , LKML , Linux PM , "Cc: Android Kernel" Subject: Re: [PATCH] PM / wakeup: show wakeup sources stats in sysfs Message-ID: <20190626014633.GA22610@kroah.com> References: <20190626005449.225796-1-trong@android.com> <20190626011221.GB22454@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 25, 2019 at 06:33:08PM -0700, Tri Vo wrote: > On Tue, Jun 25, 2019 at 6:12 PM Greg KH wrote: > > > +static ssize_t wakeup_source_count_show(struct wakeup_source *ws, > > > + struct wakeup_source_attribute *attr, > > > + char *buf) > > > +{ > > > + unsigned long flags; > > > + unsigned long var; > > > + > > > + spin_lock_irqsave(&ws->lock, flags); > > > + if (strcmp(attr->attr.name, "active_count") == 0) > > > + var = ws->active_count; > > > + else if (strcmp(attr->attr.name, "event_count") == 0) > > > + var = ws->event_count; > > > + else if (strcmp(attr->attr.name, "wakeup_count") == 0) > > > + var = ws->wakeup_count; > > > + else > > > + var = ws->expire_count; > > > + spin_unlock_irqrestore(&ws->lock, flags); > > > + > > > + return sprintf(buf, "%lu\n", var); > > > +} > > > > Why is this lock always needed to be grabbed? You are just reading a > > value, who cares if it changes inbetween reading it and returning the > > buffer string as it can change at that point in time anyway? > > Right, we don't care if the value changes in between us reading and > printing it. However, IIUC not grabbing this lock results in a data > race, which is undefined behavior. A data race where? Writing to the value? How can that happen? All you are doing is incrementing this variable elsewhere, what is the worst that can happen? thanks, greg k-h