2021-04-29 06:02:23

by Anand K. Mistry

[permalink] [raw]
Subject: [PATCH v2] x86: Add a prompt for HPET_EMULATE_RTC

This does two things:
1. Makes the option visible in menuconfig, allowing the user to easily
disable this option
2. Allows olddefconfig to respect the option if it is set in the old
.config file

It's not clear exactly why the second consequence is true, but it
appears to be because when the conf tool reads the config file, it only
respects the existing setting if the option is "visible" (see
scripts/kconfig/symbol.c:381).

Signed-off-by: Anand K Mistry <[email protected]>
---
This patch was previously discussed at
https://lore.kernel.org/lkml/20210204132043.1.I2392cf11fb353d10459958100b69d93346fa167c@changeid/
Sending as a v2 because a merge conflict exists with commit
3228e1dc80983 ("x86/Kconfig: Remove HPET_EMULATE_RTC depends on RTC")

Changes in v2:
- Rebase
- Fix typo in commit message

arch/x86/Kconfig | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 0fc82237414d..55e652aa42d1 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -896,6 +896,7 @@ config HPET_TIMER

config HPET_EMULATE_RTC
def_bool y
+ prompt "HPET RTC emulation"
depends on HPET_TIMER && (RTC_DRV_CMOS=m || RTC_DRV_CMOS=y)

# Mark as expert because too many people got it wrong.
--
2.31.1.498.g6c1eba8ee3d-goog


2021-05-03 07:39:53

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCH v2] x86: Add a prompt for HPET_EMULATE_RTC

On Thu, Apr 29 2021 at 16:00, Anand K. Mistry wrote:

> This does two things:
> 1. Makes the option visible in menuconfig, allowing the user to easily
> disable this option
> 2. Allows olddefconfig to respect the option if it is set in the old
> .config file

Well, it's pretty clear WHAT it does, but there is absolutely no
reasoning WHY this knob is needed in the first place.

Thanks,

tglx

2021-05-04 01:49:03

by Anand K. Mistry

[permalink] [raw]
Subject: Re: [PATCH v2] x86: Add a prompt for HPET_EMULATE_RTC

On Mon, 3 May 2021 at 17:38, Thomas Gleixner <[email protected]> wrote:
>
> On Thu, Apr 29 2021 at 16:00, Anand K. Mistry wrote:
>
> > This does two things:
> > 1. Makes the option visible in menuconfig, allowing the user to easily
> > disable this option
> > 2. Allows olddefconfig to respect the option if it is set in the old
> > .config file
>
> Well, it's pretty clear WHAT it does, but there is absolutely no
> reasoning WHY this knob is needed in the first place.

Without this option, 'make oldolddefconfig' ignores the option in the
old .confg file and just sets it to the calculated default for the
platform. An easy way to test this is to do 'make defconfig' on
x86-64, set CONFIG_HPET_EMULATE_RTC=n in the generated .config, and
run 'make olddefconfig'. Without this patch, olddefconfig will ignore
the set option and overwrite it with CONFIG_HPET_EMULATE_RTC=y.

Or, tested on 5.12:
~/linux-stable % make defconfig
... SNIP
#
# configuration written to .config
#
~/linux-stable % grep CONFIG_HPET_EMULATE_RTC .config
CONFIG_HPET_EMULATE_RTC=y
~/linux-stable % sed -i 's/EMULATE_RTC=y/EMULATE_RTC=n/g' .config
~/linux-stable % grep CONFIG_HPET_EMULATE_RTC .config
CONFIG_HPET_EMULATE_RTC=n
~/linux-stable % make olddefconfig
#
# configuration written to .config
#
~/linux-stable % grep CONFIG_HPET_EMULATE_RTC .config
CONFIG_HPET_EMULATE_RTC=y

With this patch, the 'make olddefconfig' results in:
~/linux-stable % grep CONFIG_HPET_EMULATE_RTC .config
# CONFIG_HPET_EMULATE_RTC is not set

So, part of the why is that this enables the use of olddefconfig with
the CONFIG_HPET_EMULATE_RTC option. The other part of why is that my
team uses 'make olddefconfig' by providing a base config and then
using olddefconfig to fill in the unset values with defaults to make a
complete config file for a kernel build. I'd like to disable RTC
emulation on a particular platform, but I can't use a config option to
do it without this patch because 'make olddefconfig' will just ignore
the option.

Debugging why this was the case, I discovered the kconfig tools
(https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/kconfig/symbol.c#n379)
ignore set values if the option is not visible. Why this is the case,
I don't know. But it looks like in order to have kconfig respect the
config value, it must be visible.

>
> Thanks,
>
> tglx




--
Anand K. Mistry
Software Engineer
Google Australia

2021-05-04 08:55:44

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCH v2] x86: Add a prompt for HPET_EMULATE_RTC

On Tue, May 04 2021 at 11:21, Anand K. Mistry wrote:
> On Mon, 3 May 2021 at 17:38, Thomas Gleixner <[email protected]> wrote:
>> On Thu, Apr 29 2021 at 16:00, Anand K. Mistry wrote:
>>
>> > This does two things:
>> > 1. Makes the option visible in menuconfig, allowing the user to easily
>> > disable this option
>> > 2. Allows olddefconfig to respect the option if it is set in the old
>> > .config file
>>
>> Well, it's pretty clear WHAT it does, but there is absolutely no
>> reasoning WHY this knob is needed in the first place.
>
> Without this option, 'make oldolddefconfig' ignores the option in the
> old .confg file and just sets it to the calculated default for the
> platform. An easy way to test this is to do 'make defconfig' on
> x86-64, set CONFIG_HPET_EMULATE_RTC=n in the generated .config, and
> run 'make olddefconfig'. Without this patch, olddefconfig will ignore
> the set option and overwrite it with CONFIG_HPET_EMULATE_RTC=y.

Rightfully so because it's a functional correctness issue. When HPET is
enabled in legacy mode it takes over the RTC interrupt line, which makes
RTC alarms disfunctional and therefore we have to emulate it.

So, no.

> So, part of the why is that this enables the use of olddefconfig with
> the CONFIG_HPET_EMULATE_RTC option. The other part of why is that my
> team uses 'make olddefconfig' by providing a base config and then
> using olddefconfig to fill in the unset values with defaults to make a
> complete config file for a kernel build. I'd like to disable RTC
> emulation on a particular platform, but I can't use a config option to
> do it without this patch because 'make olddefconfig' will just ignore
> the option.

You can like to disable it, but that does not make it more correct. See
above. If your platform does not have RTC_DRV_CMOS then you have to
disable that which will also clear CONFIG_HPET_EMULATE_RTC.

Thanks,

tglx

2022-03-03 00:11:47

by Raul Rangel

[permalink] [raw]
Subject: Re: [PATCH v2] x86: Add a prompt for HPET_EMULATE_RTC

On Tue, May 04, 2021 at 09:55:16AM +0200, Thomas Gleixner wrote:
> On Tue, May 04 2021 at 11:21, Anand K. Mistry wrote:
> > On Mon, 3 May 2021 at 17:38, Thomas Gleixner <[email protected]> wrote:
> >> On Thu, Apr 29 2021 at 16:00, Anand K. Mistry wrote:
> >>
> >> > This does two things:
> >> > 1. Makes the option visible in menuconfig, allowing the user to easily
> >> > disable this option
> >> > 2. Allows olddefconfig to respect the option if it is set in the old
> >> > .config file
> >>
> >> Well, it's pretty clear WHAT it does, but there is absolutely no
> >> reasoning WHY this knob is needed in the first place.
> >
> > Without this option, 'make oldolddefconfig' ignores the option in the
> > old .confg file and just sets it to the calculated default for the
> > platform. An easy way to test this is to do 'make defconfig' on
> > x86-64, set CONFIG_HPET_EMULATE_RTC=n in the generated .config, and
> > run 'make olddefconfig'. Without this patch, olddefconfig will ignore
> > the set option and overwrite it with CONFIG_HPET_EMULATE_RTC=y.
>
> Rightfully so because it's a functional correctness issue. When HPET is
> enabled in legacy mode it takes over the RTC interrupt line, which makes
> RTC alarms disfunctional and therefore we have to emulate it.
>
> So, no.
>
> > So, part of the why is that this enables the use of olddefconfig with
> > the CONFIG_HPET_EMULATE_RTC option. The other part of why is that my
> > team uses 'make olddefconfig' by providing a base config and then
> > using olddefconfig to fill in the unset values with defaults to make a
> > complete config file for a kernel build. I'd like to disable RTC
> > emulation on a particular platform, but I can't use a config option to
> > do it without this patch because 'make olddefconfig' will just ignore
> > the option.
>
> You can like to disable it, but that does not make it more correct. See
> above. If your platform does not have RTC_DRV_CMOS then you have to
> disable that which will also clear CONFIG_HPET_EMULATE_RTC.

So on recent AMD Chromebooks we have disabled the RTC emulation by
setting rtc-cmos.use_acpi_alarm=1.

* https://chromium-review.googlesource.com/c/chromiumos/overlays/board-overlays/+/3472221
* https://chromium-review.googlesource.com/c/chromiumos/overlays/board-overlays/+/2355073

It looks like recent Intel platforms have also disabled the RTC
emulation.

* https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/third_party/kernel/v5.15/drivers/rtc/rtc-cmos.c;l=1202

One thing I've been wondering is why is the legacy mode enabled
unconditionally by the kernel?

* https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/third_party/kernel/v5.15/arch/x86/kernel/hpet.c;l=1096

If it's not enabled, can we leave it disabled? I know some firmware
doesn't correctly populate the INT_ROUTE_CAP to describe which IRQs
are available, but if it is populated can we use it and avoid the
RTC HPET emulation layer? I'm not sure what the story is on MSIs or if
that's a supported use case.

I have been leaving the INT_ROUTE_CAP register unset on the AMD
Chromebooks since it's getting ignored by the kernel.

Thanks,
Raul

>
> Thanks,
>
> tglx