linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pierre Ossman <drzeus-list@drzeus.cx>
To: Andi Kleen <andi@firstfloor.org>
Cc: Andi Kleen <andi@firstfloor.org>,
	"Pallipadi, Venkatesh" <venkatesh.pallipadi@intel.com>,
	Dave Jones <davej@codemonkey.org.uk>,
	Alan Stern <stern@rowland.harvard.edu>,
	LKML <linux-kernel@vger.kernel.org>,
	Adam Belay <abelay@novell.com>, Lee Revell <rlrevell@joe-job.com>,
	linux-pm@lists.linux-foundation.org, Pavel Machek <pavel@ucw.cz>
Subject: Re: [linux-pm] [PATCH] cpuidle: avoid singing capacitors
Date: Tue, 4 Mar 2008 19:04:46 +0100	[thread overview]
Message-ID: <20080304190446.775165e3@mjolnir.drzeus.cx> (raw)
In-Reply-To: <20080304174315.GB27332@one.firstfloor.org>

On Tue, 4 Mar 2008 18:43:15 +0100
Andi Kleen <andi@firstfloor.org> wrote:

> > And how can I tell if this handler has run? Not that it really matters I guess, as I don't think running it from the cpuidle governor is very sane.
>  
> After irq_enter->tick_nohz_update_jiffies() 
> 
> You might need a new callback into the idle governours for this though.
> 

I don't think I quite see the point. If we can't force an update, then
it doesn't really help us knowing if the jiffies value is stale or not.

Anyway, I'm running the following patch for now. I'll keep it on my
machine for a few days and see if I still hear crickets.

diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
index 78d77c5..73f954d 100644
--- a/drivers/cpuidle/governors/menu.c
+++ b/drivers/cpuidle/governors/menu.c
@@ -16,6 +16,9 @@
 
 #define BREAK_FUZZ	4	/* 4 us */
 
+static unsigned int min_deep_sleep = 0;
+static unsigned int failed_deep = 0;
+
 struct menu_device {
 	int		last_state_idx;
 
@@ -23,6 +26,8 @@ struct menu_device {
 	unsigned int	predicted_us;
 	unsigned int	last_measured_us;
 	unsigned int	elapsed_us;
+
+	unsigned long	last_deep;
 };
 
 static DEFINE_PER_CPU(struct menu_device, menu_devices);
@@ -50,9 +55,33 @@ static int menu_select(struct cpuidle_device *dev)
 			break;
 		if (s->exit_latency > pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY))
 			break;
+
+		/*
+		 * In order to avoid the problem of "singing capacitors",
+		 * don't enter a deep sleep for short durations (2 ms seems
+		 * to do the trick). This will, hopefully, keep the problem
+		 * inaudible.
+		 */
+		if (min_deep_sleep && (s->flags & CPUIDLE_FLAG_DEEP)) {
+			if (time_before_eq(jiffies, data->last_deep +
+				HZ * min_deep_sleep / USEC_PER_SEC))
+				break;
+#if 0
+			if (min_deep_sleep > data->expected_us)
+				break;
+			if (min_deep_sleep > data->predicted_us)
+				break;
+			if (min_deep_sleep > data->last_measured_us)
+				break;
+#endif
+		}
 	}
 
 	data->last_state_idx = i - 1;
+
+	if (dev->states[i - 1].flags & CPUIDLE_FLAG_DEEP)
+		data->last_deep = jiffies;
+
 	return i - 1;
 }
 
@@ -80,6 +109,10 @@ static void menu_reflect(struct cpuidle_device *dev)
 	if (!(target->flags & CPUIDLE_FLAG_TIME_VALID))
 		measured_us = USEC_PER_SEC / HZ;
 
+	if ((target->flags & CPUIDLE_FLAG_DEEP) &&
+	    (cpuidle_get_last_residency(dev) < min_deep_sleep))
+		failed_deep++;
+
 	/* Predict time remaining until next break event */
 	if (measured_us + BREAK_FUZZ < data->expected_us - target->exit_latency) {
 		data->predicted_us = max(measured_us, data->last_measured_us);
@@ -103,6 +136,11 @@ static int menu_enable_device(struct cpuidle_device *dev)
 	struct menu_device *data = &per_cpu(menu_devices, dev->cpu);
 
 	memset(data, 0, sizeof(struct menu_device));
+	/*
+	 * 0 might be slightly ahead of the current jiffies count, so
+	 * it's a bad initial value.
+	 */
+	data->last_deep = jiffies;
 
 	return 0;
 }
@@ -132,6 +170,11 @@ static void __exit exit_menu(void)
 	cpuidle_unregister_governor(&menu_governor);
 }
 
+module_param(min_deep_sleep, uint, 0644)
+MODULE_PARM_DESC(min_deep_sleep, "min time (us) to spend in deep sleep to avoid noise")
+
+module_param(failed_deep, uint, 0644)
+
 MODULE_LICENSE("GPL");
 module_init(init_menu);
 module_exit(exit_menu);


-- 
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  PulseAudio, core developer          http://pulseaudio.org
  rdesktop, core developer          http://www.rdesktop.org

  reply	other threads:[~2008-03-04 18:06 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-29 18:38 [RFC][PATCH] cpuidle: avoid singing capacitors Pierre Ossman
2008-02-29 21:44 ` Lennart Sorensen
2008-03-01 12:31   ` Pierre Ossman
2008-03-01 13:40 ` Pierre Ossman
2008-03-02  2:27 ` Lee Revell
2008-03-02 14:17   ` Pierre Ossman
2008-03-03 12:36 ` Andi Kleen
2008-03-03 20:18 ` [PATCH] " Pierre Ossman
2008-03-03 20:46   ` Pavel Machek
2008-03-03 21:03     ` Pierre Ossman
2008-03-03 21:08       ` Pavel Machek
2008-03-03 21:14         ` Pallipadi, Venkatesh
2008-03-03 21:17           ` Pierre Ossman
2008-03-03 22:04             ` Pallipadi, Venkatesh
2008-03-03 23:05               ` [linux-pm] " Alan Stern
2008-03-03 23:10                 ` Andi Kleen
2008-03-04  4:00                   ` Dave Jones
2008-03-04  6:14                     ` Pierre Ossman
2008-03-04 17:19                       ` Pierre Ossman
2008-03-04 17:29                         ` Andi Kleen
2008-03-04 17:30                           ` Pierre Ossman
2008-03-04 17:43                             ` Andi Kleen
2008-03-04 18:04                               ` Pierre Ossman [this message]
2008-03-04 18:34                                 ` Andi Kleen
2008-03-05  6:04                                   ` Pierre Ossman
2008-03-05 15:48                                     ` Andi Kleen
2008-03-05 16:53                                       ` Pierre Ossman
2008-03-05 17:32                                         ` Andi Kleen
2008-03-04 19:01                         ` Pallipadi, Venkatesh
2008-03-05  6:02                           ` Pierre Ossman
2008-03-05  8:40                             ` Pierre Ossman
2008-03-05  9:03                               ` Pavel Machek
2008-03-05 13:42                                 ` Pierre Ossman
2008-03-05 13:47                                   ` Pavel Machek
2008-03-05 13:52                                     ` Pierre Ossman
2008-03-06  8:27                               ` Pierre Ossman
2008-03-09 14:16                                 ` Pierre Ossman
2008-03-09 18:19                                   ` Rafael J. Wysocki
2008-03-09 18:50                                   ` Alan Stern
2008-03-09 19:30                                   ` Henrique de Moraes Holschuh
2008-03-09 20:14                                     ` Pierre Ossman
2008-03-09 20:41                                       ` Henrique de Moraes Holschuh
2008-03-09 20:54                                         ` Henrique de Moraes Holschuh
2008-03-10 10:00                                   ` Pavel Machek
2008-03-10 12:49                                     ` Pierre Ossman
2008-03-10 13:04                                       ` Andi Kleen
2008-03-10 13:29                                         ` Pierre Ossman
2008-03-12 19:11                                       ` Len Brown
2008-03-13  8:10                                         ` Pavel Machek
2008-03-13 10:42                                           ` Andi Kleen
2008-03-14  4:13                                             ` Len Brown
2008-03-13 16:34                                         ` Pierre Ossman
2008-03-13 16:47                                           ` Pallipadi, Venkatesh
2008-03-13 17:44                                             ` Pierre Ossman
2008-03-13 17:49                                           ` Pierre Ossman
2008-03-14 19:40                                           ` Pierre Ossman
2008-03-14 21:15                                             ` Pallipadi, Venkatesh
2008-03-15  0:41                                               ` Pierre Ossman
2008-03-11  7:51                                   ` Pierre Ossman
2008-03-11 10:48                                     ` Andi Kleen
2008-03-11 15:20                                       ` Pierre Ossman
2008-03-11 17:31                                         ` Pierre Ossman
2008-03-12 19:17                                       ` Len Brown
2008-03-12 20:31                               ` Len Brown
2008-03-04  9:40                     ` Andi Kleen
2008-03-03 23:09               ` Andi Kleen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080304190446.775165e3@mjolnir.drzeus.cx \
    --to=drzeus-list@drzeus.cx \
    --cc=abelay@novell.com \
    --cc=andi@firstfloor.org \
    --cc=davej@codemonkey.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=pavel@ucw.cz \
    --cc=rlrevell@joe-job.com \
    --cc=stern@rowland.harvard.edu \
    --cc=venkatesh.pallipadi@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).