OPNsense Forum

English Forums => Hardware and Performance => Topic started by: becks0815 on April 20, 2022, 07:17:34 pm

Title: Power consumption reduction with Cstates?
Post by: becks0815 on April 20, 2022, 07:17:34 pm
I have a protectli Fw4 clone, running 22.1.6. While playing around with methods to reduce power consumption, I spotted the following:


Code: [Select]
root@OPNsense:~ # sysctl dev.cpu |grep cx
dev.cpu.3.cx_method: C1/mwait/hwc C2/mwait/hwc C3/mwait/hwc
dev.cpu.3.cx_usage_counters: 304429829 0 0
dev.cpu.3.cx_usage: 100.00% 0.00% 0.00% last 312us
dev.cpu.3.cx_lowest: C1
dev.cpu.3.cx_supported: C1/1/1 C2/2/500 C3/3/1000
dev.cpu.2.cx_method: C1/mwait/hwc C2/mwait/hwc C3/mwait/hwc
dev.cpu.2.cx_usage_counters: 352002831 0 0
dev.cpu.2.cx_usage: 100.00% 0.00% 0.00% last 47us
dev.cpu.2.cx_lowest: C1
dev.cpu.2.cx_supported: C1/1/1 C2/2/500 C3/3/1000
dev.cpu.1.cx_method: C1/mwait/hwc C2/mwait/hwc C3/mwait/hwc
dev.cpu.1.cx_usage_counters: 288856368 0 0
dev.cpu.1.cx_usage: 100.00% 0.00% 0.00% last 305us
dev.cpu.1.cx_lowest: C1
dev.cpu.1.cx_supported: C1/1/1 C2/2/500 C3/3/1000
dev.cpu.0.cx_method: C1/mwait/hwc C2/mwait/hwc C3/mwait/hwc
dev.cpu.0.cx_usage_counters: 268697840 0 0
dev.cpu.0.cx_usage: 100.00% 0.00% 0.00% last 529us
dev.cpu.0.cx_lowest: C1
dev.cpu.0.cx_supported: C1/1/1 C2/2/500 C3/3/1000


My machine is able to support C1, C2 and C3 states, but the lowest C-state set by the OS is C1, and therrfor all cores run on C1 for 100% of the time.


Then I ran the commands to change this:



Code: [Select]
# sysctl dev.cpu.0.cx_lowest=C3

# sysctl dev.cpu.1.cx_lowest=C3

# sysctl dev.cpu.2.cx_lowest=C3

# sysctl dev.cpu.3.cx_lowest=C3




and now I can see the following:


Code: [Select]
root@OPNsense:/usr # sysctl dev.cpu.0.cx_usage
dev.cpu.0.cx_usage: 49.94% 20.18% 29.86% last 7798us


So core 0 suddenly only keeps C1 for 50% of the time but drops to C2/C3 for the rest. This should reduce power consumption at least a bit.


As far as I understand, I can also add the settings in the tunables in opnsense and make them permanent. I just had no time to run some tests with my FW to confirm this. I also lack a method to monitor the power consumption at the moment but will do this as soon as I can shut down the FW and plug in a power meter.


Maybe someone else wants to try this and test if he can save some energy by enabling unused C-states of his hardware?
Title: Re: Power consumption reduction with Cstates?
Post by: meyergru on April 21, 2022, 08:52:06 pm
Thank you for that pointer.

I did not measure the difference, but I can see a temperature difference of ~3°C when enabling C3 on two of my Celeron boxes. With the DEC750, C3 is not even supported and the temperature difference for C2 seems neglegible, so YMMV.
Title: Re: Power consumption reduction with Cstates?
Post by: becks0815 on April 21, 2022, 09:18:49 pm
You are welcome. I have enabled the settings on my box yesterday and haven't run into any issues. The FW4 runs stable, even when I try to fill up the bandwidth with various services, just to see how it behaves.

Combined with powerd++ which really makes a difference on an older CPU like the J3160 I use, just by looking at the temperature of the CPU (at least 5-7°C lower, especially under load), I am sure it makes a difference in the power consumption.
Title: Re: Power consumption reduction with Cstates?
Post by: abulafia on May 12, 2022, 10:07:39 pm
There is also sysctl hw.acpi.cpu.cx_lowest

Have you tried if
Code: [Select]
sysctl hw.acpi.cpu.cx_lowest=c3has any effect on your system (the command as such works)?
Title: Re: Power consumption reduction with Cstates?
Post by: becks0815 on June 28, 2022, 09:39:37 am
Saw the last one today...

I have tested it (with the other options already enabled) but didn't see any differences.
Title: Re: Power consumption reduction with Cstates?
Post by: becks0815 on June 29, 2022, 08:22:21 am
Additional note:

Add four new entries under system -> settings -> tunables:
Code: [Select]
dev.cpu.0.cx_lowest
dev.cpu.1.cx_lowest
dev.cpu.2.cx_lowest
dev.cpu.3.cx_lowest

and use C3 as value for each of them. Then the tunings survive a reboot.
Title: Re: Power consumption reduction with Cstates?
Post by: meyergru on June 29, 2022, 10:52:37 am
Be aware that using lower C-states may introduce spurious instability - my Topton N5105-based unit showed that behaviour once I went lower than C1.