Skip to contentSkip to conversation

AMD, powernow: Update P-state directly when _PSD's CoordType is DOMAIN_COORD_TYPE_HW_ALL

PATCH In review Boris Ostrovsky 2 participants 6 messages Aug 16, 2012 – Aug 17, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 AMD, powernow: Update P-state directly when _PSD's CoordType is DOMAIN_COORD_TYPE_HW_ALL

# HG changeset patch
# User Boris Ostrovsky <[email protected]>
# Date 1345135101 -7200
# Node ID 85190245a94d9945b7656c971ba36f7d1eff5c19
# Parent 6d56e31fe1e1dc793379d662a36ff1731760eb0c
AMD, powernow: Update P-state directly when _PSD's CoordType is DOMAIN_COORD_TYPE_HW_ALL

When _PSD's CoordType is DOMAIN_COORD_TYPE_HW_ALL (i.e. shared_type is CPUFREQ_SHARED_TYPE_HW) which most often is the case on servers, there is no reason to go into on_selected_cpus() code, we call call transition_pstate() directly.

xen/arch/x86/acpi/cpufreq/powernow.c +24 -37
diff -r 6d56e31fe1e1 -r 85190245a94d xen/arch/x86/acpi/cpufreq/powernow.c
@@ -56,20 +56,9 @@
 
 static struct cpufreq_driver powernow_cpufreq_driver;
 
-struct drv_cmd {
-    unsigned int type;
-    const cpumask_t *mask;
-    u32 val;
-    int turbo;
-};
-
-static void transition_pstate(void *drvcmd)
+static void transition_pstate(void *pstate)
 {
-    struct drv_cmd *cmd;
-    cmd = (struct drv_cmd *) drvcmd;
-
-
-    wrmsrl(MSR_PSTATE_CTRL, cmd->val);
+    wrmsrl(MSR_PSTATE_CTRL, *(int *)pstate);
 }
 
 static void update_cpb(void *data)
@@ -106,13 +95,11 @@ static int powernow_cpufreq_target(struc
 {
     struct acpi_cpufreq_data *data = cpufreq_drv_data[policy->cpu];
     struct processor_performance *perf;
-    struct cpufreq_freqs freqs;
     cpumask_t online_policy_cpus;
-    struct drv_cmd cmd;
-    unsigned int next_state = 0; /* Index into freq_table */
-    unsigned int next_perf_state = 0; /* Index into perf table */
-    int result = 0;
-    int j = 0;
+    unsigned int next_state; /* Index into freq_table */
+    unsigned int next_perf_state; /* Index into perf table */
+    int result;
+    int j;
 
     if (unlikely(data == NULL ||
         data->acpi_data == NULL || data->freq_table == NULL)) {
@@ -125,9 +112,7 @@ static int powernow_cpufreq_target(struc
                                             target_freq,
                                             relation, &next_state);
     if (unlikely(result))
-        return -ENODEV;
-
-    cpumask_and(&online_policy_cpus, policy->cpus, &cpu_online_map);
+        return result;
 
     next_perf_state = data->freq_table[next_state].index;
     if (perf->state == next_perf_state) {
@@ -137,26 +122,28 @@ static int powernow_cpufreq_target(struc
             return 0;
     }
 
-    if (policy->shared_type != CPUFREQ_SHARED_TYPE_ANY)
-        cmd.mask = &online_policy_cpus;
-    else
-        cmd.mask = cpumask_of(policy->cpu);
+    if (policy->shared_type == CPUFREQ_SHARED_TYPE_HW &&
+        likely(policy->cpu == smp_processor_id())) {
+        transition_pstate(&next_perf_state);
+        cpufreq_statistic_update(policy->cpu, perf->state, next_perf_state);
+    } else {
+        cpumask_and(&online_policy_cpus, policy->cpus, &cpu_online_map);
 
-    freqs.old = perf->states[perf->state].core_frequency * 1000;
-    freqs.new = data->freq_table[next_state].frequency;
+        if (policy->shared_type == CPUFREQ_SHARED_TYPE_ALL ||
+            unlikely(policy->cpu != smp_processor_id()))
+            on_selected_cpus(&online_policy_cpus, transition_pstate,
+                             &next_perf_state, 1);
+        else
+            transition_pstate(&next_perf_state);
 
-    cmd.val = next_perf_state;
-    cmd.turbo = policy->turbo;
-
-    on_selected_cpus(cmd.mask, transition_pstate, &cmd, 1);
-
-    for_each_cpu(j, &online_policy_cpus)
-        cpufreq_statistic_update(j, perf->state, next_perf_state);
+        for_each_cpu(j, &online_policy_cpus)
+            cpufreq_statistic_update(j, perf->state, next_perf_state);
+    }    
 
     perf->state = next_perf_state;
-    policy->cur = freqs.new;
+    policy->cur = data->freq_table[next_state].frequency;
 
-    return result;
+    return 0;
 }
 
 static int powernow_cpufreq_verify(struct cpufreq_policy *policy)
#1 lore raw
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky

AMD, powernow: Update P-state directly when _PSD's CoordType is DOMAIN_COORD_TYPE_HW_ALL

When _PSD's CoordType is DOMAIN_COORD_TYPE_HW_ALL (i.e. shared_type is CPUFREQ_SHARED_TYPE_HW) which most often is the case on servers, there is no reason to go into on_selected_cpus() code, we call call transition_pstate() directly.

Looks good to me in general (one minor comment below, but no need to resubmit just because of this). But it's not really clear to me whether this actually improves anything (knowing of which is needed to decide whether to put this in now or after 4.2).

Quoted 12 lines
xen/arch/x86/acpi/cpufreq/powernow.c +0 -6
@@ -56,20 +56,9 @@
 
 static struct cpufreq_driver powernow_cpufreq_driver;
 
-struct drv_cmd {
-    unsigned int type;
-    const cpumask_t *mask;
-    u32 val;
-    int turbo;
-};

xen/arch/x86/acpi/cpufreq/powernow.c line 61

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/powernow.c +2 -7
-
-static void transition_pstate(void *drvcmd)
+static void transition_pstate(void *pstate)
 {
-    struct drv_cmd *cmd;
-    cmd = (struct drv_cmd *) drvcmd;
-
-
-    wrmsrl(MSR_PSTATE_CTRL, cmd->val);
+    wrmsrl(MSR_PSTATE_CTRL, *(int *)pstate);

The variable a pointer to which gets passed in for this function is "unsigned int", so you surely would need to cast to that type instead of plain "int".

Jan

Quoted 82 lines
xen/arch/x86/acpi/cpufreq/powernow.c +22 -24
 }
 
 static void update_cpb(void *data)
@@ -106,13 +95,11 @@ static int powernow_cpufreq_target(struc
 {
     struct acpi_cpufreq_data *data = cpufreq_drv_data[policy->cpu];
     struct processor_performance *perf;
-    struct cpufreq_freqs freqs;
     cpumask_t online_policy_cpus;
-    struct drv_cmd cmd;
-    unsigned int next_state = 0; /* Index into freq_table */
-    unsigned int next_perf_state = 0; /* Index into perf table */
-    int result = 0;
-    int j = 0;
+    unsigned int next_state; /* Index into freq_table */
+    unsigned int next_perf_state; /* Index into perf table */
+    int result;
+    int j;
 
     if (unlikely(data == NULL ||
         data->acpi_data == NULL || data->freq_table == NULL)) {
@@ -125,9 +112,7 @@ static int powernow_cpufreq_target(struc
                                             target_freq,
                                             relation, &next_state);
     if (unlikely(result))
-        return -ENODEV;
-
-    cpumask_and(&online_policy_cpus, policy->cpus, &cpu_online_map);
+        return result;
 
     next_perf_state = data->freq_table[next_state].index;
     if (perf->state == next_perf_state) {
@@ -137,26 +122,28 @@ static int powernow_cpufreq_target(struc
             return 0;
     }
 
-    if (policy->shared_type != CPUFREQ_SHARED_TYPE_ANY)
-        cmd.mask = &online_policy_cpus;
-    else
-        cmd.mask = cpumask_of(policy->cpu);
+    if (policy->shared_type == CPUFREQ_SHARED_TYPE_HW &&
+        likely(policy->cpu == smp_processor_id())) {
+        transition_pstate(&next_perf_state);
+        cpufreq_statistic_update(policy->cpu, perf->state, next_perf_state);
+    } else {
+        cpumask_and(&online_policy_cpus, policy->cpus, &cpu_online_map);
 
-    freqs.old = perf->states[perf->state].core_frequency * 1000;
-    freqs.new = data->freq_table[next_state].frequency;
+        if (policy->shared_type == CPUFREQ_SHARED_TYPE_ALL ||
+            unlikely(policy->cpu != smp_processor_id()))
+            on_selected_cpus(&online_policy_cpus, transition_pstate,
+                             &next_perf_state, 1);
+        else
+            transition_pstate(&next_perf_state);
 
-    cmd.val = next_perf_state;
-    cmd.turbo = policy->turbo;
-
-    on_selected_cpus(cmd.mask, transition_pstate, &cmd, 1);
-
-    for_each_cpu(j, &online_policy_cpus)
-        cpufreq_statistic_update(j, perf->state, next_perf_state);
+        for_each_cpu(j, &online_policy_cpus)
+            cpufreq_statistic_update(j, perf->state, next_perf_state);
+    }    
 
     perf->state = next_perf_state;
-    policy->cur = freqs.new;
+    policy->cur = data->freq_table[next_state].frequency;
 
-    return result;
+    return 0;
 }
 
 static int powernow_cpufreq_verify(struct cpufreq_policy *policy)

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

#2 lore raw
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky

AMD, powernow: Update P-state directly when _PSD's CoordType is DOMAIN_COORD_TYPE_HW_ALL

When _PSD's CoordType is DOMAIN_COORD_TYPE_HW_ALL (i.e. shared_type is CPUFREQ_SHARED_TYPE_HW) which most often is the case on servers, there is no reason to go into on_selected_cpus() code, we call call transition_pstate() directly.

Quoted 6 lines
Quoted 1 line

Looks good to me in general (one minor comment below, but no need to resubmit just because of this). But it's not really clear to me whether this actually improves anything (knowing of which is needed to decide whether to put this in now or after 4.2).

I didn't see any noticeable improvement but then I may not have run the right tests.

I imagine this may be helpful, for example, in webserver-type environments with frequent P-state transitions when new connections are requested and short-lived threads/processes are created. But I haven't been able to set this up to observe this.

I think post-4.2 is fine.

-boris

Quoted 115 lines
Quoted 13 lines
xen/arch/x86/acpi/cpufreq/powernow.c +0 -6
@@ -56,20 +56,9 @@
 
  static struct cpufreq_driver powernow_cpufreq_driver;
 
-struct drv_cmd {
-    unsigned int type;
-    const cpumask_t *mask;
-    u32 val;
-    int turbo;
-};

xen/arch/x86/acpi/cpufreq/powernow.c line 61

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/powernow.c +2 -7
-
-static void transition_pstate(void *drvcmd)
+static void transition_pstate(void *pstate)
  {
-    struct drv_cmd *cmd;
-    cmd = (struct drv_cmd *) drvcmd;
-
-
-    wrmsrl(MSR_PSTATE_CTRL, cmd->val);
+    wrmsrl(MSR_PSTATE_CTRL, *(int *)pstate);

The variable a pointer to which gets passed in for this function is "unsigned int", so you surely would need to cast to that type instead of plain "int".

Jan

Quoted 82 lines
xen/arch/x86/acpi/cpufreq/powernow.c +22 -24
  }
 
  static void update_cpb(void *data)
@@ -106,13 +95,11 @@ static int powernow_cpufreq_target(struc
  {
      struct acpi_cpufreq_data *data = cpufreq_drv_data[policy->cpu];
      struct processor_performance *perf;
-    struct cpufreq_freqs freqs;
      cpumask_t online_policy_cpus;
-    struct drv_cmd cmd;
-    unsigned int next_state = 0; /* Index into freq_table */
-    unsigned int next_perf_state = 0; /* Index into perf table */
-    int result = 0;
-    int j = 0;
+    unsigned int next_state; /* Index into freq_table */
+    unsigned int next_perf_state; /* Index into perf table */
+    int result;
+    int j;
 
      if (unlikely(data == NULL ||
          data->acpi_data == NULL || data->freq_table == NULL)) {
@@ -125,9 +112,7 @@ static int powernow_cpufreq_target(struc
                                              target_freq,
                                              relation, &next_state);
      if (unlikely(result))
-        return -ENODEV;
-
-    cpumask_and(&online_policy_cpus, policy->cpus, &cpu_online_map);
+        return result;
 
      next_perf_state = data->freq_table[next_state].index;
      if (perf->state == next_perf_state) {
@@ -137,26 +122,28 @@ static int powernow_cpufreq_target(struc
              return 0;
      }
 
-    if (policy->shared_type != CPUFREQ_SHARED_TYPE_ANY)
-        cmd.mask = &online_policy_cpus;
-    else
-        cmd.mask = cpumask_of(policy->cpu);
+    if (policy->shared_type == CPUFREQ_SHARED_TYPE_HW &&
+        likely(policy->cpu == smp_processor_id())) {
+        transition_pstate(&next_perf_state);
+        cpufreq_statistic_update(policy->cpu, perf->state, next_perf_state);
+    } else {
+        cpumask_and(&online_policy_cpus, policy->cpus, &cpu_online_map);
 
-    freqs.old = perf->states[perf->state].core_frequency * 1000;
-    freqs.new = data->freq_table[next_state].frequency;
+        if (policy->shared_type == CPUFREQ_SHARED_TYPE_ALL ||
+            unlikely(policy->cpu != smp_processor_id()))
+            on_selected_cpus(&online_policy_cpus, transition_pstate,
+                             &next_perf_state, 1);
+        else
+            transition_pstate(&next_perf_state);
 
-    cmd.val = next_perf_state;
-    cmd.turbo = policy->turbo;
-
-    on_selected_cpus(cmd.mask, transition_pstate, &cmd, 1);
-
-    for_each_cpu(j, &online_policy_cpus)
-        cpufreq_statistic_update(j, perf->state, next_perf_state);
+        for_each_cpu(j, &online_policy_cpus)
+            cpufreq_statistic_update(j, perf->state, next_perf_state);
+    }
 
      perf->state = next_perf_state;
-    policy->cur = freqs.new;
+    policy->cur = data->freq_table[next_state].frequency;
 
-    return result;
+    return 0;
  }
 
  static int powernow_cpufreq_verify(struct cpufreq_policy *policy)

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

#3 lore raw
In reply to Boris Ostrovsky

xen/arch/x86/acpi/cpufreq/powernow.c static int powernow_cpufreq_target(struc · line 128

Quoted 13 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky
xen/arch/x86/acpi/cpufreq/powernow.c +4 -4
@@ -137,26 +122,28 @@ static int powernow_cpufreq_target(struc
             return 0;
     }
 
-    if (policy->shared_type != CPUFREQ_SHARED_TYPE_ANY)
-        cmd.mask = &online_policy_cpus;
-    else
-        cmd.mask = cpumask_of(policy->cpu);
+    if (policy->shared_type == CPUFREQ_SHARED_TYPE_HW &&
+        likely(policy->cpu == smp_processor_id())) {
+        transition_pstate(&next_perf_state);
+        cpufreq_statistic_update(policy->cpu, perf->state, next_perf_state);

Actually - is this enough? Doesn't this also need to be done based on policy->cpus?

Jan

Quoted 38 lines
xen/arch/x86/acpi/cpufreq/powernow.c +13 -11
+    } else {
+        cpumask_and(&online_policy_cpus, policy->cpus, &cpu_online_map);
 
-    freqs.old = perf->states[perf->state].core_frequency * 1000;
-    freqs.new = data->freq_table[next_state].frequency;
+        if (policy->shared_type == CPUFREQ_SHARED_TYPE_ALL ||
+            unlikely(policy->cpu != smp_processor_id()))
+            on_selected_cpus(&online_policy_cpus, transition_pstate,
+                             &next_perf_state, 1);
+        else
+            transition_pstate(&next_perf_state);
 
-    cmd.val = next_perf_state;
-    cmd.turbo = policy->turbo;
-
-    on_selected_cpus(cmd.mask, transition_pstate, &cmd, 1);
-
-    for_each_cpu(j, &online_policy_cpus)
-        cpufreq_statistic_update(j, perf->state, next_perf_state);
+        for_each_cpu(j, &online_policy_cpus)
+            cpufreq_statistic_update(j, perf->state, next_perf_state);
+    }    
 
     perf->state = next_perf_state;
-    policy->cur = freqs.new;
+    policy->cur = data->freq_table[next_state].frequency;
 
-    return result;
+    return 0;
 }
 
 static int powernow_cpufreq_verify(struct cpufreq_policy *policy)

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

#4 lore raw
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky
xen/arch/x86/acpi/cpufreq/powernow.c +0 -0
@@ -137,26 +122,28 @@ static int powernow_cpufreq_target(struc
              return 0;
      }
 
Quoted 11 lines

xen/arch/x86/acpi/cpufreq/powernow.c static int powernow_cpufreq_target(struc · line 128

Quoted 8 lines
xen/arch/x86/acpi/cpufreq/powernow.c +4 -4
-    if (policy->shared_type != CPUFREQ_SHARED_TYPE_ANY)
-        cmd.mask = &online_policy_cpus;
-    else
-        cmd.mask = cpumask_of(policy->cpu);
+    if (policy->shared_type == CPUFREQ_SHARED_TYPE_HW &&
+        likely(policy->cpu == smp_processor_id())) {
+        transition_pstate(&next_perf_state);
+        cpufreq_statistic_update(policy->cpu, perf->state, next_perf_state);

Actually - is this enough? Doesn't this also need to be done based on policy->cpus?

With HW-coordinated transitions there is a policy structure per CPU so policy->cpus is always 1 and policy->cpu is the same as policy->cpus. You can see this in cpufreq_add_cpu(), when hw_all is set.

(This is consistent with ACPI spec:
When hardware coordinates transitions, OSPM continues to initiate state transitions as it would if there were no dependencies.
)

-boris

Quoted 45 lines

Jan

Quoted 38 lines
xen/arch/x86/acpi/cpufreq/powernow.c +13 -11
+    } else {
+        cpumask_and(&online_policy_cpus, policy->cpus, &cpu_online_map);
 
-    freqs.old = perf->states[perf->state].core_frequency * 1000;
-    freqs.new = data->freq_table[next_state].frequency;
+        if (policy->shared_type == CPUFREQ_SHARED_TYPE_ALL ||
+            unlikely(policy->cpu != smp_processor_id()))
+            on_selected_cpus(&online_policy_cpus, transition_pstate,
+                             &next_perf_state, 1);
+        else
+            transition_pstate(&next_perf_state);
 
-    cmd.val = next_perf_state;
-    cmd.turbo = policy->turbo;
-
-    on_selected_cpus(cmd.mask, transition_pstate, &cmd, 1);
-
-    for_each_cpu(j, &online_policy_cpus)
-        cpufreq_statistic_update(j, perf->state, next_perf_state);
+        for_each_cpu(j, &online_policy_cpus)
+            cpufreq_statistic_update(j, perf->state, next_perf_state);
+    }
 
      perf->state = next_perf_state;
-    policy->cur = freqs.new;
+    policy->cur = data->freq_table[next_state].frequency;
 
-    return result;
+    return 0;
  }
 
  static int powernow_cpufreq_verify(struct cpufreq_policy *policy)

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

#5 lore raw
Quoted 23 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky
xen/arch/x86/acpi/cpufreq/powernow.c +0 -0
@@ -137,26 +122,28 @@ static int powernow_cpufreq_target(struc
              return 0;
      }
 
Quoted 11 lines

xen/arch/x86/acpi/cpufreq/powernow.c static int powernow_cpufreq_target(struc · line 128

Quoted 8 lines
xen/arch/x86/acpi/cpufreq/powernow.c +4 -4
-    if (policy->shared_type != CPUFREQ_SHARED_TYPE_ANY)
-        cmd.mask = &online_policy_cpus;
-    else
-        cmd.mask = cpumask_of(policy->cpu);
+    if (policy->shared_type == CPUFREQ_SHARED_TYPE_HW &&
+        likely(policy->cpu == smp_processor_id())) {
+        transition_pstate(&next_perf_state);
+        cpufreq_statistic_update(policy->cpu, perf->state, next_perf_state);

Actually - is this enough? Doesn't this also need to be done based on policy->cpus?

With HW-coordinated transitions there is a policy structure per CPU so policy->cpus is always 1 and policy->cpu is the same as policy->cpus. You can see this in cpufreq_add_cpu(), when hw_all is set.

Quoted 5 lines

(This is consistent with ACPI spec:
When hardware coordinates transitions, OSPM continues to initiate state transitions as it would if there were no dependencies.
)

Ah, okay, I didn't recall that (which means in this case the stats simply can't be right, as the hardware may do as it pleases).

Jan