Re: [PATCH v6 04/10] PM / EM: add support for other devices than CPUs in Energy Model

From: Lukasz Luba
Date: Fri Apr 10 2020 - 07:35:37 EST




On 4/10/20 12:12 PM, Luis Gerhorst wrote:

Lukasz Luba writes:

+/**
+ * em_dev_unregister_perf_domain() - Unregister Energy Model (EM) for a device
+ * @devÂÂÂÂÂÂÂ : Device for which the EM is registered
+ *
+ * Try to unregister the EM for the specified device (it checks current
+ * reference counter). The EM for CPUs will not be freed.
+ */
+void em_dev_unregister_perf_domain(struct device *dev)
+{
+ÂÂÂ struct em_device *em_dev, *tmp;
+
+ÂÂÂ if (IS_ERR_OR_NULL(dev))
+ÂÂÂÂÂÂÂ return;
+
+ÂÂÂ /* We don't support freeing CPU structures in hotplug */
+ÂÂÂ if (_is_cpu_device(dev)) {
+ÂÂÂÂÂÂÂ dev_dbg_once(dev, "EM: the structures are not going to be removed\n");
+ÂÂÂÂÂÂÂ return;
+ÂÂÂ }
+
+ÂÂÂ mutex_lock(&em_pd_mutex);
+
+ÂÂÂ if (list_empty(&em_pd_dev_list)) {
+ÂÂÂÂÂÂÂ mutex_unlock(&em_pd_mutex);
+ÂÂÂÂÂÂÂ return;
+ÂÂÂ }
+
+ÂÂÂ list_for_each_entry_safe(em_dev, tmp, &em_pd_dev_list, em_dev_list) {
+ÂÂÂÂÂÂÂ if (em_dev->dev == dev) {
+ÂÂÂÂÂÂÂÂÂÂÂ kref_put(&em_dev->kref, _em_release);
+ÂÂÂÂÂÂÂÂÂÂÂ break;
+ÂÂÂÂÂÂÂ }
+ÂÂÂ }
+
+ÂÂÂ mutex_unlock(&em_pd_mutex);
+}
+EXPORT_SYMBOL_GPL(em_dev_unregister_perf_domain);

Ok, so em_dev_unregister_perf_domain() does not support the CPU device
and a subsequent em_register_perf_domain() will fail with EEXIST.

Correct. At the current mainline Energy Model we don't even have
em_unregister_perf_domain function. I had to introduce it in order
to support other devices which might have drivers loaded/unloaded
as modules.



Is there a way to unregister/change the CPU's energy model during
runtime without restarting the whole system?

Not for the CPU for now.

It is possible for other devices. When you have i.e. a module driver for
a device and in your code there is a (*active_power)(), then it is
possible to change EM by unloading/loading the module.

For the CPU we don't have this requirement for production code. I will
add you to CC list when something like this would pop-up for a
prototyping/experimentation code. We have been analyzing some options.

Regards,
Lukasz