linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Kacur <jkacur@redhat.com>
To: rt-users <linux-rt-users@vger.kernel.org>,
	Clark Williams <williams@redhat.com>
Cc: John Kacur <jkacur@redhat.com>
Subject: [PATCH 3/6] cyclictest: Always print an err message if write of 0 to cpu-dma_latency fails
Date: Thu, 14 Aug 2014 18:18:07 +0200	[thread overview]
Message-ID: <1408033090-24866-4-git-send-email-jkacur@redhat.com> (raw)
In-Reply-To: <1408033090-24866-1-git-send-email-jkacur@redhat.com>

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>
---
 src/cyclictest/cyclictest.c | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index 01dfc75fd70c..64f1764681b0 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);
 }
 
 
-- 
1.8.1.4


  parent reply	other threads:[~2014-08-14 16:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-14 16:18 [PATCH 0/6] Miscellaneous cyclictest patches John Kacur
2014-08-14 16:18 ` [PATCH 1/6] lib: Rework err_msg_n to output strerror after message John Kacur
2014-08-14 16:18 ` [PATCH 2/6] rt_numa.h: Suppress discards 'const' qualifier warning John Kacur
2014-08-14 16:18 ` John Kacur [this message]
2014-08-14 16:18 ` [PATCH 4/6] cyclictest: Change the output from function sighand() to stderr John Kacur
2014-08-14 16:18 ` [PATCH 5/6] cyclictest: Fix help for long options only John Kacur
2014-08-18 20:26   ` Michael
2014-08-18 20:45     ` John Kacur
2014-08-14 16:18 ` [PATCH 6/6] cyclictest: Add long option --laptop to preserve battery power John Kacur
2014-08-14 16:38   ` John Kacur
2014-08-18 20:29   ` Michael
2014-08-18 20:46     ` John Kacur

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1408033090-24866-4-git-send-email-jkacur@redhat.com \
    --to=jkacur@redhat.com \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=williams@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).