Skip to content

Commit fcb6a15

Browse files
Dirk Brandewierafaeljw
authored andcommitted
intel_pstate: Take core C0 time into account for core busy calculation
Take non-idle time into account when calculating core busy time. This ensures that intel_pstate will notice a decrease in load. References: https://bugzilla.kernel.org/show_bug.cgi?id=66581 Cc: 3.10+ <stable@vger.kernel.org> # 3.10+ Signed-off-by: Dirk Brandewie <dirk.j.brandewie@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 38dbfb5 commit fcb6a15

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

‎drivers/cpufreq/intel_pstate.c‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct sample {
5757
int32_t core_pct_busy;
5858
u64 aperf;
5959
u64 mperf;
60+
unsigned long long tsc;
6061
int freq;
6162
};
6263

@@ -96,6 +97,7 @@ struct cpudata {
9697

9798
u64 prev_aperf;
9899
u64 prev_mperf;
100+
unsigned long long prev_tsc;
99101
int sample_ptr;
100102
struct sample samples[SAMPLE_COUNT];
101103
};
@@ -548,30 +550,41 @@ static inline void intel_pstate_calc_busy(struct cpudata *cpu,
548550
struct sample *sample)
549551
{
550552
u64 core_pct;
551-
core_pct = div64_u64(int_tofp(sample->aperf * 100),
552-
sample->mperf);
553-
sample->freq = fp_toint(cpu->pstate.max_pstate * core_pct * 1000);
553+
u64 c0_pct;
554554

555-
sample->core_pct_busy = core_pct;
555+
core_pct = div64_u64(sample->aperf * 100, sample->mperf);
556+
557+
c0_pct = div64_u64(sample->mperf * 100, sample->tsc);
558+
sample->freq = fp_toint(
559+
mul_fp(int_tofp(cpu->pstate.max_pstate),
560+
int_tofp(core_pct * 1000)));
561+
562+
sample->core_pct_busy = mul_fp(int_tofp(core_pct),
563+
div_fp(int_tofp(c0_pct + 1), int_tofp(100)));
556564
}
557565

558566
static inline void intel_pstate_sample(struct cpudata *cpu)
559567
{
560568
u64 aperf, mperf;
569+
unsigned long long tsc;
561570

562571
rdmsrl(MSR_IA32_APERF, aperf);
563572
rdmsrl(MSR_IA32_MPERF, mperf);
573+
tsc = native_read_tsc();
564574

565575
cpu->sample_ptr = (cpu->sample_ptr + 1) % SAMPLE_COUNT;
566576
cpu->samples[cpu->sample_ptr].aperf = aperf;
567577
cpu->samples[cpu->sample_ptr].mperf = mperf;
578+
cpu->samples[cpu->sample_ptr].tsc = tsc;
568579
cpu->samples[cpu->sample_ptr].aperf -= cpu->prev_aperf;
569580
cpu->samples[cpu->sample_ptr].mperf -= cpu->prev_mperf;
581+
cpu->samples[cpu->sample_ptr].tsc -= cpu->prev_tsc;
570582

571583
intel_pstate_calc_busy(cpu, &cpu->samples[cpu->sample_ptr]);
572584

573585
cpu->prev_aperf = aperf;
574586
cpu->prev_mperf = mperf;
587+
cpu->prev_tsc = tsc;
575588
}
576589

577590
static inline void intel_pstate_set_sample_time(struct cpudata *cpu)

0 commit comments

Comments
 (0)