Received: by 10.223.185.116 with SMTP id b49csp8532361wrg; Fri, 2 Mar 2018 03:35:56 -0800 (PST) X-Google-Smtp-Source: AG47ELt9d8D0ugUhzf9UeVhSqhZ3VhFK5kvS/o8Smm3gyAiVR0V94WCUvzdy3pYqhP3Ukk2oFIVt X-Received: by 2002:a17:902:32a2:: with SMTP id z31-v6mr5129968plb.32.1519990556787; Fri, 02 Mar 2018 03:35:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519990556; cv=none; d=google.com; s=arc-20160816; b=Y9BQQzyw/rvd6c+nsWogQmfUCmLzgJVCbFDUwoAywknnXzMrjGSVWbc6iOfkl8YQMH y0SUdMFcY0Ob8L2HJWGkSDz3TKb3nOeUpBm2V9kw+9n2scoB7Frs7K9w426Fdqz7jo8Y ugm2f+iAyfi1RejExjM/bU/F7J+j6mV1VWYX65L0W/y9FZzLMtZnM3ylNmYgKl/AmKbh 6AXlsDq95PNBFbX2NPB02Mt4aT6lat2p5IrD1MeXRX+/Rb+x3kdhF+/HEBZIr3BOM9Ij oigfyEJPmiJIh8gZ35CzP88JWWgoJYk8vnCIHDTb6MusaU3JP95H3EzkAnR0zPtMqxBg ZWbg== 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=Fnypi+D9EAAMsRF57FoCvv7PBXotEr3s4sSrHNdwVCk=; b=WsKOtD2qYdiqlPXS7Nj/bFhCYSmtNGtjDiTo9RFYi0aeq5GGoyi74vT6UVt8o+VklM tUHWwwP9ZTftTOHGLaO8onmUNGqQuAtgNRYsv5UpLaEx10URqPXhgsTqmenWbQXn0vmJ FsxvVYVybK5+a7/S2xQNdTiPf59nk1PVVrkFtJdn9ppkAVENR+rDGzNHje2Jm6fF81mj KerlWmuTB12kei49uj6JFVJDNuNB03VQhGUixKoB4i6WirG0imLJnTjpLaJBnrs5n0Lj 5mbRa+d6O5o1t1ZSVRJdcdrYHO0bJkmfyk8fAGJamByAFxHtI87cugtHfSc1TYMTULD6 bgvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TJ56Yrra; 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 s12si3853218pgq.491.2018.03.02.03.35.41; Fri, 02 Mar 2018 03:35:56 -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=TJ56Yrra; 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 S1946456AbeCBLeo (ORCPT + 99 others); Fri, 2 Mar 2018 06:34:44 -0500 Received: from mail-io0-f193.google.com ([209.85.223.193]:42627 "EHLO mail-io0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1946442AbeCBLei (ORCPT ); Fri, 2 Mar 2018 06:34:38 -0500 Received: by mail-io0-f193.google.com with SMTP id u84so10325615iod.9; Fri, 02 Mar 2018 03:34:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=Fnypi+D9EAAMsRF57FoCvv7PBXotEr3s4sSrHNdwVCk=; b=TJ56YrraZLCYUrXUqo0QaJn2cJbjMmjE7hASnCKpm+00Zf43kGxisGCereFdBVVLiH RfDMID2HD5gh9uGIpyXpsWCOx/BAs+S5W0ac6AZN+kJKZAJ7QM+agi9mWtIGRlu+AMYB SxU5541UDImSGdsakHszJawgtgg5DIQgKU6vqfJilc2TI8ukYFTN8vaX72SnO7zW99xZ UkfU1ubI7Z56ViNm6y3pHVdcleokYq8ac0iraXEGPgibW2AdJ0+Jti/4ZZfUID2kVsTY zU6fEQFYaXze9oT7sMsapsuxP/6yqz5r7+m1Dij2Rh91kWW0Xm6n4/0GUMLO/ZezU+xR 8k9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=Fnypi+D9EAAMsRF57FoCvv7PBXotEr3s4sSrHNdwVCk=; b=QkSdFMFR48m4jC0PwJhC9JGYg8RW/nRIFPcbC0Oamew6bqsy78r5Q5KHNWkevN2thB IWskm7lKP3+WLDcyJ55VI6+Tm5So0PL/mm5a+BdpWuQPdlOhwKfFdGEUMZpUi5I4x85s mpOzKWcY9kxAHy2SzXAawRn2yRXPGVKefjYBxYJghuKxPSP2pvkH+D3NzE4OOzsL68fP bvj9ntGLr/dn7xjTCBamMt6P3x4x2h3O6IxTXZEJFPT4H5mPCz0BQCSAlEgDR3LtsKOr t93DTh24P+zhsdx8uDtIkUkvCFh84QqeQmS2VlZ9Ss58zNks4fAHRmWfK7DguvxOiYTA wiuA== X-Gm-Message-State: AElRT7Gs64QjmrA78Bii4uX4+LLm+xDtQuVw4JziCysosQxmtlg1+yrX pVdX9Ylp94FeOX3fXGWBzkxqtxkfo1hmuh4z6iY= X-Received: by 10.107.114.21 with SMTP id n21mr5986029ioc.294.1519990477391; Fri, 02 Mar 2018 03:34:37 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.59.71 with HTTP; Fri, 2 Mar 2018 03:34:36 -0800 (PST) In-Reply-To: References: <1519966860-32519-1-git-send-email-opensource.ganesh@gmail.com> From: Ganesh Mahendran Date: Fri, 2 Mar 2018 19:34:36 +0800 Message-ID: Subject: Re: [PATCH] PM / wakeup: use seq_open() to show wakeup stats To: "Rafael J. Wysocki" 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 Hi, Rafael: 2018-03-02 16:58 GMT+08:00 Rafael J. Wysocki : > 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? We got report of android watchdog timeout when memory situation is bad. > >> 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. wakeup_sources_stats_seq_[start | end] are called in seq_read(). So rcu_read_unlock() will soon be called in seq_read(). I am not familar with rcu. I refered to kmemleak.c which use seq_open() to show the stats. Thanks for your review. > >> + 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 >>