aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpufreq/intel_pstate.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/cpufreq/intel_pstate.c')
-rw-r--r--drivers/cpufreq/intel_pstate.c73
1 files changed, 43 insertions, 30 deletions
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 2ba53f4f6af2..fcb929ec5304 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -49,9 +49,9 @@ static inline int32_t mul_fp(int32_t x, int32_t y)
49 return ((int64_t)x * (int64_t)y) >> FRAC_BITS; 49 return ((int64_t)x * (int64_t)y) >> FRAC_BITS;
50} 50}
51 51
52static inline int32_t div_fp(int32_t x, int32_t y) 52static inline int32_t div_fp(s64 x, s64 y)
53{ 53{
54 return div_s64((int64_t)x << FRAC_BITS, y); 54 return div64_s64((int64_t)x << FRAC_BITS, y);
55} 55}
56 56
57static inline int ceiling_fp(int32_t x) 57static inline int ceiling_fp(int32_t x)
@@ -69,6 +69,7 @@ struct sample {
69 int32_t core_pct_busy; 69 int32_t core_pct_busy;
70 u64 aperf; 70 u64 aperf;
71 u64 mperf; 71 u64 mperf;
72 u64 tsc;
72 int freq; 73 int freq;
73 ktime_t time; 74 ktime_t time;
74}; 75};
@@ -110,6 +111,7 @@ struct cpudata {
110 ktime_t last_sample_time; 111 ktime_t last_sample_time;
111 u64 prev_aperf; 112 u64 prev_aperf;
112 u64 prev_mperf; 113 u64 prev_mperf;
114 u64 prev_tsc;
113 struct sample sample; 115 struct sample sample;
114}; 116};
115 117
@@ -397,7 +399,7 @@ static ssize_t store_no_turbo(struct kobject *a, struct attribute *b,
397 399
398 update_turbo_state(); 400 update_turbo_state();
399 if (limits.turbo_disabled) { 401 if (limits.turbo_disabled) {
400 pr_warn("Turbo disabled by BIOS or unavailable on processor\n"); 402 pr_warn("intel_pstate: Turbo disabled by BIOS or unavailable on processor\n");
401 return -EPERM; 403 return -EPERM;
402 } 404 }
403 405
@@ -485,7 +487,7 @@ static void __init intel_pstate_sysfs_expose_params(void)
485static void intel_pstate_hwp_enable(void) 487static void intel_pstate_hwp_enable(void)
486{ 488{
487 hwp_active++; 489 hwp_active++;
488 pr_info("intel_pstate HWP enabled\n"); 490 pr_info("intel_pstate: HWP enabled\n");
489 491
490 wrmsrl( MSR_PM_ENABLE, 0x1); 492 wrmsrl( MSR_PM_ENABLE, 0x1);
491} 493}
@@ -536,7 +538,7 @@ static void byt_set_pstate(struct cpudata *cpudata, int pstate)
536 538
537 val |= vid; 539 val |= vid;
538 540
539 wrmsrl(MSR_IA32_PERF_CTL, val); 541 wrmsrl_on_cpu(cpudata->cpu, MSR_IA32_PERF_CTL, val);
540} 542}
541 543
542#define BYT_BCLK_FREQS 5 544#define BYT_BCLK_FREQS 5
@@ -679,6 +681,7 @@ static struct cpu_defaults knl_params = {
679 .get_max = core_get_max_pstate, 681 .get_max = core_get_max_pstate,
680 .get_min = core_get_min_pstate, 682 .get_min = core_get_min_pstate,
681 .get_turbo = knl_get_turbo_pstate, 683 .get_turbo = knl_get_turbo_pstate,
684 .get_scaling = core_get_scaling,
682 .set = core_set_pstate, 685 .set = core_set_pstate,
683 }, 686 },
684}; 687};
@@ -705,19 +708,20 @@ static void intel_pstate_get_min_max(struct cpudata *cpu, int *min, int *max)
705 *min = clamp_t(int, min_perf, cpu->pstate.min_pstate, max_perf); 708 *min = clamp_t(int, min_perf, cpu->pstate.min_pstate, max_perf);
706} 709}
707 710
708static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate) 711static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate, bool force)
709{ 712{
710 int max_perf, min_perf; 713 int max_perf, min_perf;
711 714
712 update_turbo_state(); 715 if (force) {
713 716 update_turbo_state();
714 intel_pstate_get_min_max(cpu, &min_perf, &max_perf);
715 717
716 pstate = clamp_t(int, pstate, min_perf, max_perf); 718 intel_pstate_get_min_max(cpu, &min_perf, &max_perf);
717 719
718 if (pstate == cpu->pstate.current_pstate) 720 pstate = clamp_t(int, pstate, min_perf, max_perf);
719 return;
720 721
722 if (pstate == cpu->pstate.current_pstate)
723 return;
724 }
721 trace_cpu_frequency(pstate * cpu->pstate.scaling, cpu->cpu); 725 trace_cpu_frequency(pstate * cpu->pstate.scaling, cpu->cpu);
722 726
723 cpu->pstate.current_pstate = pstate; 727 cpu->pstate.current_pstate = pstate;
@@ -734,7 +738,7 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
734 738
735 if (pstate_funcs.get_vid) 739 if (pstate_funcs.get_vid)
736 pstate_funcs.get_vid(cpu); 740 pstate_funcs.get_vid(cpu);
737 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate); 741 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate, false);
738} 742}
739 743
740static inline void intel_pstate_calc_busy(struct cpudata *cpu) 744static inline void intel_pstate_calc_busy(struct cpudata *cpu)
@@ -757,23 +761,28 @@ static inline void intel_pstate_sample(struct cpudata *cpu)
757{ 761{
758 u64 aperf, mperf; 762 u64 aperf, mperf;
759 unsigned long flags; 763 unsigned long flags;
764 u64 tsc;
760 765
761 local_irq_save(flags); 766 local_irq_save(flags);
762 rdmsrl(MSR_IA32_APERF, aperf); 767 rdmsrl(MSR_IA32_APERF, aperf);
763 rdmsrl(MSR_IA32_MPERF, mperf); 768 rdmsrl(MSR_IA32_MPERF, mperf);
769 tsc = native_read_tsc();
764 local_irq_restore(flags); 770 local_irq_restore(flags);
765 771
766 cpu->last_sample_time = cpu->sample.time; 772 cpu->last_sample_time = cpu->sample.time;
767 cpu->sample.time = ktime_get(); 773 cpu->sample.time = ktime_get();
768 cpu->sample.aperf = aperf; 774 cpu->sample.aperf = aperf;
769 cpu->sample.mperf = mperf; 775 cpu->sample.mperf = mperf;
776 cpu->sample.tsc = tsc;
770 cpu->sample.aperf -= cpu->prev_aperf; 777 cpu->sample.aperf -= cpu->prev_aperf;
771 cpu->sample.mperf -= cpu->prev_mperf; 778 cpu->sample.mperf -= cpu->prev_mperf;
779 cpu->sample.tsc -= cpu->prev_tsc;
772 780
773 intel_pstate_calc_busy(cpu); 781 intel_pstate_calc_busy(cpu);
774 782
775 cpu->prev_aperf = aperf; 783 cpu->prev_aperf = aperf;
776 cpu->prev_mperf = mperf; 784 cpu->prev_mperf = mperf;
785 cpu->prev_tsc = tsc;
777} 786}
778 787
779static inline void intel_hwp_set_sample_time(struct cpudata *cpu) 788static inline void intel_hwp_set_sample_time(struct cpudata *cpu)
@@ -795,7 +804,7 @@ static inline void intel_pstate_set_sample_time(struct cpudata *cpu)
795static inline int32_t intel_pstate_get_scaled_busy(struct cpudata *cpu) 804static inline int32_t intel_pstate_get_scaled_busy(struct cpudata *cpu)
796{ 805{
797 int32_t core_busy, max_pstate, current_pstate, sample_ratio; 806 int32_t core_busy, max_pstate, current_pstate, sample_ratio;
798 u32 duration_us; 807 s64 duration_us;
799 u32 sample_time; 808 u32 sample_time;
800 809
801 /* 810 /*
@@ -822,8 +831,8 @@ static inline int32_t intel_pstate_get_scaled_busy(struct cpudata *cpu)
822 * to adjust our busyness. 831 * to adjust our busyness.
823 */ 832 */
824 sample_time = pid_params.sample_rate_ms * USEC_PER_MSEC; 833 sample_time = pid_params.sample_rate_ms * USEC_PER_MSEC;
825 duration_us = (u32) ktime_us_delta(cpu->sample.time, 834 duration_us = ktime_us_delta(cpu->sample.time,
826 cpu->last_sample_time); 835 cpu->last_sample_time);
827 if (duration_us > sample_time * 3) { 836 if (duration_us > sample_time * 3) {
828 sample_ratio = div_fp(int_tofp(sample_time), 837 sample_ratio = div_fp(int_tofp(sample_time),
829 int_tofp(duration_us)); 838 int_tofp(duration_us));
@@ -838,6 +847,10 @@ static inline void intel_pstate_adjust_busy_pstate(struct cpudata *cpu)
838 int32_t busy_scaled; 847 int32_t busy_scaled;
839 struct _pid *pid; 848 struct _pid *pid;
840 signed int ctl; 849 signed int ctl;
850 int from;
851 struct sample *sample;
852
853 from = cpu->pstate.current_pstate;
841 854
842 pid = &cpu->pid; 855 pid = &cpu->pid;
843 busy_scaled = intel_pstate_get_scaled_busy(cpu); 856 busy_scaled = intel_pstate_get_scaled_busy(cpu);
@@ -845,7 +858,17 @@ static inline void intel_pstate_adjust_busy_pstate(struct cpudata *cpu)
845 ctl = pid_calc(pid, busy_scaled); 858 ctl = pid_calc(pid, busy_scaled);
846 859
847 /* Negative values of ctl increase the pstate and vice versa */ 860 /* Negative values of ctl increase the pstate and vice versa */
848 intel_pstate_set_pstate(cpu, cpu->pstate.current_pstate - ctl); 861 intel_pstate_set_pstate(cpu, cpu->pstate.current_pstate - ctl, true);
862
863 sample = &cpu->sample;
864 trace_pstate_sample(fp_toint(sample->core_pct_busy),
865 fp_toint(busy_scaled),
866 from,
867 cpu->pstate.current_pstate,
868 sample->mperf,
869 sample->aperf,
870 sample->tsc,
871 sample->freq);
849} 872}
850 873
851static void intel_hwp_timer_func(unsigned long __data) 874static void intel_hwp_timer_func(unsigned long __data)
@@ -859,21 +882,11 @@ static void intel_hwp_timer_func(unsigned long __data)
859static void intel_pstate_timer_func(unsigned long __data) 882static void intel_pstate_timer_func(unsigned long __data)
860{ 883{
861 struct cpudata *cpu = (struct cpudata *) __data; 884 struct cpudata *cpu = (struct cpudata *) __data;
862 struct sample *sample;
863 885
864 intel_pstate_sample(cpu); 886 intel_pstate_sample(cpu);
865 887
866 sample = &cpu->sample;
867
868 intel_pstate_adjust_busy_pstate(cpu); 888 intel_pstate_adjust_busy_pstate(cpu);
869 889
870 trace_pstate_sample(fp_toint(sample->core_pct_busy),
871 fp_toint(intel_pstate_get_scaled_busy(cpu)),
872 cpu->pstate.current_pstate,
873 sample->mperf,
874 sample->aperf,
875 sample->freq);
876
877 intel_pstate_set_sample_time(cpu); 890 intel_pstate_set_sample_time(cpu);
878} 891}
879 892
@@ -936,7 +949,7 @@ static int intel_pstate_init_cpu(unsigned int cpunum)
936 949
937 add_timer_on(&cpu->timer, cpunum); 950 add_timer_on(&cpu->timer, cpunum);
938 951
939 pr_debug("Intel pstate controlling: cpu %d\n", cpunum); 952 pr_debug("intel_pstate: controlling: cpu %d\n", cpunum);
940 953
941 return 0; 954 return 0;
942} 955}
@@ -1002,13 +1015,13 @@ static void intel_pstate_stop_cpu(struct cpufreq_policy *policy)
1002 int cpu_num = policy->cpu; 1015 int cpu_num = policy->cpu;
1003 struct cpudata *cpu = all_cpu_data[cpu_num]; 1016 struct cpudata *cpu = all_cpu_data[cpu_num];
1004 1017
1005 pr_info("intel_pstate CPU %d exiting\n", cpu_num); 1018 pr_debug("intel_pstate: CPU %d exiting\n", cpu_num);
1006 1019
1007 del_timer_sync(&all_cpu_data[cpu_num]->timer); 1020 del_timer_sync(&all_cpu_data[cpu_num]->timer);
1008 if (hwp_active) 1021 if (hwp_active)
1009 return; 1022 return;
1010 1023
1011 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate); 1024 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate, false);
1012} 1025}
1013 1026
1014static int intel_pstate_cpu_init(struct cpufreq_policy *policy) 1027static int intel_pstate_cpu_init(struct cpufreq_policy *policy)