Received: by 10.223.185.116 with SMTP id b49csp8741374wrg; Fri, 2 Mar 2018 07:11:17 -0800 (PST) X-Google-Smtp-Source: AG47ELvMFrvW9tP32IdNw9x/dWVA81HOM2+nyG6U4W3rSPBxjbPzTPDBd3uJ6jdimYWaTtAVVxN+ X-Received: by 10.98.245.131 with SMTP id b3mr6030262pfm.20.1520003477003; Fri, 02 Mar 2018 07:11:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520003476; cv=none; d=google.com; s=arc-20160816; b=cxwZgc1DM+kb04hx7OCTG5llz2w2Y1JzrG/mr8HRTLP7bazZZx0DaZi3C9YiG1+fQ5 NngEhlvsOLOtrcYs2ojpevtyexMo8xWTCb0K6+Uk/exJU/sziG7coC2QGNgOc3X4jyss QMVMHRTBBAHsxfCt8hoPDed6oitso5A9P9/fT7x6/FoUAF2AqBZNnlh3njjbd+S00kQt u1q6VVVZWOGeDcgMc3Sq/9TP9ucCYu5vwfp4caBEHxgVQ4Z59IpxIrSwwngOX3V7uS/L 6jOe4jfYKuc726nrHtTK/NwssAQXCmxddv84k5dFPRDCDnQpFMtpnmXw9JXVLYiC24zo d3NQ== 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 :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=/rshMEDXdlwj8f3K0fvtt90IwUtoqfRLAV/eMewEnkg=; b=VpRazvWyYFUQU7WJSmh/gKyTtRf28BqeUAX7aaDj58U/sDfDBZEJBxo+VYqSEKkzmA 9rsWAIMqVmlB/mA9KaFVpjhuj8N3EgY95U2Qsdo/yPZbdYHnGChEbfcmBSh9+wIdCOdZ qW3SRwrZLy1blkvopWOypoPaSfYQmYd+sUAA5rD7WL7YGh/Rm5SLeK+wRPQhAyc2DuBw l3v6XFGxdaws8m2HAmdmnawHGMAQgltERSouAolTOv2oHeoJgRhMCbmTw28haBw/F17r xWTi6WSWkMfYVALUYz5CsZjY8yV2r5xv9ZJ7ybVh05wGZeA/gjnZHKKhh7gqmSVxGvwo td2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=r6qO70LU; 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 z72si4098358pgd.819.2018.03.02.07.11.02; Fri, 02 Mar 2018 07:11:16 -0800 (PST) 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=fail header.i=@gmail.com header.s=20161025 header.b=r6qO70LU; 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 S1030456AbeCBLsW (ORCPT + 99 others); Fri, 2 Mar 2018 06:48:22 -0500 Received: from mail-ot0-f196.google.com ([74.125.82.196]:46831 "EHLO mail-ot0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936210AbeCBLsJ (ORCPT ); Fri, 2 Mar 2018 06:48:09 -0500 Received: by mail-ot0-f196.google.com with SMTP id g97so8457957otg.13; Fri, 02 Mar 2018 03:48:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=/rshMEDXdlwj8f3K0fvtt90IwUtoqfRLAV/eMewEnkg=; b=r6qO70LUKG+j6lljzf9Iw3EN+JD0BeJMjvbMeD/sMMi987wDXpZ+n/bJgzjhngi++b eBWEN3p7b6LZMDVG5Xc+jO9QXsELp6Nr9MY9e904jU2jkHer9EBuj6JpynS16Z+yhS6U 9AIKRqLt16IwGuGzmn+pIvQ8mODbg6lwSccYc6cleGsgWPVWOGNTUe+Vet2dvmnQVS6f tsqHr71vEjAsEa3xUKGnNk3J7p/2O2EC0I/yhl1UPRsz6AGiSX2eQESr//jRdg/hSFkl MzbOP5Fy4a2/9lDDZoN4jYtwILKwEfvi1Fu2qSfncpfc9WDoUajbbCS+76gmICHY59qj x4Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=/rshMEDXdlwj8f3K0fvtt90IwUtoqfRLAV/eMewEnkg=; b=MvFJ15SV9mxPdLIiqibzijCRbRbTR/bV23dQvHkWfC3tnkhf1aU9/GJmUe39d5j5Ni h9SzbQrkTn8MsGTq3OaDbQ7NcGtL4O4K5ZgWNqN/pMlnciuUr3fhetWcAPeuoBRC/6TZ cV/jH4R4xUz93hSrM3IhRjAXf1jqLxRE6LG3LuJ1MfRlOYhm6TWh4JG3e2nBqkDJfY8c 7lIXuOWmqt56k8hzk0GhFrEZm3fji086JwSZlBnwdIM9DL1YVtOlCBY/mF/FlhZe6N5V zOjoPlVf5WMMDukSi6q9wJFEbO5UNda8CuRgPj9O8pmaROymNN3nv5WFRrWsw0g8zMA3 LG3Q== X-Gm-Message-State: APf1xPDIdc+SeYDEfrgic99X3snpyk8GzXcxevm4qUl7fa61p+t+roTi PSsM9x/d/xUy5cVLJp+bGQcjvmwBgIeqyIyOobMdQw== X-Received: by 10.157.56.196 with SMTP id k4mr3462081ote.305.1519991288420; Fri, 02 Mar 2018 03:48:08 -0800 (PST) MIME-Version: 1.0 Received: by 10.157.44.146 with HTTP; Fri, 2 Mar 2018 03:48:08 -0800 (PST) In-Reply-To: References: <1519966860-32519-1-git-send-email-opensource.ganesh@gmail.com> From: "Rafael J. Wysocki" Date: Fri, 2 Mar 2018 12:48:08 +0100 X-Google-Sender-Auth: CoSK79_8RIJVnVQ_iJkYni2tZpk Message-ID: Subject: Re: [PATCH] PM / wakeup: use seq_open() to show wakeup stats To: Ganesh Mahendran Cc: "Rafael J. Wysocki" , "Rafael J. Wysocki" , Pavel Machek , Len Brown , Greg Kroah-Hartman , Linux PM , Linux Kernel Mailing List 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 Fri, Mar 2, 2018 at 12:34 PM, Ganesh Mahendran wrote: > Hi, Rafael: > > 2018-03-02 16:58 GMT+08:00 Rafael J. Wysocki : >> On Fri, Mar 2, 2018 at 6:01 AM, Ganesh Mahendran >> wrote: >>> single_open() interface requires that the whole output must >>> fit into a single buffer. This will lead to timeout when >>> system memory is not in a good situation. >> >> Did you actually see this problem with this particular file or is it >> theoretical? > > We got report of android watchdog timeout when memory situation > is bad. I see. >> >>> This patch use seq_open() to show wakeup stats. This method >>> need only one page, so timeout will not be observed. >>> >>> Signed-off-by: Ganesh Mahendran >>> --- >>> drivers/base/power/wakeup.c | 71 +++++++++++++++++++++++++++++++++++---------- >>> 1 file changed, 56 insertions(+), 15 deletions(-) >>> >>> diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c >>> index ea01621..c64609a 100644 >>> --- a/drivers/base/power/wakeup.c >>> +++ b/drivers/base/power/wakeup.c >>> @@ -1029,32 +1029,73 @@ static int print_wakeup_source_stats(struct seq_file *m, >>> return 0; >>> } >>> >>> +static void *wakeup_sources_stats_seq_start(struct seq_file *m, >>> + loff_t *pos) >>> +{ >>> + struct wakeup_source *ws; >>> + loff_t n = *pos; >>> + >>> + if (n == 0) { >>> + seq_puts(m, "name\t\tactive_count\tevent_count\twakeup_count\t" >>> + "expire_count\tactive_since\ttotal_time\tmax_time\t" >>> + "last_change\tprevent_suspend_time\n"); >>> + } >>> + >>> + rcu_read_lock(); >> >> The code running after this cannot sleep. Use >> srcu_read_lock(&wakeup_srcu) instead. > > wakeup_sources_stats_seq_[start | end] are called in seq_read(). > So rcu_read_unlock() will soon be called in seq_read(). But you have to guarantee that the code between rcu_read_lock() and rcu_read_unlock() will *never* sleep. > I am not familar with rcu. So you need to get familiar with it to make changes involving it. Otherwise you may fall a victim of the Wizard's Second Rule. > I refered to kmemleak.c which use seq_open() > to show the stats. I see. You need to use srcu_read_lock(&wakeup_srcu) in this file anyway.