Skip to contentSkip to conversation

firmware: arm_scmi: add a getter for power of performance states

PATCH Superseded Quentin Perret 2 participants 5 messages Sep 3, 2018 – Sep 10, 2018 System control & power/management interface (SCPI/SCMI) Message Protocol drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 firmware: arm_scmi: add a getter for power of performance states

The SCMI protocol can be used to get power estimates from firmware corresponding to each performance state of a device. Although these power costs are already managed by the SCMI firmware driver, they are not exposed to any external subsystem yet.

Fix this by adding a new get_power() interface to the exisiting perf_ops defined for the SCMI protocol.

---
v2: rebased on 4.19-rc2

---
 drivers/firmware/arm_scmi/perf.c | 28 ++++++++++++++++++++++++++++
 include/linux/scmi_protocol.h    |  4 ++++
 2 files changed, 32 insertions(+)
drivers/firmware/arm_scmi/perf.c +28 -0
index 721e6c57beae..272abd2cb3f0 100644
@@ -421,6 +421,33 @@ static int scmi_dvfs_freq_get(const struct scmi_handle *handle, u32 domain,
 	return ret;
 }
 
+static int scmi_dvfs_power_get(const struct scmi_handle *handle, u32 domain,
+			       unsigned long *freq, unsigned long *power)
+{
+	struct scmi_perf_info *pi = handle->perf_priv;
+	struct perf_dom_info *dom;
+	unsigned long opp_freq;
+	int idx, ret = -EINVAL;
+	struct scmi_opp *opp;
+
+	dom = pi->dom_info + domain;
+	if (!dom)
+		return -EIO;
+
+	for (opp = dom->opp, idx = 0; idx < dom->opp_count; idx++, opp++) {
+		opp_freq = opp->perf * dom->mult_factor;
+		if (opp_freq < *freq)
+			continue;
+
+		*freq = opp_freq;
+		*power = opp->power;
+		ret = 0;
+		break;
+	}
+
+	return ret;
+}
+
 static struct scmi_perf_ops perf_ops = {
 	.limits_set = scmi_perf_limits_set,
 	.limits_get = scmi_perf_limits_get,
@@ -431,6 +458,7 @@ static struct scmi_perf_ops perf_ops = {
 	.device_opps_add = scmi_dvfs_device_opps_add,
 	.freq_set = scmi_dvfs_freq_set,
 	.freq_get = scmi_dvfs_freq_get,
+	.power_get = scmi_dvfs_power_get,
 };
 
 static int scmi_perf_protocol_init(struct scmi_handle *handle)
include/linux/scmi_protocol.h +4 -0
index f4c9fc0fc755..2ecbd2c5a249 100644
@@ -91,6 +91,8 @@ struct scmi_clk_ops {
  *	to sustained performance level mapping
  * @freq_get: gets the frequency for a given device using sustained frequency
  *	to sustained performance level mapping
+ * @power_get: gets the power dissipated for a given performance domain at a
+ *      given frequency
  */
 struct scmi_perf_ops {
 	int (*limits_set)(const struct scmi_handle *handle, u32 domain,
@@ -110,6 +112,8 @@ struct scmi_perf_ops {
 			unsigned long rate, bool poll);
 	int (*freq_get)(const struct scmi_handle *handle, u32 domain,
 			unsigned long *rate, bool poll);
+	int (*power_get)(const struct scmi_handle *handle, u32 domain,
+			 unsigned long *rate, unsigned long *power);
 };
 
 /**
Signature · 1 line
2.17.1
#1 lore raw
Quoted 21 lines · Quentin Perret

The SCMI protocol can be used to get power estimates from firmware corresponding to each performance state of a device. Although these power costs are already managed by the SCMI firmware driver, they are not exposed to any external subsystem yet.

Fix this by adding a new get_power() interface to the exisiting perf_ops defined for the SCMI protocol.

---
v2: rebased on 4.19-rc2

---
 drivers/firmware/arm_scmi/perf.c | 28 ++++++++++++++++++++++++++++
 include/linux/scmi_protocol.h    |  4 ++++
 2 files changed, 32 insertions(+)
drivers/firmware/arm_scmi/perf.c +0 -0
index 721e6c57beae..272abd2cb3f0 100644

drivers/firmware/arm_scmi/perf.c static int scmi_dvfs_freq_get(const struct scmi_handle *handle, u32 domain, · line 425

Quoted 5 lines
drivers/firmware/arm_scmi/perf.c +2 -0
@@ -421,6 +421,33 @@ static int scmi_dvfs_freq_get(const struct scmi_handle *handle, u32 domain,
 	return ret;
 }
 
+static int scmi_dvfs_power_get(const struct scmi_handle *handle, u32 domain,
+			       unsigned long *freq, unsigned long *power)

I feel the name "power_get" gives me feeling that it refers to instant power than the computed value. At least in scmi interface, freq_get provides current value of running frequency. I am not sure of the consistency in the naming in other subsystems.

Does it makes sense to name it "scmi_dvfs_est_power_get" as it actually refers to estimated power cost ?

Quoted 29 lines
drivers/firmware/arm_scmi/perf.c +25 -0
+{
+	struct scmi_perf_info *pi = handle->perf_priv;
+	struct perf_dom_info *dom;
+	unsigned long opp_freq;
+	int idx, ret = -EINVAL;
+	struct scmi_opp *opp;
+
+	dom = pi->dom_info + domain;
+	if (!dom)
+		return -EIO;
+
+	for (opp = dom->opp, idx = 0; idx < dom->opp_count; idx++, opp++) {
+		opp_freq = opp->perf * dom->mult_factor;
+		if (opp_freq < *freq)
+			continue;
+
+		*freq = opp_freq;
+		*power = opp->power;
+		ret = 0;
+		break;
+	}
+
+	return ret;
+}
+
 static struct scmi_perf_ops perf_ops = {
 	.limits_set = scmi_perf_limits_set,
 	.limits_get = scmi_perf_limits_get,

drivers/firmware/arm_scmi/perf.c static struct scmi_perf_ops perf_ops = { · line 461

Quoted 4 lines
drivers/firmware/arm_scmi/perf.c +1 -0
@@ -431,6 +458,7 @@ static struct scmi_perf_ops perf_ops = {
 	.device_opps_add = scmi_dvfs_device_opps_add,
 	.freq_set = scmi_dvfs_freq_set,
 	.freq_get = scmi_dvfs_freq_get,
+	.power_get = scmi_dvfs_power_get,

same here s/.power_get/.est_power_get/

include/linux/scmi_protocol.h struct scmi_clk_ops { · line 94

Quoted 12 lines
drivers/firmware/arm_scmi/perf.c +0 -0
 };
 
 static int scmi_perf_protocol_init(struct scmi_handle *handle)
include/linux/scmi_protocol.h +1 -0
index f4c9fc0fc755..2ecbd2c5a249 100644
@@ -91,6 +91,8 @@ struct scmi_clk_ops {
  *	to sustained performance level mapping
  * @freq_get: gets the frequency for a given device using sustained frequency
  *	to sustained performance level mapping
+ * @power_get: gets the power dissipated for a given performance domain at a

s/power dissipated/estimated power cost/

--
Regards,
Sudeep

#2 lore raw
Quoted 25 lines · Sudeep Holla
Quoted 24 lines · Quentin Perret

The SCMI protocol can be used to get power estimates from firmware corresponding to each performance state of a device. Although these power costs are already managed by the SCMI firmware driver, they are not exposed to any external subsystem yet.

Fix this by adding a new get_power() interface to the exisiting perf_ops defined for the SCMI protocol.

---
v2: rebased on 4.19-rc2

---
 drivers/firmware/arm_scmi/perf.c | 28 ++++++++++++++++++++++++++++
 include/linux/scmi_protocol.h    |  4 ++++
 2 files changed, 32 insertions(+)
drivers/firmware/arm_scmi/perf.c +0 -0
index 721e6c57beae..272abd2cb3f0 100644
@@ -421,6 +421,33 @@ static int scmi_dvfs_freq_get(const struct scmi_handle *handle, u32 domain,
 	return ret;
 }
 
Quoted 7 lines

drivers/firmware/arm_scmi/perf.c static int scmi_dvfs_freq_get(const struct scmi_handle *handle, u32 domain, · line 425

Quoted 2 lines
drivers/firmware/arm_scmi/perf.c +2 -0
+static int scmi_dvfs_power_get(const struct scmi_handle *handle, u32 domain,
+			       unsigned long *freq, unsigned long *power)

I feel the name "power_get" gives me feeling that it refers to instant power than the computed value. At least in scmi interface, freq_get provides current value of running frequency. I am not sure of the consistency in the naming in other subsystems.

Right, I see your point.

Quoted 2 lines

Does it makes sense to name it "scmi_dvfs_est_power_get" as it actually refers to estimated power cost ?

"scmi_dvfs_est_power_get" sounds good to me.

Quoted 38 lines
Quoted 29 lines
drivers/firmware/arm_scmi/perf.c +25 -0
+{
+	struct scmi_perf_info *pi = handle->perf_priv;
+	struct perf_dom_info *dom;
+	unsigned long opp_freq;
+	int idx, ret = -EINVAL;
+	struct scmi_opp *opp;
+
+	dom = pi->dom_info + domain;
+	if (!dom)
+		return -EIO;
+
+	for (opp = dom->opp, idx = 0; idx < dom->opp_count; idx++, opp++) {
+		opp_freq = opp->perf * dom->mult_factor;
+		if (opp_freq < *freq)
+			continue;
+
+		*freq = opp_freq;
+		*power = opp->power;
+		ret = 0;
+		break;
+	}
+
+	return ret;
+}
+
 static struct scmi_perf_ops perf_ops = {
 	.limits_set = scmi_perf_limits_set,
 	.limits_get = scmi_perf_limits_get,

drivers/firmware/arm_scmi/perf.c static struct scmi_perf_ops perf_ops = { · line 461

Quoted 4 lines
drivers/firmware/arm_scmi/perf.c +1 -0
@@ -431,6 +458,7 @@ static struct scmi_perf_ops perf_ops = {
 	.device_opps_add = scmi_dvfs_device_opps_add,
 	.freq_set = scmi_dvfs_freq_set,
 	.freq_get = scmi_dvfs_freq_get,
+	.power_get = scmi_dvfs_power_get,

same here s/.power_get/.est_power_get/

Quoted 2 lines
drivers/firmware/arm_scmi/perf.c +0 -0
 };
 
Quoted 12 lines

include/linux/scmi_protocol.h struct scmi_clk_ops { · line 94

Quoted 10 lines
drivers/firmware/arm_scmi/perf.c +0 -0
 static int scmi_perf_protocol_init(struct scmi_handle *handle)
include/linux/scmi_protocol.h +1 -0
index f4c9fc0fc755..2ecbd2c5a249 100644
@@ -91,6 +91,8 @@ struct scmi_clk_ops {
  *	to sustained performance level mapping
  * @freq_get: gets the frequency for a given device using sustained frequency
  *	to sustained performance level mapping
+ * @power_get: gets the power dissipated for a given performance domain at a

s/power dissipated/estimated power cost/

Ack for the two remarks above.
I'll spin a v3 soon.

Thanks!
Quentin

#3 lore raw

PATCH v3 1/1 firmware: arm_scmi: add a getter for power of performance states

The SCMI protocol can be used to get power estimates from firmware corresponding to each performance state of a device. Although these power costs are already managed by the SCMI firmware driver, they are not exposed to any external subsystem yet.

Fix this by adding a new get_power() interface to the exisiting perf_ops defined for the SCMI protocol.

---
v3: Changed the accessor name to "scmi_dvfs_est_power_get"
v2: rebased on 4.19-rc2

---
 drivers/firmware/arm_scmi/perf.c | 28 ++++++++++++++++++++++++++++
 include/linux/scmi_protocol.h    |  4 ++++
 2 files changed, 32 insertions(+)
drivers/firmware/arm_scmi/perf.c +28 -0
index 721e6c57beae..3e6453b4ea1d 100644
@@ -421,6 +421,33 @@ static int scmi_dvfs_freq_get(const struct scmi_handle *handle, u32 domain,
 	return ret;
 }
 
+static int scmi_dvfs_est_power_get(const struct scmi_handle *handle, u32 domain,
+			       unsigned long *freq, unsigned long *power)
+{
+	struct scmi_perf_info *pi = handle->perf_priv;
+	struct perf_dom_info *dom;
+	unsigned long opp_freq;
+	int idx, ret = -EINVAL;
+	struct scmi_opp *opp;
+
+	dom = pi->dom_info + domain;
+	if (!dom)
+		return -EIO;
+
+	for (opp = dom->opp, idx = 0; idx < dom->opp_count; idx++, opp++) {
+		opp_freq = opp->perf * dom->mult_factor;
+		if (opp_freq < *freq)
+			continue;
+
+		*freq = opp_freq;
+		*power = opp->power;
+		ret = 0;
+		break;
+	}
+
+	return ret;
+}
+
 static struct scmi_perf_ops perf_ops = {
 	.limits_set = scmi_perf_limits_set,
 	.limits_get = scmi_perf_limits_get,
@@ -431,6 +458,7 @@ static struct scmi_perf_ops perf_ops = {
 	.device_opps_add = scmi_dvfs_device_opps_add,
 	.freq_set = scmi_dvfs_freq_set,
 	.freq_get = scmi_dvfs_freq_get,
+	.est_power_get = scmi_dvfs_est_power_get,
 };
 
 static int scmi_perf_protocol_init(struct scmi_handle *handle)
include/linux/scmi_protocol.h +4 -0
index f4c9fc0fc755..e4db899c1cfb 100644
@@ -91,6 +91,8 @@ struct scmi_clk_ops {
  *	to sustained performance level mapping
  * @freq_get: gets the frequency for a given device using sustained frequency
  *	to sustained performance level mapping
+ * @est_power_get: gets the estimated power cost for a given performance domain
+ *	at a given frequency
  */
 struct scmi_perf_ops {
 	int (*limits_set)(const struct scmi_handle *handle, u32 domain,
@@ -110,6 +112,8 @@ struct scmi_perf_ops {
 			unsigned long rate, bool poll);
 	int (*freq_get)(const struct scmi_handle *handle, u32 domain,
 			unsigned long *rate, bool poll);
+	int (*est_power_get)(const struct scmi_handle *handle, u32 domain,
+			 unsigned long *rate, unsigned long *power);
 };
 
 /**
Signature · 1 line
2.17.1
Applied
#4 lore raw
Quoted 8 lines · Quentin Perret

The SCMI protocol can be used to get power estimates from firmware corresponding to each performance state of a device. Although these power costs are already managed by the SCMI firmware driver, they are not exposed to any external subsystem yet.

Fix this by adding a new get_power() interface to the exisiting perf_ops defined for the SCMI protocol.

Thanks, applied.

Signature · 2 lines
Regards,
Sudeep