From de064d5311593b6905d909295932c88a6125bf00 Mon Sep 17 00:00:00 2001 From: kettenis Date: Tue, 11 Jun 2024 15:44:55 +0000 Subject: [PATCH] Clamp CPU clock frequencies to [min, max] range when determining the initial perflevel. ok deraadt@, phessler@, patrick@, jca@ --- sys/arch/arm/arm/cpu.c | 6 +++++- sys/arch/arm64/arm64/cpu.c | 6 +++++- sys/arch/riscv64/riscv64/cpu.c | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/sys/arch/arm/arm/cpu.c b/sys/arch/arm/arm/cpu.c index cedce406d8d..f51404f73be 100644 --- a/sys/arch/arm/arm/cpu.c +++ b/sys/arch/arm/arm/cpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.c,v 1.59 2023/10/24 13:20:09 claudio Exp $ */ +/* $OpenBSD: cpu.c,v 1.60 2024/06/11 15:44:55 kettenis Exp $ */ /* $NetBSD: cpu.c,v 1.56 2004/04/14 04:01:49 bsh Exp $ */ @@ -836,6 +836,10 @@ cpu_opp_mountroot(struct device *self) min = ot->ot_opp_hz_min; max = ot->ot_opp_hz_max; level_hz = clock_get_frequency(ci->ci_node, NULL); + if (level_hz < min) + level_hz = min; + if (level_hz > max) + level_hz = max; level = howmany(100 * (level_hz - min), (max - min)); } diff --git a/sys/arch/arm64/arm64/cpu.c b/sys/arch/arm64/arm64/cpu.c index a41b7697d14..49927bb30ad 100644 --- a/sys/arch/arm64/arm64/cpu.c +++ b/sys/arch/arm64/arm64/cpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.c,v 1.118 2024/05/30 04:16:25 tb Exp $ */ +/* $OpenBSD: cpu.c,v 1.119 2024/06/11 15:44:55 kettenis Exp $ */ /* * Copyright (c) 2016 Dale Rahn @@ -1802,6 +1802,10 @@ cpu_opp_mountroot(struct device *self) min = ot->ot_opp_hz_min; max = ot->ot_opp_hz_max; level_hz = clock_get_frequency(ci->ci_node, NULL); + if (level_hz < min) + level_hz = min; + if (level_hz > max) + level_hz = max; level = howmany(100 * (level_hz - min), (max - min)); } diff --git a/sys/arch/riscv64/riscv64/cpu.c b/sys/arch/riscv64/riscv64/cpu.c index 0649c79cc01..0d40b236569 100644 --- a/sys/arch/riscv64/riscv64/cpu.c +++ b/sys/arch/riscv64/riscv64/cpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.c,v 1.18 2024/01/26 16:59:47 kettenis Exp $ */ +/* $OpenBSD: cpu.c,v 1.19 2024/06/11 15:44:55 kettenis Exp $ */ /* * Copyright (c) 2016 Dale Rahn @@ -674,6 +674,10 @@ cpu_opp_mountroot(struct device *self) min = ot->ot_opp_hz_min; max = ot->ot_opp_hz_max; level_hz = clock_get_frequency(ci->ci_node, NULL); + if (level_hz < min) + level_hz = min; + if (level_hz > max) + level_hz = max; level = howmany(100 * (level_hz - min), (max - min)); } -- 2.20.1