Lines Matching full:rp

108 	int (*check_unit)(struct rapl_package *rp, int cpu);
110 u64 (*compute_time_window)(struct rapl_package *rp, u64 val,
146 static void rapl_init_domains(struct rapl_package *rp);
155 static void package_power_limit_irq_save(struct rapl_package *rp);
201 struct rapl_package *rp = rd->rp; in release_zone() local
208 rp->domains = NULL; in release_zone()
331 struct rapl_package *rp; in set_power_limit() local
343 rp = rd->rp; in set_power_limit()
366 package_power_limit_irq_save(rp); in set_power_limit()
549 static void rapl_init_domains(struct rapl_package *rp) in rapl_init_domains() argument
553 struct rapl_domain *rd = rp->domains; in rapl_init_domains()
556 unsigned int mask = rp->domain_map & (1 << i); in rapl_init_domains()
561 rd->rp = rp; in rapl_init_domains()
563 if (i == RAPL_DOMAIN_PLATFORM && rp->id > 0) { in rapl_init_domains()
565 topology_physical_package_id(rp->lead_cpu)); in rapl_init_domains()
578 if (rp->priv->limits[i] >= 2) { in rapl_init_domains()
584 if (rp->priv->limits[i] == 3) { in rapl_init_domains()
590 rd->regs[j] = rp->priv->regs[i][j]; in rapl_init_domains()
618 struct rapl_package *rp = rd->rp; in rapl_unit_xlate() local
623 units = rp->power_unit; in rapl_unit_xlate()
631 units = rp->energy_unit; in rapl_unit_xlate()
634 return rapl_defaults->compute_time_window(rp, value, to_raw); in rapl_unit_xlate()
750 struct rapl_primitive_info *rp = &rpi[prim_fixed]; in rapl_read_data_raw() local
754 if (!rp->name || rp->flag & RAPL_PRIMITIVE_DUMMY) in rapl_read_data_raw()
757 ra.reg = rd->regs[rp->id]; in rapl_read_data_raw()
761 cpu = rd->rp->lead_cpu; in rapl_read_data_raw()
764 if (prim == FW_LOCK && rd->rp->priv->limits[rd->id] == 2) { in rapl_read_data_raw()
765 rp->mask = POWER_HIGH_LOCK; in rapl_read_data_raw()
766 rp->shift = 63; in rapl_read_data_raw()
769 if (rp->flag & RAPL_PRIMITIVE_DERIVED) { in rapl_read_data_raw()
774 ra.mask = rp->mask; in rapl_read_data_raw()
776 if (rd->rp->priv->read_raw(cpu, &ra)) { in rapl_read_data_raw()
781 value = ra.value >> rp->shift; in rapl_read_data_raw()
784 *data = rapl_unit_xlate(rd, rp->unit, value, 0); in rapl_read_data_raw()
797 struct rapl_primitive_info *rp = &rpi[prim_fixed]; in rapl_write_data_raw() local
803 cpu = rd->rp->lead_cpu; in rapl_write_data_raw()
804 bits = rapl_unit_xlate(rd, rp->unit, value, 1); in rapl_write_data_raw()
805 bits <<= rp->shift; in rapl_write_data_raw()
806 bits &= rp->mask; in rapl_write_data_raw()
810 ra.reg = rd->regs[rp->id]; in rapl_write_data_raw()
811 ra.mask = rp->mask; in rapl_write_data_raw()
814 ret = rd->rp->priv->write_raw(cpu, &ra); in rapl_write_data_raw()
830 static int rapl_check_unit_core(struct rapl_package *rp, int cpu) in rapl_check_unit_core() argument
835 ra.reg = rp->priv->reg_unit; in rapl_check_unit_core()
837 if (rp->priv->read_raw(cpu, &ra)) { in rapl_check_unit_core()
839 rp->priv->reg_unit, cpu); in rapl_check_unit_core()
844 rp->energy_unit = ENERGY_UNIT_SCALE * 1000000 / (1 << value); in rapl_check_unit_core()
847 rp->power_unit = 1000000 / (1 << value); in rapl_check_unit_core()
850 rp->time_unit = 1000000 / (1 << value); in rapl_check_unit_core()
853 rp->name, rp->energy_unit, rp->time_unit, rp->power_unit); in rapl_check_unit_core()
858 static int rapl_check_unit_atom(struct rapl_package *rp, int cpu) in rapl_check_unit_atom() argument
863 ra.reg = rp->priv->reg_unit; in rapl_check_unit_atom()
865 if (rp->priv->read_raw(cpu, &ra)) { in rapl_check_unit_atom()
867 rp->priv->reg_unit, cpu); in rapl_check_unit_atom()
872 rp->energy_unit = ENERGY_UNIT_SCALE * 1 << value; in rapl_check_unit_atom()
875 rp->power_unit = (1 << value) * 1000; in rapl_check_unit_atom()
878 rp->time_unit = 1000000 / (1 << value); in rapl_check_unit_atom()
881 rp->name, rp->energy_unit, rp->time_unit, rp->power_unit); in rapl_check_unit_atom()
889 struct rapl_package *rp = (struct rapl_package *)info; in power_limit_irq_save_cpu() local
893 if (!(rp->power_limit_irq & PACKAGE_PLN_INT_SAVED)) { in power_limit_irq_save_cpu()
894 rp->power_limit_irq = l & PACKAGE_THERM_INT_PLN_ENABLE; in power_limit_irq_save_cpu()
895 rp->power_limit_irq |= PACKAGE_PLN_INT_SAVED; in power_limit_irq_save_cpu()
911 static void package_power_limit_irq_save(struct rapl_package *rp) in package_power_limit_irq_save() argument
916 smp_call_function_single(rp->lead_cpu, power_limit_irq_save_cpu, rp, 1); in package_power_limit_irq_save()
923 static void package_power_limit_irq_restore(struct rapl_package *rp) in package_power_limit_irq_restore() argument
931 if (!(rp->power_limit_irq & PACKAGE_PLN_INT_SAVED)) in package_power_limit_irq_restore()
936 if (rp->power_limit_irq & PACKAGE_THERM_INT_PLN_ENABLE) in package_power_limit_irq_restore()
983 static u64 rapl_compute_time_window_core(struct rapl_package *rp, u64 value, in rapl_compute_time_window_core() argument
995 value = (1 << y) * (4 + f) * rp->time_unit / 4; in rapl_compute_time_window_core()
997 if (value < rp->time_unit) in rapl_compute_time_window_core()
1000 do_div(value, rp->time_unit); in rapl_compute_time_window_core()
1008 static u64 rapl_compute_time_window_atom(struct rapl_package *rp, u64 value, in rapl_compute_time_window_atom() argument
1016 return (value) ? value * rp->time_unit : rp->time_unit; in rapl_compute_time_window_atom()
1018 value = div64_u64(value, rp->time_unit); in rapl_compute_time_window_atom()
1141 static void rapl_update_domain_data(struct rapl_package *rp) in rapl_update_domain_data() argument
1146 for (dmn = 0; dmn < rp->nr_domains; dmn++) { in rapl_update_domain_data()
1147 pr_debug("update %s domain %s data\n", rp->name, in rapl_update_domain_data()
1148 rp->domains[dmn].name); in rapl_update_domain_data()
1151 if (!rapl_read_data_raw(&rp->domains[dmn], prim, in rapl_update_domain_data()
1153 rp->domains[dmn].rdd.primitives[prim] = val; in rapl_update_domain_data()
1159 static int rapl_package_register_powercap(struct rapl_package *rp) in rapl_package_register_powercap() argument
1166 rapl_update_domain_data(rp); in rapl_package_register_powercap()
1169 for (rd = rp->domains; rd < rp->domains + rp->nr_domains; rd++) { in rapl_package_register_powercap()
1172 pr_debug("register package domain %s\n", rp->name); in rapl_package_register_powercap()
1174 rp->priv->control_type, rp->name, in rapl_package_register_powercap()
1179 rp->name); in rapl_package_register_powercap()
1183 rp->power_zone = power_zone; in rapl_package_register_powercap()
1193 for (rd = rp->domains; rd < rp->domains + rp->nr_domains; rd++) { in rapl_package_register_powercap()
1194 struct powercap_zone *parent = rp->power_zone; in rapl_package_register_powercap()
1203 rp->priv->control_type, in rapl_package_register_powercap()
1210 rp->name, rd->name); in rapl_package_register_powercap()
1222 while (--rd >= rp->domains) { in rapl_package_register_powercap()
1223 pr_debug("unregister %s domain %s\n", rp->name, rd->name); in rapl_package_register_powercap()
1224 powercap_unregister_zone(rp->priv->control_type, in rapl_package_register_powercap()
1231 static int rapl_check_domain(int cpu, int domain, struct rapl_package *rp) in rapl_check_domain() argument
1241 ra.reg = rp->priv->regs[domain][RAPL_DOMAIN_REG_STATUS]; in rapl_check_domain()
1252 if (rp->priv->read_raw(cpu, &ra) || !ra.value) in rapl_check_domain()
1276 rd->rp->name, rd->name); in rapl_detect_powerlimit()
1292 static int rapl_detect_domains(struct rapl_package *rp, int cpu) in rapl_detect_domains() argument
1299 if (!rapl_check_domain(cpu, i, rp)) { in rapl_detect_domains()
1300 rp->domain_map |= 1 << i; in rapl_detect_domains()
1304 rp->nr_domains = bitmap_weight(&rp->domain_map, RAPL_DOMAIN_MAX); in rapl_detect_domains()
1305 if (!rp->nr_domains) { in rapl_detect_domains()
1306 pr_debug("no valid rapl domains found in %s\n", rp->name); in rapl_detect_domains()
1309 pr_debug("found %d domains on %s\n", rp->nr_domains, rp->name); in rapl_detect_domains()
1311 rp->domains = kcalloc(rp->nr_domains + 1, sizeof(struct rapl_domain), in rapl_detect_domains()
1313 if (!rp->domains) in rapl_detect_domains()
1316 rapl_init_domains(rp); in rapl_detect_domains()
1318 for (rd = rp->domains; rd < rp->domains + rp->nr_domains; rd++) in rapl_detect_domains()
1325 void rapl_remove_package(struct rapl_package *rp) in rapl_remove_package() argument
1329 package_power_limit_irq_restore(rp); in rapl_remove_package()
1331 for (rd = rp->domains; rd < rp->domains + rp->nr_domains; rd++) { in rapl_remove_package()
1344 rp->name, rd->name); in rapl_remove_package()
1345 powercap_unregister_zone(rp->priv->control_type, in rapl_remove_package()
1349 powercap_unregister_zone(rp->priv->control_type, in rapl_remove_package()
1351 list_del(&rp->plist); in rapl_remove_package()
1352 kfree(rp); in rapl_remove_package()
1360 struct rapl_package *rp; in rapl_find_package_domain() local
1362 list_for_each_entry(rp, &rapl_packages, plist) { in rapl_find_package_domain()
1363 if (rp->id == id in rapl_find_package_domain()
1364 && rp->priv->control_type == priv->control_type) in rapl_find_package_domain()
1365 return rp; in rapl_find_package_domain()
1376 struct rapl_package *rp; in rapl_add_package() local
1382 rp = kzalloc(sizeof(struct rapl_package), GFP_KERNEL); in rapl_add_package()
1383 if (!rp) in rapl_add_package()
1387 rp->id = id; in rapl_add_package()
1388 rp->lead_cpu = cpu; in rapl_add_package()
1389 rp->priv = priv; in rapl_add_package()
1392 snprintf(rp->name, PACKAGE_DOMAIN_NAME_LENGTH, in rapl_add_package()
1396 snprintf(rp->name, PACKAGE_DOMAIN_NAME_LENGTH, "package-%d", in rapl_add_package()
1400 if (rapl_detect_domains(rp, cpu) || rapl_defaults->check_unit(rp, cpu)) { in rapl_add_package()
1404 ret = rapl_package_register_powercap(rp); in rapl_add_package()
1406 INIT_LIST_HEAD(&rp->plist); in rapl_add_package()
1407 list_add(&rp->plist, &rapl_packages); in rapl_add_package()
1408 return rp; in rapl_add_package()
1412 kfree(rp->domains); in rapl_add_package()
1413 kfree(rp); in rapl_add_package()
1420 struct rapl_package *rp; in power_limit_state_save() local
1425 list_for_each_entry(rp, &rapl_packages, plist) { in power_limit_state_save()
1426 if (!rp->power_zone) in power_limit_state_save()
1428 rd = power_zone_to_rapl_domain(rp->power_zone); in power_limit_state_save()
1461 struct rapl_package *rp; in power_limit_state_restore() local
1466 list_for_each_entry(rp, &rapl_packages, plist) { in power_limit_state_restore()
1467 if (!rp->power_zone) in power_limit_state_restore()
1469 rd = power_zone_to_rapl_domain(rp->power_zone); in power_limit_state_restore()