13 Jan, 2021

1 commit


09 Jan, 2020

1 commit


11 Dec, 2019

1 commit

  • It turns out that cpuidle_driver_state_disabled() can be called
    before registering the cpufreq driver on some platforms, which
    was not expected when it was introduced and which leads to a NULL
    pointer dereference when trying to walk the CPUs associated with
    the given cpuidle driver.

    Fix the problem by making cpuidle_driver_state_disabled() check if
    the driver's mask of CPUs associated with it is present and to set
    CPUIDLE_FLAG_UNUSABLE for the given idle state in the driver's states
    list if that is not the case to cause __cpuidle_register_device() to
    set CPUIDLE_STATE_DISABLED_BY_DRIVER for that state for all cpuidle
    devices registered by it later.

    Fixes: cbda56d5fefc ("cpuidle: Introduce cpuidle_driver_state_disabled() for driver quirks")
    Reported-by: Daniel Lezcano
    Tested-by: Daniel Lezcano
    Signed-off-by: Rafael J. Wysocki

    Rafael J. Wysocki
     

19 Nov, 2019

1 commit

  • Commit 99e98d3fb100 ("cpuidle: Consolidate disabled state checks")
    overlooked the fact that the imx6q and tegra20 cpuidle drivers use
    the "disabled" field in struct cpuidle_state for quirks which trigger
    after the initialization of cpuidle, so reading the initial value of
    that field is not sufficient for those drivers.

    In order to allow them to implement the quirks without using the
    "disabled" field in struct cpuidle_state, introduce a new helper
    function and modify them to use it.

    Fixes: 99e98d3fb100 ("cpuidle: Consolidate disabled state checks")
    Reported-by: Len Brown
    Signed-off-by: Rafael J. Wysocki

    Rafael J. Wysocki
     

12 Nov, 2019

1 commit

  • Currently, the cpuidle subsystem uses microseconds as the unit of
    time which (among other things) causes the idle loop to incur some
    integer division overhead for no clear benefit.

    In order to allow cpuidle to measure time in nanoseconds, add two
    new fields, exit_latency_ns and target_residency_ns, to represent the
    exit latency and target residency of an idle state in nanoseconds,
    respectively, to struct cpuidle_state and initialize them with the
    help of the corresponding values in microseconds provided by drivers.
    Additionally, change cpuidle_governor_latency_req() to return the
    idle state exit latency constraint in nanoseconds.

    Also meeasure idle state residency (last_residency_ns in struct
    cpuidle_device and time_ns in struct cpuidle_driver) in nanoseconds
    and update the cpuidle core and governors accordingly.

    However, the menu governor still computes typical intervals in
    microseconds to avoid integer overflows.

    Signed-off-by: Rafael J. Wysocki
    Acked-by: Peter Zijlstra (Intel)
    Acked-by: Doug Smythies
    Tested-by: Doug Smythies

    Rafael J. Wysocki
     

25 Oct, 2019

1 commit

  • Fix __cpuidle_set_driver() to check if any of the CPUs in the mask has
    a driver different from drv already and, if so, return -EBUSY before
    updating any cpuidle_drivers per-CPU pointers.

    Fixes: 82467a5a885d ("cpuidle: simplify multiple driver support")
    Cc: 3.11+ # 3.11+
    Signed-off-by: Zhenzhong Duan
    [ rjw: Subject & changelog ]
    Signed-off-by: Rafael J. Wysocki

    Zhenzhong Duan
     

11 Sep, 2019

1 commit

  • The recently introduced haltpoll driver is largely only useful with
    haltpoll governor. To allow drivers to associate with a particular idle
    behaviour, add a @governor property to 'struct cpuidle_driver' and thus
    allow a cpuidle driver to switch to a *preferred* governor on idle driver
    registration. We save the previous governor, and when an idle driver is
    unregistered we switch back to that.

    The @governor can be overridden by cpuidle.governor= boot param or
    alternatively be ignored if the governor doesn't exist.

    Signed-off-by: Joao Martins
    Signed-off-by: Rafael J. Wysocki

    Joao Martins
     

30 Aug, 2017

3 commits

  • Make the drivers that want to include the polling state into their
    states table initialize it explicitly and drop the initialization of
    it (which in fact is conditional, but that is not obvious from the
    code) from the core.

    Signed-off-by: Rafael J. Wysocki
    Tested-by: Sudeep Holla
    Acked-by: Daniel Lezcano

    Rafael J. Wysocki
     
  • Move the polling state initialization code to a separate file built
    conditionally on CONFIG_ARCH_HAS_CPU_RELAX to get rid of the #ifdef
    in driver.c.

    Signed-off-by: Rafael J. Wysocki
    Tested-by: Sudeep Holla
    Acked-by: Daniel Lezcano

    Rafael J. Wysocki
     
  • On some architectures the first (index 0) idle state is a polling
    one and it doesn't really save energy, so there is the
    CPUIDLE_DRIVER_STATE_START symbol allowing some pieces of
    cpuidle code to avoid using that state.

    However, this makes the code rather hard to follow. It is better
    to explicitly avoid the polling state, so add a new cpuidle state
    flag CPUIDLE_FLAG_POLLING to mark it and make the relevant code
    check that flag for the first state instead of using the
    CPUIDLE_DRIVER_STATE_START symbol.

    In the ACPI processor driver that cannot always rely on the state
    flags (like before the states table has been set up) define
    a new internal symbol ACPI_IDLE_STATE_START equivalent to the
    CPUIDLE_DRIVER_STATE_START one and drop the latter.

    Signed-off-by: Rafael J. Wysocki
    Tested-by: Sudeep Holla
    Acked-by: Daniel Lezcano

    Rafael J. Wysocki
     

02 Mar, 2017

1 commit


08 Oct, 2016

1 commit

  • When doing an nmi backtrace of many cores, most of which are idle, the
    output is a little overwhelming and very uninformative. Suppress
    messages for cpus that are idling when they are interrupted and just
    emit one line, "NMI backtrace for N skipped: idling at pc 0xNNN".

    We do this by grouping all the cpuidle code together into a new
    .cpuidle.text section, and then checking the address of the interrupted
    PC to see if it lies within that section.

    This commit suitably tags x86 and tile idle routines, and only adds in
    the minimal framework for other architectures.

    Link: http://lkml.kernel.org/r/1472487169-14923-5-git-send-email-cmetcalf@mellanox.com
    Signed-off-by: Chris Metcalf
    Acked-by: Peter Zijlstra (Intel)
    Tested-by: Peter Zijlstra (Intel)
    Tested-by: Daniel Thompson [arm]
    Tested-by: Petr Mladek
    Cc: Aaron Tomlin
    Cc: Peter Zijlstra (Intel)
    Cc: "Rafael J. Wysocki"
    Cc: Russell King
    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Chris Metcalf
     

03 Sep, 2015

1 commit


03 Apr, 2015

1 commit


13 Nov, 2014

1 commit

  • The only place where the time is invalid is when the ACPI_CSTATE_FFH entry
    method is not set. Otherwise for all the drivers, the time can be correctly
    measured.

    Instead of duplicating the CPUIDLE_FLAG_TIME_VALID flag in all the drivers
    for all the states, just invert the logic by replacing it by the flag
    CPUIDLE_FLAG_TIME_INVALID, hence we can set this flag only for the acpi idle
    driver, remove the former flag from all the drivers and invert the logic with
    this flag in the different governor.

    Signed-off-by: Daniel Lezcano
    Signed-off-by: Rafael J. Wysocki

    Daniel Lezcano
     

29 Jul, 2014

1 commit


05 Jun, 2014

1 commit

  • poll_idle is the archetypal polling idle loop; tell the core idle
    code about it.

    This avoids pointless IPIs when all of the other cpuidle states are
    disabled.

    Signed-off-by: Andy Lutomirski
    Signed-off-by: Peter Zijlstra
    Cc: nicolas.pitre@linaro.org
    Cc: umgwanakikbuti@gmail.com
    Cc: Daniel Lezcano
    Cc: Linus Torvalds
    Cc: Rafael J. Wysocki
    Cc: linux-kernel@vger.kernel.org
    Cc: linux-pm@vger.kernel.org
    Link: http://lkml.kernel.org/r/c65ce49615d338bae8fb79df5daffab19353c900.1401902905.git.luto@amacapital.net
    Signed-off-by: Ingo Molnar

    Andy Lutomirski
     

07 Mar, 2014

1 commit

  • For some platforms, a poll state is inserted in the cpuidle driver states.
    The flags for the state do not indicate that timekeeping is not affected.
    As the state does not do anything apart from calling cpu_relax(), the
    times returned by ktime_get should remain valid. Add the missing flag.

    Signed-off-by: Tuukka Tikkanen
    Signed-off-by: Rafael J. Wysocki

    tuukka.tikkanen@linaro.org
     

30 Oct, 2013

5 commits


31 Aug, 2013

1 commit


11 Jun, 2013

2 commits

  • Add kerneldoc (and other) comments to the cpuidle driver's framework
    code.

    Signed-off-by: Daniel Lezcano
    Signed-off-by: Rafael J. Wysocki

    Daniel Lezcano
     
  • Commit bf4d1b5 (cpuidle: support multiple drivers) introduced support
    for using multiple cpuidle drivers at the same time. It added a
    couple of new APIs to register the driver per CPU, but that led to
    some unnecessary code complexity related to the kernel config options
    deciding whether or not the multiple driver support is enabled. The
    code has to work as it did before when the multiple driver support is
    not enabled and the multiple driver support has to be compatible with
    the previously existing API.

    Remove the new API, not used by any driver in the tree yet (but
    needed for the HMP cpuidle drivers that will be submitted soon), and
    add a new cpumask pointer to the cpuidle driver structure that will
    point to the mask of CPUs handled by the given driver. That will
    allow the cpuidle_[un]register_driver() API to be used for the
    multiple driver support along with the cpuidle_[un]register()
    functions added recently.

    [rjw: Changelog]
    Signed-off-by: Daniel Lezcano
    Signed-off-by: Rafael J. Wysocki

    Daniel Lezcano
     

01 Apr, 2013

1 commit

  • The commit 89878baa73f0f1c679355006bd8632e5d78f96c2 introduced
    the CPUIDLE_FLAG_TIMER_STOP flag where we specify a specific idle
    state stops the local timer.

    Now use this flag to check at init time if one state will need
    the broadcast timer and, in this case, setup the broadcast timer
    framework. That prevents multiple code duplication in the drivers.

    Signed-off-by: Daniel Lezcano
    Signed-off-by: Rafael J. Wysocki

    Daniel Lezcano
     

15 Jan, 2013

1 commit

  • We realized that the power usage field is never filled and when it
    is filled for tegra, the power_specified flag is not set causing all
    of these values to be reset when the driver is initialized with
    set_power_state().

    However, the power_specified flag can be simply removed under the
    assumption that the states are always backward sorted, which is the
    case with the current code.

    This change allows the menu governor select function and the
    cpuidle_play_dead() to be simplified. Moreover, the
    set_power_states() function can removed as it does not make sense
    any more.

    Drop the power_specified flag from struct cpuidle_driver and make
    the related changes as described above.

    As a consequence, this also fixes the bug where on the dynamic
    C-states system, the power fields are not initialized.

    [rjw: Changelog]
    References: https://bugzilla.kernel.org/show_bug.cgi?id=42870
    References: https://bugzilla.kernel.org/show_bug.cgi?id=43349
    References: https://lkml.org/lkml/2012/10/16/518
    Signed-off-by: Daniel Lezcano
    Signed-off-by: Rafael J. Wysocki

    Daniel Lezcano
     

03 Jan, 2013

1 commit

  • Commit bf4d1b5 (cpuidle: support multiple drivers) introduced
    locking in cpuidle_get_cpu_driver(), which is used in the
    idle_call() function.

    This leads to a contention problem with a large number of CPUs,
    because they all try to run the idle routine at the same time.

    The lock can be safely removed because of how is used the cpuidle
    API. Namely, cpuidle_register_driver() is called first, but the
    cpuidle idle function is not entered before cpuidle_register_device()
    is called, because the cpuidle device is not enabled then. Moreover,
    cpuidle_unregister_driver(), which would reset the driver value to
    NULL, is not called before cpuidle_unregister_device().

    All of the cpuidle drivers use the API in the same way.

    In general, a cleanup around the lock is necessary and a proper
    refcounting mechanism should be used to ensure the consistency in the
    API (for example, cpuidle_unregister_driver() should fail if the
    driver's refcount is not 0). However, these modifications will require
    some code reorganization and rewrite which will be too intrusive for
    a fix.

    For this reason, fix the contention problem introduced by commit
    bf4d1b5 by simply removing the locking from cpuidle_get_cpu_driver(),
    which restores the original behavior of that routine.

    [rjw: Changelog.]
    Reported-and-tested-by: Russ Anderson
    Signed-off-by: Daniel Lezcano
    Signed-off-by: Rafael J. Wysocki

    Daniel Lezcano
     

15 Nov, 2012

4 commits

  • With the tegra3 and the big.LITTLE [1] new architectures, several cpus
    with different characteristics (latencies and states) can co-exists on the
    system.

    The cpuidle framework has the limitation of handling only identical cpus.

    This patch removes this limitation by introducing the multiple driver support
    for cpuidle.

    This option is configurable at compile time and should be enabled for the
    architectures mentioned above. So there is no impact for the other platforms
    if the option is disabled. The option defaults to 'n'. Note the multiple drivers
    support is also compatible with the existing drivers, even if just one driver is
    needed, all the cpu will be tied to this driver using an extra small chunk of
    processor memory.

    The multiple driver support use a per-cpu driver pointer instead of a global
    variable and the accessor to this variable are done from a cpu context.

    In order to keep the compatibility with the existing drivers, the function
    'cpuidle_register_driver' and 'cpuidle_unregister_driver' will register
    the specified driver for all the cpus.

    The semantic for the output of /sys/devices/system/cpu/cpuidle/current_driver
    remains the same except the driver name will be related to the current cpu.

    The /sys/devices/system/cpu/cpu[0-9]/cpuidle/driver/name files are added
    allowing to read the per cpu driver name.

    [1] http://lwn.net/Articles/481055/

    Signed-off-by: Daniel Lezcano
    Acked-by: Peter De Schrijver
    Signed-off-by: Rafael J. Wysocki

    Daniel Lezcano
     
  • This patch is a preparation for the multiple cpuidle drivers support.

    As the next patch will introduce the multiple drivers with the Kconfig
    option and we want to keep the code clean and understandable, this patch
    defines a set of functions for encapsulating some common parts and splits
    what should be done under a lock from the rest.

    [rjw: Modified the subject and changelog slightly.]
    Signed-off-by: Daniel Lezcano
    Acked-by: Peter De Schrijver
    Signed-off-by: Rafael J. Wysocki

    Daniel Lezcano
     
  • The code is racy and the check with cpuidle_curr_driver should be
    done under the lock.

    I don't find a path in the different drivers where that could happen
    because the arch specific drivers are written in such way it is not
    possible to register a driver while it is unregistered, except maybe
    in a very improbable case when "intel_idle" and "processor_idle" are
    competing. One could unregister a driver, while the other one is
    registering.

    Signed-off-by: Daniel Lezcano
    Acked-by: Peter De Schrijver
    Signed-off-by: Rafael J. Wysocki

    Daniel Lezcano
     
  • We want to support different cpuidle drivers co-existing together.
    In this case we should move the refcount to the cpuidle_driver
    structure to handle several drivers at a time.

    Signed-off-by: Daniel Lezcano
    Acked-by: Peter De Schrijver
    Signed-off-by: Rafael J. Wysocki

    Daniel Lezcano
     

22 Sep, 2012

1 commit

  • The function __cpuidle_register_driver name is confusing because it
    suggests, conforming to the coding style of the kernel, it registers
    the driver without taking a lock. Actually, it just fill the different
    power field states with a decresing value if the power has not been
    specified.

    Clarify the purpose of the function by changing its name and
    move the condition out of this function.

    This patch fix nothing and does not change the behavior of the
    function. It is just for the sake of clarity.

    IHMO, reading in the code:

    + if (!drv->power_specified)
    + set_power_states(drv);

    is much more explicit than:

    - __cpuidle_register_driver(drv);

    Signed-off-by: Daniel Lezcano
    Signed-off-by: Rafael J. Wysocki

    Daniel Lezcano
     

20 Sep, 2012

1 commit


04 Jul, 2012

1 commit


30 Mar, 2012

1 commit


07 Nov, 2011

1 commit

  • This patch makes the cpuidle_states structure global (single copy)
    instead of per-cpu. The statistics needed on per-cpu basis
    by the governor are kept per-cpu. This simplifies the cpuidle
    subsystem as state registration is done by single cpu only.
    Having single copy of cpuidle_states saves memory. Rare case
    of asymmetric C-states can be handled within the cpuidle driver
    and architectures such as POWER do not have asymmetric C-states.

    Having single/global registration of all the idle states,
    dynamic C-state transitions on x86 are handled by
    the boot cpu. Here, the boot cpu would disable all the devices,
    re-populate the states and later enable all the devices,
    irrespective of the cpu that would receive the notification first.

    Reference:
    https://lkml.org/lkml/2011/4/25/83

    Signed-off-by: Deepthi Dharwar
    Signed-off-by: Trinabh Gupta
    Tested-by: Jean Pihet
    Reviewed-by: Kevin Hilman
    Acked-by: Arjan van de Ven
    Acked-by: Kevin Hilman
    Signed-off-by: Len Brown

    Deepthi Dharwar
     

04 Aug, 2011

1 commit

  • useful for disabling cpuidle to fall back
    to architecture-default idle loop

    cpuidle drivers and governors will fail to register.
    on x86 they'll say so:

    intel_idle: intel_idle yielding to (null)
    ACPI: acpi_idle yielding to (null)

    Signed-off-by: Len Brown

    Len Brown
     

28 May, 2010

1 commit

  • cpuidle_register_driver() sets cpuidle_curr_driver
    cpuidle_unregister_driver() clears cpuidle_curr_driver

    We should't expose cpuidle_curr_driver to
    potential modification except via these interfaces.
    So make it static and create cpuidle_get_driver() to observe it.

    Signed-off-by: Len Brown

    Len Brown