Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp3044588ybh; Mon, 5 Aug 2019 11:00:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqzpHmvACEoTpcQMEzj+47rN7LeigDk2WdW+najw5OlTX5xsFeIfG56m7ZiIOq2GaOPgt5HT X-Received: by 2002:a17:90a:1b48:: with SMTP id q66mr18569799pjq.83.1565028037702; Mon, 05 Aug 2019 11:00:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565028037; cv=none; d=google.com; s=arc-20160816; b=Tc8UrmszujckJ7sV2h5oNSRV01IIJz6z0x3IITsD7c9FX3NyJbmlrAmaMdRu+7Mwvr g0F4kbpZ5NAeshPTWMb6BMykcU3WNBHxwICQPLGU9o5XEbYT0pjbokXFOXNv9+l/IdDh mgV64nZdkRwBvG+pUNXdNrfddd+DGwDzuTkqPePmxGqmmv2JVikAsRxpN51B/Z1Xg/TS 2pIgr3XYCobPFtsJdcaK/n7otN6oqgJutKbxFP/KXOQRZRppFsvIKVB09Er1mp5ibpHF nirvt2CJXFkJxC4dyDvQgGjrFZW8hHCqIVRFSTiFw8ug7zM+qIeHeSuokSg+wexbL5Fk hqSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=ud8kaTYnOTLsJDKCOZKHErxyavHvXjt//haLV/7Osr0=; b=zUd1jrbfhtTho40wZ5cY2flJYHw1gppjuxHUm7W8ieF2rvdpVxK2PxdsZtZmqnGCF/ hkARSsgpQtDBd1fWFHUhtAGE4tAfYspKQY02SgEQyuKF3AvzHRXAE8KBXefWbCUR2IR2 9J+9yHdS892vcS7yMBqY7Gaq4YNwdzf5DNDHHO9cuIZ/a7CNf9hMHhMQVeO126qq+iXt 5vmq3Nk2LHoJm4Ee/gZPyj1zr3doiLc4Wmw6Iq4Hws3q6x0+KJjT3xMn2PcL7RbUOuHP BqIMNuzXdKzPxLmTuD5DtMJ+Sbvzd1HEKbEqM4s8U+Tom0zEnCKup/4dC0YDULV9T11F AaRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b=hGv9CDgT; 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 c7si13711528pgk.126.2019.08.05.11.00.21; Mon, 05 Aug 2019 11:00:37 -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=hGv9CDgT; 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 S1728885AbfHER7i (ORCPT + 99 others); Mon, 5 Aug 2019 13:59:38 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:45064 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726779AbfHER7h (ORCPT ); Mon, 5 Aug 2019 13:59:37 -0400 Received: by mail-pl1-f196.google.com with SMTP id y8so36780030plr.12 for ; Mon, 05 Aug 2019 10:59:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=android.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ud8kaTYnOTLsJDKCOZKHErxyavHvXjt//haLV/7Osr0=; b=hGv9CDgTazwbClR18fPbNFhTKGeCpdG7RyYZ0RgTJwkDw2aXb20quOE6DK9Eht6Z7z 2MofnoF7J4WkV1cYD08hq/4gFHLbNc5XqtgO+cXa9HIL6zH5+G6dcDy46jNhO7QohcBB KqlzL7A3QAjCFunqxat85FVs4BDNh8lb7lCvGlqIFTjgA9iiGf67aABNq4oWuQXDcf75 C/RWme/+HRNYZOySvQLeFJ6j4o8EitJf03vvmqVPdku+9AHjBJTgJ9j45Du7RlPmP6s1 6xpMQqA9OexXzEbbjrT3gFx1ylDOAk3kRJO/qr894VSkZ0uVau7xs9NhaVJ2P4hmPw8Z kJQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ud8kaTYnOTLsJDKCOZKHErxyavHvXjt//haLV/7Osr0=; b=gmPqRL4wD610r/GFwudgbZInw/RonEXBV/yYxaprgduYgtfZp6NQ7coADhZ73yJz+O MyQQSfg7wL+a5h5YWOTUf1DYg1VRLT+hiTvijxjN6SJw/XxYKcm9DqSRhZDdQAAsR/wg +eXRPSFD9LUhl79uWIR6kUABQ0ar6z7nAbMG77ZzGhkcQxdq+R7clz+BvIkta56IdMBd E8SCyYEmA316aqeolb5AkhjJeYvNHm4DEQrXMXyDx4EjCpQ0L1b0HWYToYBI2hM/+Xz9 EbJbTJVyGog9hSUs6kBc72NGcReJVgulfSfdzUvpB1JoGRWIRfHwh1ntA4lAavH2P6+E xJ4g== X-Gm-Message-State: APjAAAUOTadCF3ggcmOW4lK944C0aqgxyIN8wfidDTrbwTJbRsWLhajp LfvgS5Yxg1KNR/CBz96eyyY= X-Received: by 2002:a17:902:7894:: with SMTP id q20mr140347877pll.339.1565027976621; Mon, 05 Aug 2019 10:59:36 -0700 (PDT) Received: from trong0.mtv.corp.google.com ([2620:15c:211:0:469:982a:29da:f29b]) by smtp.gmail.com with ESMTPSA id f19sm124403670pfk.180.2019.08.05.10.59.35 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 05 Aug 2019 10:59:36 -0700 (PDT) From: Tri Vo To: rjw@rjwysocki.net, gregkh@linuxfoundation.org, viresh.kumar@linaro.org Cc: rafael@kernel.org, hridya@google.com, sspatil@google.com, kaleshsingh@google.com, ravisadineni@chromium.org, swboyd@chromium.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, kernel-team@android.com, Tri Vo Subject: [PATCH v7 0/3] PM / wakeup: show wakeup sources stats in sysfs Date: Mon, 5 Aug 2019 10:58:45 -0700 Message-Id: <20190805175848.163558-1-trong@android.com> X-Mailer: git-send-email 2.22.0.770.g0f2c4a37fd-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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/*. Patch 1 and 2 do some cleanup to simplify our changes to how wakeup sources are created. Patch 3 implements wakeup sources stats in sysfs. Tri Vo (3): PM / wakeup: Drop wakeup_source_init(), wakeup_source_prepare() PM / wakeup: Use wakeup_source_register() in wakelock.c PM / wakeup: Show wakeup sources stats in sysfs Documentation/ABI/testing/sysfs-class-wakeup | 76 +++++++++ drivers/acpi/device_pm.c | 3 +- drivers/base/power/Makefile | 2 +- drivers/base/power/power.h | 9 ++ drivers/base/power/wakeup.c | 59 ++++--- drivers/base/power/wakeup_stats.c | 161 +++++++++++++++++++ fs/eventpoll.c | 4 +- include/linux/pm_wakeup.h | 21 +-- kernel/power/autosleep.c | 2 +- kernel/power/wakelock.c | 32 ++-- kernel/time/alarmtimer.c | 2 +- 11 files changed, 316 insertions(+), 55 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. v6: - Changed stats location to /sys/class/wakeup/ws/* - Replaced ida_simple_get()/ida_simple_remove() with ida_alloc()/ida_free() as the former is deprecated. - Reverted changes to device_init_wakeup(). Rafael is preparing a patch to deal with extra wakeup source allocation in a separate patch. v7: - Removed wakeup_source_init(), wakeup_source_prepare(). - Removed duplicate wakeup source creation code from kernel/power/wakelock. - Moved ID allocation to wakeup source object creation time. - Changed stats location back to /sys/class/wakeup/wakeup/* - Remove wakeup source device's "power" attributes. -- 2.22.0.770.g0f2c4a37fd-goog