summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClark Williams <williams@redhat.com>2011-09-20 13:41:02 -0500
committerClark Williams <williams@redhat.com>2011-09-20 13:41:02 -0500
commit1310f57cfe4b65646ddaaea26ad5f2469e211757 (patch)
treefaa4957648cb13708d1ac674e947cba4b79fc8d0
parent3edea442f644c112f47e17f876ba06e986007653 (diff)
downloadcyclictest-1310f57cfe4b65646ddaaea26ad5f2469e211757.tar.gz
use latency trick to hold system in idle=poll for duration of cyclictest run
Use the /dev/cpu_dma_latency power management interface to hold the system in idle=poll state while cyclictest is running. Look in the kernel documenation: Documentation/power/pm_qos_interface.txt for more information. Signed-off-by: Clark Williams <williams@redhat.com>
-rw-r--r--src/cyclictest/cyclictest.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index 4b4de99..1428770 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -191,6 +191,38 @@ static char **traceptr;
static int traceopt_count;
static int traceopt_size;
+static int latency_trick_fd = -1;
+
+/* Latency trick
+ * if the file /dev/cpu_dma_latency exists,
+ * open it and write a zero into it. This will tell
+ * the power management system not to transition to
+ * a high cstate (in fact, the system acts like idle=poll)
+ * When the fd to /dev/cpu_dma_latency is closed, the behavior
+ * goes back to the system default.
+ *
+ * Documentation/power/pm_qos_interface.txt
+ */
+static void latency_trick(void)
+{
+ struct stat s;
+ int ret;
+
+ if (stat("/dev/cpu_dma_latency", &s) == 0) {
+ latency_trick_fd = open("/dev/cpu_dma_latency", O_RDWR);
+ if (latency_trick_fd == -1)
+ return;
+ ret = write(latency_trick_fd, "0x00000000", 10);
+ if (ret == 0) {
+ printf("error setting cpu_dma_latency to zero!: %s\n", strerror(errno));
+ close(latency_trick_fd);
+ return;
+ }
+ printf("cpu_dma_latency set to zero\n");
+ }
+}
+
+
enum kernelversion {
KV_NOT_SUPPORTED,
KV_26_LT18,
@@ -1304,13 +1336,15 @@ int main(int argc, char **argv)
/* Checks if numa is on, program exits if numa on but not available */
numa_on_and_available();
- /* lock all memory (prevent paging) */
+ /* lock all memory (prevent swapping) */
if (lockall)
if (mlockall(MCL_CURRENT|MCL_FUTURE) == -1) {
perror("mlockall");
goto out;
}
+ /* use the /dev/cpu_dma_latency trick if it's there */
+ latency_trick();
kernelversion = check_kernel();
@@ -1562,5 +1596,9 @@ int main(int argc, char **argv)
if (kernelversion < KV_26_33)
restorekernvars();
+ /* close the latency_trick fd if it's open */
+ if (latency_trick_fd >= 0)
+ close(latency_trick_fd);
+
exit(ret);
}