66// Licensed under the Apache License, Version 2.0 (the "License");
77// you may not use this file except in compliance with the License.
88// You may obtain a copy of the License at
9- //
9+ //
1010// http://www.apache.org/licenses/LICENSE-2.0
11- //
11+ //
1212// Unless required by applicable law or agreed to in writing, software
1313// distributed under the License is distributed on an "AS IS" BASIS,
1414// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -184,7 +184,7 @@ namespace
184184
185185} // < namespace
186186
187- bool CPUID::isAmdCpu ()
187+ bool CPUID::is_amd_cpu ()
188188{
189189 auto result = cpuid (0 , 0 );
190190 return
@@ -193,7 +193,7 @@ bool CPUID::isAmdCpu()
193193 && memcmp (reinterpret_cast <char *>(&result.ECX ), " DMAc" , 4 ) == 0 ;
194194}
195195
196- bool CPUID::isIntelCpu ()
196+ bool CPUID::is_intel_cpu ()
197197{
198198 auto result = cpuid (0 , 0 );
199199 return
@@ -202,7 +202,7 @@ bool CPUID::isIntelCpu()
202202 && memcmp (reinterpret_cast <char *>(&result.ECX ), " ntel" , 4 ) == 0 ;
203203}
204204
205- bool CPUID::hasFeature (Feature f)
205+ bool CPUID::has_feature (Feature f)
206206{
207207 const auto feature_info = get_feature_info (f);
208208 const auto cpuid_result = cpuid (feature_info.func , feature_info.subfunc );
@@ -215,3 +215,21 @@ bool CPUID::hasFeature(Feature f)
215215 case Register::EDX: return (cpuid_result.EDX & feature_info.bitmask ) != 0 ;
216216 }
217217}
218+
219+ #define KVM_CPUID_SIGNATURE 0x40000000
220+
221+ unsigned CPUID::kvm_function ()
222+ {
223+ auto res = cpuid (KVM_CPUID_SIGNATURE, 0 );
224+ // / "KVMKVMKVM"
225+ if (res.EBX == 0x4b4d564b && res.ECX == 0x564b4d56 && res.EDX == 0x4d )
226+ return res.EAX ;
227+ return 0 ;
228+ }
229+ bool CPUID::kvm_feature (unsigned id)
230+ {
231+ unsigned func = kvm_function ();
232+ if (func == 0 ) return false ;
233+ auto res = cpuid (func, 0 );
234+ return (res.EAX & (1 << id)) != 0 ;
235+ }
0 commit comments