Commit 7ebf8eff authored by Zhang Rui's avatar Zhang Rui Committed by Rafael J. Wysocki

intel_rapl: introduce struct rapl_if_private

Introduce a new structure, rapl_if_private, to save the private data
for different RAPL Interface.
Reviewed-by: default avatarPandruvada, Srinivas <srinivas.pandruvada@intel.com>
Tested-by: default avatarPandruvada, Srinivas <srinivas.pandruvada@intel.com>
Signed-off-by: default avatarZhang Rui <rui.zhang@intel.com>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent ff956826
...@@ -75,6 +75,9 @@ enum unit_type { ...@@ -75,6 +75,9 @@ enum unit_type {
TIME_UNIT, TIME_UNIT,
}; };
/* private data for RAPL MSR Interface */
static struct rapl_if_priv rapl_msr_priv;
/* per domain data, some are optional */ /* per domain data, some are optional */
#define NR_RAW_PRIMITIVES (NR_RAPL_PRIMITIVES - 2) #define NR_RAW_PRIMITIVES (NR_RAPL_PRIMITIVES - 2)
...@@ -155,17 +158,14 @@ static const char * const rapl_domain_names[] = { ...@@ -155,17 +158,14 @@ static const char * const rapl_domain_names[] = {
"psys", "psys",
}; };
static struct powercap_control_type *control_type; /* PowerCap Controller */
static struct rapl_domain *platform_rapl_domain; /* Platform (PSys) domain */
/* caller to ensure CPU hotplug lock is held */ /* caller to ensure CPU hotplug lock is held */
static struct rapl_package *rapl_find_package_domain(int cpu) static struct rapl_package *rapl_find_package_domain(int cpu, struct rapl_if_priv *priv)
{ {
int id = topology_logical_die_id(cpu); int id = topology_logical_die_id(cpu);
struct rapl_package *rp; struct rapl_package *rp;
list_for_each_entry(rp, &rapl_packages, plist) { list_for_each_entry(rp, &rapl_packages, plist) {
if (rp->id == id) if (rp->id == id && rp->priv->control_type == priv->control_type)
return rp; return rp;
} }
...@@ -1090,12 +1090,12 @@ static void rapl_update_domain_data(struct rapl_package *rp) ...@@ -1090,12 +1090,12 @@ static void rapl_update_domain_data(struct rapl_package *rp)
static void rapl_unregister_powercap(void) static void rapl_unregister_powercap(void)
{ {
if (platform_rapl_domain) { if (&rapl_msr_priv.platform_rapl_domain) {
powercap_unregister_zone(control_type, powercap_unregister_zone(rapl_msr_priv.control_type,
&platform_rapl_domain->power_zone); &rapl_msr_priv.platform_rapl_domain->power_zone);
kfree(platform_rapl_domain); kfree(rapl_msr_priv.platform_rapl_domain);
} }
powercap_unregister_control_type(control_type); powercap_unregister_control_type(rapl_msr_priv.control_type);
} }
static int rapl_package_register_powercap(struct rapl_package *rp) static int rapl_package_register_powercap(struct rapl_package *rp)
...@@ -1113,7 +1113,7 @@ static int rapl_package_register_powercap(struct rapl_package *rp) ...@@ -1113,7 +1113,7 @@ static int rapl_package_register_powercap(struct rapl_package *rp)
nr_pl = find_nr_power_limit(rd); nr_pl = find_nr_power_limit(rd);
pr_debug("register package domain %s\n", rp->name); pr_debug("register package domain %s\n", rp->name);
power_zone = powercap_register_zone(&rd->power_zone, power_zone = powercap_register_zone(&rd->power_zone,
control_type, rp->priv->control_type,
rp->name, NULL, rp->name, NULL,
&zone_ops[rd->id], &zone_ops[rd->id],
nr_pl, nr_pl,
...@@ -1140,7 +1140,7 @@ static int rapl_package_register_powercap(struct rapl_package *rp) ...@@ -1140,7 +1140,7 @@ static int rapl_package_register_powercap(struct rapl_package *rp)
/* number of power limits per domain varies */ /* number of power limits per domain varies */
nr_pl = find_nr_power_limit(rd); nr_pl = find_nr_power_limit(rd);
power_zone = powercap_register_zone(&rd->power_zone, power_zone = powercap_register_zone(&rd->power_zone,
control_type, rd->name, rp->priv->control_type, rd->name,
rp->power_zone, rp->power_zone,
&zone_ops[rd->id], nr_pl, &zone_ops[rd->id], nr_pl,
&constraint_ops); &constraint_ops);
...@@ -1161,7 +1161,7 @@ static int rapl_package_register_powercap(struct rapl_package *rp) ...@@ -1161,7 +1161,7 @@ static int rapl_package_register_powercap(struct rapl_package *rp)
*/ */
while (--rd >= rp->domains) { while (--rd >= rp->domains) {
pr_debug("unregister %s domain %s\n", rp->name, rd->name); pr_debug("unregister %s domain %s\n", rp->name, rd->name);
powercap_unregister_zone(control_type, &rd->power_zone); powercap_unregister_zone(rp->priv->control_type, &rd->power_zone);
} }
return ret; return ret;
...@@ -1191,9 +1191,9 @@ static int __init rapl_register_psys(void) ...@@ -1191,9 +1191,9 @@ static int __init rapl_register_psys(void)
rd->rpl[0].name = pl1_name; rd->rpl[0].name = pl1_name;
rd->rpl[1].prim_id = PL2_ENABLE; rd->rpl[1].prim_id = PL2_ENABLE;
rd->rpl[1].name = pl2_name; rd->rpl[1].name = pl2_name;
rd->rp = rapl_find_package_domain(0); rd->rp = rapl_find_package_domain(0, &rapl_msr_priv);
power_zone = powercap_register_zone(&rd->power_zone, control_type, power_zone = powercap_register_zone(&rd->power_zone, rapl_msr_priv.control_type,
"psys", NULL, "psys", NULL,
&zone_ops[RAPL_DOMAIN_PLATFORM], &zone_ops[RAPL_DOMAIN_PLATFORM],
2, &constraint_ops); 2, &constraint_ops);
...@@ -1203,17 +1203,17 @@ static int __init rapl_register_psys(void) ...@@ -1203,17 +1203,17 @@ static int __init rapl_register_psys(void)
return PTR_ERR(power_zone); return PTR_ERR(power_zone);
} }
platform_rapl_domain = rd; rapl_msr_priv.platform_rapl_domain = rd;
return 0; return 0;
} }
static int __init rapl_register_powercap(void) static int __init rapl_register_powercap(void)
{ {
control_type = powercap_register_control_type(NULL, "intel-rapl", NULL); rapl_msr_priv.control_type = powercap_register_control_type(NULL, "intel-rapl", NULL);
if (IS_ERR(control_type)) { if (IS_ERR(rapl_msr_priv.control_type)) {
pr_debug("failed to register powercap control_type.\n"); pr_debug("failed to register powercap control_type.\n");
return PTR_ERR(control_type); return PTR_ERR(rapl_msr_priv.control_type);
} }
return 0; return 0;
} }
...@@ -1338,16 +1338,16 @@ static void rapl_remove_package(struct rapl_package *rp) ...@@ -1338,16 +1338,16 @@ static void rapl_remove_package(struct rapl_package *rp)
} }
pr_debug("remove package, undo power limit on %s: %s\n", pr_debug("remove package, undo power limit on %s: %s\n",
rp->name, rd->name); rp->name, rd->name);
powercap_unregister_zone(control_type, &rd->power_zone); powercap_unregister_zone(rp->priv->control_type, &rd->power_zone);
} }
/* do parent zone last */ /* do parent zone last */
powercap_unregister_zone(control_type, &rd_package->power_zone); powercap_unregister_zone(rp->priv->control_type, &rd_package->power_zone);
list_del(&rp->plist); list_del(&rp->plist);
kfree(rp); kfree(rp);
} }
/* called from CPU hotplug notifier, hotplug lock held */ /* called from CPU hotplug notifier, hotplug lock held */
static struct rapl_package *rapl_add_package(int cpu) static struct rapl_package *rapl_add_package(int cpu, struct rapl_if_priv *priv)
{ {
int id = topology_logical_die_id(cpu); int id = topology_logical_die_id(cpu);
struct rapl_package *rp; struct rapl_package *rp;
...@@ -1361,6 +1361,7 @@ static struct rapl_package *rapl_add_package(int cpu) ...@@ -1361,6 +1361,7 @@ static struct rapl_package *rapl_add_package(int cpu)
/* add the new package to the list */ /* add the new package to the list */
rp->id = id; rp->id = id;
rp->lead_cpu = cpu; rp->lead_cpu = cpu;
rp->priv = priv;
if (topology_max_die_per_package() > 1) if (topology_max_die_per_package() > 1)
snprintf(rp->name, PACKAGE_DOMAIN_NAME_LENGTH, snprintf(rp->name, PACKAGE_DOMAIN_NAME_LENGTH,
...@@ -1399,9 +1400,9 @@ static int rapl_cpu_online(unsigned int cpu) ...@@ -1399,9 +1400,9 @@ static int rapl_cpu_online(unsigned int cpu)
{ {
struct rapl_package *rp; struct rapl_package *rp;
rp = rapl_find_package_domain(cpu); rp = rapl_find_package_domain(cpu, &rapl_msr_priv);
if (!rp) { if (!rp) {
rp = rapl_add_package(cpu); rp = rapl_add_package(cpu, &rapl_msr_priv);
if (IS_ERR(rp)) if (IS_ERR(rp))
return PTR_ERR(rp); return PTR_ERR(rp);
} }
...@@ -1414,7 +1415,7 @@ static int rapl_cpu_down_prep(unsigned int cpu) ...@@ -1414,7 +1415,7 @@ static int rapl_cpu_down_prep(unsigned int cpu)
struct rapl_package *rp; struct rapl_package *rp;
int lead_cpu; int lead_cpu;
rp = rapl_find_package_domain(cpu); rp = rapl_find_package_domain(cpu, &rapl_msr_priv);
if (!rp) if (!rp)
return 0; return 0;
...@@ -1427,8 +1428,6 @@ static int rapl_cpu_down_prep(unsigned int cpu) ...@@ -1427,8 +1428,6 @@ static int rapl_cpu_down_prep(unsigned int cpu)
return 0; return 0;
} }
static enum cpuhp_state pcap_rapl_online;
static void power_limit_state_save(void) static void power_limit_state_save(void)
{ {
struct rapl_package *rp; struct rapl_package *rp;
...@@ -1538,7 +1537,7 @@ static int __init rapl_init(void) ...@@ -1538,7 +1537,7 @@ static int __init rapl_init(void)
rapl_cpu_online, rapl_cpu_down_prep); rapl_cpu_online, rapl_cpu_down_prep);
if (ret < 0) if (ret < 0)
goto err_unreg; goto err_unreg;
pcap_rapl_online = ret; rapl_msr_priv.pcap_rapl_online = ret;
/* Don't bail out if PSys is not supported */ /* Don't bail out if PSys is not supported */
rapl_register_psys(); rapl_register_psys();
...@@ -1550,7 +1549,7 @@ static int __init rapl_init(void) ...@@ -1550,7 +1549,7 @@ static int __init rapl_init(void)
return 0; return 0;
err_unreg_all: err_unreg_all:
cpuhp_remove_state(pcap_rapl_online); cpuhp_remove_state(rapl_msr_priv.pcap_rapl_online);
err_unreg: err_unreg:
rapl_unregister_powercap(); rapl_unregister_powercap();
...@@ -1560,7 +1559,7 @@ static int __init rapl_init(void) ...@@ -1560,7 +1559,7 @@ static int __init rapl_init(void)
static void __exit rapl_exit(void) static void __exit rapl_exit(void)
{ {
unregister_pm_notifier(&rapl_pm_notifier); unregister_pm_notifier(&rapl_pm_notifier);
cpuhp_remove_state(pcap_rapl_online); cpuhp_remove_state(rapl_msr_priv.pcap_rapl_online);
rapl_unregister_powercap(); rapl_unregister_powercap();
} }
......
...@@ -88,6 +88,20 @@ struct rapl_domain { ...@@ -88,6 +88,20 @@ struct rapl_domain {
struct rapl_package *rp; struct rapl_package *rp;
}; };
/**
* struct rapl_if_priv: private data for different RAPL interfaces
* @control_type: Each RAPL interface must have its own powercap
* control type.
* @platform_rapl_domain: Optional. Some RAPL interface may have platform
* level RAPL control.
* @pcap_rapl_online: CPU hotplug state for each RAPL interface.
*/
struct rapl_if_priv {
struct powercap_control_type *control_type;
struct rapl_domain *platform_rapl_domain;
enum cpuhp_state pcap_rapl_online;
};
/* maximum rapl package domain name: package-%d-die-%d */ /* maximum rapl package domain name: package-%d-die-%d */
#define PACKAGE_DOMAIN_NAME_LENGTH 30 #define PACKAGE_DOMAIN_NAME_LENGTH 30
...@@ -108,6 +122,7 @@ struct rapl_package { ...@@ -108,6 +122,7 @@ struct rapl_package {
/* Track active cpus */ /* Track active cpus */
struct cpumask cpumask; struct cpumask cpumask;
char name[PACKAGE_DOMAIN_NAME_LENGTH]; char name[PACKAGE_DOMAIN_NAME_LENGTH];
struct rapl_if_priv *priv;
}; };
#endif /* __INTEL_RAPL_H__ */ #endif /* __INTEL_RAPL_H__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment