Skip to content

Commit c7cd6f0

Browse files
spandruvadarafaeljw
authored andcommitted
powercap: idle_inject: Support 100% idle injection
The users of the idle injection framework allow 100% idle injection. For example: thermal/cpuidle_cooling.c driver. When the ratio is set to 100%, the runtime_duration becomes zero. However, idle_inject_set_duration() in the idle injection framework silently ignores run_duration_us == 0 without any error (it is a void function). The caller will then assume that everything is fine and 100% idle is effective, but in reality the idle duration will not change. There are two options: - The caller may change their max state to 99% instead of 100% and document that 100% is not supported by the idle inject framework. - Add 100% idle support to the idle inject framework. Since there are other protections via RT throttling, this framework can allow 100% idle. The RT throttling will be activated at 95% idle by default. The caller disabling RT throttling and injecting 100% idle, should be aware that CPU can't be used at all. The idle inject timer is started for (run_duration_us + idle_duration_us) duration. Hence replace (run_duration_us && idle_duration_us) with (run_duration_us + idle_duration_us) in the function idle_inject_set_duration(). Also check for !(run_duration_us + idle_duration_us) to return -EINVAL in idle_inject_start(). Signed-off-by: Srinivas Pandruvada <[email protected]> Acked-by: Daniel Lezcano <[email protected]> [ rjw: Changelog edits ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 7adc688 commit c7cd6f0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/powercap/idle_inject.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,12 @@ void idle_inject_set_duration(struct idle_inject_device *ii_dev,
155155
unsigned int run_duration_us,
156156
unsigned int idle_duration_us)
157157
{
158-
if (run_duration_us && idle_duration_us) {
158+
if (run_duration_us + idle_duration_us) {
159159
WRITE_ONCE(ii_dev->run_duration_us, run_duration_us);
160160
WRITE_ONCE(ii_dev->idle_duration_us, idle_duration_us);
161161
}
162+
if (!run_duration_us)
163+
pr_debug("CPU is forced to 100 percent idle\n");
162164
}
163165

164166
/**
@@ -201,7 +203,7 @@ int idle_inject_start(struct idle_inject_device *ii_dev)
201203
unsigned int idle_duration_us = READ_ONCE(ii_dev->idle_duration_us);
202204
unsigned int run_duration_us = READ_ONCE(ii_dev->run_duration_us);
203205

204-
if (!idle_duration_us || !run_duration_us)
206+
if (!(idle_duration_us + run_duration_us))
205207
return -EINVAL;
206208

207209
pr_debug("Starting injecting idle cycles on CPUs '%*pbl'\n",

0 commit comments

Comments
 (0)