Skip to content

Commit 4dcb78e

Browse files
committed
intel_idle: Introduce 'states_off' module parameter
In certain system configurations it may not be desirable to use some C-states assumed to be available by intel_idle and the driver needs to be prevented from using them even before the cpuidle sysfs interface becomes accessible to user space. Currently, the only way to achieve that is by setting the 'max_cstate' module parameter to a value lower than the index of the shallowest of the C-states in question, but that may be overly intrusive, because it effectively makes all of the idle states deeper than the 'max_cstate' one go away (and the C-state to avoid may be in the middle of the range normally regarded as available). To allow that limitation to be overcome, introduce a new module parameter called 'states_off' to represent a list of idle states to be disabled by default in the form of a bitmask and update the documentation to cover it. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 3a5be9b commit 4dcb78e

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

‎Documentation/admin-guide/pm/intel_idle.rst‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ and ``idle=nomwait``. If any of them is present in the kernel command line, the
168168
``MWAIT`` instruction is not allowed to be used, so the initialization of
169169
``intel_idle`` will fail.
170170

171-
Apart from that there are three module parameters recognized by ``intel_idle``
171+
Apart from that there are four module parameters recognized by ``intel_idle``
172172
itself that can be set via the kernel command line (they cannot be updated via
173173
sysfs, so that is the only way to change their values).
174174

@@ -195,6 +195,23 @@ driver ignore the system's ACPI tables entirely or use them for all of the
195195
recognized processor models, respectively (they both are unset by default and
196196
``use_acpi`` has no effect if ``no_acpi`` is set).
197197

198+
The value of the ``states_off`` module parameter (0 by default) represents a
199+
list of idle states to be disabled by default in the form of a bitmask.
200+
201+
Namely, the positions of the bits that are set in the ``states_off`` value are
202+
the indices of idle states to be disabled by default (as reflected by the names
203+
of the corresponding idle state directories in ``sysfs``, :file:`state0`,
204+
:file:`state1` ... :file:`state<i>` ..., where ``<i>`` is the index of the given
205+
idle state; see :ref:`idle-states-representation` in :doc:`cpuidle`).
206+
207+
For example, if ``states_off`` is equal to 3, the driver will disable idle
208+
states 0 and 1 by default, and if it is equal to 8, idle state 3 will be
209+
disabled by default and so on (bit positions beyond the maximum idle state index
210+
are ignored).
211+
212+
The idle states disabled this way can be enabled (on a per-CPU basis) from user
213+
space via ``sysfs``.
214+
198215

199216
.. _intel-idle-core-and-package-idle-states:
200217

‎drivers/idle/intel_idle.c‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ static struct cpuidle_driver intel_idle_driver = {
6363
};
6464
/* intel_idle.max_cstate=0 disables driver */
6565
static int max_cstate = CPUIDLE_STATE_MAX - 1;
66+
static unsigned int disabled_states_mask;
6667

6768
static unsigned int mwait_substates;
6869

@@ -1234,6 +1235,9 @@ static void __init intel_idle_init_cstates_acpi(struct cpuidle_driver *drv)
12341235
if (cx->type > ACPI_STATE_C2)
12351236
state->flags |= CPUIDLE_FLAG_TLB_FLUSHED;
12361237

1238+
if (disabled_states_mask & BIT(cstate))
1239+
state->flags |= CPUIDLE_FLAG_OFF;
1240+
12371241
state->enter = intel_idle;
12381242
state->enter_s2idle = intel_idle_s2idle;
12391243
}
@@ -1466,9 +1470,10 @@ static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
14661470
/* Structure copy. */
14671471
drv->states[drv->state_count] = cpuidle_state_table[cstate];
14681472

1469-
if ((icpu->use_acpi || force_use_acpi) &&
1470-
intel_idle_off_by_default(mwait_hint) &&
1471-
!(cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_ALWAYS_ENABLE))
1473+
if ((disabled_states_mask & BIT(drv->state_count)) ||
1474+
((icpu->use_acpi || force_use_acpi) &&
1475+
intel_idle_off_by_default(mwait_hint) &&
1476+
!(cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_ALWAYS_ENABLE)))
14721477
drv->states[drv->state_count].flags |= CPUIDLE_FLAG_OFF;
14731478

14741479
drv->state_count++;
@@ -1487,6 +1492,10 @@ static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
14871492
static void __init intel_idle_cpuidle_driver_init(struct cpuidle_driver *drv)
14881493
{
14891494
cpuidle_poll_state_init(drv);
1495+
1496+
if (disabled_states_mask & BIT(0))
1497+
drv->states[0].flags |= CPUIDLE_FLAG_OFF;
1498+
14901499
drv->state_count = 1;
14911500

14921501
if (icpu)
@@ -1667,3 +1676,11 @@ device_initcall(intel_idle_init);
16671676
* is the easiest way (currently) to continue doing that.
16681677
*/
16691678
module_param(max_cstate, int, 0444);
1679+
/*
1680+
* The positions of the bits that are set in this number are the indices of the
1681+
* idle states to be disabled by default (as reflected by the names of the
1682+
* corresponding idle state directories in sysfs, "state0", "state1" ...
1683+
* "state<i>" ..., where <i> is the index of the given state).
1684+
*/
1685+
module_param_named(states_off, disabled_states_mask, uint, 0444);
1686+
MODULE_PARM_DESC(states_off, "Mask of disabled idle states");

0 commit comments

Comments
 (0)