From patchwork Thu Mar 12 00:40:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 45708 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 368BE214C6 for ; Thu, 12 Mar 2015 00:41:09 +0000 (UTC) Received: by lbvp9 with SMTP id p9sf9338356lbv.0 for ; Wed, 11 Mar 2015 17:41:08 -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=4wBr0TrzeQle5TJdsOTdGtOlgsG0QrFpR42qE0AJ/rs=; b=BlZq15cVXAvPBUg0V6d/p0bcn+v5uLBUgP06bWrueGM+kAUsnfuJLYSD1ZWg1A8WmE POAImxeeRb9jG5VbmA3Z0JMKpD9SCKN2tJK5oSHoD8L4UmqKY2syCxK65jHp3aChArLh 3bY/D7+ALZ4TyaSQpje4dfufhqYj+9oSrMFnOZ//KmxAff2ZDE3tcmft/Szpnt9c5L6q pg6X95jrODOecPNe5buywEuiHZ/4TypbEbKIMimrg5PwN0G47oBfrr7NIFNhUBVjMZVk IBlMcssU/iTIOh40Lwp4AuOHj7Bo6CUO2DSHXx9rOpwD/HKtNP4Ov+nIR2IYk7b8FUDT VlTQ== X-Gm-Message-State: ALoCoQn5K0J+XxXrkkNMoZNuLVaRLF7zN63lO6GvVCGZEcqFhdDziTTlx2aoLdXE5qqt3xRUKF8x X-Received: by 10.194.161.194 with SMTP id xu2mr5896766wjb.1.1426120868177; Wed, 11 Mar 2015 17:41:08 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.48 with SMTP id t16ls211109lal.55.gmail; Wed, 11 Mar 2015 17:41:07 -0700 (PDT) X-Received: by 10.152.29.102 with SMTP id j6mr37518651lah.12.1426120867844; Wed, 11 Mar 2015 17:41:07 -0700 (PDT) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id xv12si3354238lab.65.2015.03.11.17.41.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Mar 2015 17:41:07 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by lbiz12 with SMTP id z12so12563647lbi.12 for ; Wed, 11 Mar 2015 17:41:07 -0700 (PDT) X-Received: by 10.152.116.11 with SMTP id js11mr14830402lab.106.1426120867739; Wed, 11 Mar 2015 17:41:07 -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.35.133 with SMTP id h5csp3098694lbj; Wed, 11 Mar 2015 17:41:06 -0700 (PDT) X-Received: by 10.70.61.202 with SMTP id s10mr57662506pdr.86.1426120838329; Wed, 11 Mar 2015 17:40:38 -0700 (PDT) Received: from mail-pd0-f170.google.com (mail-pd0-f170.google.com. [209.85.192.170]) by mx.google.com with ESMTPS id v11si5892987pas.64.2015.03.11.17.40.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Mar 2015 17:40:38 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.192.170 as permitted sender) client-ip=209.85.192.170; Received: by pdbfl12 with SMTP id fl12so15366509pdb.9 for ; Wed, 11 Mar 2015 17:40:37 -0700 (PDT) X-Received: by 10.70.90.110 with SMTP id bv14mr77337872pdb.8.1426120837440; Wed, 11 Mar 2015 17:40:37 -0700 (PDT) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id qa1sm7783493pdb.84.2015.03.11.17.40.36 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Mar 2015 17:40:36 -0700 (PDT) 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: Wed, 11 Mar 2015 17:40:12 -0700 Message-Id: <1426120815-32528-17-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1426120815-32528-1-git-send-email-john.stultz@linaro.org> References: <1426120815-32528-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.172 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(); +}