]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
Merge branch 'turbostat' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 1 Mar 2017 22:34:38 +0000 (23:34 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 1 Mar 2017 22:34:38 +0000 (23:34 +0100)
Pull changes related to turbostat for v4.11 from Len Brown.

* 'turbostat' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux: (44 commits)
  tools/power turbostat: version 17.02.24
  tools/power turbostat: bugfix: --add u32 was printed as u64
  tools/power turbostat: show error on exec
  tools/power turbostat: dump p-state software config
  tools/power turbostat: show package number, even without --debug
  tools/power turbostat: support "--hide C1" etc.
  tools/power turbostat: move --Package and --processor into the --cpu option
  tools/power turbostat: turbostat.8 update
  tools/power turbostat: update --list feature
  tools/power turbostat: use wide columns to display large numbers
  tools/power turbostat: Add --list option to show available header names
  tools/power turbostat: fix zero IRQ count shown in one-shot command mode
  tools/power turbostat: add --cpu parameter
  tools/power turbostat: print sysfs C-state stats
  tools/power turbostat: extend --add option to accept /sys path
  tools/power turbostat: skip unused counters on BDX
  tools/power turbostat: fix decoding for GLM, DNV, SKX turbo-ratio limits
  tools/power turbostat: skip unused counters on SKX
  tools/power turbostat: Denverton: use HW CC1 counter, skip C3, C7
  tools/power turbostat: initial Gemini Lake SOC support
  ...

1  2 
arch/x86/include/asm/msr-index.h
drivers/cpufreq/intel_pstate.c

index 00293a94ffaf5a68023022eb6c0b74ba5bac62ef,312fb7e14cdd98a1a3b551c4af609d23652ba459..d8b5f8ab8ef9e79fb76586bc3ca0f7f27325123e
@@@ -46,7 -46,7 +46,7 @@@
  #define MSR_FSB_FREQ                  0x000000cd
  #define MSR_PLATFORM_INFO             0x000000ce
  
- #define MSR_NHM_SNB_PKG_CST_CFG_CTL   0x000000e2
+ #define MSR_PKG_CST_CONFIG_CONTROL    0x000000e2
  #define NHM_C3_AUTO_DEMOTE            (1UL << 25)
  #define NHM_C1_AUTO_DEMOTE            (1UL << 26)
  #define ATM_LNC_C6_AUTO_DEMOTE                (1UL << 25)
  /* C-state Residency Counters */
  #define MSR_PKG_C3_RESIDENCY          0x000003f8
  #define MSR_PKG_C6_RESIDENCY          0x000003f9
+ #define MSR_ATOM_PKG_C6_RESIDENCY     0x000003fa
  #define MSR_PKG_C7_RESIDENCY          0x000003fa
  #define MSR_CORE_C3_RESIDENCY         0x000003fc
  #define MSR_CORE_C6_RESIDENCY         0x000003fd
  #define MSR_PKG_BOTH_CORE_GFXE_C0_RES 0x0000065B
  
  #define MSR_CORE_C1_RES                       0x00000660
+ #define MSR_MODULE_C6_RES_MS          0x00000664
  
  #define MSR_CC6_DEMOTION_POLICY_CONFIG        0x00000668
  #define MSR_MC6_DEMOTION_POLICY_CONFIG        0x00000669
  
+ #define MSR_ATOM_CORE_RATIOS          0x0000066a
+ #define MSR_ATOM_CORE_VIDS            0x0000066b
+ #define MSR_ATOM_CORE_TURBO_RATIOS    0x0000066c
+ #define MSR_ATOM_CORE_TURBO_VIDS      0x0000066d
  #define MSR_CORE_PERF_LIMIT_REASONS   0x00000690
  #define MSR_GFX_PERF_LIMIT_REASONS    0x000006B0
  #define MSR_RING_PERF_LIMIT_REASONS   0x000006B1
  
  #define MSR_IA32_TEMPERATURE_TARGET   0x000001a2
  
+ #define MSR_MISC_FEATURE_CONTROL      0x000001a4
  #define MSR_MISC_PWR_MGMT             0x000001aa
  
  #define MSR_IA32_ENERGY_PERF_BIAS     0x000001b0
  #define MSR_IA32_MISC_ENABLE_IP_PREF_DISABLE_BIT      39
  #define MSR_IA32_MISC_ENABLE_IP_PREF_DISABLE          (1ULL << MSR_IA32_MISC_ENABLE_IP_PREF_DISABLE_BIT)
  
 +/* MISC_FEATURE_ENABLES non-architectural features */
 +#define MSR_MISC_FEATURE_ENABLES      0x00000140
 +
 +#define MSR_MISC_FEATURE_ENABLES_RING3MWAIT_BIT               1
 +
  #define MSR_IA32_TSC_DEADLINE         0x000006E0
  
  /* P4/Xeon+ specific */
index eb0f7fb716858992f00bb4a02285b3d0189b1f07,6e68b556305a681cc9788dfcd14efce83d0c15e3..676a92413e6830b329b1837d9a8d06736ddbabbb
  
  #define INTEL_CPUFREQ_TRANSITION_LATENCY      20000
  
- #define ATOM_RATIOS           0x66a
- #define ATOM_VIDS             0x66b
- #define ATOM_TURBO_RATIOS     0x66c
- #define ATOM_TURBO_VIDS               0x66d
  #ifdef CONFIG_ACPI
  #include <acpi/processor.h>
  #include <acpi/cppc_acpi.h>
@@@ -358,8 -353,6 +353,8 @@@ static struct pstate_funcs pstate_func
  static int hwp_active __read_mostly;
  static bool per_cpu_limits __read_mostly;
  
 +static bool driver_registered __read_mostly;
 +
  #ifdef CONFIG_ACPI
  static bool acpi_ppc;
  #endif
@@@ -396,7 -389,6 +391,7 @@@ static struct perf_limits *limits = &pe
  static struct perf_limits *limits = &powersave_limits;
  #endif
  
 +static DEFINE_MUTEX(intel_pstate_driver_lock);
  static DEFINE_MUTEX(intel_pstate_limits_lock);
  
  #ifdef CONFIG_ACPI
@@@ -541,6 -533,7 +536,6 @@@ static void intel_pstate_exit_perf_limi
  
        acpi_processor_unregister_performance(policy->cpu);
  }
 -
  #else
  static inline void intel_pstate_init_acpi_perf_limits(struct cpufreq_policy *policy)
  {
@@@ -875,10 -868,7 +870,10 @@@ static void intel_pstate_hwp_set(struc
  
                rdmsrl_on_cpu(cpu, MSR_HWP_CAPABILITIES, &cap);
                hw_min = HWP_LOWEST_PERF(cap);
 -              hw_max = HWP_HIGHEST_PERF(cap);
 +              if (limits->no_turbo)
 +                      hw_max = HWP_GUARANTEED_PERF(cap);
 +              else
 +                      hw_max = HWP_HIGHEST_PERF(cap);
                range = hw_max - hw_min;
  
                max_perf_pct = perf_limits->max_perf_pct;
  
                adj_range = max_perf_pct * range / 100;
                max = hw_min + adj_range;
 -              if (limits->no_turbo) {
 -                      hw_max = HWP_GUARANTEED_PERF(cap);
 -                      if (hw_max < max)
 -                              max = hw_max;
 -              }
  
                value &= ~HWP_MAX_PERF(~0L);
                value |= HWP_MAX_PERF(max);
@@@ -1007,57 -1002,35 +1002,57 @@@ static int pid_param_get(void *data, u6
  }
  DEFINE_SIMPLE_ATTRIBUTE(fops_pid_param, pid_param_get, pid_param_set, "%llu\n");
  
 +static struct dentry *debugfs_parent;
 +
  struct pid_param {
        char *name;
        void *value;
 +      struct dentry *dentry;
  };
  
  static struct pid_param pid_files[] = {
 -      {"sample_rate_ms", &pid_params.sample_rate_ms},
 -      {"d_gain_pct", &pid_params.d_gain_pct},
 -      {"i_gain_pct", &pid_params.i_gain_pct},
 -      {"deadband", &pid_params.deadband},
 -      {"setpoint", &pid_params.setpoint},
 -      {"p_gain_pct", &pid_params.p_gain_pct},
 -      {NULL, NULL}
 +      {"sample_rate_ms", &pid_params.sample_rate_ms},
 +      {"d_gain_pct", &pid_params.d_gain_pct},
 +      {"i_gain_pct", &pid_params.i_gain_pct},
 +      {"deadband", &pid_params.deadband},
 +      {"setpoint", &pid_params.setpoint},
 +      {"p_gain_pct", &pid_params.p_gain_pct},
 +      {NULL, NULL}
  };
  
 -static void __init intel_pstate_debug_expose_params(void)
 +static void intel_pstate_debug_expose_params(void)
  {
 -      struct dentry *debugfs_parent;
 -      int i = 0;
 +      int i;
  
        debugfs_parent = debugfs_create_dir("pstate_snb", NULL);
        if (IS_ERR_OR_NULL(debugfs_parent))
                return;
 -      while (pid_files[i].name) {
 -              debugfs_create_file(pid_files[i].name, 0660,
 -                                  debugfs_parent, pid_files[i].value,
 -                                  &fops_pid_param);
 -              i++;
 +
 +      for (i = 0; pid_files[i].name; i++) {
 +              struct dentry *dentry;
 +
 +              dentry = debugfs_create_file(pid_files[i].name, 0660,
 +                                           debugfs_parent, pid_files[i].value,
 +                                           &fops_pid_param);
 +              if (!IS_ERR(dentry))
 +                      pid_files[i].dentry = dentry;
 +      }
 +}
 +
 +static void intel_pstate_debug_hide_params(void)
 +{
 +      int i;
 +
 +      if (IS_ERR_OR_NULL(debugfs_parent))
 +              return;
 +
 +      for (i = 0; pid_files[i].name; i++) {
 +              debugfs_remove(pid_files[i].dentry);
 +              pid_files[i].dentry = NULL;
        }
 +
 +      debugfs_remove(debugfs_parent);
 +      debugfs_parent = NULL;
  }
  
  /************************** debugfs end ************************/
                return sprintf(buf, "%u\n", limits->object);            \
        }
  
 +static ssize_t intel_pstate_show_status(char *buf);
 +static int intel_pstate_update_status(const char *buf, size_t size);
 +
 +static ssize_t show_status(struct kobject *kobj,
 +                         struct attribute *attr, char *buf)
 +{
 +      ssize_t ret;
 +
 +      mutex_lock(&intel_pstate_driver_lock);
 +      ret = intel_pstate_show_status(buf);
 +      mutex_unlock(&intel_pstate_driver_lock);
 +
 +      return ret;
 +}
 +
 +static ssize_t store_status(struct kobject *a, struct attribute *b,
 +                          const char *buf, size_t count)
 +{
 +      char *p = memchr(buf, '\n', count);
 +      int ret;
 +
 +      mutex_lock(&intel_pstate_driver_lock);
 +      ret = intel_pstate_update_status(buf, p ? p - buf : count);
 +      mutex_unlock(&intel_pstate_driver_lock);
 +
 +      return ret < 0 ? ret : count;
 +}
 +
  static ssize_t show_turbo_pct(struct kobject *kobj,
                                struct attribute *attr, char *buf)
  {
        int total, no_turbo, turbo_pct;
        uint32_t turbo_fp;
  
 +      mutex_lock(&intel_pstate_driver_lock);
 +
 +      if (!driver_registered) {
 +              mutex_unlock(&intel_pstate_driver_lock);
 +              return -EAGAIN;
 +      }
 +
        cpu = all_cpu_data[0];
  
        total = cpu->pstate.turbo_pstate - cpu->pstate.min_pstate + 1;
        no_turbo = cpu->pstate.max_pstate - cpu->pstate.min_pstate + 1;
        turbo_fp = div_fp(no_turbo, total);
        turbo_pct = 100 - fp_toint(mul_fp(turbo_fp, int_tofp(100)));
 +
 +      mutex_unlock(&intel_pstate_driver_lock);
 +
        return sprintf(buf, "%u\n", turbo_pct);
  }
  
@@@ -1130,18 -1065,8 +1125,18 @@@ static ssize_t show_num_pstates(struct 
        struct cpudata *cpu;
        int total;
  
 +      mutex_lock(&intel_pstate_driver_lock);
 +
 +      if (!driver_registered) {
 +              mutex_unlock(&intel_pstate_driver_lock);
 +              return -EAGAIN;
 +      }
 +
        cpu = all_cpu_data[0];
        total = cpu->pstate.turbo_pstate - cpu->pstate.min_pstate + 1;
 +
 +      mutex_unlock(&intel_pstate_driver_lock);
 +
        return sprintf(buf, "%u\n", total);
  }
  
@@@ -1150,21 -1075,12 +1145,21 @@@ static ssize_t show_no_turbo(struct kob
  {
        ssize_t ret;
  
 +      mutex_lock(&intel_pstate_driver_lock);
 +
 +      if (!driver_registered) {
 +              mutex_unlock(&intel_pstate_driver_lock);
 +              return -EAGAIN;
 +      }
 +
        update_turbo_state();
        if (limits->turbo_disabled)
                ret = sprintf(buf, "%u\n", limits->turbo_disabled);
        else
                ret = sprintf(buf, "%u\n", limits->no_turbo);
  
 +      mutex_unlock(&intel_pstate_driver_lock);
 +
        return ret;
  }
  
@@@ -1178,20 -1094,12 +1173,20 @@@ static ssize_t store_no_turbo(struct ko
        if (ret != 1)
                return -EINVAL;
  
 +      mutex_lock(&intel_pstate_driver_lock);
 +
 +      if (!driver_registered) {
 +              mutex_unlock(&intel_pstate_driver_lock);
 +              return -EAGAIN;
 +      }
 +
        mutex_lock(&intel_pstate_limits_lock);
  
        update_turbo_state();
        if (limits->turbo_disabled) {
                pr_warn("Turbo disabled by BIOS or unavailable on processor\n");
                mutex_unlock(&intel_pstate_limits_lock);
 +              mutex_unlock(&intel_pstate_driver_lock);
                return -EPERM;
        }
  
  
        intel_pstate_update_policies();
  
 +      mutex_unlock(&intel_pstate_driver_lock);
 +
        return count;
  }
  
@@@ -1216,13 -1122,6 +1211,13 @@@ static ssize_t store_max_perf_pct(struc
        if (ret != 1)
                return -EINVAL;
  
 +      mutex_lock(&intel_pstate_driver_lock);
 +
 +      if (!driver_registered) {
 +              mutex_unlock(&intel_pstate_driver_lock);
 +              return -EAGAIN;
 +      }
 +
        mutex_lock(&intel_pstate_limits_lock);
  
        limits->max_sysfs_pct = clamp_t(int, input, 0 , 100);
  
        intel_pstate_update_policies();
  
 +      mutex_unlock(&intel_pstate_driver_lock);
 +
        return count;
  }
  
@@@ -1253,13 -1150,6 +1248,13 @@@ static ssize_t store_min_perf_pct(struc
        if (ret != 1)
                return -EINVAL;
  
 +      mutex_lock(&intel_pstate_driver_lock);
 +
 +      if (!driver_registered) {
 +              mutex_unlock(&intel_pstate_driver_lock);
 +              return -EAGAIN;
 +      }
 +
        mutex_lock(&intel_pstate_limits_lock);
  
        limits->min_sysfs_pct = clamp_t(int, input, 0 , 100);
  
        intel_pstate_update_policies();
  
 +      mutex_unlock(&intel_pstate_driver_lock);
 +
        return count;
  }
  
  show_one(max_perf_pct, max_perf_pct);
  show_one(min_perf_pct, min_perf_pct);
  
 +define_one_global_rw(status);
  define_one_global_rw(no_turbo);
  define_one_global_rw(max_perf_pct);
  define_one_global_rw(min_perf_pct);
@@@ -1291,7 -1178,6 +1286,7 @@@ define_one_global_ro(turbo_pct)
  define_one_global_ro(num_pstates);
  
  static struct attribute *intel_pstate_attributes[] = {
 +      &status.attr,
        &no_turbo.attr,
        &turbo_pct.attr,
        &num_pstates.attr,
@@@ -1367,7 -1253,7 +1362,7 @@@ static int atom_get_min_pstate(void
  {
        u64 value;
  
-       rdmsrl(ATOM_RATIOS, value);
+       rdmsrl(MSR_ATOM_CORE_RATIOS, value);
        return (value >> 8) & 0x7F;
  }
  
@@@ -1375,7 -1261,7 +1370,7 @@@ static int atom_get_max_pstate(void
  {
        u64 value;
  
-       rdmsrl(ATOM_RATIOS, value);
+       rdmsrl(MSR_ATOM_CORE_RATIOS, value);
        return (value >> 16) & 0x7F;
  }
  
@@@ -1383,7 -1269,7 +1378,7 @@@ static int atom_get_turbo_pstate(void
  {
        u64 value;
  
-       rdmsrl(ATOM_TURBO_RATIOS, value);
+       rdmsrl(MSR_ATOM_CORE_TURBO_RATIOS, value);
        return value & 0x7F;
  }
  
@@@ -1445,7 -1331,7 +1440,7 @@@ static void atom_get_vid(struct cpudat
  {
        u64 value;
  
-       rdmsrl(ATOM_VIDS, value);
+       rdmsrl(MSR_ATOM_CORE_VIDS, value);
        cpudata->vid.min = int_tofp((value >> 8) & 0x7f);
        cpudata->vid.max = int_tofp((value >> 16) & 0x7f);
        cpudata->vid.ratio = div_fp(
                int_tofp(cpudata->pstate.max_pstate -
                        cpudata->pstate.min_pstate));
  
-       rdmsrl(ATOM_TURBO_VIDS, value);
+       rdmsrl(MSR_ATOM_CORE_TURBO_VIDS, value);
        cpudata->vid.turbo = value & 0x7f;
  }
  
@@@ -1473,71 -1359,48 +1468,71 @@@ static int core_get_max_pstate_physical
        return (value >> 8) & 0xFF;
  }
  
 +static int core_get_tdp_ratio(u64 plat_info)
 +{
 +      /* Check how many TDP levels present */
 +      if (plat_info & 0x600000000) {
 +              u64 tdp_ctrl;
 +              u64 tdp_ratio;
 +              int tdp_msr;
 +              int err;
 +
 +              /* Get the TDP level (0, 1, 2) to get ratios */
 +              err = rdmsrl_safe(MSR_CONFIG_TDP_CONTROL, &tdp_ctrl);
 +              if (err)
 +                      return err;
 +
 +              /* TDP MSR are continuous starting at 0x648 */
 +              tdp_msr = MSR_CONFIG_TDP_NOMINAL + (tdp_ctrl & 0x03);
 +              err = rdmsrl_safe(tdp_msr, &tdp_ratio);
 +              if (err)
 +                      return err;
 +
 +              /* For level 1 and 2, bits[23:16] contain the ratio */
 +              if (tdp_ctrl & 0x03)
 +                      tdp_ratio >>= 16;
 +
 +              tdp_ratio &= 0xff; /* ratios are only 8 bits long */
 +              pr_debug("tdp_ratio %x\n", (int)tdp_ratio);
 +
 +              return (int)tdp_ratio;
 +      }
 +
 +      return -ENXIO;
 +}
 +
  static int core_get_max_pstate(void)
  {
        u64 tar;
        u64 plat_info;
        int max_pstate;
 +      int tdp_ratio;
        int err;
  
        rdmsrl(MSR_PLATFORM_INFO, plat_info);
        max_pstate = (plat_info >> 8) & 0xFF;
  
 +      tdp_ratio = core_get_tdp_ratio(plat_info);
 +      if (tdp_ratio <= 0)
 +              return max_pstate;
 +
 +      if (hwp_active) {
 +              /* Turbo activation ratio is not used on HWP platforms */
 +              return tdp_ratio;
 +      }
 +
        err = rdmsrl_safe(MSR_TURBO_ACTIVATION_RATIO, &tar);
        if (!err) {
 +              int tar_levels;
 +
                /* Do some sanity checking for safety */
 -              if (plat_info & 0x600000000) {
 -                      u64 tdp_ctrl;
 -                      u64 tdp_ratio;
 -                      int tdp_msr;
 -
 -                      err = rdmsrl_safe(MSR_CONFIG_TDP_CONTROL, &tdp_ctrl);
 -                      if (err)
 -                              goto skip_tar;
 -
 -                      tdp_msr = MSR_CONFIG_TDP_NOMINAL + (tdp_ctrl & 0x3);
 -                      err = rdmsrl_safe(tdp_msr, &tdp_ratio);
 -                      if (err)
 -                              goto skip_tar;
 -
 -                      /* For level 1 and 2, bits[23:16] contain the ratio */
 -                      if (tdp_ctrl)
 -                              tdp_ratio >>= 16;
 -
 -                      tdp_ratio &= 0xff; /* ratios are only 8 bits long */
 -                      if (tdp_ratio - 1 == tar) {
 -                              max_pstate = tar;
 -                              pr_debug("max_pstate=TAC %x\n", max_pstate);
 -                      } else {
 -                              goto skip_tar;
 -                      }
 +              tar_levels = tar & 0xff;
 +              if (tdp_ratio - 1 == tar_levels) {
 +                      max_pstate = tar_levels;
 +                      pr_debug("max_pstate=TAC %x\n", max_pstate);
                }
        }
  
 -skip_tar:
        return max_pstate;
  }
  
@@@ -2204,20 -2067,6 +2199,20 @@@ static int intel_pstate_set_policy(stru
  
  static int intel_pstate_verify_policy(struct cpufreq_policy *policy)
  {
 +      struct cpudata *cpu = all_cpu_data[policy->cpu];
 +      struct perf_limits *perf_limits;
 +
 +      if (policy->policy == CPUFREQ_POLICY_PERFORMANCE)
 +              perf_limits = &performance_limits;
 +      else
 +              perf_limits = &powersave_limits;
 +
 +      update_turbo_state();
 +      policy->cpuinfo.max_freq = perf_limits->turbo_disabled ||
 +                                      perf_limits->no_turbo ?
 +                                      cpu->pstate.max_freq :
 +                                      cpu->pstate.turbo_freq;
 +
        cpufreq_verify_within_cpu_limits(policy);
  
        if (policy->policy != CPUFREQ_POLICY_POWERSAVE &&
@@@ -2445,111 -2294,6 +2440,111 @@@ static struct cpufreq_driver intel_cpuf
  
  static struct cpufreq_driver *intel_pstate_driver = &intel_pstate;
  
 +static void intel_pstate_driver_cleanup(void)
 +{
 +      unsigned int cpu;
 +
 +      get_online_cpus();
 +      for_each_online_cpu(cpu) {
 +              if (all_cpu_data[cpu]) {
 +                      if (intel_pstate_driver == &intel_pstate)
 +                              intel_pstate_clear_update_util_hook(cpu);
 +
 +                      kfree(all_cpu_data[cpu]);
 +                      all_cpu_data[cpu] = NULL;
 +              }
 +      }
 +      put_online_cpus();
 +}
 +
 +static int intel_pstate_register_driver(void)
 +{
 +      int ret;
 +
 +      ret = cpufreq_register_driver(intel_pstate_driver);
 +      if (ret) {
 +              intel_pstate_driver_cleanup();
 +              return ret;
 +      }
 +
 +      mutex_lock(&intel_pstate_limits_lock);
 +      driver_registered = true;
 +      mutex_unlock(&intel_pstate_limits_lock);
 +
 +      if (intel_pstate_driver == &intel_pstate && !hwp_active &&
 +          pstate_funcs.get_target_pstate != get_target_pstate_use_cpu_load)
 +              intel_pstate_debug_expose_params();
 +
 +      return 0;
 +}
 +
 +static int intel_pstate_unregister_driver(void)
 +{
 +      if (hwp_active)
 +              return -EBUSY;
 +
 +      if (intel_pstate_driver == &intel_pstate && !hwp_active &&
 +          pstate_funcs.get_target_pstate != get_target_pstate_use_cpu_load)
 +              intel_pstate_debug_hide_params();
 +
 +      mutex_lock(&intel_pstate_limits_lock);
 +      driver_registered = false;
 +      mutex_unlock(&intel_pstate_limits_lock);
 +
 +      cpufreq_unregister_driver(intel_pstate_driver);
 +      intel_pstate_driver_cleanup();
 +
 +      return 0;
 +}
 +
 +static ssize_t intel_pstate_show_status(char *buf)
 +{
 +      if (!driver_registered)
 +              return sprintf(buf, "off\n");
 +
 +      return sprintf(buf, "%s\n", intel_pstate_driver == &intel_pstate ?
 +                                      "active" : "passive");
 +}
 +
 +static int intel_pstate_update_status(const char *buf, size_t size)
 +{
 +      int ret;
 +
 +      if (size == 3 && !strncmp(buf, "off", size))
 +              return driver_registered ?
 +                      intel_pstate_unregister_driver() : -EINVAL;
 +
 +      if (size == 6 && !strncmp(buf, "active", size)) {
 +              if (driver_registered) {
 +                      if (intel_pstate_driver == &intel_pstate)
 +                              return 0;
 +
 +                      ret = intel_pstate_unregister_driver();
 +                      if (ret)
 +                              return ret;
 +              }
 +
 +              intel_pstate_driver = &intel_pstate;
 +              return intel_pstate_register_driver();
 +      }
 +
 +      if (size == 7 && !strncmp(buf, "passive", size)) {
 +              if (driver_registered) {
 +                      if (intel_pstate_driver != &intel_pstate)
 +                              return 0;
 +
 +                      ret = intel_pstate_unregister_driver();
 +                      if (ret)
 +                              return ret;
 +              }
 +
 +              intel_pstate_driver = &intel_cpufreq;
 +              return intel_pstate_register_driver();
 +      }
 +
 +      return -EINVAL;
 +}
 +
  static int no_load __initdata;
  static int no_hwp __initdata;
  static int hwp_only __initdata;
@@@ -2737,9 -2481,9 +2732,9 @@@ static const struct x86_cpu_id hwp_supp
  
  static int __init intel_pstate_init(void)
  {
 -      int cpu, rc = 0;
        const struct x86_cpu_id *id;
        struct cpu_defaults *cpu_def;
 +      int rc = 0;
  
        if (no_load)
                return -ENODEV;
@@@ -2771,29 -2515,45 +2766,29 @@@ hwp_cpu_matched
        if (intel_pstate_platform_pwr_mgmt_exists())
                return -ENODEV;
  
 +      if (!hwp_active && hwp_only)
 +              return -ENOTSUPP;
 +
        pr_info("Intel P-state driver initializing\n");
  
        all_cpu_data = vzalloc(sizeof(void *) * num_possible_cpus());
        if (!all_cpu_data)
                return -ENOMEM;
  
 -      if (!hwp_active && hwp_only)
 -              goto out;
 -
        intel_pstate_request_control_from_smm();
  
 -      rc = cpufreq_register_driver(intel_pstate_driver);
 -      if (rc)
 -              goto out;
 -
 -      if (intel_pstate_driver == &intel_pstate && !hwp_active &&
 -          pstate_funcs.get_target_pstate != get_target_pstate_use_cpu_load)
 -              intel_pstate_debug_expose_params();
 -
        intel_pstate_sysfs_expose_params();
  
 +      mutex_lock(&intel_pstate_driver_lock);
 +      rc = intel_pstate_register_driver();
 +      mutex_unlock(&intel_pstate_driver_lock);
 +      if (rc)
 +              return rc;
 +
        if (hwp_active)
                pr_info("HWP enabled\n");
  
 -      return rc;
 -out:
 -      get_online_cpus();
 -      for_each_online_cpu(cpu) {
 -              if (all_cpu_data[cpu]) {
 -                      if (intel_pstate_driver == &intel_pstate)
 -                              intel_pstate_clear_update_util_hook(cpu);
 -
 -                      kfree(all_cpu_data[cpu]);
 -              }
 -      }
 -
 -      put_online_cpus();
 -      vfree(all_cpu_data);
 -      return -ENODEV;
 +      return 0;
  }
  device_initcall(intel_pstate_init);