mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Prarit Bhargava <prarit@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: corbet@lwn.net, rtc-linux@googlegroups.com,
	linux-doc@vger.kernel.org, a.zummo@towertech.it,
	Prarit Bhargava <prarit@redhat.com>
Subject: [PATCH 2/2] Documentation, update rtctest.c to verify passage of time
Date: Mon, 16 Mar 2015 11:58:55 -0400	[thread overview]
Message-ID: <1426521535-12501-3-git-send-email-prarit@redhat.com> (raw)
In-Reply-To: <1426521535-12501-1-git-send-email-prarit@redhat.com>

rtctest.c checks to see if PIE is functioning by testing if 20 interrupts occur
at rates from 2HZ to 64HZ.  While this check is good, it does not check to
see if the correct amount of time has actually passed.  This misses
situations where the RTC may be operating at a higher or lower frequency
than expected.

This patch introduces a simple check to verify if the time passed is
less than 10% of what was programmed into the RTC.

Also make a simple one line change to rtc.txt to point to the right test
program.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
---
 Documentation/rtc/rtc.txt   |    2 +-
 Documentation/rtc/rtctest.c |   13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/Documentation/rtc/rtc.txt b/Documentation/rtc/rtc.txt
index fd6e0cd..7f05eb7 100644
--- a/Documentation/rtc/rtc.txt
+++ b/Documentation/rtc/rtc.txt
@@ -204,4 +204,4 @@ Some common examples:
 
     *	RTC_PIE_ON, RTC_PIE_OFF: These are also emulated by the generic code.
 
-If all else fails, check out the rtc-test.c driver!
+If all else fails, check out the Documentation/rtc/rtctest.c driver!
diff --git a/Documentation/rtc/rtctest.c b/Documentation/rtc/rtctest.c
index 1e06f46..d80ae85 100644
--- a/Documentation/rtc/rtctest.c
+++ b/Documentation/rtc/rtctest.c
@@ -36,6 +36,7 @@ int main(int argc, char **argv)
 	unsigned long tmp, data;
 	struct rtc_time rtc_tm;
 	const char *rtc = default_rtc;
+	struct timeval start, end, diff;
 
 	switch (argc) {
 	case 2:
@@ -230,12 +231,24 @@ test_PIE:
 		}
 
 		for (i=1; i<21; i++) {
+			gettimeofday(&start, NULL);
 			/* This blocks */
 			retval = read(fd, &data, sizeof(unsigned long));
 			if (retval == -1) {
 				perror("read");
 				exit(errno);
 			}
+			gettimeofday(&end, NULL);
+			timersub(&end, &start, &diff);
+			if (diff.tv_sec > 0 ||
+			    diff.tv_usec > ((1000000L / tmp) * 1.10)) {
+				fprintf(stderr, "\nPIE delta error: %ld.%06ld should be close to 0.%06ld\n",
+				       diff.tv_sec, diff.tv_usec,
+				       (1000000L / tmp));
+				fflush(stdout);
+				exit(-1);
+			}
+
 			fprintf(stderr, " %d",i);
 			fflush(stderr);
 			irqcount++;
-- 
1.7.9.3


  parent reply	other threads:[~2015-03-16 16:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-16 15:58 [PATCH 0/2] Documentation, update RTC documentation Prarit Bhargava
2015-03-16 15:58 ` [PATCH 1/2] Documentation, add rtc directory and split up rtc.txt Prarit Bhargava
2015-03-16 15:58 ` Prarit Bhargava [this message]
2015-03-16 17:10 ` [PATCH 0/2] Documentation, update RTC documentation Jonathan Corbet
2015-03-18 19:12   ` Prarit Bhargava

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=1426521535-12501-3-git-send-email-prarit@redhat.com \
    --to=prarit@redhat.com \
    --cc=a.zummo@towertech.it \
    --cc=corbet@lwn.net \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rtc-linux@googlegroups.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

Powered by JetHome