Skip to content

Commit c6702c9

Browse files
Wei Huangbonzini
authored andcommitted
KVM: x86/vPMU: rename a few PMU functions
Before introducing a pmu.h header for them, make the naming more consistent. Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 6a39bbc commit c6702c9

File tree

4 files changed

+49
-49
lines changed

4 files changed

+49
-49
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,14 +1198,14 @@ int kvm_is_in_guest(void);
11981198
void kvm_pmu_init(struct kvm_vcpu *vcpu);
11991199
void kvm_pmu_destroy(struct kvm_vcpu *vcpu);
12001200
void kvm_pmu_reset(struct kvm_vcpu *vcpu);
1201-
void kvm_pmu_cpuid_update(struct kvm_vcpu *vcpu);
1202-
bool kvm_pmu_msr(struct kvm_vcpu *vcpu, u32 msr);
1201+
void kvm_pmu_refresh(struct kvm_vcpu *vcpu);
1202+
bool kvm_pmu_is_valid_msr(struct kvm_vcpu *vcpu, u32 msr);
12031203
int kvm_pmu_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *data);
12041204
int kvm_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info);
1205-
int kvm_pmu_check_pmc(struct kvm_vcpu *vcpu, unsigned pmc);
1206-
int kvm_pmu_read_pmc(struct kvm_vcpu *vcpu, unsigned pmc, u64 *data);
1207-
void kvm_handle_pmu_event(struct kvm_vcpu *vcpu);
1208-
void kvm_deliver_pmi(struct kvm_vcpu *vcpu);
1205+
int kvm_pmu_is_valid_msr_idx(struct kvm_vcpu *vcpu, unsigned pmc);
1206+
int kvm_pmu_rdpmc(struct kvm_vcpu *vcpu, unsigned pmc, u64 *data);
1207+
void kvm_pmu_handle_event(struct kvm_vcpu *vcpu);
1208+
void kvm_pmu_deliver_pmi(struct kvm_vcpu *vcpu);
12091209

12101210
int __x86_set_memory_region(struct kvm *kvm,
12111211
const struct kvm_userspace_memory_region *mem);

arch/x86/kvm/cpuid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ int kvm_update_cpuid(struct kvm_vcpu *vcpu)
111111
/* Update physical-address width */
112112
vcpu->arch.maxphyaddr = cpuid_query_maxphyaddr(vcpu);
113113

114-
kvm_pmu_cpuid_update(vcpu);
114+
kvm_pmu_refresh(vcpu);
115115
return 0;
116116
}
117117

arch/x86/kvm/pmu.c

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static inline u64 pmc_bitmask(struct kvm_pmc *pmc)
5252
return pmu->counter_bitmask[pmc->type];
5353
}
5454

55-
static inline bool pmc_enabled(struct kvm_pmc *pmc)
55+
static inline bool pmc_is_enabled(struct kvm_pmc *pmc)
5656
{
5757
struct kvm_pmu *pmu = &pmc->vcpu->arch.pmu;
5858
return test_bit(pmc->idx, (unsigned long *)&pmu->global_ctrl);
@@ -87,20 +87,20 @@ static struct kvm_pmc *global_idx_to_pmc(struct kvm_pmu *pmu, int idx)
8787
return get_fixed_pmc_idx(pmu, idx - INTEL_PMC_IDX_FIXED);
8888
}
8989

90-
void kvm_deliver_pmi(struct kvm_vcpu *vcpu)
90+
void kvm_pmu_deliver_pmi(struct kvm_vcpu *vcpu)
9191
{
9292
if (vcpu->arch.apic)
9393
kvm_apic_local_deliver(vcpu->arch.apic, APIC_LVTPC);
9494
}
9595

96-
static void trigger_pmi(struct irq_work *irq_work)
96+
static void kvm_pmi_trigger_fn(struct irq_work *irq_work)
9797
{
9898
struct kvm_pmu *pmu = container_of(irq_work, struct kvm_pmu,
9999
irq_work);
100100
struct kvm_vcpu *vcpu = container_of(pmu, struct kvm_vcpu,
101101
arch.pmu);
102102

103-
kvm_deliver_pmi(vcpu);
103+
kvm_pmu_deliver_pmi(vcpu);
104104
}
105105

106106
static void kvm_perf_overflow(struct perf_event *perf_event,
@@ -138,7 +138,7 @@ static void kvm_perf_overflow_intr(struct perf_event *perf_event,
138138
}
139139
}
140140

141-
static u64 read_pmc(struct kvm_pmc *pmc)
141+
static u64 pmc_read_counter(struct kvm_pmc *pmc)
142142
{
143143
u64 counter, enabled, running;
144144

@@ -153,16 +153,16 @@ static u64 read_pmc(struct kvm_pmc *pmc)
153153
return counter & pmc_bitmask(pmc);
154154
}
155155

156-
static void stop_counter(struct kvm_pmc *pmc)
156+
static void pmc_stop_counter(struct kvm_pmc *pmc)
157157
{
158158
if (pmc->perf_event) {
159-
pmc->counter = read_pmc(pmc);
159+
pmc->counter = pmc_read_counter(pmc);
160160
perf_event_release_kernel(pmc->perf_event);
161161
pmc->perf_event = NULL;
162162
}
163163
}
164164

165-
static void reprogram_counter(struct kvm_pmc *pmc, u32 type,
165+
static void pmc_reprogram_counter(struct kvm_pmc *pmc, u32 type,
166166
unsigned config, bool exclude_user, bool exclude_kernel,
167167
bool intr, bool in_tx, bool in_tx_cp)
168168
{
@@ -224,9 +224,9 @@ static void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)
224224

225225
pmc->eventsel = eventsel;
226226

227-
stop_counter(pmc);
227+
pmc_stop_counter(pmc);
228228

229-
if (!(eventsel & ARCH_PERFMON_EVENTSEL_ENABLE) || !pmc_enabled(pmc))
229+
if (!(eventsel & ARCH_PERFMON_EVENTSEL_ENABLE) || !pmc_is_enabled(pmc))
230230
return;
231231

232232
event_select = eventsel & ARCH_PERFMON_EVENTSEL_EVENT;
@@ -246,7 +246,7 @@ static void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)
246246
if (type == PERF_TYPE_RAW)
247247
config = eventsel & X86_RAW_EVENT_MASK;
248248

249-
reprogram_counter(pmc, type, config,
249+
pmc_reprogram_counter(pmc, type, config,
250250
!(eventsel & ARCH_PERFMON_EVENTSEL_USR),
251251
!(eventsel & ARCH_PERFMON_EVENTSEL_OS),
252252
eventsel & ARCH_PERFMON_EVENTSEL_INT,
@@ -259,19 +259,19 @@ static void reprogram_fixed_counter(struct kvm_pmc *pmc, u8 en_pmi, int idx)
259259
unsigned en = en_pmi & 0x3;
260260
bool pmi = en_pmi & 0x8;
261261

262-
stop_counter(pmc);
262+
pmc_stop_counter(pmc);
263263

264-
if (!en || !pmc_enabled(pmc))
264+
if (!en || !pmc_is_enabled(pmc))
265265
return;
266266

267-
reprogram_counter(pmc, PERF_TYPE_HARDWARE,
267+
pmc_reprogram_counter(pmc, PERF_TYPE_HARDWARE,
268268
arch_events[fixed_pmc_events[idx]].event_type,
269269
!(en & 0x2), /* exclude user */
270270
!(en & 0x1), /* exclude kernel */
271271
pmi, false, false);
272272
}
273273

274-
static inline u8 fixed_en_pmi(u64 ctrl, int idx)
274+
static inline u8 fixed_ctrl_field(u64 ctrl, int idx)
275275
{
276276
return (ctrl >> (idx * 4)) & 0xf;
277277
}
@@ -281,10 +281,10 @@ static void reprogram_fixed_counters(struct kvm_pmu *pmu, u64 data)
281281
int i;
282282

283283
for (i = 0; i < pmu->nr_arch_fixed_counters; i++) {
284-
u8 en_pmi = fixed_en_pmi(data, i);
284+
u8 en_pmi = fixed_ctrl_field(data, i);
285285
struct kvm_pmc *pmc = get_fixed_pmc_idx(pmu, i);
286286

287-
if (fixed_en_pmi(pmu->fixed_ctr_ctrl, i) == en_pmi)
287+
if (fixed_ctrl_field(pmu->fixed_ctr_ctrl, i) == en_pmi)
288288
continue;
289289

290290
reprogram_fixed_counter(pmc, en_pmi, i);
@@ -293,7 +293,7 @@ static void reprogram_fixed_counters(struct kvm_pmu *pmu, u64 data)
293293
pmu->fixed_ctr_ctrl = data;
294294
}
295295

296-
static void reprogram_idx(struct kvm_pmu *pmu, int idx)
296+
static void reprogram_counter(struct kvm_pmu *pmu, int idx)
297297
{
298298
struct kvm_pmc *pmc = global_idx_to_pmc(pmu, idx);
299299

@@ -305,7 +305,7 @@ static void reprogram_idx(struct kvm_pmu *pmu, int idx)
305305
else {
306306
int fidx = idx - INTEL_PMC_IDX_FIXED;
307307
reprogram_fixed_counter(pmc,
308-
fixed_en_pmi(pmu->fixed_ctr_ctrl, fidx), fidx);
308+
fixed_ctrl_field(pmu->fixed_ctr_ctrl, fidx), fidx);
309309
}
310310
}
311311

@@ -317,10 +317,10 @@ static void global_ctrl_changed(struct kvm_pmu *pmu, u64 data)
317317
pmu->global_ctrl = data;
318318

319319
for_each_set_bit(bit, (unsigned long *)&diff, X86_PMC_IDX_MAX)
320-
reprogram_idx(pmu, bit);
320+
reprogram_counter(pmu, bit);
321321
}
322322

323-
bool kvm_pmu_msr(struct kvm_vcpu *vcpu, u32 msr)
323+
bool kvm_pmu_is_valid_msr(struct kvm_vcpu *vcpu, u32 msr)
324324
{
325325
struct kvm_pmu *pmu = &vcpu->arch.pmu;
326326
int ret;
@@ -362,7 +362,7 @@ int kvm_pmu_get_msr(struct kvm_vcpu *vcpu, u32 index, u64 *data)
362362
default:
363363
if ((pmc = get_gp_pmc(pmu, index, MSR_IA32_PERFCTR0)) ||
364364
(pmc = get_fixed_pmc(pmu, index))) {
365-
*data = read_pmc(pmc);
365+
*data = pmc_read_counter(pmc);
366366
return 0;
367367
} else if ((pmc = get_gp_pmc(pmu, index, MSR_P6_EVNTSEL0))) {
368368
*data = pmc->eventsel;
@@ -415,7 +415,7 @@ int kvm_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
415415
(pmc = get_fixed_pmc(pmu, index))) {
416416
if (!msr_info->host_initiated)
417417
data = (s64)(s32)data;
418-
pmc->counter += data - read_pmc(pmc);
418+
pmc->counter += data - pmc_read_counter(pmc);
419419
return 0;
420420
} else if ((pmc = get_gp_pmc(pmu, index, MSR_P6_EVNTSEL0))) {
421421
if (data == pmc->eventsel)
@@ -429,7 +429,7 @@ int kvm_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
429429
return 1;
430430
}
431431

432-
int kvm_pmu_check_pmc(struct kvm_vcpu *vcpu, unsigned pmc)
432+
int kvm_pmu_is_valid_msr_idx(struct kvm_vcpu *vcpu, unsigned pmc)
433433
{
434434
struct kvm_pmu *pmu = &vcpu->arch.pmu;
435435
bool fixed = pmc & (1u << 30);
@@ -438,7 +438,7 @@ int kvm_pmu_check_pmc(struct kvm_vcpu *vcpu, unsigned pmc)
438438
(fixed && pmc >= pmu->nr_arch_fixed_counters);
439439
}
440440

441-
int kvm_pmu_read_pmc(struct kvm_vcpu *vcpu, unsigned pmc, u64 *data)
441+
int kvm_pmu_rdpmc(struct kvm_vcpu *vcpu, unsigned pmc, u64 *data)
442442
{
443443
struct kvm_pmu *pmu = &vcpu->arch.pmu;
444444
bool fast_mode = pmc & (1u << 31);
@@ -452,15 +452,15 @@ int kvm_pmu_read_pmc(struct kvm_vcpu *vcpu, unsigned pmc, u64 *data)
452452
if (fixed && pmc >= pmu->nr_arch_fixed_counters)
453453
return 1;
454454
counters = fixed ? pmu->fixed_counters : pmu->gp_counters;
455-
ctr = read_pmc(&counters[pmc]);
455+
ctr = pmc_read_counter(&counters[pmc]);
456456
if (fast_mode)
457457
ctr = (u32)ctr;
458458
*data = ctr;
459459

460460
return 0;
461461
}
462462

463-
void kvm_pmu_cpuid_update(struct kvm_vcpu *vcpu)
463+
void kvm_pmu_refresh(struct kvm_vcpu *vcpu)
464464
{
465465
struct kvm_pmu *pmu = &vcpu->arch.pmu;
466466
struct kvm_cpuid_entry2 *entry;
@@ -527,8 +527,8 @@ void kvm_pmu_init(struct kvm_vcpu *vcpu)
527527
pmu->fixed_counters[i].vcpu = vcpu;
528528
pmu->fixed_counters[i].idx = i + INTEL_PMC_IDX_FIXED;
529529
}
530-
init_irq_work(&pmu->irq_work, trigger_pmi);
531-
kvm_pmu_cpuid_update(vcpu);
530+
init_irq_work(&pmu->irq_work, kvm_pmi_trigger_fn);
531+
kvm_pmu_refresh(vcpu);
532532
}
533533

534534
void kvm_pmu_reset(struct kvm_vcpu *vcpu)
@@ -539,12 +539,12 @@ void kvm_pmu_reset(struct kvm_vcpu *vcpu)
539539
irq_work_sync(&pmu->irq_work);
540540
for (i = 0; i < INTEL_PMC_MAX_GENERIC; i++) {
541541
struct kvm_pmc *pmc = &pmu->gp_counters[i];
542-
stop_counter(pmc);
542+
pmc_stop_counter(pmc);
543543
pmc->counter = pmc->eventsel = 0;
544544
}
545545

546546
for (i = 0; i < INTEL_PMC_MAX_FIXED; i++)
547-
stop_counter(&pmu->fixed_counters[i]);
547+
pmc_stop_counter(&pmu->fixed_counters[i]);
548548

549549
pmu->fixed_ctr_ctrl = pmu->global_ctrl = pmu->global_status =
550550
pmu->global_ovf_ctrl = 0;
@@ -555,7 +555,7 @@ void kvm_pmu_destroy(struct kvm_vcpu *vcpu)
555555
kvm_pmu_reset(vcpu);
556556
}
557557

558-
void kvm_handle_pmu_event(struct kvm_vcpu *vcpu)
558+
void kvm_pmu_handle_event(struct kvm_vcpu *vcpu)
559559
{
560560
struct kvm_pmu *pmu = &vcpu->arch.pmu;
561561
u64 bitmask;
@@ -571,6 +571,6 @@ void kvm_handle_pmu_event(struct kvm_vcpu *vcpu)
571571
continue;
572572
}
573573

574-
reprogram_idx(pmu, bit);
574+
reprogram_counter(pmu, bit);
575575
}
576576
}

arch/x86/kvm/x86.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ bool kvm_rdpmc(struct kvm_vcpu *vcpu)
913913
u64 data;
914914
int err;
915915

916-
err = kvm_pmu_read_pmc(vcpu, ecx, &data);
916+
err = kvm_pmu_rdpmc(vcpu, ecx, &data);
917917
if (err)
918918
return err;
919919
kvm_register_write(vcpu, VCPU_REGS_RAX, (u32)data);
@@ -2231,7 +2231,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
22312231
pr = true;
22322232
case MSR_P6_EVNTSEL0:
22332233
case MSR_P6_EVNTSEL1:
2234-
if (kvm_pmu_msr(vcpu, msr))
2234+
if (kvm_pmu_is_valid_msr(vcpu, msr))
22352235
return kvm_pmu_set_msr(vcpu, msr_info);
22362236

22372237
if (pr || data != 0)
@@ -2277,7 +2277,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
22772277
default:
22782278
if (msr && (msr == vcpu->kvm->arch.xen_hvm_config.msr))
22792279
return xen_hvm_config(vcpu, data);
2280-
if (kvm_pmu_msr(vcpu, msr))
2280+
if (kvm_pmu_is_valid_msr(vcpu, msr))
22812281
return kvm_pmu_set_msr(vcpu, msr_info);
22822282
if (!ignore_msrs) {
22832283
vcpu_unimpl(vcpu, "unhandled wrmsr: 0x%x data %llx\n",
@@ -2435,7 +2435,7 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
24352435
case MSR_P6_PERFCTR1:
24362436
case MSR_P6_EVNTSEL0:
24372437
case MSR_P6_EVNTSEL1:
2438-
if (kvm_pmu_msr(vcpu, msr_info->index))
2438+
if (kvm_pmu_is_valid_msr(vcpu, msr_info->index))
24392439
return kvm_pmu_get_msr(vcpu, msr_info->index, &msr_info->data);
24402440
msr_info->data = 0;
24412441
break;
@@ -2561,7 +2561,7 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
25612561
msr_info->data = vcpu->arch.osvw.status;
25622562
break;
25632563
default:
2564-
if (kvm_pmu_msr(vcpu, msr_info->index))
2564+
if (kvm_pmu_is_valid_msr(vcpu, msr_info->index))
25652565
return kvm_pmu_get_msr(vcpu, msr_info->index, &msr_info->data);
25662566
if (!ignore_msrs) {
25672567
vcpu_unimpl(vcpu, "unhandled rdmsr: 0x%x\n", msr_info->index);
@@ -4966,13 +4966,13 @@ static void emulator_set_smbase(struct x86_emulate_ctxt *ctxt, u64 smbase)
49664966
static int emulator_check_pmc(struct x86_emulate_ctxt *ctxt,
49674967
u32 pmc)
49684968
{
4969-
return kvm_pmu_check_pmc(emul_to_vcpu(ctxt), pmc);
4969+
return kvm_pmu_is_valid_msr_idx(emul_to_vcpu(ctxt), pmc);
49704970
}
49714971

49724972
static int emulator_read_pmc(struct x86_emulate_ctxt *ctxt,
49734973
u32 pmc, u64 *pdata)
49744974
{
4975-
return kvm_pmu_read_pmc(emul_to_vcpu(ctxt), pmc, pdata);
4975+
return kvm_pmu_rdpmc(emul_to_vcpu(ctxt), pmc, pdata);
49764976
}
49774977

49784978
static void emulator_halt(struct x86_emulate_ctxt *ctxt)
@@ -6542,9 +6542,9 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
65426542
if (kvm_check_request(KVM_REQ_NMI, vcpu))
65436543
process_nmi(vcpu);
65446544
if (kvm_check_request(KVM_REQ_PMU, vcpu))
6545-
kvm_handle_pmu_event(vcpu);
6545+
kvm_pmu_handle_event(vcpu);
65466546
if (kvm_check_request(KVM_REQ_PMI, vcpu))
6547-
kvm_deliver_pmi(vcpu);
6547+
kvm_pmu_deliver_pmi(vcpu);
65486548
if (kvm_check_request(KVM_REQ_SCAN_IOAPIC, vcpu))
65496549
vcpu_scan_ioapic(vcpu);
65506550
if (kvm_check_request(KVM_REQ_APIC_PAGE_RELOAD, vcpu))

0 commit comments

Comments
 (0)