Skip to contentSkip to conversation

x86: Use deep C states for off-lined CPUs

PATCH Superseded Boris Ostrovsky 4 participants 11 messages Feb 28, 2012 – Mar 1, 2012

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: Use deep C states for off-lined CPUs

# HG changeset patch
# User Boris Ostrovsky <[email protected]> # Date 1330466573 -3600
# Node ID 9e5991ad9c85b5176ce269001e7957e8805dd93c # Parent a7bacdc5449a2f7bb9c35b2a1334b463fe9f29a9
x86: Use deep C states for off-lined CPUs

Currently when a core is taken off-line it is placed in C1 state (unless MONITOR/MWAIT is used). This patch allows a core to go to deeper C states resulting in significantly higher power savings.

xen/arch/x86/acpi/cpu_idle.c +16 -2
diff -r a7bacdc5449a -r 9e5991ad9c85 xen/arch/x86/acpi/cpu_idle.c
@@ -573,10 +573,10 @@ static void acpi_dead_idle(void)
     if ( (cx = &power->states[power->count-1]) == NULL )
         goto default_halt;
 
-    mwait_ptr = (void *)&mwait_wakeup(smp_processor_id());
-
     if ( cx->entry_method == ACPI_CSTATE_EM_FFH )
     {
+        mwait_ptr = (void *)&mwait_wakeup(smp_processor_id());
+
         /*
          * Cache must be flushed as the last operation before sleeping.
          * Otherwise, CPU may still hold dirty data, breaking cache coherency,
@@ -601,6 +601,20 @@ static void acpi_dead_idle(void)
             mb();
             __mwait(cx->address, 0);
         }
+    } 
+    else if ( cx->entry_method == ACPI_CSTATE_EM_SYSIO )
+    {
+        /* Avoid references to shared data after the cache flush */
+        u32 address = cx->address;
+        u32 pmtmr_ioport_local = pmtmr_ioport;
+
+        wbinvd();	
+
+        while ( 1 )
+        {
+            inb(address);
+            inl(pmtmr_ioport_local);
+        }
     }
 
 default_halt:
#1 lore raw

I noticed the following comments when using mwait based idle:
-------------------------------------------------------------------------

        while ( 1 )
        {
            /*
             * 1. The CLFLUSH is a workaround for erratum AAI65 for
             * the Xeon 7400 series.
             * 2. The WBINVD is insufficient due to the spurious-wakeup
             * case where we return around the loop.
             * 3. Unlike wbinvd, clflush is a light weight but not serializing
             * instruction, hence memory fence is necessary to make sure all
             * load/store visible before flush cache line.
             */
            mb();
            clflush(mwait_ptr);
            __monitor(mwait_ptr, 0, 0);
            mb();
            __mwait(cx->address, 0);
        }
    }

-------------------------------------------------------------------------
Your patch should follow it too.

best regards
yang

Quoted 63 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Boris Ostrovsky
Sent: Wednesday, February 29, 2012 6:09 AM
To: [email protected]
Cc: [email protected]
Subject: [Xen-devel] [PATCH] x86: Use deep C states for off-lined CPUs

# HG changeset patch
# User Boris Ostrovsky <[email protected]> # Date 1330466573 -3600 # Node ID 9e5991ad9c85b5176ce269001e7957e8805dd93c
# Parent a7bacdc5449a2f7bb9c35b2a1334b463fe9f29a9
x86: Use deep C states for off-lined CPUs

Currently when a core is taken off-line it is placed in C1 state (unless MONITOR/MWAIT is used). This patch allows a core to go to deeper C states resulting in significantly higher power savings.

diff -r a7bacdc5449a -r 9e5991ad9c85 xen/arch/x86/acpi/cpu_idle.c

xen/arch/x86/acpi/cpu_idle.c +16 -2
@@ -573,10 +573,10 @@ static void acpi_dead_idle(void)
     if ( (cx = &power->states[power->count-1]) == NULL )
         goto default_halt;
 
-    mwait_ptr = (void *)&mwait_wakeup(smp_processor_id());
-
     if ( cx->entry_method == ACPI_CSTATE_EM_FFH )
     {
+        mwait_ptr = (void *)&mwait_wakeup(smp_processor_id());
+
         /*
          * Cache must be flushed as the last operation before sleeping.
          * Otherwise, CPU may still hold dirty data, breaking cache coherency,
@@ -601,6 +601,20 @@ static void acpi_dead_idle(void)
             mb();
             __mwait(cx->address, 0);
         }
+    }
+    else if ( cx->entry_method == ACPI_CSTATE_EM_SYSIO )
+    {
+        /* Avoid references to shared data after the cache flush */
+        u32 address = cx->address;
+        u32 pmtmr_ioport_local = pmtmr_ioport;
+
+        wbinvd();
+
+        while ( 1 )
+        {
+            inb(address);
+            inl(pmtmr_ioport_local);
+        }
     }
 
 default_halt:

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw

The patch is adding IO-based C-states. My understading is that CFLUSH was to work around a MONITOR-related erratum.

Or are you referring to something else?

-boris

________________________________________
From: Zhang, Yang Z [[email protected]]
Sent: Tuesday, February 28, 2012 8:37 PM
To: Ostrovsky, Boris; [email protected]
Subject: RE: [Xen-devel] [PATCH] x86: Use deep C states for off-lined CPUs

I noticed the following comments when using mwait based idle:
-------------------------------------------------------------------------

        while ( 1 )
        {
            /*
             * 1. The CLFLUSH is a workaround for erratum AAI65 for
             * the Xeon 7400 series.
             * 2. The WBINVD is insufficient due to the spurious-wakeup
             * case where we return around the loop.
             * 3. Unlike wbinvd, clflush is a light weight but not serializing
             * instruction, hence memory fence is necessary to make sure all
             * load/store visible before flush cache line.
             */
            mb();
            clflush(mwait_ptr);
            __monitor(mwait_ptr, 0, 0);
            mb();
            __mwait(cx->address, 0);
        }
    }

-------------------------------------------------------------------------
Your patch should follow it too.

best regards
yang

Quoted 63 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Boris Ostrovsky
Sent: Wednesday, February 29, 2012 6:09 AM
To: [email protected]
Cc: [email protected]
Subject: [Xen-devel] [PATCH] x86: Use deep C states for off-lined CPUs

# HG changeset patch
# User Boris Ostrovsky <[email protected]> # Date 1330466573 -3600 # Node ID 9e5991ad9c85b5176ce269001e7957e8805dd93c
# Parent a7bacdc5449a2f7bb9c35b2a1334b463fe9f29a9
x86: Use deep C states for off-lined CPUs

Currently when a core is taken off-line it is placed in C1 state (unless MONITOR/MWAIT is used). This patch allows a core to go to deeper C states resulting in significantly higher power savings.

diff -r a7bacdc5449a -r 9e5991ad9c85 xen/arch/x86/acpi/cpu_idle.c

xen/arch/x86/acpi/cpu_idle.c Tue Feb 28 23:02:53 2012 +0100 renamed from xen/arch/x86/acpi/cpu_idle.c Mon Feb 27 17:05:18 2012 +0000 +16 -2
@@ -573,10 +573,10 @@ static void acpi_dead_idle(void)
     if ( (cx = &power->states[power->count-1]) == NULL )
         goto default_halt;
 
-    mwait_ptr = (void *)&mwait_wakeup(smp_processor_id());
-
     if ( cx->entry_method == ACPI_CSTATE_EM_FFH )
     {
+        mwait_ptr = (void *)&mwait_wakeup(smp_processor_id());
+
         /*
          * Cache must be flushed as the last operation before sleeping.
          * Otherwise, CPU may still hold dirty data, breaking cache coherency,
@@ -601,6 +601,20 @@ static void acpi_dead_idle(void)
             mb();
             __mwait(cx->address, 0);
         }
+    }
+    else if ( cx->entry_method == ACPI_CSTATE_EM_SYSIO )
+    {
+        /* Avoid references to shared data after the cache flush */
+        u32 address = cx->address;
+        u32 pmtmr_ioport_local = pmtmr_ioport;
+
+        wbinvd();
+
+        while ( 1 )
+        {
+            inb(address);
+            inl(pmtmr_ioport_local);
+        }
     }
 
 default_halt:

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw

Hmm, no.

It need flush cache, as long as *deep Cx* would be spurious-wokenup.
The reason clflush here is, it's a light-weight flush, in fact it also could use wbinvd if not consider performance.

For halt, it don't need to do so since cpu still keep snoop when sleep.

Thanks,
Jinsong

Quoted 113 lines · Boris

The patch is adding IO-based C-states. My understading is that CFLUSH was to work around a MONITOR-related erratum.

Or are you referring to something else?

-boris

________________________________________
From: Zhang, Yang Z [[email protected]]
Sent: Tuesday, February 28, 2012 8:37 PM
To: Ostrovsky, Boris; [email protected]
Subject: RE: [Xen-devel] [PATCH] x86: Use deep C states for off-lined CPUs

I noticed the following comments when using mwait based idle:
-------------------------------------------------------------------------
while ( 1 )
{
/*
* 1. The CLFLUSH is a workaround for erratum AAI65 for
* the Xeon 7400 series.
* 2. The WBINVD is insufficient due to the
spurious-wakeup
* case where we return around the loop.
* 3. Unlike wbinvd, clflush is a light weight but not
serializing
* instruction, hence memory fence is necessary to make
sure all

             * load/store visible before flush cache line.
             */
            mb();
            clflush(mwait_ptr);
            __monitor(mwait_ptr, 0, 0);
            mb();
            __mwait(cx->address, 0);
        }
    }

-------------------------------------------------------------------------
Your patch should follow it too.

best regards
yang

Quoted 57 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Boris Ostrovsky
Sent: Wednesday, February 29, 2012 6:09 AM
To: [email protected]
Cc: [email protected]
Subject: [Xen-devel] [PATCH] x86: Use deep C states for off-lined CPUs

# HG changeset patch
# User Boris Ostrovsky <[email protected]> # Date 1330466573 -3600 # Node ID 9e5991ad9c85b5176ce269001e7957e8805dd93c # Parent a7bacdc5449a2f7bb9c35b2a1334b463fe9f29a9
x86: Use deep C states for off-lined CPUs

Currently when a core is taken off-line it is placed in C1 state (unless MONITOR/MWAIT is used). This patch allows a core to go to deeper C states resulting in significantly higher power savings.

diff -r a7bacdc5449a -r 9e5991ad9c85 xen/arch/x86/acpi/cpu_idle.c

xen/arch/x86/acpi/cpu_idle.c Tue Feb 28 23:02:53 2012 +0100 renamed from xen/arch/x86/acpi/cpu_idle.c Mon Feb 27 17:05:18 2012 +0000 +1 -1
@@ -573,10 +573,10 @@ static void acpi_dead_idle(void)
     if ( (cx = &power->states[power->count-1]) == NULL )         
 goto default_halt; 
 
-    mwait_ptr = (void *)&mwait_wakeup(smp_processor_id()); -
     if ( cx->entry_method == ACPI_CSTATE_EM_FFH )
     {
+        mwait_ptr = (void *)&mwait_wakeup(smp_processor_id()); +
         /*
          * Cache must be flushed as the last operation before

sleeping.
* Otherwise, CPU may still hold dirty data, breaking cache
coherency, @@ -601,6 +601,20 @@ static void acpi_dead_idle(void)

             mb(); __mwait(cx->address, 0);
         }
xen/arch/x86/acpi/cpu_idle.c Tue Feb 28 23:02:53 2012 +0100 renamed from xen/arch/x86/acpi/cpu_idle.c Mon Feb 27 17:05:18 2012 +0000 +13 -0
+    }
+    else if ( cx->entry_method == ACPI_CSTATE_EM_SYSIO ) +    {
+        /* Avoid references to shared data after the cache flush */
+        u32 address = cx->address;
+        u32 pmtmr_ioport_local = pmtmr_ioport;
+
+        wbinvd();
+
+        while ( 1 )
+        {
+            inb(address);
+            inl(pmtmr_ioport_local);
+        }
     }
 
 default_halt:
Quoted 4 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#4 lore raw
Quoted 4 lines · Jinsong

Hmm, no.

It need flush cache, as long as *deep Cx* would be spurious-wokenup.
The reason clflush here is, it's a light-weight flush, in fact it also could use wbinvd if not consider performance.

What address would need to be CFLUSH'd ? Both "address" and "pmtmr_ioport_local"?

Quoted 2 lines

For halt, it don't need to do so since cpu still keep snoop when sleep.

If cpu not snoop when in deeper C-states, wouldn't we have a problem with acpi_idle_do_entry()? There is a code path (at least for for C2) where the cache is not flushed.

Incidentally, if CFLUSH is required for MONITOR then perhaps mwait_idle_with_hints() needs to have it as well?

-boris

Quoted 120 lines

Thanks,
Jinsong

Quoted 113 lines · Boris

The patch is adding IO-based C-states. My understading is that CFLUSH was to work around a MONITOR-related erratum.

Or are you referring to something else?

-boris

________________________________________
From: Zhang, Yang Z [[email protected]]
Sent: Tuesday, February 28, 2012 8:37 PM
To: Ostrovsky, Boris; [email protected]
Subject: RE: [Xen-devel] [PATCH] x86: Use deep C states for off-lined CPUs

I noticed the following comments when using mwait based idle:
-------------------------------------------------------------------------
while ( 1 )
{
/*
* 1. The CLFLUSH is a workaround for erratum AAI65 for
* the Xeon 7400 series.
* 2. The WBINVD is insufficient due to the
spurious-wakeup
* case where we return around the loop.
* 3. Unlike wbinvd, clflush is a light weight but not
serializing
* instruction, hence memory fence is necessary to make
sure all

              * load/store visible before flush cache line.
              */
             mb();
             clflush(mwait_ptr);
             __monitor(mwait_ptr, 0, 0);
             mb();
             __mwait(cx->address, 0);
         }
     }

-------------------------------------------------------------------------
Your patch should follow it too.

best regards
yang

Quoted 57 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Boris Ostrovsky
Sent: Wednesday, February 29, 2012 6:09 AM
To: [email protected]
Cc: [email protected]
Subject: [Xen-devel] [PATCH] x86: Use deep C states for off-lined CPUs

# HG changeset patch
# User Boris Ostrovsky<[email protected]> # Date 1330466573 -3600 # Node ID 9e5991ad9c85b5176ce269001e7957e8805dd93c # Parent a7bacdc5449a2f7bb9c35b2a1334b463fe9f29a9
x86: Use deep C states for off-lined CPUs

Currently when a core is taken off-line it is placed in C1 state (unless MONITOR/MWAIT is used). This patch allows a core to go to deeper C states resulting in significantly higher power savings.

diff -r a7bacdc5449a -r 9e5991ad9c85 xen/arch/x86/acpi/cpu_idle.c

xen/arch/x86/acpi/cpu_idle.c Tue Feb 28 23:02:53 2012 +0100 renamed from xen/arch/x86/acpi/cpu_idle.c Mon Feb 27 17:05:18 2012 +0000 +1 -1
@@ -573,10 +573,10 @@ static void acpi_dead_idle(void)
      if ( (cx =&power->states[power->count-1]) == NULL )
 goto default_halt;
 
-    mwait_ptr = (void *)&mwait_wakeup(smp_processor_id()); -
      if ( cx->entry_method == ACPI_CSTATE_EM_FFH )
      {
+        mwait_ptr = (void *)&mwait_wakeup(smp_processor_id()); +
          /*
           * Cache must be flushed as the last operation before

sleeping.
* Otherwise, CPU may still hold dirty data, breaking cache
coherency, @@ -601,6 +601,20 @@ static void acpi_dead_idle(void)

              mb(); __mwait(cx->address, 0);
          }
xen/arch/x86/acpi/cpu_idle.c Tue Feb 28 23:02:53 2012 +0100 renamed from xen/arch/x86/acpi/cpu_idle.c Mon Feb 27 17:05:18 2012 +0000 +13 -0
+    }
+    else if ( cx->entry_method == ACPI_CSTATE_EM_SYSIO ) +    {
+        /* Avoid references to shared data after the cache flush */
+        u32 address = cx->address;
+        u32 pmtmr_ioport_local = pmtmr_ioport;
+
+        wbinvd();
+
+        while ( 1 )
+        {
+            inb(address);
+            inl(pmtmr_ioport_local);
+        }
      }
 
  default_halt:
Quoted 4 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#5 lore raw
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky
Quoted 4 lines · Jinsong

Hmm, no.

It need flush cache, as long as *deep Cx* would be spurious-wokenup. The reason clflush here is, it's a light-weight flush, in fact it also could

use wbinvd if not consider performance.

What address would need to be CFLUSH'd ? Both "address" and "pmtmr_ioport_local"?

Hardly - these are both I/O ports.

Jan

#6 lore raw
In reply to Boris Ostrovsky
Quoted 9 lines · Boris Ostrovsky
Quoted 5 lines · Jinsong

Hmm, no.

It need flush cache, as long as *deep Cx* would be spurious-wokenup. The reason clflush here is, it's a light-weight flush, in fact it also could use wbinvd if not consider performance.

What address would need to be CFLUSH'd ? Both "address" and "pmtmr_ioport_local"?

if while loop only involve inb/inl port, no need to flush.

Quoted 8 lines
Quoted 4 lines

For halt, it don't need to do so since cpu still keep snoop when sleep.

If cpu not snoop when in deeper C-states, wouldn't we have a problem with acpi_idle_do_entry()? There is a code path (at least for for C2) where the cache is not flushed.

No problem for C1/C2, only C3 and deeper would stop snoop.

Quoted 4 lines

Incidentally, if CFLUSH is required for MONITOR then perhaps mwait_idle_with_hints() needs to have it as well?

No need to do so, wbinvd has been done before mwait_idle_with_hints enter C3, and it has different scenario with acpi_dead_idle which is a while(1) loop.

Thanks,
Jinsong

#7 lore raw
In reply to Boris Ostrovsky

I don't think we should go back to old SYSIO method, the history here is:

Xen originally has SYSIO method when offline cpu, but at c/s 23022 we cancel it as reason below
======================
x86: Fix cpu offline bug: cancel SYSIO method when play dead

Play dead is a fragile and tricky point of cpu offline logic. For how to play cpu dead, linux kernel changed several times: Very old kernel support 3 ways to play cpu dead: mwait, SYSIO, and halt, just like what cpuidle did when enter C3; Later, it cancel mwait and SYSIO support, only use halt to play dead; Latest linux 2.6.38 add mwait support when cpu dead.

This patch cancel SYSIO method when cpu dead, keep same with latest kernel.

SYSIO is an obsoleted method to enter deep C, with some tricky hardware behavior, and seldom supported in new platform. Xen experiment indicate that when cpu dead, SYSIO method would trigger unknown issue which would bring strange error. We now cancel SYSIO method when cpu dead, after all, correctness is more important than power save, and btw new platform use mwait.
======================

Thanks,
Jinsong

Quoted 57 lines · Boris Ostrovsky

# HG changeset patch
# User Boris Ostrovsky <[email protected]> # Date 1330466573 -3600
# Node ID 9e5991ad9c85b5176ce269001e7957e8805dd93c # Parent a7bacdc5449a2f7bb9c35b2a1334b463fe9f29a9
x86: Use deep C states for off-lined CPUs

Currently when a core is taken off-line it is placed in C1 state (unless MONITOR/MWAIT is used). This patch allows a core to go to deeper C states resulting in significantly higher power savings.

diff -r a7bacdc5449a -r 9e5991ad9c85 xen/arch/x86/acpi/cpu_idle.c

xen/arch/x86/acpi/cpu_idle.c +2 -2
@@ -573,10 +573,10 @@ static void acpi_dead_idle(void)
     if ( (cx = &power->states[power->count-1]) == NULL )
         goto default_halt;
 
-    mwait_ptr = (void *)&mwait_wakeup(smp_processor_id());
-
     if ( cx->entry_method == ACPI_CSTATE_EM_FFH )
     {
+        mwait_ptr = (void *)&mwait_wakeup(smp_processor_id());
+
         /*
          * Cache must be flushed as the last operation before

sleeping.
* Otherwise, CPU may still hold dirty data, breaking cache
coherency, @@ -601,6 +601,20 @@ static void acpi_dead_idle(void)

             mb();
             __mwait(cx->address, 0);
         }
xen/arch/x86/acpi/cpu_idle.c +14 -0
+    }
+    else if ( cx->entry_method == ACPI_CSTATE_EM_SYSIO )
+    {
+        /* Avoid references to shared data after the cache flush */
+        u32 address = cx->address;
+        u32 pmtmr_ioport_local = pmtmr_ioport;
+
+        wbinvd();
+
+        while ( 1 )
+        {
+            inb(address);
+            inl(pmtmr_ioport_local);
+        }
     }
 
 default_halt:

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#8 lore raw

As far as I can tell the most relevant change in Linux was this: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commitdiff;h=ea53069231f9317062910d6e772cca4ce93de8c8
and it sounds that it was made mostly because MWAIT-based idle is more efficient on Intel processors. That's not the case on AMD where IO-based idle is preferred (and I am not aware of any issues, at least so far).

I can make the patch to be AMD_specific but since for the most parts the logic is the same as in acpi_idle_do_entry() won't we have to modify that function as well?

-boris

Quoted 87 lines · Jinsong

I don't think we should go back to old SYSIO method, the history here is:

Xen originally has SYSIO method when offline cpu, but at c/s 23022 we cancel it as reason below
======================
x86: Fix cpu offline bug: cancel SYSIO method when play dead

Play dead is a fragile and tricky point of cpu offline logic. For how to play cpu dead, linux kernel changed several times: Very old kernel support 3 ways to play cpu dead: mwait, SYSIO, and halt, just like what cpuidle did when enter C3; Later, it cancel mwait and SYSIO support, only use halt to play dead; Latest linux 2.6.38 add mwait support when cpu dead.

This patch cancel SYSIO method when cpu dead, keep same with latest kernel.

SYSIO is an obsoleted method to enter deep C, with some tricky hardware behavior, and seldom supported in new platform. Xen experiment indicate that when cpu dead, SYSIO method would trigger unknown issue which would bring strange error. We now cancel SYSIO method when cpu dead, after all, correctness is more important than power save, and btw new platform use mwait.
======================

Thanks,
Jinsong

Quoted 57 lines · Boris Ostrovsky

# HG changeset patch
# User Boris Ostrovsky<[email protected]> # Date 1330466573 -3600
# Node ID 9e5991ad9c85b5176ce269001e7957e8805dd93c # Parent a7bacdc5449a2f7bb9c35b2a1334b463fe9f29a9
x86: Use deep C states for off-lined CPUs

Currently when a core is taken off-line it is placed in C1 state (unless MONITOR/MWAIT is used). This patch allows a core to go to deeper C states resulting in significantly higher power savings.

diff -r a7bacdc5449a -r 9e5991ad9c85 xen/arch/x86/acpi/cpu_idle.c

xen/arch/x86/acpi/cpu_idle.c +2 -2
@@ -573,10 +573,10 @@ static void acpi_dead_idle(void)
      if ( (cx =&power->states[power->count-1]) == NULL )
          goto default_halt;
 
-    mwait_ptr = (void *)&mwait_wakeup(smp_processor_id());
-
      if ( cx->entry_method == ACPI_CSTATE_EM_FFH )
      {
+        mwait_ptr = (void *)&mwait_wakeup(smp_processor_id());
+
          /*
           * Cache must be flushed as the last operation before

sleeping.
* Otherwise, CPU may still hold dirty data, breaking cache
coherency, @@ -601,6 +601,20 @@ static void acpi_dead_idle(void)

              mb();
              __mwait(cx->address, 0);
          }
xen/arch/x86/acpi/cpu_idle.c +14 -0
+    }
+    else if ( cx->entry_method == ACPI_CSTATE_EM_SYSIO )
+    {
+        /* Avoid references to shared data after the cache flush */
+        u32 address = cx->address;
+        u32 pmtmr_ioport_local = pmtmr_ioport;
+
+        wbinvd();
+
+        while ( 1 )
+        {
+            inb(address);
+            inl(pmtmr_ioport_local);
+        }
      }
 
  default_halt:

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#9 lore raw
Quoted 11 lines · Boris Ostrovsky

As far as I can tell the most relevant change in Linux was this:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commitdiff;h=ea53069231f9317062910d6e772cca4ce93de8c8
and it sounds that it was made mostly because MWAIT-based idle is more efficient on Intel processors. That's not the case on AMD where IO-based idle is preferred (and I am not aware of any issues, at least so far).

I can make the patch to be AMD_specific but since for the most parts the logic is the same as in acpi_idle_do_entry() won't we have to modify that function as well?

AMD specific approach is OK to me.

Thanks,
Jinsong

Quoted 84 lines · Jinsong
Quoted 82 lines

I don't think we should go back to old SYSIO method, the history here is:

Xen originally has SYSIO method when offline cpu, but at c/s 23022 we cancel it as reason below ====================== x86: Fix cpu offline bug: cancel SYSIO method when play dead

Play dead is a fragile and tricky point of cpu offline logic. For how
to play cpu dead, linux kernel changed several times: Very old kernel support 3 ways to play cpu dead: mwait, SYSIO, and halt, just like what cpuidle did when enter C3; Later, it cancel mwait and SYSIO support, only use halt to play dead; Latest linux 2.6.38 add mwait support when cpu dead.

This patch cancel SYSIO method when cpu dead, keep same with latest kernel.

SYSIO is an obsoleted method to enter deep C, with some tricky hardware behavior, and seldom supported in new platform. Xen experiment indicate that when cpu dead, SYSIO method would trigger unknown issue which would bring strange error. We now cancel SYSIO method when cpu dead, after all, correctness is more important than power save, and btw new platform use mwait.
======================

Thanks,
Jinsong

Quoted 52 lines · Boris Ostrovsky

# HG changeset patch
# User Boris Ostrovsky<[email protected]> # Date 1330466573 -3600
# Node ID 9e5991ad9c85b5176ce269001e7957e8805dd93c # Parent a7bacdc5449a2f7bb9c35b2a1334b463fe9f29a9
x86: Use deep C states for off-lined CPUs

Currently when a core is taken off-line it is placed in C1 state (unless MONITOR/MWAIT is used). This patch allows a core to go to deeper C states resulting in significantly higher power savings.

diff -r a7bacdc5449a -r 9e5991ad9c85 xen/arch/x86/acpi/cpu_idle.c

xen/arch/x86/acpi/cpu_idle.c +1 -1
@@ -573,10 +573,10 @@ static void acpi_dead_idle(void)
      if ( (cx =&power->states[power->count-1]) == NULL )          
 goto default_halt; 
 
-    mwait_ptr = (void *)&mwait_wakeup(smp_processor_id()); -
      if ( cx->entry_method == ACPI_CSTATE_EM_FFH )       {
+        mwait_ptr = (void *)&mwait_wakeup(smp_processor_id()); +
          /*
           * Cache must be flushed as the last operation before

sleeping.
* Otherwise, CPU may still hold dirty data, breaking
cache coherency, @@ -601,6 +601,20 @@ static void

              acpi_dead_idle(void)               mb();
          __mwait(cx->address, 0); }
xen/arch/x86/acpi/cpu_idle.c +13 -0
+    }
+    else if ( cx->entry_method == ACPI_CSTATE_EM_SYSIO ) +    {
+        /* Avoid references to shared data after the cache flush */
+        u32 address = cx->address;
+        u32 pmtmr_ioport_local = pmtmr_ioport;
+
+        wbinvd();
+
+        while ( 1 )
+        {
+            inb(address);
+            inl(pmtmr_ioport_local);
+        }
      }
 
  default_halt:

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#10 lore raw
In reply to Boris Ostrovsky

xen/arch/x86/acpi/cpu_idle.c static void acpi_dead_idle(void) · line 579

Quoted 13 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky
xen/arch/x86/acpi/cpu_idle.c +2 -2
@@ -573,10 +573,10 @@ static void acpi_dead_idle(void)
     if ( (cx = &power->states[power->count-1]) == NULL )
         goto default_halt;
 
-    mwait_ptr = (void *)&mwait_wakeup(smp_processor_id());
-
     if ( cx->entry_method == ACPI_CSTATE_EM_FFH )
     {
+        mwait_ptr = (void *)&mwait_wakeup(smp_processor_id());
+

If you're concerned about the placement of this (the change being unrelated to what your patch is aiming it anyway), then you should
- explain why
- move the declaration of mwait_ptr also into the if() scope

Quoted 11 lines
xen/arch/x86/acpi/cpu_idle.c +4 -0
         /*
          * Cache must be flushed as the last operation before sleeping.
          * Otherwise, CPU may still hold dirty data, breaking cache coherency,
@@ -601,6 +601,20 @@ static void acpi_dead_idle(void)
             mb();
             __mwait(cx->address, 0);
         }
+    } 
+    else if ( cx->entry_method == ACPI_CSTATE_EM_SYSIO )
+    {
+        /* Avoid references to shared data after the cache flush */

xen/arch/x86/acpi/cpu_idle.c static void acpi_dead_idle(void) · line 617

Quoted 10 lines
xen/arch/x86/acpi/cpu_idle.c +10 -0
+        u32 address = cx->address;
+        u32 pmtmr_ioport_local = pmtmr_ioport;
+
+        wbinvd();	
+
+        while ( 1 )
+        {
+            inb(address);
+            inl(pmtmr_ioport_local);
+        }

You will need to eliminate the reservations of the Intel folks for this to be accepted, I'm afraid, or make this AMD specific (provided the issues pointed out by them don't affect AMD systems).

Jan

Quoted 3 lines
xen/arch/x86/acpi/cpu_idle.c +0 -0
     }
 
 default_halt: