Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7589458ybi; Mon, 22 Jul 2019 16:20:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqxxdBBvjVHpI20UHDqssU6/LHecEG8Ln9V6gqYVmyznDdsyhZ+crw7ZnruSI6uahOHf6L0y X-Received: by 2002:a17:90a:9905:: with SMTP id b5mr81157348pjp.70.1563837632139; Mon, 22 Jul 2019 16:20:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563837632; cv=none; d=google.com; s=arc-20160816; b=gjy/VA3BQl5+5jloK4fH2L9hWznwlZfBY7oNm5kjGgd5n+Yh9Q7wIwiLi1NQ8CzNqg 3zLnmXjLKrYLOnEJOM1P+2ZsLHOyN5NJM3VT98G1DRdXm3SeE9volhpMxOfA6X3MkAFW DpJPdH1QPQ+q/rywtZs3f04OjUlw2XbdhPmFjb5eAlmjw/eLc+aJhzkB0+/mivs4xoJU TWvt6Ofxxo1A8GJeqokYPbk6I8iBTuJRULkIrIuv/aBZA8tOOFJ+i5KT2iJRnXCyBI1/ wB6iElvjbiJL1UAaZwT/m6Bsvy+MjqXznbsIClNoaMEgOt2rr7EeV2JQ7qHVnScINxa/ HfUA== 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=J6ELu1lgzjUvv37OXpojPn/RA3Hbvj8E2leT/A0LtLM=; b=wx3U+0nes/Bwmm3/yhcQKZRTB0ryfWb5WCVWKIANAD81V3Ydoy14PPMex7HJrg99md I4Wyyo5f2cYGll2xnDw9O1WX1H0amb4veuu8x+1+3BNP+2UbqNt1drR5mssCOKDUgYCu WBp09/pRB/VRnpGdxhjL7nUdASxZfX+9iD+ffMd15pfeuVOr8ksQrbwvA/oMkKz+eQDo HBr1lxiuD7TV6mvx1pj2ctust5FIyFx/GQq9owDSz1yNhPCrzgIFqqo+eJ2DkJjDtaSX MFU8v4JsREQkjpBLmt1xAwULxasg2PaKcIVPh3ubTHPsDoiU/G1U6YyadREYeUTNL4Jf yM+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YlyyurH9; 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 145si10021061pfb.262.2019.07.22.16.20.15; Mon, 22 Jul 2019 16:20:32 -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=YlyyurH9; 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 S1731577AbfGVSW4 (ORCPT + 99 others); Mon, 22 Jul 2019 14:22:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:60040 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726120AbfGVSW4 (ORCPT ); Mon, 22 Jul 2019 14:22:56 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 7B52021901; Mon, 22 Jul 2019 18:22:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563819775; bh=J9M7faZ41fDOYZssXZM6tk4l7o043dO6n8/RMOul8QQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YlyyurH9m+xtpjE6DT+vlJNbAd1S2BPOTLxWBn89GnqD2uyJuv5XYTe2nU+DY0wV2 awRf1tuM1dRG+t8rpdDPX36lb2irTphUakv8OwyH9vVXYqvS8VTJRh0PGPfHZpsXLK gWJ7eRbUoWwwWm6pXQaFOv7gx1WemlQNM+o8IwG0= Date: Mon, 22 Jul 2019 20:22:52 +0200 From: Greg KH To: Ravi Chandra Sadineni Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, rjw@rjwysocki.net, pavel@ucw.cz, len.brown@intel.com, bhe@redhat.com, dyoung@redhat.com, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, tbroch@chromium.org Subject: Re: [PATCH] power:sysfs: Expose device wakeup_event_count. Message-ID: <20190722182252.GA24412@kroah.com> References: <20190722180258.255949-1-ravisadineni@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190722180258.255949-1-ravisadineni@chromium.org> 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 Mon, Jul 22, 2019 at 11:02:58AM -0700, Ravi Chandra Sadineni wrote: > Device level event_count can help user level daemon to track if a > praticular device has seen an wake interrupt during a suspend resume > cycle. Thus expose it via sysfs. > > Signed-off-by: Ravi Chandra Sadineni > --- > Documentation/ABI/testing/sysfs-devices-power | 11 ++++++++++ > drivers/base/power/sysfs.c | 20 +++++++++++++++++++ > 2 files changed, 31 insertions(+) > > diff --git a/Documentation/ABI/testing/sysfs-devices-power b/Documentation/ABI/testing/sysfs-devices-power > index 1ca04b4f0489..344549f4013f 100644 > --- a/Documentation/ABI/testing/sysfs-devices-power > +++ b/Documentation/ABI/testing/sysfs-devices-power > @@ -89,6 +89,17 @@ Description: > attribute is not present. If the device is not enabled to wake > up the system from sleep states, this attribute is empty. > > +What: /sys/devices/.../power/wakeup_event_count > +Date: July 2019 > +Contact: Ravi Chandra sadineni > +Description: > + The /sys/devices/.../wakeup_event_count attribute contains the > + number of signaled wakeup events associated with the device. > + This attribute is read-only. If the device is not capable to > + wake up the system from sleep states, this attribute is not > + present. If the device is not enabled to wake up the system > + from sleep states, this attribute is empty. The attribute is not "empty" it returns just an empty line. Is that really a good thing if you are expecting a number? > + > What: /sys/devices/.../power/wakeup_active_count > Date: September 2010 > Contact: Rafael J. Wysocki > diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c > index f42044d9711c..8dc1235b9784 100644 > --- a/drivers/base/power/sysfs.c > +++ b/drivers/base/power/sysfs.c > @@ -357,6 +357,25 @@ static ssize_t wakeup_count_show(struct device *dev, > > static DEVICE_ATTR_RO(wakeup_count); > > +static ssize_t wakeup_event_count_show(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + unsigned long count = 0; > + bool enabled = false; > + > + spin_lock_irq(&dev->power.lock); > + if (dev->power.wakeup) { > + count = dev->power.wakeup->event_count; > + enabled = true; > + } > + spin_unlock_irq(&dev->power.lock); Why do you need to lock? The state and count can change right after the lock, so what does this help with? > + return enabled ? sprintf(buf, "%lu\n", count) : sprintf(buf, "\n"); Use a real if statement please. > +} > + > +static DEVICE_ATTR_RO(wakeup_event_count); > + > + > + too many empty lines :) thanks, greg k-h