Received: by 10.223.185.116 with SMTP id b49csp8470376wrg; Fri, 2 Mar 2018 02:18:38 -0800 (PST) X-Google-Smtp-Source: AG47ELvrsCn2fZYI2yowCpCmf7PyRZg+s7jKsh543KbklZTkef4swRYWrxscs6VhbrV0F9SlhFLC X-Received: by 10.98.14.200 with SMTP id 69mr5136626pfo.168.1519985917919; Fri, 02 Mar 2018 02:18:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519985917; cv=none; d=google.com; s=arc-20160816; b=hWvPs4ojEYwGfBU+rfTp+Zw3IFTd/6IlC/0zLzT2+skBxDvXqljb1XRveaYTLG+aNi BLbHefhjit8HP5C45NCsb7+GrwHRE8WmHW88dRTQTdsgx4heOmE0FIJLhyZWnZ7JpyuM 6IYQKlWXvOmHjwifmzEBsktDpbqAFpoDmadAYDG5hvHURRbyo4nVTYsIHQkzbma+F54a sxTD6ykgRYb7OpMI00wWntCjM9i83lM4ZmCbHzWeTCj2ofLUxlqccxK0eV8wsoeYy5xT RSOUkJONCZf+2qO3YXnwq0/9JYIyc8i5IQ4eVaQAtALleOzECvH2DLaV6l9cTc3/1y2e QSnw== 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=Mn6hhv9JYdsM27vJ8ldVWfpoKHtD89xCOOszSrwSK0c=; b=qcVwqg0auMMrhnF+gyoVUbf+wFPGEKq/Q7pdDhM9izT+NeCBnWdghoYzVKcHvj6SxH nMsSq3luPLVNiJg4nrTW8j0c1FxUWXDjR9161BS3Z/bzP3zeIJ+ONTtCvOUbIxyoZOtj LP66pd//zu0fSOUqvitu8RDl8RLebVLwcyP7al6tbfYsE1aA/Gjz9V+sqSUuNymn8hlm lHDyH7GNbXGdYCT1vnLrerAdHNhgQiUJWycS8qeAB9PmQl4FFK5KuWjqGdxzo0WtrOnn S7Qrr7DTFTFIyZR9xtB2TiI/ugA5qWQynBovr4XqiJCthakbk93nZ8AUTx2TyQ6oCptR O9OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=jB0Gsy92; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c63si4668760pfd.51.2018.03.02.02.18.23; Fri, 02 Mar 2018 02:18:37 -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=fail header.i=@gmail.com header.s=20161025 header.b=jB0Gsy92; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1426295AbeCBKQ5 (ORCPT + 99 others); Fri, 2 Mar 2018 05:16:57 -0500 Received: from mail-ot0-f195.google.com ([74.125.82.195]:40492 "EHLO mail-ot0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424206AbeCBI6Y (ORCPT ); Fri, 2 Mar 2018 03:58:24 -0500 Received: by mail-ot0-f195.google.com with SMTP id l12so8131846otj.7; Fri, 02 Mar 2018 00:58:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=Mn6hhv9JYdsM27vJ8ldVWfpoKHtD89xCOOszSrwSK0c=; b=jB0Gsy92ym+2NALlEzXOclMu8GXS2LVjCSI9a5fHO24Jc5A0+E1DvlGhvF4bZuWnpE 3JsfoarNTDQPQlgaoj0AVEjhhRp2tLGCoZBzFmd7j3nKQBR7SOgzeTRijyRGwXPrYy2p nLy9JGqJBVAmXSfRZGay1fe39whqSMMamBdBQLKfn2xG8RI3nyTuG262LIzjIA5BZXXz 2UByeJLcbQbBrIzLa+n57zuqvH99SueWCqmlNqmbN/JLn4+LA3bKEZ8EppQ6N3f2YzKP 9HQKesgQCCDSvwEwUibpv7yrEPBel43sDMtytS2Dxw4jVWB+zQpCGt75CZekRolZHHt7 cDbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=Mn6hhv9JYdsM27vJ8ldVWfpoKHtD89xCOOszSrwSK0c=; b=gD3rS/0806TqOIeRjOTcXkxuR+SWdxZvHuG+iGDl/RCwCHF2N9evAeub96DrTW1tdh 0cDS8JZcZB77mkBBzHtKwjKZJFL88Ju1hu9SnTkI3yINzhVkODpntHG+Qz48IDnifgwr c1OFXg2gM4UVn5N19uBDgSWLbhUBVa/yAL/l2hDugdZrlxR0XAvq5lWHE148srEyfx8C A4NEdFMKfzK61BXvu1bV668sGCOWQXaQt6qSfbj+yl9OMcAFvY0R7NkIboJiqJEARyPn h4bJA9ItFzlC4ayNRMPho6LSQyR/tYPFNY6ZRnYrf6V+f02cw4YaUCeywBncsfyKUmoh 8AQw== X-Gm-Message-State: AElRT7GeeT9S9titXY92VDH2R8bG+loGEqf2301D0/955I+f/tYlYz+7 JPLU3HuolOOgng5zJRttdRBc1QD0uJ9bLpi8qFY= X-Received: by 10.157.10.67 with SMTP id 61mr3258457otg.370.1519981103315; Fri, 02 Mar 2018 00:58:23 -0800 (PST) MIME-Version: 1.0 Received: by 10.157.44.146 with HTTP; Fri, 2 Mar 2018 00:58:22 -0800 (PST) In-Reply-To: <1519966860-32519-1-git-send-email-opensource.ganesh@gmail.com> References: <1519966860-32519-1-git-send-email-opensource.ganesh@gmail.com> From: "Rafael J. Wysocki" Date: Fri, 2 Mar 2018 09:58:22 +0100 X-Google-Sender-Auth: wnbVNDkAopPGRUZOAmu2KdCCizI Message-ID: Subject: Re: [PATCH] PM / wakeup: use seq_open() to show wakeup stats To: Ganesh Mahendran Cc: "Rafael J. Wysocki" , Pavel Machek , Len Brown , Greg Kroah-Hartman , Linux PM , Linux Kernel Mailing List 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 On Fri, Mar 2, 2018 at 6:01 AM, 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. Did you actually see this problem with this particular file or is it theoretical? > 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(); The code running after this cannot sleep. Use srcu_read_lock(&wakeup_srcu) instead. > + 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 >