Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6600918ybi; Wed, 31 Jul 2019 17:48:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqwlmP72lAI3Plm48VaxgjR90p7LPPIPFTHq4j74z0V7OEgyC7smr5/gxRdVIFtp3dYOzFEh X-Received: by 2002:a17:902:6ac6:: with SMTP id i6mr123702437plt.233.1564620485543; Wed, 31 Jul 2019 17:48:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564620485; cv=none; d=google.com; s=arc-20160816; b=TSoDpMryXlq4jBYZkcj+9MWnviD/hplpzVKr+bBtwwbBhLeyUCYAd5fj9Tw8HBK77k 3SjvVl0kYb7J/2BVLy3i7VdZP3v/gWvR2W3RGgLVH7yDhcbC5rBctIf5Rc/8c9i/BY6F vMGBeIQN5Mmhjrqtzbmxo1IjcvxLwDTD2RydwNlB39mx2Xn6HQi7I/FqYGh5XCiMMVCy v7JyXzJhAAzee7L8wr7JRQKj1/X5x6mgjwlYEAbroEuYA+nIRnSSD0t9pzpI4BUcr+Zr yjR4iShg5Ny9HB9EElD3dL8ZjxT/hyc08q4Um8ZeE+5ajFie9pnSYVdsmODzc7MkcKrO F8NQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:user-agent:subject:to:from:cc :references:in-reply-to:content-transfer-encoding:mime-version :message-id:dkim-signature; bh=Gk2QCSUiXttK0DpMjrYYxGGSGPwiVtPzozTzPLwckQk=; b=pCAQGia3bm8mIAasOigtRUJ49ViM9P6NGc7HmP8s7Q/BFIDFZ20auKOstWziBIcQy4 G4M9wD4h19sGZ/7OOdCJe2LYU9LnG6quXHKGOCXGJE/h7Mmwif/WuiwWrgK9XG6JA9/q 8PD/av92zekk3ngpdDOPwE27GvOnvpWdKYqFZiJuHvyr7Ptvx1ZAXmKAolPR5plQof2k lDQ8Z7e5LjO6aVNSWbIJIfg2LplDK0zjIbzGsiFCQZlpAT2zVSok1xNwDwh0hc76nI8K sljSGWwiozLBoWEFjGohK9s0ATAup8nfpagElMLzM6qGWit8/LF1badoGpMrYofNdMP0 1fkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OZNZh5Rg; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p4si17231752pgk.496.2019.07.31.17.47.50; Wed, 31 Jul 2019 17:48:05 -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=@chromium.org header.s=google header.b=OZNZh5Rg; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729012AbfHAApq (ORCPT + 99 others); Wed, 31 Jul 2019 20:45:46 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:33233 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728847AbfHAApp (ORCPT ); Wed, 31 Jul 2019 20:45:45 -0400 Received: by mail-pl1-f194.google.com with SMTP id c14so31138309plo.0 for ; Wed, 31 Jul 2019 17:45:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=message-id:mime-version:content-transfer-encoding:in-reply-to :references:cc:from:to:subject:user-agent:date; bh=Gk2QCSUiXttK0DpMjrYYxGGSGPwiVtPzozTzPLwckQk=; b=OZNZh5RgQj+c21xd9fx1O0GKIykxqvn0eo7tx5caoozgFnc6gFlrrU00H6PijLBp/T 8Ed2i5y7wYz0704iX7SL1rPJPnwQ7nEta0IkzPUcGhqq5UdZpxjkmXAG/EJLo9xTQAWJ TIZv4yn7bzDpkyXOp2JwxU+BzcaybpOJiwP90= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:mime-version :content-transfer-encoding:in-reply-to:references:cc:from:to:subject :user-agent:date; bh=Gk2QCSUiXttK0DpMjrYYxGGSGPwiVtPzozTzPLwckQk=; b=iVuDXtNzkLWlQMsT73dzGIthpPT9ZDLpfJ/QKdzlufWYZJKjm3gw2UTlacVNzpCsLq fXSWpGkr683kGkSQQRZKzmerxZKyNLFtcciF1VMwBCN8lPp0pHfokKtqAtpyRm7vxJ57 250ixS4sKy4AtFXJM0cLtdyAIdBC7h5kYPCHpFO2ZT2slnwJEz995PjjQSN8ksGddsGx wtcGHw/cMuH/BFIowvuu6VEkFb1oQwRFDd7H1bRLbNYyRqcQa0or+hgx7hWBvd6x3Vu2 DmhTK44jCvIDO60sneZ6wYLqXS75tscziEQ09+a6WPKMpW1sg9NLIUrIZEAcwSm767RF Yriw== X-Gm-Message-State: APjAAAX689okX2KbJzjAs21HVe4z79prZedZNyLmDW+AT3fVCyiC6bXT DtgYiOClMSNR9UhEPHkEyOx2fA== X-Received: by 2002:a17:902:e30b:: with SMTP id cg11mr22374400plb.335.1564620343901; Wed, 31 Jul 2019 17:45:43 -0700 (PDT) Received: from chromium.org ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id p65sm68869957pfp.58.2019.07.31.17.45.42 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 17:45:43 -0700 (PDT) Message-ID: <5d423637.1c69fb81.62114.ca6f@mx.google.com> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <5d42281c.1c69fb81.bcda1.71f5@mx.google.com> References: <20190731215514.212215-1-trong@android.com> <32598586.Mjd66ZhNnG@kreacher> <6987393.M0uybTKmdI@kreacher> <5d42281c.1c69fb81.bcda1.71f5@mx.google.com> Cc: "Rafael J. Wysocki" , Greg Kroah-Hartman , Viresh Kumar , "Rafael J. Wysocki" , Hridya Valsaraju , Sandeep Patil , Kalesh Singh , Ravi Chandra Sadineni , LKML , Linux PM , "Cc: Android Kernel" From: Stephen Boyd To: "Rafael J. Wysocki" , Tri Vo Subject: Re: [PATCH v6] PM / wakeup: show wakeup sources stats in sysfs User-Agent: alot/0.8.1 Date: Wed, 31 Jul 2019 17:45:42 -0700 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Stephen Boyd (2019-07-31 16:45:31) >=20 > This approach also nicely detects duplicate wakeup source names in the > case that the string passed in to wakeup_source_register() is already > used on the virtual bus. This was clearly untested! Here's a better one. This is what I see on my device with this patch squashed in: localhost ~ # cat /sys/kernel/debug/wakeup_sources=20 name active_count event_count wakeup_count expire_coun= t active_since total_time max_time last_change prevent_s= uspend_time 1-1.2.4.1 0 0 0 0 = 0 0 0 0 0 1-1.1 0 0 0 0 = 0 0 0 0 0 gpio-keys 0 0 0 0 = 0 0 0 0 0 spi10.0 0 0 0 0 = 0 0 0 0 0 a88000.spi:ec@0:keyboard-controller 0 0 0 = 0 0 0 0 0 0 alarmtimer 0 0 0 0 = 0 0 0 0 0 cros-ec-rtc.1.auto 0 0 0 0 = 0 0 0 0 0 a8f8800.usb 0 0 0 0 = 0 0 0 0 0 a6f8800.usb 0 0 0 0 = 0 0 0 0 0 localhost ~ # ls -l /sys/class/wakeup/=20 total 0 lrwxrwxrwx. 1 root root 0 Jul 31 17:43 alarmtimer -> ../../devices/platform= /soc/ac0000.geniqup/a88000.spi/spi_master/spi10/spi10.0/cros-ec-dev.0.auto/= cros-ec-rtc.1.auto/rtc/rtc0/alarmtimer lrwxrwxrwx. 1 root root 0 Jul 31 17:43 wakeup0 -> ../../devices/platform/so= c/a6f8800.usb/wakeup/wakeup0 lrwxrwxrwx. 1 root root 0 Jul 31 17:43 wakeup1 -> ../../devices/platform/so= c/a8f8800.usb/wakeup/wakeup1 lrwxrwxrwx. 1 root root 0 Jul 31 17:43 wakeup2 -> ../../devices/platform/so= c/ac0000.geniqup/a88000.spi/spi_master/spi10/spi10.0/cros-ec-dev.0.auto/cro= s-ec-rtc.1.auto/wakeup/wakeup2 lrwxrwxrwx. 1 root root 0 Jul 31 17:43 wakeup3 -> ../../devices/platform/so= c/ac0000.geniqup/a88000.spi/spi_master/spi10/spi10.0/a88000.spi:ec@0:keyboa= rd-controller/wakeup/wakeup3 lrwxrwxrwx. 1 root root 0 Jul 31 17:43 wakeup4 -> ../../devices/platform/so= c/ac0000.geniqup/a88000.spi/spi_master/spi10/spi10.0/wakeup/wakeup4 lrwxrwxrwx. 1 root root 0 Jul 31 17:43 wakeup5 -> ../../devices/platform/gp= io-keys/wakeup/wakeup5 lrwxrwxrwx. 1 root root 0 Jul 31 17:43 wakeup6 -> ../../devices/platform/so= c/a8f8800.usb/a800000.dwc3/xhci-hcd.7.auto/usb1/1-1/1-1.1/wakeup/wakeup6 lrwxrwxrwx. 1 root root 0 Jul 31 17:43 wakeup7 -> ../../devices/platform/so= c/a8f8800.usb/a800000.dwc3/xhci-hcd.7.auto/usb1/1-1/1-1.2/1-1.2.4/1-1.2.4.1= /wakeup/wakeup7 ----8<---- diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c index 79668b45eae6..ec414f0db0b1 100644 --- a/drivers/base/power/wakeup.c +++ b/drivers/base/power/wakeup.c @@ -201,7 +201,7 @@ EXPORT_SYMBOL_GPL(wakeup_source_remove); /** * wakeup_source_register - Create wakeup source and add it to the list. * @dev: Device this wakeup source is associated with (or NULL if virtual). - * @name: Name of the wakeup source to register. + * @name: Name of the wakeup source to register (or NULL if device wakeup). */ struct wakeup_source *wakeup_source_register(struct device *dev, const char *name) @@ -209,9 +209,9 @@ struct wakeup_source *wakeup_source_register(struct dev= ice *dev, struct wakeup_source *ws; int ret; =20 - ws =3D wakeup_source_create(name); + ws =3D wakeup_source_create(name ? : dev_name(dev)); if (ws) { - ret =3D wakeup_source_sysfs_add(dev, ws); + ret =3D wakeup_source_sysfs_add(dev, ws, !!name); if (ret) { kfree_const(ws->name); kfree(ws); @@ -275,7 +275,7 @@ int device_wakeup_enable(struct device *dev) if (pm_suspend_target_state !=3D PM_SUSPEND_ON) dev_dbg(dev, "Suspicious %s() during system transition!\n", __func__); =20 - ws =3D wakeup_source_register(dev, dev_name(dev)); + ws =3D wakeup_source_register(dev, NULL); if (!ws) return -ENOMEM; =20 diff --git a/drivers/base/power/wakeup_stats.c b/drivers/base/power/wakeup_= stats.c index a26f019faca9..0f4c59b02d5d 100644 --- a/drivers/base/power/wakeup_stats.c +++ b/drivers/base/power/wakeup_stats.c @@ -81,15 +81,6 @@ static ssize_t last_change_ms_show(struct device *dev, } static DEVICE_ATTR_RO(last_change_ms); =20 -static ssize_t name_show(struct device *dev, struct device_attribute *attr, - char *buf) -{ - struct wakeup_source *ws =3D dev_get_drvdata(dev); - - return sprintf(buf, "%s\n", ws->name); -} -static DEVICE_ATTR_RO(name); - static ssize_t prevent_suspend_time_ms_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -106,7 +97,6 @@ static ssize_t prevent_suspend_time_ms_show(struct devic= e *dev, static DEVICE_ATTR_RO(prevent_suspend_time_ms); =20 static struct attribute *wakeup_source_attrs[] =3D { - &dev_attr_name.attr, &dev_attr_active_count.attr, &dev_attr_event_count.attr, &dev_attr_wakeup_count.attr, @@ -126,22 +116,35 @@ static DEFINE_IDA(wakeup_ida); * wakeup_source_sysfs_add - Add wakeup_source attributes to sysfs. * @parent: Device given wakeup source is associated with (or NULL if virt= ual). * @ws: Wakeup source to be added in sysfs. + * @use_ws_name: True to use ws->name or false to use 'wakeupN' for device= name */ -int wakeup_source_sysfs_add(struct device *parent, struct wakeup_source *w= s) +int wakeup_source_sysfs_add(struct device *parent, struct wakeup_source *w= s, + bool use_ws_name) { struct device *dev; int id; =20 - id =3D ida_alloc(&wakeup_ida, GFP_KERNEL); - if (id < 0) - return id; - ws->id =3D id; + ws->id =3D -1; + if (use_ws_name) { + dev =3D device_create_with_groups(wakeup_class, parent, + MKDEV(0, 0), ws, + wakeup_source_groups, + ws->name); + } else { + id =3D ida_alloc(&wakeup_ida, GFP_KERNEL); + if (id < 0) + return id; + ws->id =3D id; + + dev =3D device_create_with_groups(wakeup_class, parent, + MKDEV(0, 0), ws, + wakeup_source_groups, + "wakeup%d", ws->id); + } =20 - dev =3D device_create_with_groups(wakeup_class, parent, MKDEV(0, 0), ws, - wakeup_source_groups, "ws%d", - ws->id); if (IS_ERR(dev)) { - ida_free(&wakeup_ida, ws->id); + if (ws->id >=3D 0) + ida_free(&wakeup_ida, ws->id); return PTR_ERR(dev); } =20 @@ -157,7 +160,8 @@ EXPORT_SYMBOL_GPL(wakeup_source_sysfs_add); void wakeup_source_sysfs_remove(struct wakeup_source *ws) { device_unregister(ws->dev); - ida_simple_remove(&wakeup_ida, ws->id); + if (ws->id >=3D 0) + ida_free(&wakeup_ida, ws->id); } EXPORT_SYMBOL_GPL(wakeup_source_sysfs_remove); =20 diff --git a/include/linux/pm_wakeup.h b/include/linux/pm_wakeup.h index f39f768389c8..c9fb00fca22e 100644 --- a/include/linux/pm_wakeup.h +++ b/include/linux/pm_wakeup.h @@ -107,7 +107,7 @@ extern void pm_wakeup_dev_event(struct device *dev, uns= igned int msec, bool hard =20 /* drivers/base/power/wakeup_stats.c */ extern int wakeup_source_sysfs_add(struct device *parent, - struct wakeup_source *ws); + struct wakeup_source *ws, bool use_ws_name); extern void wakeup_source_sysfs_remove(struct wakeup_source *ws); =20 #else /* !CONFIG_PM_SLEEP */ diff --git a/kernel/power/wakelock.c b/kernel/power/wakelock.c index 826fcd97647a..7f2fc5f9b3b3 100644 --- a/kernel/power/wakelock.c +++ b/kernel/power/wakelock.c @@ -192,7 +192,7 @@ static struct wakelock *wakelock_lookup_add(const char = *name, size_t len, wl->ws.name =3D wl->name; wl->ws.last_time =3D ktime_get(); =20 - ret =3D wakeup_source_sysfs_add(NULL, &wl->ws); + ret =3D wakeup_source_sysfs_add(NULL, &wl->ws, true); if (ret) { kfree(wl->name); kfree(wl);