From patchwork Mon Mar 2 21:10:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 45331 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f199.google.com (mail-we0-f199.google.com [74.125.82.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B8A8D214B5 for ; Mon, 2 Mar 2015 21:11:28 +0000 (UTC) Received: by wesq59 with SMTP id q59sf25699164wes.2 for ; Mon, 02 Mar 2015 13:11:28 -0800 (PST) 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=4wBr0TrzeQle5TJdsOTdGtOlgsG0QrFpR42qE0AJ/rs=; b=FVK/WGZcNcjC0KSa6oJaIJ7kPMM+sBHsgZV+M/G4iwG2m72fxfMU1RbnehsUxqujdC 8zqTzxwPfmkmStuPfcfOinbt30vFlRawG0ZAfO6aaHgJRzOvOWrra70A9leT2nMOSeDJ BITUI1WUJAD0G/3RZIkpGQklcXmvh3dQt4fPYXR00fduz02wyi2X4h6rfaC/YMbj6Ifh akEfgMPHcouQO7/fVQJra6oBK3e5+i0oMJluZPYHlBfJE4DBXualshEOjeu1xkDDFIFs POefvi9lr2jtZpCTYfUEF7Yw+PUm3L7KFxBvJ9ufco/e2qowm+LtzVFAEbJsn02ah5Dz Md1Q== X-Gm-Message-State: ALoCoQmA3oO2SepHYdgZJVUnTObL0X16o7ljDqwI6yxSNKSBr/JazVsOwxwDowSsXQ7PN8PjRJTH X-Received: by 10.152.6.232 with SMTP id e8mr4083866laa.2.1425330687990; Mon, 02 Mar 2015 13:11:27 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.115.140 with SMTP id jo12ls508501lab.19.gmail; Mon, 02 Mar 2015 13:11:27 -0800 (PST) X-Received: by 10.152.37.2 with SMTP id u2mr7990499laj.45.1425330687816; Mon, 02 Mar 2015 13:11:27 -0800 (PST) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id kv4si9706790lbb.102.2015.03.02.13.11.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Mar 2015 13:11:27 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by lbdu14 with SMTP id u14so11846821lbd.0 for ; Mon, 02 Mar 2015 13:11:27 -0800 (PST) X-Received: by 10.152.179.172 with SMTP id dh12mr25506554lac.76.1425330687684; Mon, 02 Mar 2015 13:11:27 -0800 (PST) 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.35.133 with SMTP id h5csp158705lbj; Mon, 2 Mar 2015 13:11:26 -0800 (PST) X-Received: by 10.66.178.139 with SMTP id cy11mr49995568pac.146.1425330664088; Mon, 02 Mar 2015 13:11:04 -0800 (PST) Received: from mail-pd0-f180.google.com (mail-pd0-f180.google.com. [209.85.192.180]) by mx.google.com with ESMTPS id e9si7282216pas.150.2015.03.02.13.11.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Mar 2015 13:11:04 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.192.180 as permitted sender) client-ip=209.85.192.180; Received: by pdno5 with SMTP id o5so42500237pdn.8 for ; Mon, 02 Mar 2015 13:11:02 -0800 (PST) X-Received: by 10.66.233.74 with SMTP id tu10mr49793148pac.135.1425330662685; Mon, 02 Mar 2015 13:11:02 -0800 (PST) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id ym10sm11765258pac.10.2015.03.02.13.11.01 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Mar 2015 13:11:01 -0800 (PST) From: John Stultz To: Linux Kernel Mailing List Cc: John Stultz , Shuah Khan , Prarit Bhargava , Thomas Gleixner , Richard Cochran Subject: [PATCH 16/19] selftests/timers: Add leapcrash test from the timetest suite Date: Mon, 2 Mar 2015 13:10:09 -0800 Message-Id: <1425330612-24280-17-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1425330612-24280-1-git-send-email-john.stultz@linaro.org> References: <1425330612-24280-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.217.182 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: , This change adds the leapcrash test which tests to see if a leapsecond deadlock which was observed from 2.6.26 to 3.3 is present on this system. Cc: Shuah Khan Cc: Prarit Bhargava Cc: Thomas Gleixner Cc: Richard Cochran Signed-off-by: John Stultz --- tools/testing/selftests/timers/Makefile | 3 +- tools/testing/selftests/timers/leapcrash.c | 120 +++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/timers/leapcrash.c diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile index da35ddd..d733324 100644 --- a/tools/testing/selftests/timers/Makefile +++ b/tools/testing/selftests/timers/Makefile @@ -5,7 +5,7 @@ LDFLAGS += -lrt -lpthread bins = posix_timers nanosleep inconsistency-check nsleep-lat raw_skew \ set-timer-lat threadtest mqueue-lat valid-adjtimex \ alarmtimer-suspend change_skew skew_consistency clocksource-switch \ - leap-a-day + leap-a-day leapcrash all: ${bins} @@ -31,6 +31,7 @@ run_destructive_tests: run_tests ./skew_consistency ./clocksource-switch ./leap-a-day -s -i 10 + ./leapcrash clean: rm -f ${bins} diff --git a/tools/testing/selftests/timers/leapcrash.c b/tools/testing/selftests/timers/leapcrash.c new file mode 100644 index 0000000..a1071bd --- /dev/null +++ b/tools/testing/selftests/timers/leapcrash.c @@ -0,0 +1,120 @@ +/* Demo leapsecond deadlock + * by: John Stultz (john.stultz@linaro.org) + * (C) Copyright IBM 2012 + * (C) Copyright 2013, 2015 Linaro Limited + * Licensed under the GPL + * + * This test demonstrates leapsecond deadlock that is possibe + * on kernels from 2.6.26 to 3.3. + * + * WARNING: THIS WILL LIKELY HARDHANG SYSTEMS AND MAY LOSE DATA + * RUN AT YOUR OWN RISK! + * To build: + * $ gcc leapcrash.c -o leapcrash -lrt + */ + + + +#include +#include +#include +#include +#include +#include +#include +#ifdef KTEST +#include "../kselftest.h" +#else +static inline int ksft_exit_pass(void) +{ + exit(0); +} +static inline int ksft_exit_fail(void) +{ + exit(1); +} +#endif + + + +/* clear NTP time_status & time_state */ +int clear_time_state(void) +{ + struct timex tx; + int ret; + + /* + * We have to call adjtime twice here, as kernels + * prior to 6b1859dba01c7 (included in 3.5 and + * -stable), had an issue with the state machine + * and wouldn't clear the STA_INS/DEL flag directly. + */ + tx.modes = ADJ_STATUS; + tx.status = STA_PLL; + ret = adjtimex(&tx); + + tx.modes = ADJ_STATUS; + tx.status = 0; + ret = adjtimex(&tx); + + return ret; +} + +/* Make sure we cleanup on ctrl-c */ +void handler(int unused) +{ + clear_time_state(); + exit(0); +} + + +int main(void) +{ + struct timex tx; + struct timespec ts; + time_t next_leap; + int count = 0; + + setbuf(stdout, NULL); + + signal(SIGINT, handler); + signal(SIGKILL, handler); + printf("This runs for a few minutes. Press ctrl-c to stop\n"); + + clear_time_state(); + + + /* Get the current time */ + clock_gettime(CLOCK_REALTIME, &ts); + + /* Calculate the next possible leap second 23:59:60 GMT */ + next_leap = ts.tv_sec; + next_leap += 86400 - (next_leap % 86400); + + for (count = 0; count < 20; count++) { + struct timeval tv; + + + /* set the time to 2 seconds before the leap */ + tv.tv_sec = next_leap - 2; + tv.tv_usec = 0; + if (settimeofday(&tv, NULL)) { + printf("Error: You're likely not running with proper (ie: root) permissions\n"); + return ksft_exit_fail(); + } + tx.modes = 0; + adjtimex(&tx); + + /* hammer on adjtime w/ STA_INS */ + while (tx.time.tv_sec < next_leap + 1) { + /* Set the leap second insert flag */ + tx.modes = ADJ_STATUS; + tx.status = STA_INS; + adjtimex(&tx); + } + clear_time_state(); + printf("."); + } + printf("[OK]\n"); + return ksft_exit_pass(); +}