Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp149796ybd; Tue, 25 Jun 2019 18:33:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqy4/XXeDpzTwltMutmlHRBESGMwHo3LhVkUvOeoEfpCVocNCSKPdfyyjw5UP7EG3H1m1n+h X-Received: by 2002:a17:902:ba82:: with SMTP id k2mr1979557pls.323.1561512828192; Tue, 25 Jun 2019 18:33:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561512828; cv=none; d=google.com; s=arc-20160816; b=vEDZHbvH8dba+uW2ZCKuuw7brianOv43ZjGTP2nfwXgJlbx3gRDQvW9EjSzTgYzMz/ dL6gbqJ6kegjq+6eoEUIo+FOfMZw2ig5zPbv4BKiUooRdjSzW/swPlGMp/ZvMRQcKP2Z 1R+CWNU2/Ntrk5n/J0VCaPLW403qMIbvPyRuBBXA2oEAL4bUfc8f75WpV7VXPogS06eG AYoQe+6l+vuh05IlgCwFoV6gF4NbzFqG/k4TzJO9byhXOdH09d2JP3IVnKx5V3RJCzh2 x6/QZMmMAc2R1XpNf9V4Cm/8OSd90pIM6h1HodEwVHR0paW7m53fNpzh+IhM3aT0lcuw a9CA== 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=VVnzFsR1solrbhevdTsXVX+Ex8gYtEcQN0RWhGvtNyk=; b=GJUi0SAtP+TLWeCqoabeItQN0BSdN3W0wUzHLolcl4tWPdDEKrDWDurrLVnGkwy8dj xiVHKaLxqt5dTyl773ALYQdiPJJzGCCX65EN2Pf8eBY2HpBNc9+E9SEh6orI6XyhLQ7W ydTZXBjiP6gfXaHHRloTfb/QmCa6V6USuYmo9ecgEhQkMe3J8UOaBRJgff8yS/AljByu zn2lOJsCtt/oGUVOhC7g4aZ2PSSelpd6gTe8mHQ8jCs6nIigcg9LlEVAjFz8LLUuut2P 8sIhrZ68oCLgB24tZY0J6mTcaZMfpolifFDxZ0u77t9nCqMDk+bD9sOk+Jdt042n7VNE cNaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b=kSHpaSnk; 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 h61si1717487plb.256.2019.06.25.18.33.32; Tue, 25 Jun 2019 18:33:48 -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=kSHpaSnk; 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 S1726339AbfFZBdU (ORCPT + 99 others); Tue, 25 Jun 2019 21:33:20 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:41934 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726037AbfFZBdU (ORCPT ); Tue, 25 Jun 2019 21:33:20 -0400 Received: by mail-ot1-f67.google.com with SMTP id 43so851963otf.8 for ; Tue, 25 Jun 2019 18:33:20 -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=VVnzFsR1solrbhevdTsXVX+Ex8gYtEcQN0RWhGvtNyk=; b=kSHpaSnkgeS/BsbriFI9eSDuwr1sEjGmgFxxXI+nQIrKVjQ4s50ErtfHe9lYgRmNCv Bkl88QBc2kijsyTb4CFaeF2DLB3tqZVDYVkAROMhPxROtnL/cvM/D2lZvStIl/NF48IW 02wr2mcDC7G2RBzcPM18dWr9ttPU2et+htrNMrnZfSIWPJ1qk9ddTi3nyVc03DeQ3BX+ JaW6KdavGqEjPW7i+seR06HIrcCuFmbeLCs7NcNvnl8Z9YFEKNZjGc9bbB3legVIHLA2 vVPJKQq4VoBYw1qt+qiTzVBG6VcfbQs1P/u3P+1tqa/cmF+Ej992IKuSeixCuiR8SLfE yZ9w== 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=VVnzFsR1solrbhevdTsXVX+Ex8gYtEcQN0RWhGvtNyk=; b=PEgsSUV0Z1H5Nlt5E9m+2dLIK/NPNxJR1MG+KyJo3DJNrUjcSbar4C4InyHvCLBaBN jPcf1oPPqOzHvr1qjkN2ap+PfUOelBQQm5OeRt0o6nCKwWbaFXZ1iBWHMJZo7MlFHgUP 552Pg+hlb5CtccYNclTSC0BZA7PAE3d5gYdiqDeGf8MU/hnK+B4XpEev6MSjUjpLbq+I 0EaHzxT1laS18SKEWiFrPjrG9KFwdyWJkaku1kS1oSm4lzmVgo+vAs0J3dPJCbX7FSbX lIKBK1eJjQZQ//qxnEWIaSmeWFiLKGoowzk2oLbFV+psPk7ctFEeCw2/GP0sRiFn3717 lgPA== X-Gm-Message-State: APjAAAVgFHubvBkas+89Qxv1SqMLlqVbGoiEGdYJli0MLQuL/VmWb6Z6 mPD9iaAVCQDJ6B9LmU0KEV5YPZn62NrMQlBl87++XGlXu1w= X-Received: by 2002:a9d:5911:: with SMTP id t17mr1129812oth.159.1561512799820; Tue, 25 Jun 2019 18:33:19 -0700 (PDT) MIME-Version: 1.0 References: <20190626005449.225796-1-trong@android.com> <20190626011221.GB22454@kroah.com> In-Reply-To: <20190626011221.GB22454@kroah.com> From: Tri Vo Date: Tue, 25 Jun 2019 18:33:08 -0700 Message-ID: Subject: Re: [PATCH] PM / wakeup: show wakeup sources stats in sysfs To: Greg KH Cc: "Rafael J. Wysocki" , Viresh Kumar , "Rafael J. Wysocki" , Hridya Valsaraju , Sandeep Patil , LKML , Linux PM , "Cc: Android Kernel" 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 Tue, Jun 25, 2019 at 6:12 PM Greg KH wrote: > > On Tue, Jun 25, 2019 at 05:54:49PM -0700, 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, expose wakeup > > sources statistics in sysfs under /sys/power/wakeup_sources// > > > > Add following attributes to each wakeup source. These attributes match > > the columns of /sys/kernel/debug/wakeup_sources. > > > > active_count > > event_count > > wakeup_count > > expire_count > > active_time (named "active_since" in debugfs) > > total_time > > max_time > > last_change > > prevent_suspend_time > > Can you also add a Documentation/ABI/ update for your new sysfs files so > that we can properly review this? > > > Embedding a struct kobject into struct wakeup_source changes lifetime > > requirements on the latter. To that end, change deallocation of struct > > wakeup_source using kfree to kobject_put(). Will do. > > Ick, are you sure you need a new kobject here? Why wouldn't a named > attribute group work instead? That should keep this patch much smaller > and simpler. Yeah, named attribute groups might be a much cleaner way to do this. Let me investigate. > > > +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.