Skip to content

Commit f043311

Browse files
Zeppelin1979gz
authored andcommitted
#59 Add support for AMD Leaf 8000_001B
1 parent 92e8cae commit f043311

File tree

4 files changed

+183
-0
lines changed

4 files changed

+183
-0
lines changed

src/display.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,49 @@ pub fn markdown<R: crate::CpuIdReader>(cpuid: crate::CpuId<R>) {
13111311
);
13121312
}
13131313

1314+
if let Some(info) = cpuid.get_instruction_based_sampling_capabilities() {
1315+
print_title(
1316+
&skin,
1317+
"Instruction-Based Sampling Capabilities (0x8000_001b):",
1318+
);
1319+
table2(
1320+
&skin,
1321+
&[
1322+
RowGen::tuple("IBS feature flags valid", info.has_feature_flags()),
1323+
RowGen::tuple("IBS fetch sampling supporte", info.has_fetch_sampling()),
1324+
RowGen::tuple(
1325+
"IBS execution sampling supported",
1326+
info.has_execution_sampling(),
1327+
),
1328+
RowGen::tuple(
1329+
"Read write of op counter supported",
1330+
info.has_read_write_operation_counter(),
1331+
),
1332+
RowGen::tuple("Op counting mode supported", info.has_operation_counter()),
1333+
RowGen::tuple(
1334+
"Branch target address reporting supported",
1335+
info.has_branch_target_address_reporting(),
1336+
),
1337+
RowGen::tuple(
1338+
"IbsOpCurCnt and IbsOpMaxCnt extend by 7 bits",
1339+
info.has_operation_counter_extended(),
1340+
),
1341+
RowGen::tuple(
1342+
"Invalid RIP indication supported",
1343+
info.has_invalid_rip_indication(),
1344+
),
1345+
RowGen::tuple(
1346+
"Fused branch micro-op indication supported",
1347+
info.has_fused_branch_micro_op_indication(),
1348+
),
1349+
RowGen::tuple(
1350+
"L3 Miss Filtering for IBS supported",
1351+
info.has_l3_miss_filtering(),
1352+
),
1353+
],
1354+
);
1355+
}
1356+
13141357
if let Some(info) = cpuid.get_processor_topology_info() {
13151358
print_title(&skin, "Processor Topology Info (0x8000_001e):");
13161359
table2(

src/extended.rs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,109 @@ bitflags! {
15761576
}
15771577
}
15781578

1579+
/// Performance Optimization Identifier (LEAF=0x8000_001A).
1580+
///
1581+
/// # Platforms
1582+
/// ✅ AMD ❌ Intel
1583+
#[derive(PartialEq, Eq, Debug)]
1584+
pub struct InstructionBasedSamplingCapabilities {
1585+
eax: InstructionBasedSamplingCapabilitiesEax,
1586+
/// Reserved
1587+
_ebx: u32,
1588+
/// Reserved
1589+
_ecx: u32,
1590+
/// Reserved
1591+
_edx: u32,
1592+
}
1593+
1594+
impl InstructionBasedSamplingCapabilities {
1595+
pub(crate) fn new(data: CpuIdResult) -> Self {
1596+
Self {
1597+
eax: InstructionBasedSamplingCapabilitiesEax::from_bits_truncate(data.eax),
1598+
_ebx: data.ebx,
1599+
_ecx: data.ecx,
1600+
_edx: data.edx,
1601+
}
1602+
}
1603+
1604+
/// IBS feature flags valid if set.
1605+
pub fn has_feature_flags(&self) -> bool {
1606+
self.eax
1607+
.contains(InstructionBasedSamplingCapabilitiesEax::IBSFFV)
1608+
}
1609+
1610+
/// IBS fetch sampling supported if set.
1611+
pub fn has_fetch_sampling(&self) -> bool {
1612+
self.eax
1613+
.contains(InstructionBasedSamplingCapabilitiesEax::FETCH_SAM)
1614+
}
1615+
1616+
/// IBS execution sampling supported if set.
1617+
pub fn has_execution_sampling(&self) -> bool {
1618+
self.eax
1619+
.contains(InstructionBasedSamplingCapabilitiesEax::OP_SAM)
1620+
}
1621+
1622+
/// Read write of op counter supported if set.
1623+
pub fn has_read_write_operation_counter(&self) -> bool {
1624+
self.eax
1625+
.contains(InstructionBasedSamplingCapabilitiesEax::RD_WR_OP_CNT)
1626+
}
1627+
1628+
/// Op counting mode supported if set.
1629+
pub fn has_operation_counter(&self) -> bool {
1630+
self.eax
1631+
.contains(InstructionBasedSamplingCapabilitiesEax::OP_CNT)
1632+
}
1633+
1634+
/// Branch target address reporting supported if set.
1635+
pub fn has_branch_target_address_reporting(&self) -> bool {
1636+
self.eax
1637+
.contains(InstructionBasedSamplingCapabilitiesEax::BRN_TRGT)
1638+
}
1639+
1640+
/// IbsOpCurCnt and IbsOpMaxCnt extend by 7 bits if set.
1641+
pub fn has_operation_counter_extended(&self) -> bool {
1642+
self.eax
1643+
.contains(InstructionBasedSamplingCapabilitiesEax::OP_CNT_EXT)
1644+
}
1645+
1646+
/// Invalid RIP indication supported if set.
1647+
pub fn has_invalid_rip_indication(&self) -> bool {
1648+
self.eax
1649+
.contains(InstructionBasedSamplingCapabilitiesEax::RIP_INVALID_CHK)
1650+
}
1651+
1652+
/// Fused branch micro-op indication supported if set.
1653+
pub fn has_fused_branch_micro_op_indication(&self) -> bool {
1654+
self.eax
1655+
.contains(InstructionBasedSamplingCapabilitiesEax::OP_BRN_FUSE)
1656+
}
1657+
1658+
/// L3 Miss Filtering for IBS supported if set.
1659+
pub fn has_l3_miss_filtering(&self) -> bool {
1660+
self.eax
1661+
.contains(InstructionBasedSamplingCapabilitiesEax::IBS_L3_MISS_FILTERING)
1662+
}
1663+
}
1664+
1665+
bitflags! {
1666+
#[repr(transparent)]
1667+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1668+
struct InstructionBasedSamplingCapabilitiesEax: u32 {
1669+
const IBSFFV = 1 << 0;
1670+
const FETCH_SAM = 1 << 1;
1671+
const OP_SAM = 1 << 2;
1672+
const RD_WR_OP_CNT = 1 << 3;
1673+
const OP_CNT = 1 << 4;
1674+
const BRN_TRGT = 1 << 5;
1675+
const OP_CNT_EXT = 1 << 6;
1676+
const RIP_INVALID_CHK = 1 << 7;
1677+
const OP_BRN_FUSE = 1 << 8;
1678+
const IBS_L3_MISS_FILTERING = 1 << 11;
1679+
}
1680+
}
1681+
15791682
/// Processor Topology Information (LEAF=0x8000_001E).
15801683
///
15811684
/// # Platforms

src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ const EAX_ADVANCED_POWER_MGMT_INFO: u32 = 0x8000_0007;
319319
const EAX_PROCESSOR_CAPACITY_INFO: u32 = 0x8000_0008;
320320
const EAX_TLB_1GB_PAGE_INFO: u32 = 0x8000_0019;
321321
const EAX_PERFORMANCE_OPTIMIZATION_INFO: u32 = 0x8000_001A;
322+
const EAX_INSTRUCTION_BASED_SAMPLING_CAPABILITIES: u32 = 0x8000_001B;
322323
const EAX_CACHE_PARAMETERS_AMD: u32 = 0x8000_001D;
323324
const EAX_PROCESSOR_TOPOLOGY_INFO: u32 = 0x8000_001E;
324325
const EAX_MEMORY_ENCRYPTION_INFO: u32 = 0x8000_001F;
@@ -934,6 +935,23 @@ impl<R: CpuIdReader> CpuId<R> {
934935
}
935936
}
936937

938+
/// Instruction-Based Sampling Capabilities (LEAF=0x8000_001B)
939+
///
940+
/// # Platforms
941+
/// ✅ AMD ❌ Intel (reserved)
942+
pub fn get_instruction_based_sampling_capabilities(
943+
&self,
944+
) -> Option<InstructionBasedSamplingCapabilities> {
945+
if self.leaf_is_supported(EAX_INSTRUCTION_BASED_SAMPLING_CAPABILITIES) {
946+
Some(InstructionBasedSamplingCapabilities::new(
947+
self.read
948+
.cpuid1(EAX_INSTRUCTION_BASED_SAMPLING_CAPABILITIES),
949+
))
950+
} else {
951+
None
952+
}
953+
}
954+
937955
/// Informations about processor topology (LEAF=0x8000_001E)
938956
///
939957
/// # Platforms

src/tests/ryzen_matisse.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,25 @@ fn performance_optimization_info() {
12431243
assert!(e.has_fp256());
12441244
}
12451245

1246+
#[test]
1247+
fn instruction_based_sampling_capabilities() {
1248+
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
1249+
let e = cpuid
1250+
.get_instruction_based_sampling_capabilities()
1251+
.expect("Leaf is supported");
1252+
1253+
assert!(e.has_feature_flags());
1254+
assert!(e.has_fetch_sampling());
1255+
assert!(e.has_execution_sampling());
1256+
assert!(e.has_read_write_operation_counter());
1257+
assert!(e.has_operation_counter());
1258+
assert!(e.has_branch_target_address_reporting());
1259+
assert!(e.has_operation_counter_extended());
1260+
assert!(e.has_invalid_rip_indication());
1261+
assert!(e.has_fused_branch_micro_op_indication());
1262+
assert!(!e.has_l3_miss_filtering());
1263+
}
1264+
12461265
#[test]
12471266
fn processor_topology_info() {
12481267
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);

0 commit comments

Comments
 (0)