Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp5168925ybi; Tue, 30 Jul 2019 15:17:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqz4Qs1G7nNOenW2Wh+JCmlucI1BNR+R2KBfyYhN1ctNgRw8nOo7u+MKpOZoIn63RBAzfYGL X-Received: by 2002:a17:90a:a00d:: with SMTP id q13mr116844021pjp.80.1564525042988; Tue, 30 Jul 2019 15:17:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564525042; cv=none; d=google.com; s=arc-20160816; b=N64xiloW8F6viC436rGZYubKfjt4s9BrGG/uWmKENvwp5zzrukF2ge9UUMcuSsQgXP HcrURJ2pA+JAiRtkVlSbpMnXfVFjt++SlTNi1LzVXnvHAtZzjL+fiem90LmOZmU+9+cr /JppohhPTFUmlrouPeh4frxy90OatXRIb6H8Q6EZgS1kZIXc1fzwGegHiyEO0UOttxsj u9bzE9ufZbrJx+5ncIPV/TLqHmlq5gXnwTbdm8h8yDsEkdz427q3YHWKIPCzmVjzZq/0 DohWbOqay+pFY4Yeh8dvCclXWDSDYG3e6+L/v5MlfEA5ARqfFuXGmbWRGYK2T1+C1fSt c9kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Hn8rVqsLu57CTsIv+4AEu3lgPz7dzu5u0LtZwakTzpQ=; b=CBcvdevrB/fz5t/b261kVutjnpIQAAwAgBZ6d4q2W8AgTO4snjBjTlgVM3EtbHmXGp /Y5cUKkr4UevYPCrofpHQgmfKY7mrP/l0veN1YhwqnxQ3gPcFNiL/M1aUE8K90rP3sbP 2i30exedkc9yRMaOuaHdyOKGQlghd7uhhEqx+JRjkdWMOpuqtdkO5k33sisYDzaSRj3d ecxk+Kmo9tsEE1pKM5r5oIbqHdiO7q6+zEPOxkNNpNqLMrgbJHiPLefcJDaz9RUwff2l QAYTi7ttV1hnOuoJWj6GO+VvwflI1Kc86irtSUimTrhtvI75WSGBwXj92YzMOqnl3X/M FAlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b=aZq4W3sY; 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=REJECT sp=REJECT dis=NONE) header.from=android.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 185si31722796pgc.522.2019.07.30.15.17.08; Tue, 30 Jul 2019 15:17:22 -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=@android.com header.s=20161025 header.b=aZq4W3sY; 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=REJECT sp=REJECT dis=NONE) header.from=android.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730088AbfG3Sjq (ORCPT + 99 others); Tue, 30 Jul 2019 14:39:46 -0400 Received: from mail-oi1-f195.google.com ([209.85.167.195]:36180 "EHLO mail-oi1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729994AbfG3Sjq (ORCPT ); Tue, 30 Jul 2019 14:39:46 -0400 Received: by mail-oi1-f195.google.com with SMTP id q4so19483817oij.3 for ; Tue, 30 Jul 2019 11:39:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=android.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Hn8rVqsLu57CTsIv+4AEu3lgPz7dzu5u0LtZwakTzpQ=; b=aZq4W3sYpLbfDXk5mPkDRrGoJ9ERrPYOH1zTUawx2IBk9XlL1qSZOl4yzfvfL6lp4M mW8BUurVMViiftyaCdfttaIrynR3pQLSfUsP0pYx2Xa+rrmVgxB4/ajPx5Ia37i8SKKB JVbwfSMPoPgxuthtY56dIC9aQLYBODZDnwAlFGbDq6lG7ZhY2DSg7W8XyOvx6Opbn2Pq Qxae5KbdBEwPr1o8HPt5Can+Qah0B7u2dsFtxAtFMQEepS3fEsVCRjgRCJY4Mu29f+q6 YMQ8ayP2AL+nzAdJPXhcxlxwzyBLScI2Rp1M+5mLTjZgSUrj45+O4e1F8SPftegc70+c hPDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Hn8rVqsLu57CTsIv+4AEu3lgPz7dzu5u0LtZwakTzpQ=; b=hT8PR/aiKjgn5Du9y5NHqo7vTgyAPQwCCYduq9cviE+pDjYbcOCmL5/ZpdLizz0rin YTW/+zNSZ14nfVl2Ka59KoMxb7ypy38/t7apMN7Fev4KOh1aZYk8lFYwRoC9CxFoKcDN Mtot3kdFchlIHvZ3Odig24bpo6muoZtfIbJlWHF1C5q7FsKiLwBjJssoqk/T7ReBba5l 30AG3qnKfLyMnwa1brNJJ0Pa4mfEF2MuAmrttSReeBCMDyqtN7TecjzKZu0OG/VhB9C8 rZ6pgQu3JeeR3BZDnD65a+1F2ZMm7mqqDriE5wjX2OJ6pt9krwB7Rbbjqxe91Z9pH6He WsxQ== X-Gm-Message-State: APjAAAUNB0/kiX3n0NowcII27sjMpxoOOKiHo8VZ58fDeYrOEf88QhF3 ++torHzaacXPbHKAwp7aRvNhOg43X3kpFBgvGdw= X-Received: by 2002:aca:3509:: with SMTP id c9mr60354165oia.179.1564511985221; Tue, 30 Jul 2019 11:39:45 -0700 (PDT) MIME-Version: 1.0 References: <20190730024309.233728-1-trong@android.com> In-Reply-To: From: Tri Vo Date: Tue, 30 Jul 2019 11:39:34 -0700 Message-ID: Subject: Re: [PATCH v5] PM / wakeup: show wakeup sources stats in sysfs To: "Rafael J. Wysocki" Cc: "Rafael J. Wysocki" , Greg Kroah-Hartman , Viresh Kumar , Hridya Valsaraju , Sandeep Patil , Kalesh Singh , Ravi Chandra Sadineni , Stephen Boyd , Linux Kernel Mailing List , Linux PM , "Cc: Android Kernel" , kbuild test robot Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 29, 2019 at 10:46 PM Rafael J. Wysocki wrote: > > On Tue, Jul 30, 2019 at 4:45 AM Tri Vo wrote: > > > > Userspace can use wakeup_sources debugfs node to plot history of suspend > > blocking wakeup sources over device's boot cycle. This information can > > then be used (1) for power-specific bug reporting and (2) towards > > attributing battery consumption to specific processes over a period of > > time. > > > > However, debugfs doesn't have stable ABI. For this reason, create a > > 'struct device' to expose wakeup sources statistics in sysfs under > > /sys/class/wakeup/wakeup/*. > > > > Co-developed-by: Greg Kroah-Hartman > > Signed-off-by: Greg Kroah-Hartman > > Co-developed-by: Stephen Boyd > > Signed-off-by: Stephen Boyd > > Signed-off-by: Tri Vo > > Tested-by: Tri Vo > > Tested-by: Kalesh Singh > > Reported-by: kbuild test robot > > --- > > Documentation/ABI/testing/sysfs-class-wakeup | 76 +++++++++ > > drivers/acpi/device_pm.c | 3 +- > > drivers/base/power/Makefile | 2 +- > > drivers/base/power/wakeup.c | 21 ++- > > drivers/base/power/wakeup_stats.c | 171 +++++++++++++++++++ > > fs/eventpoll.c | 4 +- > > include/linux/pm_wakeup.h | 15 +- > > kernel/power/autosleep.c | 2 +- > > kernel/power/wakelock.c | 10 ++ > > kernel/time/alarmtimer.c | 2 +- > > 10 files changed, 294 insertions(+), 12 deletions(-) > > create mode 100644 Documentation/ABI/testing/sysfs-class-wakeup > > create mode 100644 drivers/base/power/wakeup_stats.c > > > > v2: > > - Updated Documentation/ABI/, as per Greg. > > - Removed locks in attribute functions, as per Greg. > > - Lifetimes of struct wakelock and struck wakeup_source are now different due to > > the latter embedding a refcounted kobject. Changed it so that struct wakelock > > only has a pointer to struct wakeup_source, instead of embedding it. > > - Added CONFIG_PM_SLEEP_STATS that enables/disables wakeup source statistics in > > sysfs. > > > > v3: > > Changes by Greg: > > - Reworked code to use 'struct device' instead of raw kobjects. > > - Updated documentation file. > > - Only link wakeup_stats.o when CONFIG_PM_SLEEP_STATS is enabled. > > Changes by Tri: > > - Reverted changes to kernel/power/wakelock.c. 'struct device' hides kobject > > operations. So no need to handle lifetimes in wakelock.c > > > > v4: > > - Added 'Co-developed-by:' and 'Tested-by:' fields to commit message. > > - Moved new documentation to a separate file > > Documentation/ABI/testing/sysfs-class-wakeup, as per Greg. > > - Fixed copyright header in drivers/base/power/wakeup_stats.c, as per Greg. > > > > v5: > > - Removed CONFIG_PM_SLEEP_STATS > > - Used PTR_ERR_OR_ZERO instead of if(IS_ERR(...)) + PTR_ERR, reported by > > kbuild test robot > > - Stephen reported that a call to device_init_wakeup() and writing 'enabled' to > > that device's power/wakeup file results in multiple wakeup source being > > allocated for that device. Changed device_wakeup_enable() to check if device > > wakeup was previously enabled. > > Changes by Stephen: > > - Changed stats location from /sys/class/wakeup//* to > > /sys/class/wakeup/wakeup/*, where ID is an IDA-allocated integer. This > > avoids name collisions in /sys/class/wakeup/ directory. > > - Added a "name" attribute to wakeup sources, and updated documentation. > > - Device registering the wakeup source is now the parent of the wakeup source. > > Updated wakeup_source_register()'s signature and its callers accordingly. > > And I really don't like these changes. Especially having "wakeup" > twice in the path. I can trim it down to /sys/class/wakeup//. Does that sound good? About the other change, I think making the registering device the parent of the wakeup source is a worthwhile change, since that way one can associate a wakeup source sysfs entry with the device that created it. > > Couldn't you find a simpler way to avoid the name collisions? I could also simply log an error in case of a name collision instead of failing hard. That way I can keep the old path with the wakeup source name in it. Other than that, I can't think of a way to resolve the directory name collisions without making that directory name unique, i.e. generating IDs is probably the simplest way. I'm still learning about the kernel, and I might be wrong though. What do you think?