Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powercap / RAPL: further relax energy counter checks

Energy counters may roll slowly for some RAPL domains, checking all
of them can be time consuming and takes unpredictable amount of time.
Therefore, we relax the sanity check by only checking availability of the
MSRs and non-zero value of the energy status counters. It has been shown
sufficient for all the platforms tested to filter out inactive domains.

Signed-off-by: Jacob Pan <jacob.jun.pan@linux.intel.com>
Acked-by: Durgadoss R <durgadoss.r@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Jacob Pan and committed by
Rafael J. Wysocki
9d31c676 d1db0eea

+9 -20
+9 -20
drivers/powercap/intel_rapl.c
··· 1124 1124 static int rapl_check_domain(int cpu, int domain) 1125 1125 { 1126 1126 unsigned msr; 1127 - u64 val1, val2 = 0; 1128 - int retry = 0; 1127 + u64 val = 0; 1129 1128 1130 1129 switch (domain) { 1131 1130 case RAPL_DOMAIN_PACKAGE: ··· 1143 1144 pr_err("invalid domain id %d\n", domain); 1144 1145 return -EINVAL; 1145 1146 } 1146 - if (rdmsrl_safe_on_cpu(cpu, msr, &val1)) 1147 + /* make sure domain counters are available and contains non-zero 1148 + * values, otherwise skip it. 1149 + */ 1150 + if (rdmsrl_safe_on_cpu(cpu, msr, &val) || !val) 1147 1151 return -ENODEV; 1148 1152 1149 - /* PP1/uncore/graphics domain may not be active at the time of 1150 - * driver loading. So skip further checks. 1151 - */ 1152 - if (domain == RAPL_DOMAIN_PP1) 1153 - return 0; 1154 - /* energy counters roll slowly on some domains */ 1155 - while (++retry < 10) { 1156 - usleep_range(10000, 15000); 1157 - rdmsrl_safe_on_cpu(cpu, msr, &val2); 1158 - if ((val1 & ENERGY_STATUS_MASK) != (val2 & ENERGY_STATUS_MASK)) 1159 - return 0; 1160 - } 1161 - /* if energy counter does not change, report as bad domain */ 1162 - pr_info("domain %s energy ctr %llu:%llu not working, skip\n", 1163 - rapl_domain_names[domain], val1, val2); 1164 - 1165 - return -ENODEV; 1153 + return 0; 1166 1154 } 1167 1155 1168 1156 /* Detect active and valid domains for the given CPU, caller must ··· 1166 1180 /* use physical package id to read counters */ 1167 1181 if (!rapl_check_domain(cpu, i)) 1168 1182 rp->domain_map |= 1 << i; 1183 + else 1184 + pr_warn("RAPL domain %s detection failed\n", 1185 + rapl_domain_names[i]); 1169 1186 } 1170 1187 rp->nr_domains = bitmap_weight(&rp->domain_map, RAPL_DOMAIN_MAX); 1171 1188 if (!rp->nr_domains) {