| @@ -101,49 +101,6 @@ static bool aperfmperf_snapshot_cpu(int cpu, ktime_t now, bool wait) · 100 unmodified lines |
| 101 | return time_delta <= APERFMPERF_STALE_THRESHOLD_MS; | 101 | return time_delta <= APERFMPERF_STALE_THRESHOLD_MS; |
| 102 | } | 102 | } |
| 103 | | 103 | |
| 104 | unsigned int aperfmperf_get_khz(int cpu) | | |
| 105 | { | | |
| 106 | if (!cpu_khz) | | |
| 107 | return 0; | | |
| 108 | | | |
| 109 | if (!boot_cpu_has(X86_FEATURE_APERFMPERF)) | | |
| 110 | return 0; | | |
| 111 | | | |
| 112 | if (!housekeeping_cpu(cpu, HK_TYPE_MISC)) | | |
| 113 | return 0; | | |
| 114 | | | |
| 115 | if (rcu_is_idle_cpu(cpu)) | | |
| 116 | return 0; /* Idle CPUs are completely uninteresting. */ | | |
| 117 | | | |
| 118 | aperfmperf_snapshot_cpu(cpu, ktime_get(), true); | | |
| 119 | return per_cpu(samples.khz, cpu); | | |
| 120 | } | | |
| 121 | | | |
| 122 | void arch_freq_prepare_all(void) | | |
| 123 | { | | |
| 124 | ktime_t now = ktime_get(); | | |
| 125 | bool wait = false; | | |
| 126 | int cpu; | | |
| 127 | | | |
| 128 | if (!cpu_khz) | | |
| 129 | return; | | |
| 130 | | | |
| 131 | if (!boot_cpu_has(X86_FEATURE_APERFMPERF)) | | |
| 132 | return; | | |
| 133 | | | |
| 134 | for_each_online_cpu(cpu) { | | |
| 135 | if (!housekeeping_cpu(cpu, HK_TYPE_MISC)) | | |
| 136 | continue; | | |
| 137 | if (rcu_is_idle_cpu(cpu)) | | |
| 138 | continue; /* Idle CPUs are completely uninteresting. */ | | |
| 139 | if (!aperfmperf_snapshot_cpu(cpu, now, false)) | | |
| 140 | wait = true; | | |
| 141 | } | | |
| 142 | | | |
| 143 | if (wait) | | |
| 144 | msleep(APERFMPERF_REFRESH_DELAY_MS); | | |
| 145 | } | | |
| 146 | | | |
| 147 | unsigned int arch_freq_get_on_cpu(int cpu) | 104 | unsigned int arch_freq_get_on_cpu(int cpu) |
| 148 | { | 105 | { |
| 149 | struct aperfmperf_sample *s = per_cpu_ptr(&samples, cpu); | 106 | struct aperfmperf_sample *s = per_cpu_ptr(&samples, cpu); |
| @@ -530,6 +487,40 @@ void arch_scale_freq_tick(void) · 380 unmodified lines |
| 530 | scale_freq_tick(acnt, mcnt); | 487 | scale_freq_tick(acnt, mcnt); |
| 531 | } | 488 | } |
| 532 | | 489 | |
| | 490 | /* |
| | 491 | * Discard samples older than the define maximum sample age of 20ms. There |
| | 492 | * is no point in sending IPIs in such a case. If the scheduler tick was |
| | 493 | * not running then the CPU is either idle or isolated. |
| | 494 | */ |
| | 495 | #define MAX_SAMPLE_AGE ((unsigned long)HZ / 50) |
| | 496 | |
| | 497 | unsigned int aperfmperf_get_khz(int cpu) |
| | 498 | { |
| | 499 | struct aperfmperf *s = per_cpu_ptr(&cpu_samples, cpu); |
| | 500 | unsigned long last; |
| | 501 | unsigned int seq; |
| | 502 | u64 acnt, mcnt; |
| | 503 | |
| | 504 | if (!cpu_feature_enabled(X86_FEATURE_APERFMPERF)) |
| | 505 | return 0; |
| | 506 | |
| | 507 | do { |
| | 508 | seq = raw_read_seqcount_begin(&s->seq); |
| | 509 | last = s->last_update; |
| | 510 | acnt = s->acnt; |
| | 511 | mcnt = s->mcnt; |
| | 512 | } while (read_seqcount_retry(&s->seq, seq)); |
| | 513 | |
| | 514 | /* |
| | 515 | * Bail on invalid count and when the last update was too long ago, |
| | 516 | * which covers idle and NOHZ full CPUs. |
| | 517 | */ |
| | 518 | if (!mcnt || (jiffies - last) > MAX_SAMPLE_AGE) |
| | 519 | return 0; |
| | 520 | |
| | 521 | return div64_u64((cpu_khz * acnt), mcnt); |
| | 522 | } |
| | 523 | |
| 533 | static int __init bp_init_aperfmperf(void) | 524 | static int __init bp_init_aperfmperf(void) |
| 534 | { | 525 | { |
| 535 | if (!cpu_feature_enabled(X86_FEATURE_APERFMPERF)) | 526 | if (!cpu_feature_enabled(X86_FEATURE_APERFMPERF)) |