From patchwork Fri Mar 2 05:01:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahendran Ganesh X-Patchwork-Id: 10253393 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 16AB46037F for ; Fri, 2 Mar 2018 05:01:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 053A728806 for ; Fri, 2 Mar 2018 05:01:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EBDB028809; Fri, 2 Mar 2018 05:01:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 853A028806 for ; Fri, 2 Mar 2018 05:01:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751063AbeCBFBN (ORCPT ); Fri, 2 Mar 2018 00:01:13 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:36614 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750924AbeCBFBM (ORCPT ); Fri, 2 Mar 2018 00:01:12 -0500 Received: by mail-pg0-f65.google.com with SMTP id i14so3307327pgv.3; Thu, 01 Mar 2018 21:01:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=cWyjGul+LC3Nx4Bg+vZmY3IZvVwez3KsRrrXRSiydzY=; b=bhbwFHRVATJ+7K8KnIZ0GuKcr7Pl9qtbJSFdOWzqYr11aHp1lAWajVuUEX2n32PVld SrNrP/ENft46KpegRzbL7GGJY6kuYMB6ugl4YMOAcbYXeWEHSix14d/mR8QU2jhW1ecV mnwsLMMtCi5SAwkdQaHIv3VgIItTQZJ5qAOiFZRPjTnP0ukfefKC274Y/t3kquh6qYJc aqhX4/Wo0xZi5benH0uemZ09dbmDVB++KHX5H5Q2v4FmuZE/wDSX1ydQJinoLWU1gaPE pv9M0GWcBok8Agi1nTiJn/15Em018dx8zHWc9JjlQ0iVYUwuil729Wdy5gEfPCU23ooA aIEQ== 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; bh=cWyjGul+LC3Nx4Bg+vZmY3IZvVwez3KsRrrXRSiydzY=; b=o8Gn3ySWO5yF/kjk3RCB5a0zwKWheup7QffzIXABDuOI6I3Sh71SQRJBrWcLKfbqtE 0qsvnF0fvEC/CYMqwdY/IFw0LzbSyNMbf1Dbx29KuZ9vIGfqQko7heRvW6EluOb2r5sj cPaylomnt62CJCDUPNrgbkixDgH0cz8XdAjnYPA0VsDzk5cbssS7qycYbVWAPGdfv3AL Ce4eDHairMru2Oee+ZX2PsHzrUMZr5m1+eQf8NI+vZnYCAwN2zwcBlPmDh5oFHCbwedr 4jx1zZemktsmGGdnm5DRPZ6iUSoowYnXUf/KbFGpwOWokKIwkY0UCDONUl2qMkHbiFDw K89w== X-Gm-Message-State: APf1xPD5TmjGE0LPuPUyUNhC4XKRVYIY6EK7SHYdmXE0ZyFs14r7OW05 m6Mj4geP1Zdxc6QWRInEuis= X-Google-Smtp-Source: AG47ELsc/DZW5RQiMsRC0/JWdnwkCFCncROKVyuHRFTdHC8Kx7+Zzs+r1eBuMAXwIW8uGcJjPXofTA== X-Received: by 10.101.91.78 with SMTP id y14mr3575848pgr.243.1519966871817; Thu, 01 Mar 2018 21:01:11 -0800 (PST) Received: from localhost ([221.226.180.178]) by smtp.gmail.com with ESMTPSA id o5sm11230589pfh.51.2018.03.01.21.01.10 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 01 Mar 2018 21:01:10 -0800 (PST) From: Ganesh Mahendran To: rjw@rjwysocki.net, pavel@ucw.cz, len.brown@intel.com, gregkh@linuxfoundation.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Ganesh Mahendran Subject: [PATCH] PM / wakeup: use seq_open() to show wakeup stats Date: Fri, 2 Mar 2018 13:01:00 +0800 Message-Id: <1519966860-32519-1-git-send-email-opensource.ganesh@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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(); + list_for_each_entry_rcu(ws, &wakeup_sources, entry) { + if (n-- > 0) + continue; + goto out; + } + ws = NULL; +out: + return ws; +} + +static void *wakeup_sources_stats_seq_next(struct seq_file *m, + void *v, loff_t *pos) +{ + struct wakeup_source *ws = v; + struct wakeup_source *next_ws = NULL; + + ++(*pos); + + list_for_each_entry_continue_rcu(ws, &wakeup_sources, entry) { + next_ws = ws; + break; + } + + return next_ws; +} + +static void wakeup_sources_stats_seq_stop(struct seq_file *m, void *v) +{ + rcu_read_unlock(); +} + /** * 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 int wakeup_sources_stats_seq_show(struct seq_file *m, void *v) { - struct wakeup_source *ws; - int srcuidx; + struct wakeup_source *ws = v; - 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); - - print_wakeup_source_stats(m, &deleted_ws); + print_wakeup_source_stats(m, ws); return 0; } +static const struct seq_operations wakeup_sources_stats_seq_ops = { + .start = wakeup_sources_stats_seq_start, + .next = wakeup_sources_stats_seq_next, + .stop = wakeup_sources_stats_seq_stop, + .show = wakeup_sources_stats_seq_show, +}; + static int wakeup_sources_stats_open(struct inode *inode, struct file *file) { - return single_open(file, wakeup_sources_stats_show, NULL); + return seq_open(file, &wakeup_sources_stats_seq_ops); } static const struct file_operations wakeup_sources_stats_fops = { @@ -1062,7 +1103,7 @@ static int wakeup_sources_stats_open(struct inode *inode, struct file *file) .open = wakeup_sources_stats_open, .read = seq_read, .llseek = seq_lseek, - .release = single_release, + .release = seq_release, }; static int __init wakeup_sources_debugfs_init(void)