Skip to contentSkip to conversation

x86/acpi: Drop sleep_states[] and associated print messages

PATCH In review Andrew Cooper 2 participants 5 messages Sep 2, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 x86/acpi: Drop sleep_states[] and associated print messages

sleep_states[] is a write-only array, and despite the loop logic, the printed message is consistently "ACPI sleep modes: S3". Drop it all.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 xen/arch/x86/acpi/power.c | 15 ---------------
 1 file changed, 15 deletions(-)
xen/arch/x86/acpi/power.c +0 -15
index d83e8cdd52..6ae9e29229 100644
@@ -36,7 +36,6 @@ uint32_t system_reset_counter = 1;
 static char __initdata opt_acpi_sleep[20];
 string_param("acpi_sleep", opt_acpi_sleep);
 
-static u8 sleep_states[ACPI_S_STATE_COUNT];
 static DEFINE_SPINLOCK(pm_lock);
 
 struct acpi_sleep_info acpi_sinfo;
@@ -460,7 +459,6 @@ acpi_status acpi_enter_sleep_state(u8 sleep_state)
 
 static int __init acpi_sleep_init(void)
 {
-    int i;
     char *p = opt_acpi_sleep;
 
     while ( (p != NULL) && (*p != '\0') )
@@ -474,19 +472,6 @@ static int __init acpi_sleep_init(void)
             p += strspn(p, ", \t");
     }
 
-    printk(XENLOG_INFO "ACPI sleep modes:");
-    for ( i = 0; i < ACPI_S_STATE_COUNT; i++ )
-    {
-        if ( i == ACPI_STATE_S3 )
-        {
-            sleep_states[i] = 1;
-            printk(" S%d", i);
-        }
-        else
-            sleep_states[i] = 0;
-    }
-    printk("\n");
-
     return 0;
 }
 __initcall(acpi_sleep_init);
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH 2/2 x86/apci: Adjust command line parsing for "acpi_sleep"

Perform parsing in a custom_param, rather than stashing the content in a string and parsing in an initcall. Adjust the parsing to conform to current standards.

No practical change.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>

The reason that flags is pulled into a local variable is that the codegen for acpi_video_flags is attrocious, 260 bytes!, and doubles up when used twice.

---
 xen/arch/x86/acpi/power.c | 47 ++++++++++++++++++++++++++---------------------
 1 file changed, 26 insertions(+), 21 deletions(-)
xen/arch/x86/acpi/power.c +26 -21
index 6ae9e29229..1ce5de221e 100644
@@ -33,8 +33,32 @@
 
 uint32_t system_reset_counter = 1;
 
-static char __initdata opt_acpi_sleep[20];
-string_param("acpi_sleep", opt_acpi_sleep);
+static int parse_acpi_sleep(const char *s)
+{
+    const char *ss;
+    unsigned int flag = 0;
+    int rc = 0;
+
+    do {
+        ss = strchr(s, ',');
+        if ( !ss )
+            ss = strchr(s, '\0');
+
+        if ( !cmdline_strcmp(s, "s3_bios") )
+            flag |= 1;
+        else if ( !cmdline_strcmp(s, "s3_mode") )
+            flag |= 2;
+        else
+            rc = -EINVAL;
+
+        s = ss + 1;
+    } while ( *ss );
+
+    acpi_video_flags = flag;
+
+    return 0;
+}
+custom_runtime_param("acpi_sleep", parse_acpi_sleep);
 
 static DEFINE_SPINLOCK(pm_lock);
 
@@ -456,22 +480,3 @@ acpi_status acpi_enter_sleep_state(u8 sleep_state)
 
     return_ACPI_STATUS(AE_OK);
 }
-
-static int __init acpi_sleep_init(void)
-{
-    char *p = opt_acpi_sleep;
-
-    while ( (p != NULL) && (*p != '\0') )
-    {
-        if ( !strncmp(p, "s3_bios", 7) )
-            acpi_video_flags |= 1;
-        if ( !strncmp(p, "s3_mode", 7) )
-            acpi_video_flags |= 2;
-        p = strchr(p, ',');
-        if ( p != NULL )
-            p += strspn(p, ", \t");
-    }
-
-    return 0;
-}
-__initcall(acpi_sleep_init);
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw

PATCH 2/2 x86/apci: Adjust command line parsing for "acpi_sleep"

In reply to Andrew Cooper

Perform parsing in a custom_param, rather than stashing the content in a string and parsing in an initcall. Adjust the parsing to conform to current standards.

No practical change.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>

The reason that flags is pulled into a local variable is that the codegen for acpi_video_flags is attrocious, 260 bytes!, and doubles up when used twice.

---
 xen/arch/x86/acpi/power.c | 47 ++++++++++++++++++++++++++---------------------
 1 file changed, 26 insertions(+), 21 deletions(-)
xen/arch/x86/acpi/power.c +26 -21
index 6ae9e29229..414bda205d 100644
@@ -33,8 +33,32 @@
 
 uint32_t system_reset_counter = 1;
 
-static char __initdata opt_acpi_sleep[20];
-string_param("acpi_sleep", opt_acpi_sleep);
+static int __init parse_acpi_sleep(const char *s)
+{
+    const char *ss;
+    unsigned int flag = 0;
+    int rc = 0;
+
+    do {
+        ss = strchr(s, ',');
+        if ( !ss )
+            ss = strchr(s, '\0');
+
+        if ( !cmdline_strcmp(s, "s3_bios") )
+            flag |= 1;
+        else if ( !cmdline_strcmp(s, "s3_mode") )
+            flag |= 2;
+        else
+            rc = -EINVAL;
+
+        s = ss + 1;
+    } while ( *ss );
+
+    acpi_video_flags = flag;
+
+    return 0;
+}
+custom_param("acpi_sleep", parse_acpi_sleep);
 
 static DEFINE_SPINLOCK(pm_lock);
 
@@ -456,22 +480,3 @@ acpi_status acpi_enter_sleep_state(u8 sleep_state)
 
     return_ACPI_STATUS(AE_OK);
 }
-
-static int __init acpi_sleep_init(void)
-{
-    char *p = opt_acpi_sleep;
-
-    while ( (p != NULL) && (*p != '\0') )
-    {
-        if ( !strncmp(p, "s3_bios", 7) )
-            acpi_video_flags |= 1;
-        if ( !strncmp(p, "s3_mode", 7) )
-            acpi_video_flags |= 2;
-        p = strchr(p, ',');
-        if ( p != NULL )
-            p += strspn(p, ", \t");
-    }
-
-    return 0;
-}
-__initcall(acpi_sleep_init);
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 2/2
#3 lore raw

Re: [Xen-devel] [PATCH 2/2] x86/apci: Adjust command line parsing for "acpi_sleep"

Quoted 13 lines · Andrew Cooper
xen/arch/x86/acpi/power.c +5 -2
@@ -33,8 +33,32 @@
 
 uint32_t system_reset_counter = 1;
 
-static char __initdata opt_acpi_sleep[20];
-string_param("acpi_sleep", opt_acpi_sleep);
+static int __init parse_acpi_sleep(const char *s)
+{
+    const char *ss;
+    unsigned int flag = 0;
+    int rc = 0;

xen/arch/x86/acpi/power.c line 50

Quoted 10 lines
xen/arch/x86/acpi/power.c +10 -0
+
+    do {
+        ss = strchr(s, ',');
+        if ( !ss )
+            ss = strchr(s, '\0');
+
+        if ( !cmdline_strcmp(s, "s3_bios") )
+            flag |= 1;
+        else if ( !cmdline_strcmp(s, "s3_mode") )
+            flag |= 2;

You didn't fancy using parse_boolean() here (to also allow specifying the negative forms), did you?

xen/arch/x86/acpi/power.c line 57

Quoted 7 lines
xen/arch/x86/acpi/power.c +7 -0
+        else
+            rc = -EINVAL;
+
+        s = ss + 1;
+    } while ( *ss );
+
+    acpi_video_flags = flag;

This wants to be |= , such that "acpi_sleep=s3_bios acpi_sleep=s3_mode" has the same effect as "acpi_sleep=s3_mode,s3_bios". With at least this adjustment

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by on v1 1/2
#4 lore raw
In reply to Andrew Cooper
Quoted 4 lines · Andrew Cooper

sleep_states[] is a write-only array, and despite the loop logic, the printed message is consistently "ACPI sleep modes: S3". Drop it all.

Albeit FTR I'm not convinced removing the log message is really a good idea. But we can surely re-instate it if we ever mean to support things other than S3. The only concern would be whether, as iirc was suggested somewhere, we may want to allow suppressing use of S3, in which case the log message might indeed be helpful even without us supporting other sleep states.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel