Clamp CPU clock frequencies to [min, max] range when determining the
authorkettenis <kettenis@openbsd.org>
Tue, 11 Jun 2024 15:44:55 +0000 (15:44 +0000)
committerkettenis <kettenis@openbsd.org>
Tue, 11 Jun 2024 15:44:55 +0000 (15:44 +0000)
initial perflevel.

ok deraadt@, phessler@, patrick@, jca@

sys/arch/arm/arm/cpu.c
sys/arch/arm64/arm64/cpu.c
sys/arch/riscv64/riscv64/cpu.c

index cedce40..f51404f 100644 (file)
@@ -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));
                }
 
index a41b769..49927bb 100644 (file)
@@ -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 <drahn@dalerahn.com>
@@ -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));
                }
 
index 0649c79..0d40b23 100644 (file)
@@ -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 <drahn@dalerahn.com>
@@ -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));
                }