Chapter 16. Controlling power management transitions

You can control power management transitions to improve latency.

Prerequisites

  • You have root permissions on the system.

16.1. Power saving states

Modern processors actively transition to higher power saving states (C-states) from lower states. Unfortunately, transitioning from a high power saving state back to a running state can consume more time than is optimal for a real-time application. To prevent these transitions, an application can use the Power Management Quality of Service (PM QoS) interface.

With the PM QoS interface, the system can emulate the behavior of the idle=poll and processor.max_cstate=1 parameters, but with a more fine-grained control of power saving states. idle=poll prevents the processor from entering the idle state. processor.max_cstate=1 prevents the processor from entering deeper C-states (energy-saving modes).

When an application holds the /dev/cpu_dma_latency file open, the PM QoS interface prevents the processor from entering deep sleep states, which cause unexpected latencies when they are being exited. When the file is closed, the system returns to a power-saving state.

16.2. Configuring power management states

You can control power management transitions by configuring power management states with one of the following ways:

  • Write a value to the /dev/cpu_dma_latency file to change the maximum response time for processes in microseconds and hold the file descriptor open until low latency is required.
  • Reference the /dev/cpu_dma_latency file in an application or a script.

Prerequisites

  • You have administrator privileges.

Procedure

  • Specify latency tolerance by writing a 32-bit number that represents a maximum response time in microseconds in /dev/cpu_dma_latency and keep the file descriptor open through the low-latency operation. A value of 0 disables C-state completely.

    For example:

    import os
    import os.path
    import signal
    import sys
    if not os.path.exists('/dev/cpu_dma_latency'):
     	print("no PM QOS interface on this system!")
     	sys.exit(1)
    fd = os.open('/dev/cpu_dma_latency', os.O_WRONLY)
     	 os.write(fd, b'\0\0\0\0')
     	 print("Press ^C to close /dev/cpu_dma_latency and exit")
        signal.pause()
    except KeyboardInterrupt:
        print("closing /dev/cpu_dma_latency")
        os.close(fd)
        sys.exit(0)
    Note

    The Power Management Quality of Service interface (pm_qos) interface is only active while it has an open file descriptor. Therefore, any script or program you use to access /dev/cpu_dma_latency must hold the file open until power-state transitions are allowed.