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>
Cc: Clark Williams <williams@redhat.com>, John Kacur <jkacur@redhat.com>
Subject: [PATCH 1/7] cyclictest: Clean-ups in timerthread before working on it
Date: Wed, 14 Oct 2015 15:32:12 +0200	[thread overview]
Message-ID: <1444829538-18465-2-git-send-email-jkacur@redhat.com> (raw)
In-Reply-To: <1444829538-18465-1-git-send-email-jkacur@redhat.com>

- Clean this function up a bit before modifying it
	- Don't use assignment in if statements
	- Put spaces before open braces and parentheses
	- Break lines up where possible that go over 80 chars

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/cyclictest/cyclictest.c | 50 ++++++++++++++++++++++++++-------------------
 1 file changed, 29 insertions(+), 21 deletions(-)

diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index b1f99ab22c57..00168e22fc7f 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -785,8 +785,9 @@ static void *timerthread(void *param)
 		CPU_ZERO(&mask);
 		CPU_SET(par->cpu, &mask);
 		thread = pthread_self();
-		if(pthread_setaffinity_np(thread, sizeof(mask), &mask) == -1)
-			warn("Could not set CPU affinity to CPU #%d\n", par->cpu);
+		if (pthread_setaffinity_np(thread, sizeof(mask), &mask) == -1)
+			warn("Could not set CPU affinity to CPU #%d\n",
+			     par->cpu);
 	}
 
 	interval.tv_sec = par->interval / USEC_PER_SEC;
@@ -809,11 +810,12 @@ static void *timerthread(void *param)
 	memset(&schedp, 0, sizeof(schedp));
 	schedp.sched_priority = par->prio;
 	if (setscheduler(0, par->policy, &schedp))
-		fatal("timerthread%d: failed to set priority to %d\n", par->cpu, par->prio);
+		fatal("timerthread%d: failed to set priority to %d\n",
+		      par->cpu, par->prio);
 
 	/* Get current time */
 #ifndef NO_PTHREAD_BARRIER
-	if(aligned || secaligned){
+	if (aligned || secaligned) {
 		pthread_barrier_wait(&globalt_barr);
 		if (par->tnum == 0) {
 			clock_gettime(par->clock, &globalt);
@@ -829,15 +831,14 @@ static void *timerthread(void *param)
 		}
 		pthread_barrier_wait(&align_barr);
 		now = globalt;
-		if(offset) {
+		if (offset) {
 			if (aligned)
 				now.tv_nsec += offset * par->tnum;
 			else
 				now.tv_nsec += offset;
 			tsnorm(&now);
 		}
-	}
-	else
+	} else
 #endif
 		clock_gettime(par->clock, &now);
 
@@ -854,9 +855,8 @@ static void *timerthread(void *param)
 	if (par->mode == MODE_CYCLIC) {
 		if (par->timermode == TIMER_ABSTIME)
 			tspec.it_value = next;
-		else {
+		else
 			tspec.it_value = interval;
-		}
 		timer_settime(timer, par->timermode, &tspec, NULL);
 	}
 
@@ -864,7 +864,7 @@ static void *timerthread(void *param)
 		itimer.it_interval.tv_sec = interval.tv_sec;
 		itimer.it_interval.tv_usec = interval.tv_nsec / 1000;
 		itimer.it_value = itimer.it_interval;
-		setitimer (ITIMER_REAL, &itimer, NULL);
+		setitimer(ITIMER_REAL, &itimer, NULL);
 	}
 
 	stat->threadstarted++;
@@ -884,18 +884,23 @@ static void *timerthread(void *param)
 
 		case MODE_CLOCK_NANOSLEEP:
 			if (par->timermode == TIMER_ABSTIME) {
-				if ((ret = clock_nanosleep(par->clock, TIMER_ABSTIME, &next, NULL))) {
+				ret = clock_nanosleep(par->clock, TIMER_ABSTIME,
+						      &next, NULL);
+				if (ret != 0) {
 					if (ret != EINTR)
 						warn("clock_nanosleep failed. errno: %d\n", errno);
 					goto out;
 				}
 			} else {
-				if ((ret = clock_gettime(par->clock, &now))) {
+				ret = clock_gettime(par->clock, &now);
+				if (ret != 0) {
 					if (ret != EINTR)
 						warn("clock_gettime() failed: %s", strerror(errno));
 					goto out;
 				}
-				if ((ret = clock_nanosleep(par->clock, TIMER_RELTIME, &interval, NULL))) {
+				ret = clock_nanosleep(par->clock,
+					TIMER_RELTIME, &interval, NULL);
+				if (ret != 0) {
 					if (ret != EINTR)
 						warn("clock_nanosleep() failed. errno: %d\n", errno);
 					goto out;
@@ -907,14 +912,16 @@ static void *timerthread(void *param)
 			break;
 
 		case MODE_SYS_NANOSLEEP:
-			if ((ret = clock_gettime(par->clock, &now))) {
+			ret = clock_gettime(par->clock, &now);
+			if (ret != 0) {
 				if (ret != EINTR)
 					warn("clock_gettime() failed: errno %d\n", errno);
 				goto out;
 			}
 			if (nanosleep(&interval, NULL)) {
 				if (errno != EINTR)
-					warn("nanosleep failed. errno: %d\n", errno);
+					warn("nanosleep failed. errno: %d\n",
+					     errno);
 				goto out;
 			}
 			next.tv_sec = now.tv_sec + interval.tv_sec;
@@ -922,10 +929,11 @@ static void *timerthread(void *param)
 			tsnorm(&next);
 			break;
 		}
-
-		if ((ret = clock_gettime(par->clock, &now))) {
+		ret = clock_gettime(par->clock, &now);
+		if (ret != 0) {
 			if (ret != EINTR)
-				warn("clock_getttime() failed. errno: %d\n", errno);
+				warn("clock_getttime() failed. errno: %d\n",
+				     errno);
 			goto out;
 		}
 
@@ -968,9 +976,9 @@ static void *timerthread(void *param)
 				stat->hist_overflow++;
 				if (stat->num_outliers < histogram)
 					stat->outliers[stat->num_outliers++] = stat->cycles;
-			}
-			else
+			} else {
 				stat->hist_array[diff]++;
+			}
 		}
 
 		stat->cycles++;
@@ -1003,7 +1011,7 @@ out:
 		itimer.it_value.tv_usec = 0;
 		itimer.it_interval.tv_sec = 0;
 		itimer.it_interval.tv_usec = 0;
-		setitimer (ITIMER_REAL, &itimer, NULL);
+		setitimer(ITIMER_REAL, &itimer, NULL);
 	}
 
 	/* switch to normal */
-- 
2.4.3


  reply	other threads:[~2015-10-14 13:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-14 13:32 [PATCH 0/7] rt-tests devel/v0.96 John Kacur
2015-10-14 13:32 ` John Kacur [this message]
2015-10-14 13:32 ` [PATCH 2/7] Fix some trivial typos found by codespell(1) John Kacur
2015-10-14 13:32 ` [PATCH 3/7] Makefile: add target to create OBJDIR before use John Kacur
2015-10-14 13:32 ` [PATCH 4/7] Makefile: OBJDIR should be an order-only-prerequisite John Kacur
2015-10-14 13:32 ` [PATCH 5/7] specfile: add signaltest manpage to files section and remove trailing whitespace in changelog John Kacur
2015-10-15  8:52   ` Uwe Kleine-König
2015-10-15  8:53     ` Uwe Kleine-König
2015-10-14 13:32 ` [PATCH 6/7] Makefile: have distclean remove .asc file for tarball John Kacur
2015-10-14 13:32 ` [PATCH 7/7] Makefile: Move TARGETS back to a more logical place in the Makefile 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=1444829538-18465-2-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).