Received: by 10.213.65.68 with SMTP id h4csp1894504imn; Sun, 1 Apr 2018 18:35:18 -0700 (PDT) X-Google-Smtp-Source: AIpwx49V116akqSr3/UKFQHkxSHwsm8169yglpOIsmLXkmO7uVHhx/JYczPDwvVExW6+RuFdLYe9 X-Received: by 10.98.223.16 with SMTP id u16mr5936495pfg.146.1522632918289; Sun, 01 Apr 2018 18:35:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522632918; cv=none; d=google.com; s=arc-20160816; b=GsZgRq++lWXbFH9E0BqL2V+goXb9GKSJNyszXhhpPyUov2zaA+e2hNCLctaGL44qsv kRzPh52/j0l8NCDMHd6lnDrNYe3OVLweLX7qGziTSHQVPenoZdOiF7QhlGnjj2U5Z6Du yLRC+gNeVknkjdPnR/CXuZxWkaX61oo6GsCq3CwsdoTWYMZ1nSzLxSe7x4J38z7yEL8C sl4q+3ksi143DkmDQTr5frizvVjCwPu8DrNWTUXIk1ZoWxU6+kQXhILrLCN76bpyZ6U8 +ttAbq9INo9RP+VbW9wQd16w/5DgK7y3yMRVWltP/RPFzFkhAWG9Xem+cdmsnm3ZnYY0 KLhA== 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=Z07Ej/RJv2TkFSF/34Wuie37WHiLK/C2l9u4jCcyxYk=; b=qpGz+0Ei/dfkYwiDN+e+gOEe4b7rlnBVGk/aOi+AtLx3PBlHjI2r84K+ydE2SVwiNO inSx8Eri5GO1YaExIC8HnDQRZ5ZaSIfUp55kDFfxFYjaU6K/ucbmGWi7pYjsVQrisxPk WD2+tHgAI4GetHDuowFM1gMSvTgqJCw8C4w3GSXYX627ejijK7JcFvF6husDRfaVaLp8 rFTCk9s2KrK57iQhjKagdFW6fhWmE4t3atemt/lZ264Ko2tqNt5I/eMIyTFAJZhZhp/c hQ5zletQEwzjVY5Pd/SO17D3/LCDNGDhqD7SABIUbFPAlAIE9wsT8XXwPmgvRjT6Qw7H JVtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Zvnt2itK; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h80si10221811pfj.129.2018.04.01.18.34.33; Sun, 01 Apr 2018 18:35:18 -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=@gmail.com header.s=20161025 header.b=Zvnt2itK; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754069AbeDBBbf (ORCPT + 99 others); Sun, 1 Apr 2018 21:31:35 -0400 Received: from mail-io0-f196.google.com ([209.85.223.196]:32919 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754033AbeDBBbe (ORCPT ); Sun, 1 Apr 2018 21:31:34 -0400 Received: by mail-io0-f196.google.com with SMTP id l3so16395038iog.0; Sun, 01 Apr 2018 18:31:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=Z07Ej/RJv2TkFSF/34Wuie37WHiLK/C2l9u4jCcyxYk=; b=Zvnt2itK9CXsrBv5lphUfhLaEF2D5Oism8bffb2i5wj1Dm4WqxeIRdrv2s9rbXjJw8 zpBv7zvUCIml9baOgboAffsSSdt0qitleMCJRNtsFnUc5y5TpQvIqwq5+qLeps9zG8N5 g/Lc5Rdumpqm3iMH8ryrSURuvV0blnKnPVW4jjlEhTy8mkalCJdOZ5oSkfIjPaCaU8Ul Th5ugmo1ZA2EhOe4DrIpv/LKU5sjL60HRPIVmAT/iOHjyhWCdMkzAZEUP8fc6RU2ATmF ZAdP/ZFmM1njm7O/dzlv7uNuIyxFucPBJy7ncD39fpcot8Of/dvjAorLF0UVzccvjD8x mJbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=Z07Ej/RJv2TkFSF/34Wuie37WHiLK/C2l9u4jCcyxYk=; b=Zwqbkoo3t+BZfPk9T+GhLvsC02zjhQEUSx2UycvjoCoEsb6BqEJua51k/dr5YjA9Ew yd/Zd0nooWyvy+XRpNu2hl2xhThNz5bWAdXXHLf2H66ZTpyq9b3bybjZMHLsNNA81ae5 imtYm7FwtAifNzBhbWZ0O8oolC19ah8khyJ9/F72hHj/VKI6V8IrYgFV0YP2GOv6H15t ph+XgO1j7KC6OTtMTaXnfGTpGhM+3SRFuq+KMwY0KZN+80G1s+dQ6MzJgT0k0BF7XZkZ ioRLssNVhvI1w8jdTUskDljaVlmsVDjAyYhi7yC/3uX/8VogJvwHMYZ4o+UovzoSYa8O P4Bg== X-Gm-Message-State: ALQs6tBwsDmshYo128PLIMwAkMRJEvCz8aXQE8ylYYlOFa4DW3JyU5/E WLltM00bMNE4SzrqOTDhivqvjg6F7gYquD0FrVg= X-Received: by 10.107.178.14 with SMTP id b14mr6647663iof.294.1522632693620; Sun, 01 Apr 2018 18:31:33 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.168.153 with HTTP; Sun, 1 Apr 2018 18:31:33 -0700 (PDT) In-Reply-To: <2654052.UvzeiuBsVA@aspire.rjw.lan> References: <1520239666-2964-1-git-send-email-opensource.ganesh@gmail.com> <2654052.UvzeiuBsVA@aspire.rjw.lan> From: Ganesh Mahendran Date: Mon, 2 Apr 2018 09:31:33 +0800 Message-ID: Subject: Re: [PATCH v2] PM / wakeup: use seq_open() to show wakeup stats To: "Rafael J. Wysocki" Cc: Pavel Machek , Len Brown , "Rafael J. Wysocki" , Greg KH , Linux PM , linux-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 2018-03-30 18:25 GMT+08:00 Rafael J. Wysocki : > On Monday, March 5, 2018 9:47:46 AM CEST 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. >> >> 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 >> ---- >> v2: use srcu_read_lock instead of rcu_read_lock >> --- >> drivers/base/power/wakeup.c | 77 +++++++++++++++++++++++++++++++++++---------- >> 1 file changed, 61 insertions(+), 16 deletions(-) >> >> diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c >> index ea01621..3bcab7d 100644 >> --- a/drivers/base/power/wakeup.c >> +++ b/drivers/base/power/wakeup.c >> @@ -1029,32 +1029,77 @@ static int print_wakeup_source_stats(struct seq_file *m, >> return 0; >> } >> >> -/** >> - * wakeup_sources_stats_show - Print wakeup sources statistics information. >> - * @m: seq_file to print the statistics into. >> - */ >> -static int wakeup_sources_stats_show(struct seq_file *m, void *unused) >> +static void *wakeup_sources_stats_seq_start(struct seq_file *m, >> + loff_t *pos) >> { >> struct wakeup_source *ws; >> - int srcuidx; >> + loff_t n = *pos; >> + int *srcuidx = m->private; >> >> - 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"); >> + 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"); >> + } >> >> - srcuidx = srcu_read_lock(&wakeup_srcu); >> - list_for_each_entry_rcu(ws, &wakeup_sources, entry) >> - print_wakeup_source_stats(m, ws); >> - srcu_read_unlock(&wakeup_srcu, srcuidx); >> + *srcuidx = srcu_read_lock(&wakeup_srcu); >> + list_for_each_entry_rcu(ws, &wakeup_sources, entry) { >> + if (n-- > 0) >> + continue; >> + goto out; >> + } >> + ws = NULL; >> +out: >> + return ws; >> +} > > Please clean up the above at least. Hi, Rafael When length of file "wakeup_sources" is larger than 1 page, wakeup_sources_stats_seq_start() may be called more then 1 time if the user space wants to read all of the file. So we need to locate to last read item, if it is not the first time to read the file. We can see the same logic in kmemleak_seq_start(). Thanks. > > If I'm not mistaken, you don't need the label and the goto here. >