summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Kacur <jkacur@redhat.com>2014-08-14 16:03:07 +0200
committerJohn Kacur <jkacur@redhat.com>2014-08-14 16:03:07 +0200
commit4b430a76785d630e399e60466fdc66cec3a74805 (patch)
tree03ecad55f96b3a43c24728024cc9bee1a38fe12d
parent245b19c5f69a00f36bb17adbaf0472a45ac06154 (diff)
downloadrt-tests-4b430a76785d630e399e60466fdc66cec3a74805.tar.gz
cyclictest: Always print an err message if write of 0 to cpu-dma_latency fails
In set_latency_target() there are some paths that don't print an error message even when a write of 0 to /dev/cpu_dma_latency fails. This patch does the following - always print an error message if the write to /dev/cpu_dma_latency fails - Fix the error check with the write call. (a return of 0 or -1 indicate problems - rename ret to err since this function is void and returns no value - use err_msg_n instead of printf (which also prints to stderr) Signed-off-by: John Kacur <jkacur@redhat.com>
-rw-r--r--src/cyclictest/cyclictest.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index 01dfc75..64f1764 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -233,20 +233,30 @@ static int32_t latency_target_value = 0;
static void set_latency_target(void)
{
struct stat s;
- int ret;
+ int err;
- if (stat("/dev/cpu_dma_latency", &s) == 0) {
- latency_target_fd = open("/dev/cpu_dma_latency", O_RDWR);
- if (latency_target_fd == -1)
- return;
- ret = write(latency_target_fd, &latency_target_value, 4);
- if (ret == 0) {
- printf("# error setting cpu_dma_latency to %d!: %s\n", latency_target_value, strerror(errno));
- close(latency_target_fd);
- return;
- }
- printf("# /dev/cpu_dma_latency set to %dus\n", latency_target_value);
+ errno = 0;
+ err = stat("/dev/cpu_dma_latency", &s);
+ if (err == -1) {
+ err_msg_n(errno, "WARN: stat /dev/cpu_dma_latency failed");
+ return;
+ }
+
+ errno = 0;
+ latency_target_fd = open("/dev/cpu_dma_latency", O_RDWR);
+ if (latency_target_fd == -1) {
+ err_msg_n(errno, "WARN: open /dev/cpu_dma_latency");
+ return;
+ }
+
+ errno = 0;
+ err = write(latency_target_fd, &latency_target_value, 4);
+ if (err < 1) {
+ err_msg_n(errno, "# error setting cpu_dma_latency to %d!", latency_target_value);
+ close(latency_target_fd);
+ return;
}
+ printf("# /dev/cpu_dma_latency set to %dus\n", latency_target_value);
}