Received: by 10.223.185.116 with SMTP id b49csp8270594wrg; Thu, 1 Mar 2018 21:38:51 -0800 (PST) X-Google-Smtp-Source: AG47ELtEVZpDb0x4LUibcZbc7/82SeVYMXb+VgGka4aaSl1oxWBP6TxKvqJYZ3SG8CHG9FxvBCap X-Received: by 10.99.146.26 with SMTP id o26mr3633550pgd.309.1519969131501; Thu, 01 Mar 2018 21:38:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519969131; cv=none; d=google.com; s=arc-20160816; b=HL9Ml6DDisint7T0iN566sU9Ol+qW1dTMp7XogAZqPJ+CFcgzszby5Cryugy2GYhIm msYqPHPtQMZaN26WjHcMoLXjM+xY1EX/losP22Ij740ODO0hzoPbe3+32vUTPohGSMTr MKLVhDqnH4tP9Cujb6z6ZzRKN18bq3ezWo4YAIPptx6BPnTV+mz79K44ATiLbxm8iQzX psyHqtJtIiwChdfO5QF8fZWco8oVv/mjg5pQVNAL1+CmzTydNl0WkzVNeQuy1GT9bIyf kPejBjm2+0Dl9MvXiM0xB9UCxcH2aP3Tej6Cg3W7Vu+kJYzizX7QGRwOGUcKB36paeB8 81/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=cWyjGul+LC3Nx4Bg+vZmY3IZvVwez3KsRrrXRSiydzY=; b=pOLYEKGBa3tY5ZqxgA1WkOS4k4siBPCsINTKw8ROrEiYZwbQodZ9XZvoqqVmOglYGF 4cTXtEYIxloZPQ/joWAJf/BRGFNhpKgfzOEIuqrxJTLW/c1EGh3KAWiofKDdorXnp9QY 6vkO07OSnyeoJdW3ilchCA1UtlGxzWxBY0NcH2Qwl7Y0mEA1T0xSn5Jgvj+RWGtPoBtJ tjCLJO9G9KrbhazenTvQJ9jknpUsg8WVtk8kDICJF9hF726E5g+A5Meop2WyMyfFtL0O 3Og+sUI0sPX9fVbOc6+vA6j6VtrXy2nXf+lMvr2rDxnm4tabFXEqTE7hu4FMrYr+OgO+ JgWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bhbwFHRV; 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 k6-v6si4411221pln.103.2018.03.01.21.38.37; Thu, 01 Mar 2018 21:38:51 -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=pass header.i=@gmail.com header.s=20161025 header.b=bhbwFHRV; 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 S1752237AbeCBFBO (ORCPT + 99 others); Fri, 2 Mar 2018 00:01:14 -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-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) -- 1.9.1