WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH]cpuidle: Fix possible false judge caused by type cast

To: "Xen-Devel (E-mail)" <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH]cpuidle: Fix possible false judge caused by type casting
From: "Wei, Gang" <gang.wei@xxxxxxxxx>
Date: Thu, 14 May 2009 21:41:24 +0800
Accept-language: en-US
Acceptlanguage: en-US
Cc: Keir Fraser <keir.fraser@xxxxxxxxxxxxx>
Delivery-date: Thu, 14 May 2009 06:42:00 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Thread-index: AcnUmayWTXwgEjAlQ3++DivaRb1mNw==
Thread-topic: [PATCH]cpuidle: Fix possible false judge caused by type casting
Keir, this is a fix along with an added tuning option. It should not have any 
negative impact. Could you take it in 3.4?

Jimmy

cpuidle: Fix possible false judge caused by type casting

For timer_deadline == 0 or timer_deadline - now > largest u32 case,
the expected_us (in u32 type) may become wrong.

Add a tunable option to ease conditional adjustment.

Signed-off-by: Wei Gang <gang.wei@xxxxxxxxx>

diff -r fb3e1e84d8f4 xen/arch/x86/acpi/cpu_idle.c
--- a/xen/arch/x86/acpi/cpu_idle.c      Wed May 06 12:40:51 2009 +0100
+++ b/xen/arch/x86/acpi/cpu_idle.c      Thu May 14 17:36:11 2009 +0800
@@ -624,6 +624,7 @@ static int check_cx(struct acpi_processo
 }
 
 static unsigned int latency_factor = 2;
+integer_param("idle_latency_factor", latency_factor);
 
 static void set_cx(
     struct acpi_processor_power *acpi_power,
diff -r fb3e1e84d8f4 xen/arch/x86/acpi/cpuidle_menu.c
--- a/xen/arch/x86/acpi/cpuidle_menu.c  Wed May 06 12:40:51 2009 +0100
+++ b/xen/arch/x86/acpi/cpuidle_menu.c  Thu May 14 17:36:11 2009 +0800
@@ -45,9 +45,15 @@ struct menu_device
 
 static DEFINE_PER_CPU(struct menu_device, menu_devices);
 
-static s_time_t get_sleep_length_ns(void)
+static unsigned int get_sleep_length_us(void)
 {
-    return per_cpu(timer_deadline, smp_processor_id()) - NOW();
+    s_time_t us = (per_cpu(timer_deadline, smp_processor_id()) - NOW()) / 1000;
+    /*
+     * while us < 0 or us > (u32)-1, return a large u32,
+     * choose (unsigned int)-2000 to avoid wrapping while added with exit
+     * latency because the latency should not larger than 2ms
+     */
+    return (us >> 32) ? (unsigned int)-2000 : (unsigned int)us;
 }
 
 static int menu_select(struct acpi_processor_power *power)
@@ -56,7 +62,7 @@ static int menu_select(struct acpi_proce
     int i;
 
     /* determine the expected residency time */
-    data->expected_us = (u32) get_sleep_length_ns() / 1000;
+    data->expected_us = get_sleep_length_us();
 
     /* find the deepest idle state that satisfies our constraints */
     for ( i = 2; i < power->count; i++ )

Attachment: fix-for-menu.patch
Description: fix-for-menu.patch

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH]cpuidle: Fix possible false judge caused by type casting, Wei, Gang <=