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>
This commit is contained in:
John Kacur 2014-08-14 16:03:07 +02:00
parent 245b19c5f6
commit 4b430a7678
1 changed files with 22 additions and 12 deletions

View File

@ -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)
errno = 0;
err = stat("/dev/cpu_dma_latency", &s);
if (err == -1) {
err_msg_n(errno, "WARN: stat /dev/cpu_dma_latency failed");
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));
}
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);
}
}