I’m using OpenBSD as my daily driver on my old packard bell dot s laptop, is a nice laptop and OpenBSD works perfectly out of the box. The only problem that I’m facing right now is to reduce power consumption as my plan is to re-charge just using a small solar panel. The first I realize is that OpenBSD still is not tickless, so having worked a while on illumos trying to remove tick accounting I had some ideas on where to start changing to save power, all the ideas have been taken from the NO_HZ: Reducing Scheduling-Clock Ticks document from the Linux Kernel.
Changes
As we are doing tick accounting on clock, I think this couple of changes will improve things:
- We need to skip tick accounting on cpus that are idle so they could enter deeper power saving states.
- We need to skip tick accounting on cpus with one runnable task and don’t run resched on them as they only have one task they have no other tasks to switch to.
Patches
Here is my first attempt to accomplish the previous points (I’m using OPENBSD 7.0)
Index: kern_clock.c
===================================================================
RCS file: /cvs/src/sys/kern/kern_clock.c,v
retrieving revision 1.102
diff -u -p -r1.102 kern_clock.c
--- kern_clock.c 13 Jan 2021 16:28:49 -0000 1.102
+++ kern_clock.c 2 Nov 2021 19:13:29 -0000
@@ -163,11 +163,26 @@ hardclock(struct clockframe *frame)
/*
* If no separate statistics clock is available, run it from here.
*/
+#if defined(MULTIPROCESSOR)
+ // neirac:
+ // don't schedule on an idle cpu or one
+ // that has only one runnable task.
+
+ if (((!cpu_is_idle(ci)) || (ci->ci_schedstate.spc_nrun > 1))
+ && (stathz == 0))
+ statclock(frame);
+
+ if (--ci->ci_schedstate.spc_rrticks <= 0 &&
+ ((!cpu_is_idle(ci)) ||
+ (ci->ci_schedstate.spc_nrun > 1)))
+ roundrobin(ci);
+#else
if (stathz == 0)
statclock(frame);
if (--ci->ci_schedstate.spc_rrticks <= 0)
roundrobin(ci);
+#endif
#if NDT > 0
DT_ENTER(profile, NULL);
I’m currently running this patch on my laptop, and seems temperatures have improved, and battery is lasting around2:53 hours at least the same time reported on Linux when this laptop had voidlinux installed. I’ll need to compare power consumption before and after my change to be certain.