Received: by 10.223.185.116 with SMTP id b49csp2385030wrg; Mon, 5 Mar 2018 01:48:22 -0800 (PST) X-Google-Smtp-Source: AG47ELsZtBpOlCE/6d5o/CEnjrVWtHno3f+V2m5v8lL2cT9+aABS3spjQ06Y4fhWtnFrzE7odD+T X-Received: by 10.98.74.140 with SMTP id c12mr15019062pfj.44.1520243302465; Mon, 05 Mar 2018 01:48:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520243302; cv=none; d=google.com; s=arc-20160816; b=tnbMZPI/13eB4Uhszjo6ykBiDiv3knujBmetdMnUNnfz1XV9dWj7zxhzaQC9fdyKnW wDkM23BY0/gBdlPWW+1nQ3nYjfLJkZejAJA9aKrrrfAzxG24x0MLNxY6GDV/V1ihWggU 7GM8c7d3Z633ykpQgGYf9kZyyAO9E8rYVOt9vSBMpPP/SyjMAskWCORPmF/ozpLzj9YC Zk38jDFMjjaE7AYGVGNI4Szh5GbCc0XSgbxbFT01aCjSeZKK0tAD8Ehg+kCDRJyKEtUp MH7MKw0+8IChMG+THLyN0Elq/ZYBu8Iv6E7IZ8s5grbULUZmhSIAz6m/+DdX2qSztOg9 ZiXg== 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=USs2LPnnBPP+a4qHzLgEt7V9iKhpQMPa1x6WyQCHWnQ=; b=zimNV3QJVcq7oo/A8qloulFmmrsuwCo7MbXk1iVzu1jF2CZNcyXewTB3+74iuNH6Jv TFzpc+f8qbhUaluAxlEmI7EzGJ0DFRiEl04CiI55FyPuj7/UI9itBSJpAWbUjEf1b05A JRlRHNJ9pzaFxcT8rBaldITpO2I8n6lBy8Lk+NzuoBx/OAd+9OCf9S0zZ1mH32dmwP3Q LgKH4RoN2/wP4X8llbnQMSu7b0Y7KUMrIExIAU01qKPs1q2KRHWC+JKBP9VXTh7XBaIC JZ7K0W2CRaRjQ391bBBcckHWRVSwL3iCDpN1olmJ3/yt08jzupXgbhiXDwf+Rq3C9g1/ PSXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=eHJZUvkW; 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 1-v6si9102068plk.52.2018.03.05.01.48.08; Mon, 05 Mar 2018 01:48:22 -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=eHJZUvkW; 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 S933241AbeCEIsL (ORCPT + 99 others); Mon, 5 Mar 2018 03:48:11 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:37208 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932892AbeCEIsJ (ORCPT ); Mon, 5 Mar 2018 03:48:09 -0500 Received: by mail-pf0-f194.google.com with SMTP id h11so6524904pfn.4; Mon, 05 Mar 2018 00:48:09 -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=USs2LPnnBPP+a4qHzLgEt7V9iKhpQMPa1x6WyQCHWnQ=; b=eHJZUvkWxg/MNL7K60LN/OtrtBte+pJOhyf+/BI16m88S9CeFV0W17fnpYOOZyrzBc j3C37rCXanh7DxvsGZEH+DCWsanblCI568NuBbCZDaRTiaddyqEo3MhiiF8iAfh1KiAH gTtVGIqxpWINTm8WmGfEOe9+dy0JbdPdfDFDCsfBvZVGFIlxL+JqoOrhc78TuxWeX2Q8 KbQrLBgAou7Z7hHYj6xGNv63hIlOUIaQGDzG75uRVlOtR/l29HheNaY/kQgN1xlbTI6R 7h/st0FUaQaTsnl2W4InM3vkdtEuTUmk4FqzJOPogUrccODAX3AjYEYd3oAAUidS8N55 NoOg== 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=USs2LPnnBPP+a4qHzLgEt7V9iKhpQMPa1x6WyQCHWnQ=; b=rgOPY/CRW98uPCeRu6Yru177WDBlnpA6Z2FwI4N6wM+DqugzxbaXLP/CUpz8lQ4jn5 7Ua6I+K5+TA3QqUDI2m8F6rD6MwyhMaVD1oAzvD5eefDhpfi7MH8iwaca+uRkWHivSb9 BUvgAdQM2TTbpWYZBh+mCbjWG1lLmybdI3Zhl7z2+weJRSe9n7+A2vLW52aKXFBjndCU dj8ezveBKoXvUQjvt2yJN2gJ6QvR983b1/exT2kz9eF0yn7eRXWu5lK48WrT8Y2mmk4k pv94FAz6J1/pZwrehPlVogY4aoc3uRwc7tg7kwbtivy/iKDX2pvJdl0xq7AZBi2j4WrG D+ZQ== X-Gm-Message-State: APf1xPBTyssfyYiuvmHVryEFXRsJgM1VEW54/dgZf7/gTk0g2gR8YceA 8FXFtlUGbVYC6mc01ZFX/Q7wNw== X-Received: by 10.99.108.199 with SMTP id h190mr11615683pgc.295.1520239688907; Mon, 05 Mar 2018 00:48:08 -0800 (PST) Received: from localhost ([221.226.180.178]) by smtp.gmail.com with ESMTPSA id c14sm21015241pfn.185.2018.03.05.00.48.07 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 05 Mar 2018 00:48:08 -0800 (PST) From: Ganesh Mahendran To: rjw@rjwysocki.net, pavel@ucw.cz, len.brown@intel.com, rafael@kernel.org, gregkh@linuxfoundation.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Ganesh Mahendran Subject: [PATCH v2] PM / wakeup: use seq_open() to show wakeup stats Date: Mon, 5 Mar 2018 16:47:46 +0800 Message-Id: <1520239666-2964-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 ---- 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; +} + +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 +1107,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