From patchwork Fri May 29 20:24:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 49238 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 024E022B38 for ; Fri, 29 May 2015 20:24:42 +0000 (UTC) Received: by wgez8 with SMTP id z8sf20921555wge.2 for ; Fri, 29 May 2015 13:24:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=YTL6fIriAujyYNWvCluPdcYCCVRzE4s16pDetRpOxAI=; b=mIhvXRh2AheRpiAlz2eU3S/7QSxjZQERykq4QI1OzIkhodSJJeA5hqqKExq6lEmL6p 8URguYWWkl2GHCGrsPw/43uxjyGw7it8qF1n2AfwAHZxr/zTXp/B0VYHAa6XQb7I8j+6 BnxGzo9jaB9pJTVTlLDLaDDtL7aAI5ilyk/8/TUxHWFqZDeLCILNyQRB6c29zZ+X9S8w vL0b+IAONgfK1n2NLHx7sE8ngvRztgNxZ+Pdzt3dh3aNhBB8+hJoY0Fp41ZM7x6EsGyj bAf++K/IlALR7qXGl5jDEKIVx+rKXOPaQkdO2WIDRv1q+0zDFXDCYvsnrtqlD86LMWLk pcaA== X-Gm-Message-State: ALoCoQlQIK8VLJW9RncHyLIiG3YSl4KN1Fh/RPPDUeJE1CbWdBn2k1DqNWZQN//2mFPK6DOa0uM8 X-Received: by 10.112.189.131 with SMTP id gi3mr8805503lbc.6.1432931080827; Fri, 29 May 2015 13:24:40 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.204.103 with SMTP id kx7ls417202lac.62.gmail; Fri, 29 May 2015 13:24:40 -0700 (PDT) X-Received: by 10.112.130.129 with SMTP id oe1mr9554141lbb.37.1432931080648; Fri, 29 May 2015 13:24:40 -0700 (PDT) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id wx3si5548180lbb.142.2015.05.29.13.24.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 May 2015 13:24:40 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by lagv1 with SMTP id v1so64043235lag.3 for ; Fri, 29 May 2015 13:24:40 -0700 (PDT) X-Received: by 10.112.93.37 with SMTP id cr5mr9940010lbb.106.1432931080185; Fri, 29 May 2015 13:24:40 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp615357lbb; Fri, 29 May 2015 13:24:38 -0700 (PDT) X-Received: by 10.70.132.195 with SMTP id ow3mr17767657pdb.87.1432931078176; Fri, 29 May 2015 13:24:38 -0700 (PDT) Received: from mail-pa0-f49.google.com (mail-pa0-f49.google.com. [209.85.220.49]) by mx.google.com with ESMTPS id i8si9892755pdj.174.2015.05.29.13.24.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 May 2015 13:24:38 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.49 as permitted sender) client-ip=209.85.220.49; Received: by pacrp13 with SMTP id rp13so21363622pac.2 for ; Fri, 29 May 2015 13:24:37 -0700 (PDT) X-Received: by 10.70.95.106 with SMTP id dj10mr17993125pdb.103.1432931077209; Fri, 29 May 2015 13:24:37 -0700 (PDT) Received: from localhost.localdomain (c-71-63-136-39.hsd1.or.comcast.net. [71.63.136.39]) by mx.google.com with ESMTPSA id qs8sm6452549pbc.38.2015.05.29.13.24.36 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 29 May 2015 13:24:36 -0700 (PDT) From: John Stultz To: lkml Cc: John Stultz , Prarit Bhargava , Daniel Bristot de Oliveira , Richard Cochran , Jan Kara , Jiri Bohac , Thomas Gleixner , Ingo Molnar , Shuah Khan Subject: [RFC][PATCH 1/4] selftests: timers: Add leap-second timer edge testing to leap-a-day.c Date: Fri, 29 May 2015 13:24:25 -0700 Message-Id: <1432931068-4980-2-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1432931068-4980-1-git-send-email-john.stultz@linaro.org> References: <1432931068-4980-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Prarit reported an issue w/ timers around the leapsecond, where a timer set for Midnight UTC (00:00:00) might fire a second early right before the leapsecond (23:59:60 - though it appears as a repeated 23:59:59) is applied. So I've updated the leap-a-day.c test to integrate a similar test, where we set a timer and check if it triggers at the right time, and if the ntp state transition is managed properly. Currently this test will fail. But following patches correct the issue. Cc: Prarit Bhargava Cc: Daniel Bristot de Oliveira Cc: Richard Cochran Cc: Jan Kara Cc: Jiri Bohac Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Shuah Khan Reported-by: Daniel Bristot de Oliveira Reported-by: Prarit Bhargava Signed-off-by: John Stultz --- tools/testing/selftests/timers/leap-a-day.c | 76 +++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/timers/leap-a-day.c b/tools/testing/selftests/timers/leap-a-day.c index b8272e6..331c4f7 100644 --- a/tools/testing/selftests/timers/leap-a-day.c +++ b/tools/testing/selftests/timers/leap-a-day.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -63,6 +64,9 @@ static inline int ksft_exit_fail(void) #define NSEC_PER_SEC 1000000000ULL #define CLOCK_TAI 11 +time_t next_leap; +int error_found; + /* returns 1 if a <= b, 0 otherwise */ static inline int in_order(struct timespec a, struct timespec b) { @@ -134,6 +138,34 @@ void handler(int unused) exit(0); } +void sigalarm(int signo) +{ + struct timex tx; + char buf[26]; + int ret; + + tx.modes = 0; + ret = adjtimex(&tx); + + ctime_r(&tx.time.tv_sec, buf); + buf[strlen(buf)-1] = 0; /*remove trailing\n */ + printf("%s + %6ld us (%i)\t%s - TIMER FIRED\n", + buf, + tx.time.tv_usec, + tx.tai, + time_state_str(ret)); + + if (tx.time.tv_sec < next_leap) { + printf("Error: Early timer expiration!\n"); + error_found = 1; + } + if (ret != TIME_WAIT) { + printf("Error: Incorrect NTP state?\n"); + error_found = 1; + } +} + + /* Test for known hrtimer failure */ void test_hrtimer_failure(void) { @@ -144,12 +176,19 @@ void test_hrtimer_failure(void) clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &target, NULL); clock_gettime(CLOCK_REALTIME, &now); - if (!in_order(target, now)) + if (!in_order(target, now)) { printf("ERROR: hrtimer early expiration failure observed.\n"); + error_found = 1; + } } int main(int argc, char **argv) { + timer_t tm1; + struct itimerspec its1; + struct sigevent se; + struct sigaction act; + int signum = SIGRTMAX; int settime = 0; int tai_time = 0; int insert = 1; @@ -191,6 +230,12 @@ int main(int argc, char **argv) signal(SIGINT, handler); signal(SIGKILL, handler); + /* Set up timer signal handler: */ + sigfillset(&act.sa_mask); + act.sa_flags = 0; + act.sa_handler = sigalarm; + sigaction(signum, &act, NULL); + if (iterations < 0) printf("This runs continuously. Press ctrl-c to stop\n"); else @@ -201,7 +246,7 @@ int main(int argc, char **argv) int ret; struct timespec ts; struct timex tx; - time_t now, next_leap; + time_t now; /* Get the current time */ clock_gettime(CLOCK_REALTIME, &ts); @@ -251,10 +296,27 @@ int main(int argc, char **argv) printf("Scheduling leap second for %s", ctime(&next_leap)); + /* Set up timer */ + printf("Setting timer for %s", ctime(&next_leap)); + memset(&se, 0, sizeof(se)); + se.sigev_notify = SIGEV_SIGNAL; + se.sigev_signo = signum; + se.sigev_value.sival_int = 0; + if (timer_create(CLOCK_REALTIME, &se, &tm1) == -1) { + printf("Error: timer_create failed\n"); + return ksft_exit_fail(); + } + its1.it_value.tv_sec = next_leap; + its1.it_value.tv_nsec = 0; + its1.it_interval.tv_sec = 0; + its1.it_interval.tv_nsec = 0; + timer_settime(tm1, TIMER_ABSTIME, &its1, NULL); + /* Wake up 3 seconds before leap */ ts.tv_sec = next_leap - 3; ts.tv_nsec = 0; + while (clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &ts, NULL)) printf("Something woke us up, returning to sleep\n"); @@ -276,6 +338,7 @@ int main(int argc, char **argv) while (now < next_leap + 2) { char buf[26]; struct timespec tai; + int ret; tx.modes = 0; ret = adjtimex(&tx); @@ -308,8 +371,13 @@ int main(int argc, char **argv) /* Note if kernel has known hrtimer failure */ test_hrtimer_failure(); - printf("Leap complete\n\n"); - + printf("Leap complete\n"); + if (error_found) { + printf("Errors observed\n"); + clear_time_state(); + return ksft_exit_fail(); + } + printf("\n"); if ((iterations != -1) && !(--iterations)) break; }