Bug 65531

Summary: Cpuidle governor menu selected despite NO_HZ not being enabled
Product: Power Management Reporter: Jean Delvare (jdelvare)
Component: cpuidleAssignee: Zhang Rui (rui.zhang)
Status: CLOSED CODE_FIX    
Severity: normal CC: lenb, rui.zhang, tglx, tianyu.lan, vineethchowdhary
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 3.11 Subsystem:
Regression: No Bisected commit-id:
Attachments: [PATCH] cpuidle: Default to ladder governor on ticking systems

Description Jean Delvare 2013-11-22 18:10:57 UTC
When NO_HZ is not enabled, the ladder cpuidle governor is supposed to perform better than the menu governor. However the kernel still selects the menu governor by default in that case.
Comment 1 Lan Tianyu 2013-12-11 07:29:19 UTC
This seems to require changing cpu idle governor's rating value depending on  NO_HZ status.

Len, how about adding a new kernel parameter to select which governor?
Comment 2 Lan Tianyu 2013-12-16 07:35:35 UTC
ping Len ...
Comment 3 Zhang Rui 2014-06-03 05:52:43 UTC
ping Len...
Comment 4 Zhang Rui 2015-12-28 02:52:23 UTC
To me, it seems that the problem described in comment #0 is fixed by:
commit d6f346f2d2bf511c2c59176121a6e42ce60173a0
Author: Daniel Lezcano <daniel.lezcano@linaro.org>
Date:   Tue May 28 15:51:54 2013 +0000

    cpuidle: improve governor Kconfig options
    
    Each governor is suitable for different kernel configurations: the menu
    governor suits better for a tickless system, while the ladder governor fits
    better for a periodic timer tick system.
    
    The Kconfig does not allow to [un]select a governor, thus both are compiled in
    the kernel but the init order makes the menu governor to be the last one to be
    registered, so becoming the default. The only way to switch back to the ladder
    governor is to enable the sysfs governor switch in the kernel command line.
    
    Because it seems nobody complained about this, the menu governor is used by
    default most of the time on the system, having both governors is not really
    necessary on a tickless system but there isn't a config option to disable one
    or another governor.
    
    Create a submenu for cpuidle and add a label for each governor, so we can see
    the option in the menu config and enable/disable it.
    
    The governors will be enabled depending on the CONFIG_NO_HZ option:
     - If CONFIG_NO_HZ is set, then the menu governor is selected and the ladder
       governor is optional, defaulting to 'yes'
     - If CONFIG_NO_HZ is not set, then the ladder governor is selected and the
       menu governor is optional, defaulting to 'yes'
    
    Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

I don't know why this bug is filed after the commit has been merged.
Bug close for now, please feel free to reopen it if you think the problem still exists.
Comment 5 Jean Delvare 2016-01-08 18:17:21 UTC
The commit you mention does not really fix the problem. All it does is prevent the user from unselecting the best governor. However both governors still default to y, so in practice they will both be included (unless the user explicitly disables the other one) and loaded. The menu governor has rating 20 while the ladder governor has rating 10, so the menu governor will always be preferred at boot time by default, even if CONFIG_NO_HZ is not set.

This could be easily fixed by setting the ladder governor rating to 25 when CONFIG_NO_HZ is not set (and leaving it to 10 when CONFIG_NO_HZ is set.) However this approach would not cover the case where a CONFIG_NO_HZ kernel is booted with parameter nohz=off. In order to handle this scenario, we would have to adjust the rating at boot time. I'll attach a proof-of-concept patch.

Additionally I would question the point of having both governors default to y now that the right one is forcibly selected. In practice that means pretty much everyone includes 2 governors but only ever uses 1 (as you can't switch at run-time by default.)
Comment 6 Jean Delvare 2016-01-08 18:30:32 UTC
Created attachment 199031 [details]
[PATCH] cpuidle: Default to ladder governor on ticking systems

Proof-of-concept only. If we can agree on the idea, it should be implemented in a cleaner way.
Comment 7 Jean Delvare 2016-02-02 09:54:16 UTC
Fixed in kernel v4.5:

commit 10475b34f4d71cf71cfe7c5d1f27d8ff3a4eb9bc
Author: Jean Delvare
Date:   Mon Jan 11 17:43:02 2016 +0100

    cpuidle: Don't enable all governors by default
    
commit 66a5f6b63996d8aa7cbe8841b38297bf3b338194
Author: Jean Delvare
Date:   Mon Jan 11 17:41:53 2016 +0100

    cpuidle: Default to ladder governor on ticking systems
    
commit 46373a15f65fe862f31c19a484acdf551f2b442f
Author: Jean Delvare
Date:   Mon Jan 11 17:40:31 2016 +0100

    time: nohz: Expose tick_nohz_enabled