Received: by 10.192.165.148 with SMTP id m20csp543930imm; Wed, 25 Apr 2018 04:01:40 -0700 (PDT) X-Google-Smtp-Source: AIpwx49X83VKhoOM9PGSo2JReYTftczSU16q8COADILAwyZh7K2zjyIJGIgTlLROlhW8vbM98KcL X-Received: by 10.99.99.196 with SMTP id x187mr23719559pgb.154.1524654100333; Wed, 25 Apr 2018 04:01:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524654100; cv=none; d=google.com; s=arc-20160816; b=VvwrhqWe46l3AHrBKEYfYTfQyvF/gsKVylGS+akouRv4g9V9X63brTrILAvidD3uAA /M45XD0Pf6uMiZNMJsKlh1UIAJqyJgWe3NzB1w+Cp2fjXJ0YMzhmULIKwCMLV090FxMJ wMZkjWEPzUNvj4QI24dg50UDjfRcWRa08MFYvV/vuRKGVnhmUelcznZ+UXv34y3MrVV0 wUvjE8XLzMQo+gGr3Uue86QzrM0QgnvnqucRP+ZKlp4R381kmaKAk4UfLegZhlxI2osn 7EBQA+IHWUgVNngf0QiwHcg9KJgCEIM6G4U6voiNcLxWJNjzUzqX2w+LshXzLrCNvK+Q L1LQ== 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=+YSK0If6uDJ4RXABIIMZbZ61AcmWkpQ4NLM5aaDPbFk=; b=lH+uDR+H8afoZgq/ut9OhYDZ+OLcB+O+/3W7Ahy2wmWTWsDeAAlNFN6YxnsBKpwEMT g1v+pTxCEtmKKXTqe5Aeo57rM1SIQc9zDHQsnrF0cEMpYRo4pltEwp8UEvsUxgVWtrGe UZ1npEt7+9xmDBZoNrGhTontiMMpSGYDPt4LPuVLLg0CbvB1Xi7pn5G0fc05ZeMim/+5 2P/QH5Ob1+00NXl/7lcBINiuKKrUQZ1iA9f82g5S0XADHMqDJ4zT0rFwDQqM1fJnyXx+ eu7CHqWrNA7ipjARp0usN44jnXeEZSrphTa+lGtnfMZULiZySgMWt0W7xq2Px0zx6GFZ 1BAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TWKjFWeZ; 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 f5si12744362pgv.668.2018.04.25.04.01.25; Wed, 25 Apr 2018 04:01:40 -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=TWKjFWeZ; 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 S1754154AbeDYLAX (ORCPT + 99 others); Wed, 25 Apr 2018 07:00:23 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:41244 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753067AbeDYK7v (ORCPT ); Wed, 25 Apr 2018 06:59:51 -0400 Received: by mail-pg0-f67.google.com with SMTP id m21so10070351pgv.8; Wed, 25 Apr 2018 03:59:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=+YSK0If6uDJ4RXABIIMZbZ61AcmWkpQ4NLM5aaDPbFk=; b=TWKjFWeZ9XzzpfhtRF/qhIn/p4LJFH41cMX9xFNkp/gqcElK+XtjHU6W1wCopih+q4 ZKrg9aIkRPOrNyoXIxM0gjbsWu3R1Fc15RusaB+Dlk8VdusOt0vc/her6F5zxcLqDq8S MGGMr/OqrtfEEovO6AgkTBap3627Dbbpo9w+pV+R43hdjk/BLY1JE4oX+a5UPOo7LLar yEVZ/SPqaQwRvb6+iYR06XKZpKbp2r01A9sqGg8mc0rS5ZkNY6Q6QqxtumBnwm8dGZXC 85gV9qpdqwSBTdsJVQQA8nHqQm1c8mHLc2/rxd9pGjqmtFZCmpYF4rYr08uRJo6/OeS9 jUfQ== 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=+YSK0If6uDJ4RXABIIMZbZ61AcmWkpQ4NLM5aaDPbFk=; b=rQlLDhJFCfORxkcyJXIYl8bgMWJXD3ITKoH55uttNyLtSwRALW4g7SOjRtBazyPLPs AIMdQT5XEpxElowO+x+KiMH1RrdazcebHJIKOZQ1GoP3awZXXswG8T0zhRfYjUOLGgzL tlb/8v+F/sD6/VkBFdpl/2MD2uygIhy3bgeF4ySZpEMwcsF2O/79PJFB7H6cpG2EGkCK bhakBzNFeKmHFJkwaffSb0Sj6omxaUMYF58Snykf1a3KFPM0tgVxXtJ2QiOlxFHZGnvP 4+ILTBYdU9JoKv/CdbDkKjR+D8P65dP9eVo+4Hf7ZnI7Po9K7gn0ghYAv9rXxTCUSa/4 R8QQ== X-Gm-Message-State: ALQs6tDwmPNJ4WB1CQGBzJ/cEoFT4tygM0iBnNANXSjGSDU+tSczsdtv Kc17qzA4zWlg7aHfPbWubMaZNA== X-Received: by 10.99.50.134 with SMTP id y128mr23975315pgy.419.1524653991038; Wed, 25 Apr 2018 03:59:51 -0700 (PDT) Received: from localhost (outboundhk.mxmail.xiaomi.com. [207.226.244.124]) by smtp.gmail.com with ESMTPSA id h130sm4479717pfc.98.2018.04.25.03.59.49 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 25 Apr 2018 03:59:50 -0700 (PDT) From: Ganesh Mahendran To: rjw@rjwysocki.net, pavel@ucw.cz, len.brown@intel.com, rafael@kernel.org, gregkh@linuxfoundation.org, geert@linux-m68k.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Ganesh Mahendran Subject: [PATCH v3] PM / wakeup: use seq_open() to show wakeup stats Date: Wed, 25 Apr 2018 18:59:31 +0800 Message-Id: <1524653971-10425-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 ---- v3: simplify wakeup_sources_stats_seq_start v2: use srcu_read_lock instead of rcu_read_lock --- drivers/base/power/wakeup.c | 75 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 16 deletions(-) diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c index ea01621..5872705 100644 --- a/drivers/base/power/wakeup.c +++ b/drivers/base/power/wakeup.c @@ -1029,32 +1029,75 @@ 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) + return ws; + } + + return NULL; +} + +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); - print_wakeup_source_stats(m, &deleted_ws); + 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) +{ + int *srcuidx = m->private; + + srcu_read_unlock(&wakeup_srcu, *srcuidx); +} + +/** + * wakeup_sources_stats_seq_show - Print wakeup sources statistics information. + * @m: seq_file to print the statistics into. + * @v: wakeup_source of each iteration + */ +static int wakeup_sources_stats_seq_show(struct seq_file *m, void *v) +{ + struct wakeup_source *ws = v; + + 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_private(file, &wakeup_sources_stats_seq_ops, sizeof(int)); } static const struct file_operations wakeup_sources_stats_fops = { @@ -1062,7 +1105,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_private, }; static int __init wakeup_sources_debugfs_init(void) -- 1.9.1