Hi Paolo and Gleb, The attached file is a preliminary version of AMD vPMU support for KVM. Currently I am working on a formal patch set; but realized that there are some design choice to make (see below). I thought it is better to send it out now, asking for your comments before sending out patchset v1. If you are OK with current approach, please let me know. Otherwise please share your suggestions/comments on the design choice (see suggestions below). I will send out split patch set soon. Thanks, -Wei ================ 1. OBJECTIVE To enable PMU for guest VMs running on AMD host. Currently only software events are supported for AMD guest VMs. This is useless to profile guest VM on AMD systems. 2. CURRENT DESIGN The design is similar to existing vPMU support. Many data structures such as "struct kvm_pmc" and "struct kvm_pmu" are re-used for this design. Original pmu.c code was designed with Intel PMU in mind. To avoid the confusion, the current design converts existing pmu.c into intel-pmu.c and create a similar code, named amd-pmu.c. PMU function calls in x86.c are then dispatched via function pointers (i.e. struct kvm_pmu_ops). The initial setup is done in kvm_pmu_arch_init(). 3. STATUS I have briefly tested using AMD machine and the profiling data seems to be fairly accurate. With that said, more tests are required especially on PMI and extensive HW perf events. 4. DESIGN QUESTIONS The current design is described in (2). However it is not perfect, especially due to the code similarity between intel-pmu.c and amd-pmu.c. I have other ideas listed below. Please review and give some suggestion: (a) Merge intel-pmu.c and amd-pmu.c into pmu.c * PMU will probe the architecture first before first usage; * It will still use function pointers to dispatch global functions (e.g. kvm_pmu_reset); * For static functions that are the same (e.g. pmc_is_gp), we will use the same copy; * For static functions that are slightly different (e.g. global_idx_to_pmc), we will use a shared version with if-else statement, depending on Intel or AMD. I think this approach is quite acceptable, except that there will be many if-else in the code. Not clean enough. (b) Convert intel-pmu.c => vmx.c and convert amd-pmu.c => svm.c * PMU function pointers will be created in kvm_x86_ops; * The entry functions will be created inside vmx.c and svm.c respectively; * There might be common functions defined in pmu.c. This design is viable too. But to be honest, it is a bit messy compared with (a). ==========================