Index: sys/dev/iommu/iommu_gas.c =================================================================== --- sys/dev/iommu/iommu_gas.c +++ sys/dev/iommu/iommu_gas.c @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -372,12 +373,19 @@ a->entry->flags = IOMMU_MAP_ENTRY_MAP; } +static COUNTER_U64_DEFINE_EARLY(gas_lookup); +SYSCTL_COUNTER_U64(_hw_iommu, OID_AUTO, gas_lookup, CTLFLAG_RD, + &gas_lookup, + "Number of gas node accesses"); + static int iommu_gas_lowermatch(struct iommu_gas_match_args *a, struct iommu_map_entry *entry) { struct iommu_map_entry *child; child = RB_RIGHT(entry, rb_entry); + if (child != NULL && entry->end < a->common->lowaddr) + counter_u64_add(gas_lookup, 1); if (child != NULL && entry->end < a->common->lowaddr && iommu_gas_match_one(a, entry->end, child->first, a->common->lowaddr)) { @@ -389,6 +397,8 @@ if (entry->first >= a->common->lowaddr) return (ENOMEM); child = RB_LEFT(entry, rb_entry); + if (child != NULL) + counter_u64_add(gas_lookup, 1); if (child != NULL && 0 == iommu_gas_lowermatch(a, child)) return (0); if (child != NULL && child->last < a->common->lowaddr && @@ -398,6 +408,8 @@ return (0); } child = RB_RIGHT(entry, rb_entry); + if (child != NULL && entry->end >= a->common->lowaddr) + counter_u64_add(gas_lookup, 1); if (child != NULL && 0 == iommu_gas_lowermatch(a, child)) return (0); return (ENOMEM); @@ -413,6 +425,8 @@ if (entry->last < a->common->highaddr) return (ENOMEM); child = RB_LEFT(entry, rb_entry); + if (child != NULL) + counter_u64_add(gas_lookup, 1); if (child != NULL && 0 == iommu_gas_uppermatch(a, child)) return (0); if (child != NULL && child->last >= a->common->highaddr && @@ -422,6 +436,8 @@ return (0); } child = RB_RIGHT(entry, rb_entry); + if (child != NULL) + counter_u64_add(gas_lookup, 1); if (child != NULL && entry->end >= a->common->highaddr && iommu_gas_match_one(a, entry->end, child->first, a->domain->end)) { @@ -453,6 +469,8 @@ a.entry = entry; /* Handle lower region. */ + if (common->lowaddr > 0 ||common->highaddr < domain->end) + counter_u64_add(gas_lookup, 1); if (common->lowaddr > 0) { error = iommu_gas_lowermatch(&a, RB_ROOT(&domain->rb_root));