Power consumption reduction with Cstates?

Started by becks0815, April 20, 2022, 07:17:34 PM

Previous topic - Next topic
I have a protectli Fw4 clone, running 22.1.6. While playing around with methods to reduce power consumption, I spotted the following:



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:




# 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:



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?

April 21, 2022, 08:52:06 PM #1 Last Edit: April 22, 2022, 10:53:36 AM by meyergru
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.
Intel N100, 4 x I226-V, 16 GByte, 256 GByte NVME, ZTE F6005

1100 down / 440 up, Bufferbloat A+

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.

There is also sysctl hw.acpi.cpu.cx_lowest

Have you tried if
sysctl hw.acpi.cpu.cx_lowest=c3
has any effect on your system (the command as such works)?

Saw the last one today...

I have tested it (with the other options already enabled) but didn't see any differences.

Additional note:

Add four new entries under system -> settings -> tunables:
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.

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.
Intel N100, 4 x I226-V, 16 GByte, 256 GByte NVME, ZTE F6005

1100 down / 440 up, Bufferbloat A+

I was trying to apply the same settings on a Protectli VP4670 using the Intel® Core™ i7-10810U CPU, but after running the command sysctl dev.cpu | grep cx, the output (below) only shows C1 state, is it different with the i7 CPUs to optimize power management?

dev.cpu.0.cx_method: C1/hlt
dev.cpu.0.cx_usage_counters: 11192
dev.cpu.0.cx_usage: 100.00% last 642us
dev.cpu.0.cx_lowest: C1
dev.cpu.0.cx_supported: C1/1/0