From patchwork Wed Feb 25 22:32:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 45147 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5707620502 for ; Wed, 25 Feb 2015 22:33:17 +0000 (UTC) Received: by lbdu10 with SMTP id u10sf5095800lbd.3 for ; Wed, 25 Feb 2015 14:33:16 -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=JP8YZakXkBIqqWvsyn0Wgq+tlGKBNbcZGWHB2/M9mNU=; b=H2/G25yOx2a8xnhgA/tbNtkTvGxp9MtoF8JF/8v6gMZbKnFwtMpaVdFldaL/HOKKRL gQTUUyMylK0tPUBmmJYKjU0e/74JfdoQMPwiXwKhwiRw3CPQj+kBdBcXnFHC4NCBXiJv A+w2uoFFhKA5dpChSm8Z1xkRVmM3IZx+iS73r8jhw1wQ3rvkACXpW53uUTL/PVr+iu91 b4zvkcnQfS/kJvCA0/PNK3va+kmfUK+QqfLB6d2hKy2H2/N959Na6lo4Q11uiv6NdTOc 4xcvT+kguaa3dkchrW8Veo4Na1Wcg57jwJt61HxjyQqKnjayoXFCPb4OuWcSerc/t71E NpNg== X-Gm-Message-State: ALoCoQmbk6n7p2G9epCGvq9NKEBFkJDPp/ZqujBB4MBRJrs6M8bQ1wmhOUKulcTstx4qjHeGH1gR X-Received: by 10.152.88.40 with SMTP id bd8mr841412lab.0.1424903596312; Wed, 25 Feb 2015 14:33:16 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.7.208 with SMTP id l16ls796717laa.66.gmail; Wed, 25 Feb 2015 14:33:16 -0800 (PST) X-Received: by 10.112.118.211 with SMTP id ko19mr4903700lbb.19.1424903596172; Wed, 25 Feb 2015 14:33:16 -0800 (PST) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id yg5si12401681lab.157.2015.02.25.14.33.16 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Feb 2015 14:33:16 -0800 (PST) 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 z12so7059805lbi.11 for ; Wed, 25 Feb 2015 14:33:16 -0800 (PST) X-Received: by 10.112.167.36 with SMTP id zl4mr5093033lbb.32.1424903595961; Wed, 25 Feb 2015 14:33:15 -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 h5csp2925030lbj; Wed, 25 Feb 2015 14:33:15 -0800 (PST) X-Received: by 10.66.221.135 with SMTP id qe7mr9059547pac.97.1424903568116; Wed, 25 Feb 2015 14:32:48 -0800 (PST) Received: from mail-pa0-f47.google.com (mail-pa0-f47.google.com. [209.85.220.47]) by mx.google.com with ESMTPS id cp6si12334765pad.70.2015.02.25.14.32.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Feb 2015 14:32:48 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.47 as permitted sender) client-ip=209.85.220.47; Received: by pabkx10 with SMTP id kx10so8570428pab.13 for ; Wed, 25 Feb 2015 14:32:47 -0800 (PST) X-Received: by 10.68.101.130 with SMTP id fg2mr9490402pbb.118.1424903567196; Wed, 25 Feb 2015 14:32:47 -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 qm12sm43160405pdb.36.2015.02.25.14.32.46 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Feb 2015 14:32:46 -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: Wed, 25 Feb 2015 14:32:21 -0800 Message-Id: <1424903544-26855-17-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1424903544-26855-1-git-send-email-john.stultz@linaro.org> References: <1424903544-26855-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 | 106 +++++++++++++++++++++++++++++ 2 files changed, 108 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 6acc920..e9486cd 100644 --- a/tools/testing/selftests/timers/Makefile +++ b/tools/testing/selftests/timers/Makefile @@ -3,7 +3,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} @@ -29,6 +29,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..d787681 --- /dev/null +++ b/tools/testing/selftests/timers/leapcrash.c @@ -0,0 +1,106 @@ +/* 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 + + + +/* clear NTP time_status & time_state */ +void 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); +} + +/* 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"); + exit(-1); + } + 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 0; +}