The methods to limit C-states above will all be permanent (until the system is rebooted). If you would
like to have a system have extremely low latency during certain hours, but want more power savings at
other times, there is a method to dynamically control which C-states are used.
To dynamically control C-states, open the file /dev/cpu_dma_latency and write the maximum allowable latency to it. This will prevent C-states with transition latencies higher than the specified value from being used, as long as the file /dev/cpu_dma_latency is kept open. Writing a maximum allowable latency of 0 will keep the processors in C0 (like using kernel parameter “idle=poll”), and writing a low value (usually 5 or lower) should force the processors to C1 when idle. The exact value needed to restrict processors to the C1 state depends on various factors such as which idle driver you are using, which CPUs you are using, and possibly the ACPI tables in your system. Higher values could also be written to restrict the use of C-states with latency greater than the value written. The value used should correspond to the latency values in /sys/devices/system/cpu/cpuX/cpuidle/stateY/latency (where X is the CPU number and Y is the idle state)—CPU idle states that have a greater latency than written to /dev/cpu_dma_latency should not be used.
One simple way to do this is by compiling a simple program that will write to this file, and stay open until it is killed. An example of such a program is below, and can be compiled by cutting and pasting the code into a file called setcpulatency.c, and running “make setcpulatency”. So, to minimize latency during certain hours, say from 8AM until 5PM, a cron job could be set up to run at 8AM. This cron job could run setcpulatency in the background with an argument of 0, with a cron table entry like this:
00 08 * * * /path/to/setcpulatency 0 &
Then, at 5PM, another cron job could kill any program that’s holding /dev/cpu_dma_latency open:
00 17 * * * kill -9 `lsof –t /dev/cpu_dma_latency`
Of course, this is just an example to show how C-states can be dynamically controlled... the crond service is often disabled in low latency environments, but these steps could be taken manually or run by other means.
#include <stdio.h>
#include <fcntl.h>
int main(int argc, char **argv) {
int32_t l;
int fd;
if (argc != 2) {
fprintf(stderr, "Usage: %s <latency in us>\n", argv[0]);
return 2;
}
l = atoi(argv[1]);
printf("setting latency to %d us\n", l);
fd = open("/dev/cpu_dma_latency", O_WRONLY);
if (fd < 0) {
perror("open /dev/cpu_dma_latency");
return 1;
}
if (write(fd, &l, sizeof(l)) != sizeof(l)) {
perror("write to /dev/cpu_dma_latency");
return 1;
}
}
You can disable hardware devices via commandline
I am not sure that merely disabling a device is sufficient to mitigate the DMA attack
Microsoft provides devcon
as a command line device management tool
Get It
- Obtain the Windows Driver Kit (WDK) 7.1.0 from Microsoft.
- Extract the ISO to a temporary file.
- Expand the windows installer file “”WDK\setuptools_x64fre.msi“” to a temp directory.
devcon
is located in “drive:\your\temp\folder\WinDDK\7600.16385.win7_wdk.100208-1538\tools\devcon\amd64\".
Use It
- Find the device you want to manage. Ex:
devcon find * | find "DVD"
- Disable the device ID returned. Ex:
devcon disable PCI\VEN_1102
Automate It
- Collect the IDs for all devices you wish to disable
- Add the commands to disable the devices to a simple batch file
- Call the batch file from a logoff script.
- Reverse the commands and add them to another batch file.
- Call this batch file from a logon script.
Note: it may be possible to do this using only powershell but I wasn't able to find the correct calls. The closest I found was get-wmiobject Win32_PNPEntity
Best Answer
Yes, it does save power. If a device on your motherboard is enabled, it will draw power, even if it is not being used. Depending on the device and your power management settings, your OS may turn them off, or at least into a low power state.
As stated before, yes, you are using more power and memory. However, the amount is hugely insignificant compared to the use of the CPU, graphics cards, and even the fans.
Generally, if you arent using an onboard device, disable it in BIOS. This will prevent it from getting power at all. In addition to that, the OS doesnt have to load drivers for those devices, which uses a small amount of memory. But more importantly, in my opinion, you wont accidentally confuse one device for another, as it wont be visible to the OS.
Yes, you can leave them on with no detriment, but personally I say if its not being used, dont leave it enabled. You can always turn it on later.