From patchwork Wed Jun 21 05:21:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 106041 Delivered-To: patches@linaro.org Received: by 10.140.91.2 with SMTP id y2csp1753649qgd; Tue, 20 Jun 2017 22:21:45 -0700 (PDT) X-Received: by 10.84.132.73 with SMTP id 67mr6371302ple.53.1498022505137; Tue, 20 Jun 2017 22:21:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498022505; cv=none; d=google.com; s=arc-20160816; b=ypApkut1EAcQ5zzKCNaHfbTmTBv57Kca8MdnXa08GlWc7VWOZ05NETg2BYrMclyoW7 OhtQlpScP4cb8Nnty5Js4+4Aist71owk5HIq+215OWc0w7HxDEOUd6iUszx8YFXEvIvt VORd5aUss3aEo0DQuSLVd2jeBaBcrQgnFmtYfXO+hYR2RHjl2ksiFJlLfvAny5V7BrkC B9qgb5rFEIFExkaMxKq2ThhgwPxvaJFzVojSMvuvEfFM0gjgo+oBfuFxSF6yu99Mjm40 kmy6V17uhoa895HujQYD7y9gtkpIIByxF7r5MUIS3tVG7XNhKpgh9nJt3AbjtyiY/tgd 2xcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=uMrpus7aNZATE+EKxuGLQ4WCLeLJIhHMnC+P+40H5pQ=; b=PwJfTC+HeqWgMm1jTDXQRiZFTg2BQzxv6zP39mHe3iLaDFeEztsL13fMKevkD1EPJO DMxDQg91gcwRvFqHZDyNIcpuafosiVnhKfqN38FTzN3U0XECv1lT4Sf4UlFFD+o6jtTF qPJM0VLDzQ51J+OoEfjSGXxb7WLMZshNQeCwrjlLKW2BsQbzFIhY0Fhd2xMnJih/0HRZ H79uPZoAeMUAQRQZ/eGXTjsQ+t6dmUGLu2wuXCmbCoKK08NbHw0SlMgWgvoagK1gl+fv 2p5wVy4hmIyqbSKX9/pEmWr0gjLKzp4XI6FZkhtu8BxLwOBW53DZG0KbDItyt+HNVG3v 2IQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=WkG4llf6; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::22b as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-pg0-x22b.google.com (mail-pg0-x22b.google.com. [2607:f8b0:400e:c05::22b]) by mx.google.com with ESMTPS id 2si11930696pfn.239.2017.06.20.22.21.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Jun 2017 22:21:45 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::22b as permitted sender) client-ip=2607:f8b0:400e:c05::22b; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=WkG4llf6; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::22b as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by mail-pg0-x22b.google.com with SMTP id f185so72581019pgc.0 for ; Tue, 20 Jun 2017 22:21:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uMrpus7aNZATE+EKxuGLQ4WCLeLJIhHMnC+P+40H5pQ=; b=WkG4llf6HkfjxzFZjwp3Tob1LqIKav3qBV7kbafEs6KjFsOgSGEBRvvkMIzSiExM7w FJziQWuj/C36p7EuGc9IclF2Z6AxyRgDibgmzkBNovUSH0a5yDiA7DiRvmAa0vR+Ru5I +mhx6+eskUEdL3Il9Le+hL8haHz+QExf2HXxk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uMrpus7aNZATE+EKxuGLQ4WCLeLJIhHMnC+P+40H5pQ=; b=UuZ9XCwuL57IG6McE1B2xkRf4OJTZTg0LkH24OGmEtWu1jtjrC7G/CmDQkcs/RX9T8 9Klvs0ELc3RFa7Hf9UWUXmWsmUsR+WwKQ/agOrwRd8PCbBEz/vURSdMFUZb+x6ybOsjY LoSsauZD5uNNKcmRky+5reXnGHjMffiW8+X95xPA9LtZbQS8dHbLiOw7b9jV0/oWJlim LpgTl29pkIW4gsQcU2wrlSwJ5xNpe3mix+lFC6bKZyiwAqivZuo4OrYHK8huC7+3eS8u Nmnxwtrna6dN0XJrhFPDY4EhEjm7bj0KYRMD2PyglIVqIjrSnAv7nvvdgLYdfM9Om/bQ hDNw== X-Gm-Message-State: AKS2vOyuSb077GavAG1BDPiUGbKr/JSqWXvrbYpByDO3M0rAIRKfP51m /jGKkKdDRmCbxxUpJfY= X-Received: by 10.99.108.193 with SMTP id h184mr35774753pgc.166.1498022504757; Tue, 20 Jun 2017 22:21:44 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id a69sm30405992pfg.91.2017.06.20.22.21.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 Jun 2017 22:21:43 -0700 (PDT) From: John Stultz To: lkml Cc: John Stultz , Thomas Gleixner , Ingo Molnar , Miroslav Lichvar , Richard Cochran , Prarit Bhargava , Stephen Boyd , Kevin Brodsky , Will Deacon , Daniel Mentz Subject: [PATCH 1/4] time: Clean up CLOCK_MONOTONIC_RAW time handling Date: Tue, 20 Jun 2017 22:21:30 -0700 Message-Id: <1498022493-20292-2-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498022493-20292-1-git-send-email-john.stultz@linaro.org> References: <1498022493-20292-1-git-send-email-john.stultz@linaro.org> Now that we fixed the sub-ns handling for CLOCK_MONOTONIC_RAW, remove the duplicitive tk->raw_time.tv_nsec, which can be stored in tk->tkr_raw.xtime_nsec (similarly to how its handled for monotonic time). Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Miroslav Lichvar Cc: Richard Cochran Cc: Prarit Bhargava Cc: Stephen Boyd Cc: Kevin Brodsky Cc: Will Deacon Cc: Daniel Mentz Tested-by: Daniel Mentz Signed-off-by: John Stultz --- arch/arm64/kernel/vdso.c | 6 ++--- include/linux/timekeeper_internal.h | 4 ++-- kernel/time/timekeeping.c | 45 ++++++++++++++++++++----------------- 3 files changed, 29 insertions(+), 26 deletions(-) -- 2.7.4 Acked-by: Will Deacon diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c index d0cb007..7492d90 100644 --- a/arch/arm64/kernel/vdso.c +++ b/arch/arm64/kernel/vdso.c @@ -220,10 +220,8 @@ void update_vsyscall(struct timekeeper *tk) if (!use_syscall) { /* tkr_mono.cycle_last == tkr_raw.cycle_last */ vdso_data->cs_cycle_last = tk->tkr_mono.cycle_last; - vdso_data->raw_time_sec = tk->raw_time.tv_sec; - vdso_data->raw_time_nsec = (tk->raw_time.tv_nsec << - tk->tkr_raw.shift) + - tk->tkr_raw.xtime_nsec; + vdso_data->raw_time_sec = tk->raw_sec; + vdso_data->raw_time_nsec = tk->tkr_raw.xtime_nsec; vdso_data->xtime_clock_sec = tk->xtime_sec; vdso_data->xtime_clock_nsec = tk->tkr_mono.xtime_nsec; vdso_data->cs_mono_mult = tk->tkr_mono.mult; diff --git a/include/linux/timekeeper_internal.h b/include/linux/timekeeper_internal.h index f7043cc..0a0a53d 100644 --- a/include/linux/timekeeper_internal.h +++ b/include/linux/timekeeper_internal.h @@ -51,7 +51,7 @@ struct tk_read_base { * @clock_was_set_seq: The sequence number of clock was set events * @cs_was_changed_seq: The sequence number of clocksource change events * @next_leap_ktime: CLOCK_MONOTONIC time value of a pending leap-second - * @raw_time: Monotonic raw base time in timespec64 format + * @raw_sec: CLOCK_MONOTONIC_RAW time in seconds * @cycle_interval: Number of clock cycles in one NTP interval * @xtime_interval: Number of clock shifted nano seconds in one NTP * interval. @@ -93,7 +93,7 @@ struct timekeeper { unsigned int clock_was_set_seq; u8 cs_was_changed_seq; ktime_t next_leap_ktime; - struct timespec64 raw_time; + u64 raw_sec; /* The following members are for timekeeping internal use */ u64 cycle_interval; diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index b602c48..0454bfa 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -72,6 +72,10 @@ static inline void tk_normalize_xtime(struct timekeeper *tk) tk->tkr_mono.xtime_nsec -= (u64)NSEC_PER_SEC << tk->tkr_mono.shift; tk->xtime_sec++; } + while (tk->tkr_raw.xtime_nsec >= ((u64)NSEC_PER_SEC << tk->tkr_raw.shift)) { + tk->tkr_raw.xtime_nsec -= (u64)NSEC_PER_SEC << tk->tkr_raw.shift; + tk->raw_sec++; + } } static inline struct timespec64 tk_xtime(struct timekeeper *tk) @@ -285,12 +289,14 @@ static void tk_setup_internals(struct timekeeper *tk, struct clocksource *clock) /* if changing clocks, convert xtime_nsec shift units */ if (old_clock) { int shift_change = clock->shift - old_clock->shift; - if (shift_change < 0) + if (shift_change < 0) { tk->tkr_mono.xtime_nsec >>= -shift_change; - else + tk->tkr_raw.xtime_nsec >>= -shift_change; + } else { tk->tkr_mono.xtime_nsec <<= shift_change; + tk->tkr_raw.xtime_nsec <<= shift_change; + } } - tk->tkr_raw.xtime_nsec = 0; tk->tkr_mono.shift = clock->shift; tk->tkr_raw.shift = clock->shift; @@ -619,9 +625,6 @@ static inline void tk_update_ktime_data(struct timekeeper *tk) nsec = (u32) tk->wall_to_monotonic.tv_nsec; tk->tkr_mono.base = ns_to_ktime(seconds * NSEC_PER_SEC + nsec); - /* Update the monotonic raw base */ - tk->tkr_raw.base = timespec64_to_ktime(tk->raw_time); - /* * The sum of the nanoseconds portions of xtime and * wall_to_monotonic can be greater/equal one second. Take @@ -631,6 +634,11 @@ static inline void tk_update_ktime_data(struct timekeeper *tk) if (nsec >= NSEC_PER_SEC) seconds++; tk->ktime_sec = seconds; + + /* Update the monotonic raw base */ + seconds = tk->raw_sec; + nsec = (u32)(tk->tkr_raw.xtime_nsec >> tk->tkr_raw.shift); + tk->tkr_raw.base = ns_to_ktime(seconds * NSEC_PER_SEC + nsec); } /* must hold timekeeper_lock */ @@ -672,7 +680,6 @@ static void timekeeping_update(struct timekeeper *tk, unsigned int action) static void timekeeping_forward_now(struct timekeeper *tk) { u64 cycle_now, delta; - u64 nsec; cycle_now = tk_clock_read(&tk->tkr_mono); delta = clocksource_delta(cycle_now, tk->tkr_mono.cycle_last, tk->tkr_mono.mask); @@ -684,10 +691,13 @@ static void timekeeping_forward_now(struct timekeeper *tk) /* If arch requires, add in get_arch_timeoffset() */ tk->tkr_mono.xtime_nsec += (u64)arch_gettimeoffset() << tk->tkr_mono.shift; - tk_normalize_xtime(tk); - nsec = clocksource_cyc2ns(delta, tk->tkr_raw.mult, tk->tkr_raw.shift); - timespec64_add_ns(&tk->raw_time, nsec); + tk->tkr_raw.xtime_nsec += delta * tk->tkr_raw.mult; + + /* If arch requires, add in get_arch_timeoffset() */ + tk->tkr_raw.xtime_nsec += (u64)arch_gettimeoffset() << tk->tkr_raw.shift; + + tk_normalize_xtime(tk); } /** @@ -1373,19 +1383,18 @@ int timekeeping_notify(struct clocksource *clock) void getrawmonotonic64(struct timespec64 *ts) { struct timekeeper *tk = &tk_core.timekeeper; - struct timespec64 ts64; unsigned long seq; u64 nsecs; do { seq = read_seqcount_begin(&tk_core.seq); + ts->tv_sec = tk->raw_sec; nsecs = timekeeping_get_ns(&tk->tkr_raw); - ts64 = tk->raw_time; } while (read_seqcount_retry(&tk_core.seq, seq)); - timespec64_add_ns(&ts64, nsecs); - *ts = ts64; + ts->tv_nsec = 0; + timespec64_add_ns(ts, nsecs); } EXPORT_SYMBOL(getrawmonotonic64); @@ -1509,8 +1518,7 @@ void __init timekeeping_init(void) tk_setup_internals(tk, clock); tk_set_xtime(tk, &now); - tk->raw_time.tv_sec = 0; - tk->raw_time.tv_nsec = 0; + tk->raw_sec = 0; if (boot.tv_sec == 0 && boot.tv_nsec == 0) boot = tk_xtime(tk); @@ -2011,15 +2019,12 @@ static u64 logarithmic_accumulation(struct timekeeper *tk, u64 offset, *clock_set |= accumulate_nsecs_to_secs(tk); /* Accumulate raw time */ - tk->tkr_raw.xtime_nsec += (u64)tk->raw_time.tv_nsec << tk->tkr_raw.shift; tk->tkr_raw.xtime_nsec += tk->raw_interval << shift; snsec_per_sec = (u64)NSEC_PER_SEC << tk->tkr_raw.shift; while (tk->tkr_raw.xtime_nsec >= snsec_per_sec) { tk->tkr_raw.xtime_nsec -= snsec_per_sec; - tk->raw_time.tv_sec++; + tk->raw_sec++; } - tk->raw_time.tv_nsec = tk->tkr_raw.xtime_nsec >> tk->tkr_raw.shift; - tk->tkr_raw.xtime_nsec -= (u64)tk->raw_time.tv_nsec << tk->tkr_raw.shift; /* Accumulate error between NTP and clock interval */ tk->ntp_error += tk->ntp_tick << shift; From patchwork Wed Jun 21 05:21:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 106042 Delivered-To: patches@linaro.org Received: by 10.140.91.2 with SMTP id y2csp1753658qgd; Tue, 20 Jun 2017 22:21:46 -0700 (PDT) X-Received: by 10.84.232.137 with SMTP id i9mr22166479plk.154.1498022506583; Tue, 20 Jun 2017 22:21:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498022506; cv=none; d=google.com; s=arc-20160816; b=p8nbEG6ieCr3KKbtM7yCPjYgNtu1p3LtiWUKhzjph3zoQlD92KhU9XHAP35Fj5UvlW 3QYlwvodFQ+2TDJFYk9wFXYpnRiD5W5MJpulJEFkUwP0gSNjXSigM4kErHKPTXAwEoEZ ZqmuzCaBiuPUbCRYuibfvJL+IEwP1I652X9RGhCcT6jJuS51HuSHubOgoNez7xUTYM/N /4z0zBff6feNN0Xl/ClRdR3T34JoadgBjrzb9vSR5hAJBWuu1OLd7anTmv1TqWA5tH5l VOgdFFBhuvrj7Qb7DR/Sq6ugJ1qv1ZvHftrQjo9oXG/NYO00d+INg1wMhYtRyIPQQkux Krxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=RQC3Ykek2ehmI5RGJ3BOwl0W5dTRYlzDII/mMO2NafQ=; b=A+K0T3CJ7ucHYQLo7BC3y5N5XCKqwGk6VtB6ArG0cG707upGp4OHIvgiOflzmH65eq qiNV0Vc6p6SIg87X6bHg7xh8sCqpFrX0XPtCnRtiqjfUHu7O7oDKv17J0yFXrpZ4Hz4w IcUkH8jkkcmu9Pbt9dKes/in3PRBqADG1mV6bYwitCDyfKYLU4wjDkYEwz+iVGDIoaeb YDeSC7HsykrQ188YJLQ67ubvg8/PLo+LauYPrNbC2TJ2ywQK6UT7J2lN8XK2S2CD6vyo 0XjbGFusxJlllTLxRqeaiAtQW3HjdIYoiJsX61B8aqI/5xURysoew/WaN9q6WkXaodH9 RdYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=VBRen69O; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::229 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-pf0-x229.google.com (mail-pf0-x229.google.com. [2607:f8b0:400e:c00::229]) by mx.google.com with ESMTPS id e4si13990923plk.481.2017.06.20.22.21.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Jun 2017 22:21:46 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::229 as permitted sender) client-ip=2607:f8b0:400e:c00::229; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=VBRen69O; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::229 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by mail-pf0-x229.google.com with SMTP id c73so19822660pfk.2 for ; Tue, 20 Jun 2017 22:21:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RQC3Ykek2ehmI5RGJ3BOwl0W5dTRYlzDII/mMO2NafQ=; b=VBRen69OtjYPBz4qTKY58eYQhluRTFqMGefIrF5Tciii7TbYuUOmI+6NE03ym78mCT B6gNgKgydbsNERVNMQfa9nuhFk0l4+913IAP5tYpGYmZ3Rpv+JSa93vwV17FhGJUz0o+ k/OuCSUqWU8aeNQ2RjIvpKTn/GFHIW96Kn/Aw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RQC3Ykek2ehmI5RGJ3BOwl0W5dTRYlzDII/mMO2NafQ=; b=KyD7mR8i9l7v2tA+Rwt7wZ67zWEYDdHJMye016WoTfFj5U9horRE32xGx08jeK1Ykt DTMGFLcjGHdBaTYrfPMpKootPBDfOdCle6YxBF+oohJd2HV08SmAUUQvZB71forRV0qE kxFrPABEVrKe7ssHJTOX5nFaKaO56XzGbLlaOtjCI7zaMjIwqgwuol0tRcdrryOglZMO 1tAJdMoEzyUATvPQa5tpXPndZJ9RYwfEcwFw8DPCI6HxrjCd159kuS1n30gmsEmiFSMy kJSFQTQcpuiAgdQWQuRiS102IoKSe1Qpx6dNcHfhcExENOQEBQclwYLkKo6mWh47ypAh OftA== X-Gm-Message-State: AKS2vOzx99dv4vqoDbWr2CBirapcgLjDk7tDy5BJna0iDZtTMs04qazg GfGiMurou25yOq30/rA= X-Received: by 10.84.229.5 with SMTP id b5mr12956638plk.164.1498022506307; Tue, 20 Jun 2017 22:21:46 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id a69sm30405992pfg.91.2017.06.20.22.21.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 Jun 2017 22:21:45 -0700 (PDT) From: John Stultz To: lkml Cc: John Stultz , Thomas Gleixner , Ingo Molnar , Miroslav Lichvar , Richard Cochran , Prarit Bhargava , Marcelo Tosatti , Paul Mackerras , Anton Blanchard , Benjamin Herrenschmidt , Tony Luck , Michael Ellerman , Fenghua Yu Subject: [PATCH 2/4] time: Add warning about imminent deprecation of CONFIG_GENERIC_TIME_VSYSCALL_OLD Date: Tue, 20 Jun 2017 22:21:31 -0700 Message-Id: <1498022493-20292-3-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498022493-20292-1-git-send-email-john.stultz@linaro.org> References: <1498022493-20292-1-git-send-email-john.stultz@linaro.org> CONFIG_GENERIC_TIME_VSYSCALL_OLD was introduced five years ago to allow a transition from the old vsyscall implementations to the new method (which simplified internal accounting and made timekeeping more precise). However, PPC and IA64 have yet to make the transition, despite in some cases me sending test patches to try to help it along. http://patches.linaro.org/patch/30501/ http://patches.linaro.org/patch/35412/ If its helpful, my last pass at the patches can be found here: https://git.linaro.org/people/john.stultz/linux.git dev/oldvsyscall-cleanup So I think its time to set a deadline and make it clear this is going away. So this patch adds warnings about this functionality being dropped. Likely to be in v4.15. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Miroslav Lichvar Cc: Richard Cochran Cc: Prarit Bhargava Cc: Marcelo Tosatti Cc: Paul Mackerras Cc: Anton Blanchard Cc: Benjamin Herrenschmidt Cc: Tony Luck Cc: Michael Ellerman Cc: Fenghua Yu Signed-off-by: John Stultz --- kernel/time/timekeeping.c | 1 + 1 file changed, 1 insertion(+) -- 2.7.4 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 0454bfa..cedafa0 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -516,6 +516,7 @@ static void halt_fast_timekeeper(struct timekeeper *tk) } #ifdef CONFIG_GENERIC_TIME_VSYSCALL_OLD +#warning Please contact your maintainers, as GENERIC_TIME_VSYSCALL_OLD compatibity will disappear soon. static inline void update_vsyscall(struct timekeeper *tk) { From patchwork Wed Jun 21 05:21:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 106043 Delivered-To: patches@linaro.org Received: by 10.140.91.2 with SMTP id y2csp1753666qgd; Tue, 20 Jun 2017 22:21:48 -0700 (PDT) X-Received: by 10.98.30.65 with SMTP id e62mr10768066pfe.127.1498022508300; Tue, 20 Jun 2017 22:21:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498022508; cv=none; d=google.com; s=arc-20160816; b=SbjDBmsAw7bCJLDUJI04Z6chekLxVnPZlKVyziHH0X+FofMhnoJfZhIYGRnT+lRfBO 50JUDWhCqisbP3D7yVN6hrkMFQa4dCtEfohZdZrq1yE8xYUC0sZ4aruB+PlHatZ8uj68 TxEcEx9qyQNdIbeUNjLCDMZ1Vlvv/UJrkUKMigUiUJW7zwVt5FzgX2azngvj5Q45dXiv xq7s0dBfg3Xbtf3UE17M+X03JN+LfkTmQJV4IXUYwNqQhSdb7aQF2M7srjQZqg7C9R1v Y3sYqbMBDMdpuMU/jkT51yFMd81LNBZoXsyMl6Fgf8xAm/WOgufWSl89O38PeZImIfK0 ELBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=FQMa1GYi7kdJd6yTnOwK7/OxS4BkWZVAL4XrKk70qHU=; b=ZtPQrA3wEICps5kFh/MmPSz++AOCLaZVHUSZwTF1j7tUjZlD9cHKk72zaL2aMFTQuv dvpQcRNR19sYgSp8EJrUQJxXoeUb6svS7ZTCPCZ5ByNzLiKe5G/XjGAf5hysZz9leQAI BTAiJdvUaDTjMiLfgE6JEn0X3+RvuRSwLvh8XNcsYl+PVS51LA5wDsieJk14FvDWn8Qq XeDh6MQaAbQFmlnol3QKwGmpzLkZ3hDO2UFMuvB+ev3F7nc4BGSo/ds43yjFeTLHH/9R u/km23ehxkRlrho1n+oMNNdTmFK2WTWuiLoU0tAWZXkjBGeaf1djM6uokbQx7bhNtoVx qMfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=i0iBTshE; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::236 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-pg0-x236.google.com (mail-pg0-x236.google.com. [2607:f8b0:400e:c05::236]) by mx.google.com with ESMTPS id x125si11935261pfb.457.2017.06.20.22.21.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Jun 2017 22:21:48 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::236 as permitted sender) client-ip=2607:f8b0:400e:c05::236; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=i0iBTshE; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::236 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by mail-pg0-x236.google.com with SMTP id 132so38955761pgb.2 for ; Tue, 20 Jun 2017 22:21:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FQMa1GYi7kdJd6yTnOwK7/OxS4BkWZVAL4XrKk70qHU=; b=i0iBTshEEcftudzaSWKzoT+jb+waXDqSsSD2jBA2u8ug+v31kiQPOnais4k/u7k9kH qp0hxVXdrO3CKxCg1qNpcasi8hA+hvmhUGM4m0qLHkvOBMn7I1jq8LHHBYY4CapfFVRd oTWAmCeuglwDHjgI+zMyopj/0q4pmHoTQZJEM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FQMa1GYi7kdJd6yTnOwK7/OxS4BkWZVAL4XrKk70qHU=; b=rCO2feY1XNydkNaMCPhvfokxQ66l2rFDQs5HUGhfXaDOC01b+OmFWn9YlI3Tiz868h NhmrG0Intdvv6ziefoOoBh3sJ2qocmjTvl1zUxDC1sSPhfIEGOea0dudFHctGI48jkeS nhPLpNALG2zVV0dEWWYVIHFGqUWoj1e4YmIJ6abYT8DFSlOFZNEGSV0Uh58MiqJ5ibQP YmBWmR6Ao8uQE/fU4dKnLY5bhfh1kHC53hNezxj/2gAKFcLPVHseTK0s4OSsPR9l4x2E kBSdd+Fc3St4HJcKD+1uWb6eu3cDSEgIJVzhqfXfDZTzOD/39LsOSD8iu1cN1MPHL6cg PFZA== X-Gm-Message-State: AKS2vOxQMXPb8qcG9plTJdt2Sle8y6I+a+1beKDC0cU19hp8LVJjcuco 6l07CJN1pbsDxMmqXYY= X-Received: by 10.84.248.79 with SMTP id e15mr29757896pln.118.1498022507909; Tue, 20 Jun 2017 22:21:47 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id a69sm30405992pfg.91.2017.06.20.22.21.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 Jun 2017 22:21:46 -0700 (PDT) From: John Stultz To: lkml Cc: Miroslav Lichvar , Thomas Gleixner , Ingo Molnar , Richard Cochran , Prarit Bhargava , Stephen Boyd , Shuah Khan , John Stultz Subject: [PATCH 3/4] kselftests: timers: Fix inconsistency-check to not ignore first timestamp Date: Tue, 20 Jun 2017 22:21:32 -0700 Message-Id: <1498022493-20292-4-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498022493-20292-1-git-send-email-john.stultz@linaro.org> References: <1498022493-20292-1-git-send-email-john.stultz@linaro.org> From: Miroslav Lichvar When the first timestamp in the list of clock readings was later than the second timestamp and all other timestamps were in order, the inconsistency was not reported because the index of the out-of-order timestamp was equal to the default value. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Miroslav Lichvar Cc: Richard Cochran Cc: Prarit Bhargava Cc: Stephen Boyd Cc: Shuah Khan Signed-off-by: Miroslav Lichvar Signed-off-by: John Stultz --- tools/testing/selftests/timers/inconsistency-check.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/tools/testing/selftests/timers/inconsistency-check.c b/tools/testing/selftests/timers/inconsistency-check.c index caf1bc9..74c60e8 100644 --- a/tools/testing/selftests/timers/inconsistency-check.c +++ b/tools/testing/selftests/timers/inconsistency-check.c @@ -118,7 +118,7 @@ int consistency_test(int clock_type, unsigned long seconds) start_str = ctime(&t); while (seconds == -1 || now - then < seconds) { - inconsistent = 0; + inconsistent = -1; /* Fill list */ for (i = 0; i < CALLS_PER_LOOP; i++) @@ -130,7 +130,7 @@ int consistency_test(int clock_type, unsigned long seconds) inconsistent = i; /* display inconsistency */ - if (inconsistent) { + if (inconsistent >= 0) { unsigned long long delta; printf("\%s\n", start_str); From patchwork Wed Jun 21 05:21:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 106044 Delivered-To: patches@linaro.org Received: by 10.140.91.2 with SMTP id y2csp1753672qgd; Tue, 20 Jun 2017 22:21:49 -0700 (PDT) X-Received: by 10.99.24.66 with SMTP id 2mr35593691pgy.105.1498022509811; Tue, 20 Jun 2017 22:21:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498022509; cv=none; d=google.com; s=arc-20160816; b=OG4i8KRonS7kkpTTTtHlCyPu8c2gueGMfE1Ylj1zAGBbLcrIXEtwQSRDyX0n97y/1O b67S6zg64LOe0e2mOK6inDkN4TgkcuDn5ECM6s9JLawqxC8nSHJqFsN/Dm0BcwoMhbtF jFYSC0aQ9BdzkcUNC2PDCFZoMhO5ZfHl+nxWWUlIduvclwobYWt2vuJIs10QIRPCPGxE kqPnXdaAR5OLHULrlCIwhJrKWQ3ZZ47QLA5uq+V24pP2jE0g0sr79V+G+f4eQOJrjUdD ZLijX2fBT6ItdtYzwYnj6LE/v30dNcYXLke85iakWC4SiR3bnuGc+6AAL4qFSMbtJgYK IL9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=+8SHeqrTLRCfdYP33S3w/u6D/310A7QzKx9bopHXZvQ=; b=H3A2rAcCUOyh56m4kz51G3b8vzUFaGY1howXwU1nWvH6XjLomnU2JLZIMrQBMPkHc7 mkNhskfIk9plo7yMsDPzHGxWsodik2n7eROq0+NXvfPM0gjjfxVFirWhK4oQqtPfTMAJ wC26FnzdueMZOekYi/DwUtv8kRf13kJQmTsouRJUwM7TaLEddzAXE+0xSjTj01nPtDq1 eq3OCA0xLkm1JLQTi6/TdLBugitKy6AayphvV6F+t/6xLosD2C8XzS8vo50b2UWFyb9Q 43zEwG6DtDuY9TV/H06kNRweBSlGh41LY2tPlwmU4KrEw6VF+Hgjrzqdr8RvSal8qAjA 21Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=f25IuTIM; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::22f as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-pg0-x22f.google.com (mail-pg0-x22f.google.com. [2607:f8b0:400e:c05::22f]) by mx.google.com with ESMTPS id q9si13860599plk.325.2017.06.20.22.21.49 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Jun 2017 22:21:49 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::22f as permitted sender) client-ip=2607:f8b0:400e:c05::22f; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=f25IuTIM; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::22f as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by mail-pg0-x22f.google.com with SMTP id 132so38956028pgb.2 for ; Tue, 20 Jun 2017 22:21:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+8SHeqrTLRCfdYP33S3w/u6D/310A7QzKx9bopHXZvQ=; b=f25IuTIMluW9ToWooX7vzUdbf55WEQZ5XT4AU6x4OCbp/QLjOsfO+3DOiYBjW38wPF nmDJxfaFZvppHH150uvSZkF38d9c7Z5P4rY+ymBnZVNhjZML86lJnMiBkayHVq8OqiXV n2+8FW4AUS/8jsIHNiGnXNFOVuGzzFRiaGh9I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+8SHeqrTLRCfdYP33S3w/u6D/310A7QzKx9bopHXZvQ=; b=aKSTRIyFW0OdkyEyy2C0qGFAX407SmVzpxKjoJpeOkt0lLjbiV96EJal1H3Ji6X0uc bVojs0pMYY3+9qOSUjh2TwH3ODXFV+Gqvi1dad8DjUK09r36fPYumtDfseLKQZg5/vcy zSyOA2JQN71IJnJxyPOhR1PfOyMQT4d2Wu/mPjLpfskMEw9qH7Q/xF1ui3P3LFVQTsWy f5VWLSDrClrn/eNZA5japQPuHpi5NWmO29eP/uwGxkAYstKpOWuYHiTYRJBcholGF9zp oZvpDc6UF/s1ghDw12s17fINxGfIyCxrZ0GP6x3qM2T/FwFVsZIekmQ8okhbZwba0QPV zZeA== X-Gm-Message-State: AKS2vOxrJbUhLSXkdAlk1nLpOqPiWAlDR5DIu0UZvuykbkekStR+pX32 fPt7Adk9wEnDJ2kw7DI= X-Received: by 10.84.176.195 with SMTP id v61mr39310261plb.101.1498022509476; Tue, 20 Jun 2017 22:21:49 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id a69sm30405992pfg.91.2017.06.20.22.21.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 Jun 2017 22:21:48 -0700 (PDT) From: John Stultz To: lkml Cc: Miroslav Lichvar , Thomas Gleixner , Ingo Molnar , Richard Cochran , Prarit Bhargava , Stephen Boyd , Shuah Khan , John Stultz Subject: [PATCH 4/4] kselftests: timers: Add test for frequency step Date: Tue, 20 Jun 2017 22:21:33 -0700 Message-Id: <1498022493-20292-5-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498022493-20292-1-git-send-email-john.stultz@linaro.org> References: <1498022493-20292-1-git-send-email-john.stultz@linaro.org> From: Miroslav Lichvar This test checks the response of the system clock to frequency steps made with adjtimex(). The frequency error and stability of the CLOCK_MONOTONIC clock relative to the CLOCK_MONOTONIC_RAW clock is measured in two intervals following the step. The test fails if values from the second interval exceed specified limits. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Miroslav Lichvar Cc: Richard Cochran Cc: Prarit Bhargava Cc: Stephen Boyd Cc: Shuah Khan Signed-off-by: Miroslav Lichvar Signed-off-by: John Stultz --- tools/testing/selftests/timers/Makefile | 5 +- tools/testing/selftests/timers/freq-step.c | 268 +++++++++++++++++++++++++++++ 2 files changed, 271 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/timers/freq-step.c -- 2.7.4 diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile index 5fa1d7e9..5801bbe 100644 --- a/tools/testing/selftests/timers/Makefile +++ b/tools/testing/selftests/timers/Makefile @@ -1,6 +1,6 @@ BUILD_FLAGS = -DKTEST CFLAGS += -O3 -Wl,-no-as-needed -Wall $(BUILD_FLAGS) -LDFLAGS += -lrt -lpthread +LDFLAGS += -lrt -lpthread -lm # these are all "safe" tests that don't modify # system time or require escalated privileges @@ -8,7 +8,7 @@ TEST_GEN_PROGS = posix_timers nanosleep nsleep-lat set-timer-lat mqueue-lat \ inconsistency-check raw_skew threadtest rtctest TEST_GEN_PROGS_EXTENDED = alarmtimer-suspend valid-adjtimex adjtick change_skew \ - skew_consistency clocksource-switch leap-a-day \ + skew_consistency clocksource-switch freq-step leap-a-day \ leapcrash set-tai set-2038 set-tz @@ -24,6 +24,7 @@ run_destructive_tests: run_tests ./change_skew ./skew_consistency ./clocksource-switch + ./freq-step ./leap-a-day -s -i 10 ./leapcrash ./set-tz diff --git a/tools/testing/selftests/timers/freq-step.c b/tools/testing/selftests/timers/freq-step.c new file mode 100644 index 0000000..e8c6183 --- /dev/null +++ b/tools/testing/selftests/timers/freq-step.c @@ -0,0 +1,268 @@ +/* + * This test checks the response of the system clock to frequency + * steps made with adjtimex(). The frequency error and stability of + * the CLOCK_MONOTONIC clock relative to the CLOCK_MONOTONIC_RAW clock + * is measured in two intervals following the step. The test fails if + * values from the second interval exceed specified limits. + * + * Copyright (C) Miroslav Lichvar 2017 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +#include +#include +#include +#include +#include + +#include "../kselftest.h" + +#define SAMPLES 100 +#define SAMPLE_READINGS 10 +#define MEAN_SAMPLE_INTERVAL 0.1 +#define STEP_INTERVAL 1.0 +#define MAX_PRECISION 100e-9 +#define MAX_FREQ_ERROR 10e-6 +#define MAX_STDDEV 1000e-9 + +struct sample { + double offset; + double time; +}; + +static time_t mono_raw_base; +static time_t mono_base; +static long user_hz; +static double precision; +static double mono_freq_offset; + +static double diff_timespec(struct timespec *ts1, struct timespec *ts2) +{ + return ts1->tv_sec - ts2->tv_sec + (ts1->tv_nsec - ts2->tv_nsec) / 1e9; +} + +static double get_sample(struct sample *sample) +{ + double delay, mindelay = 0.0; + struct timespec ts1, ts2, ts3; + int i; + + for (i = 0; i < SAMPLE_READINGS; i++) { + clock_gettime(CLOCK_MONOTONIC_RAW, &ts1); + clock_gettime(CLOCK_MONOTONIC, &ts2); + clock_gettime(CLOCK_MONOTONIC_RAW, &ts3); + + ts1.tv_sec -= mono_raw_base; + ts2.tv_sec -= mono_base; + ts3.tv_sec -= mono_raw_base; + + delay = diff_timespec(&ts3, &ts1); + if (delay <= 1e-9) { + i--; + continue; + } + + if (!i || delay < mindelay) { + sample->offset = diff_timespec(&ts2, &ts1); + sample->offset -= delay / 2.0; + sample->time = ts1.tv_sec + ts1.tv_nsec / 1e9; + mindelay = delay; + } + } + + return mindelay; +} + +static void reset_ntp_error(void) +{ + struct timex txc; + + txc.modes = ADJ_SETOFFSET; + txc.time.tv_sec = 0; + txc.time.tv_usec = 0; + + if (adjtimex(&txc) < 0) { + perror("[FAIL] adjtimex"); + ksft_exit_fail(); + } +} + +static void set_frequency(double freq) +{ + struct timex txc; + int tick_offset; + + tick_offset = 1e6 * freq / user_hz; + + txc.modes = ADJ_TICK | ADJ_FREQUENCY; + txc.tick = 1000000 / user_hz + tick_offset; + txc.freq = (1e6 * freq - user_hz * tick_offset) * (1 << 16); + + if (adjtimex(&txc) < 0) { + perror("[FAIL] adjtimex"); + ksft_exit_fail(); + } +} + +static void regress(struct sample *samples, int n, double *intercept, + double *slope, double *r_stddev, double *r_max) +{ + double x, y, r, x_sum, y_sum, xy_sum, x2_sum, r2_sum; + int i; + + x_sum = 0.0, y_sum = 0.0, xy_sum = 0.0, x2_sum = 0.0; + + for (i = 0; i < n; i++) { + x = samples[i].time; + y = samples[i].offset; + + x_sum += x; + y_sum += y; + xy_sum += x * y; + x2_sum += x * x; + } + + *slope = (xy_sum - x_sum * y_sum / n) / (x2_sum - x_sum * x_sum / n); + *intercept = (y_sum - *slope * x_sum) / n; + + *r_max = 0.0, r2_sum = 0.0; + + for (i = 0; i < n; i++) { + x = samples[i].time; + y = samples[i].offset; + r = fabs(x * *slope + *intercept - y); + if (*r_max < r) + *r_max = r; + r2_sum += r * r; + } + + *r_stddev = sqrt(r2_sum / n); +} + +static int run_test(int calibration, double freq_base, double freq_step) +{ + struct sample samples[SAMPLES]; + double intercept, slope, stddev1, max1, stddev2, max2; + double freq_error1, freq_error2; + int i; + + set_frequency(freq_base); + + for (i = 0; i < 10; i++) + usleep(1e6 * MEAN_SAMPLE_INTERVAL / 10); + + reset_ntp_error(); + + set_frequency(freq_base + freq_step); + + for (i = 0; i < 10; i++) + usleep(rand() % 2000000 * STEP_INTERVAL / 10); + + set_frequency(freq_base); + + for (i = 0; i < SAMPLES; i++) { + usleep(rand() % 2000000 * MEAN_SAMPLE_INTERVAL); + get_sample(&samples[i]); + } + + if (calibration) { + regress(samples, SAMPLES, &intercept, &slope, &stddev1, &max1); + mono_freq_offset = slope; + printf("CLOCK_MONOTONIC_RAW frequency offset: %11.3f ppm\n", + 1e6 * mono_freq_offset); + return 0; + } + + regress(samples, SAMPLES / 2, &intercept, &slope, &stddev1, &max1); + freq_error1 = slope * (1.0 - mono_freq_offset) - mono_freq_offset - + freq_base; + + regress(samples + SAMPLES / 2, SAMPLES / 2, &intercept, &slope, + &stddev2, &max2); + freq_error2 = slope * (1.0 - mono_freq_offset) - mono_freq_offset - + freq_base; + + printf("%6.0f %+10.3f %6.0f %7.0f %+10.3f %6.0f %7.0f\t", + 1e6 * freq_step, + 1e6 * freq_error1, 1e9 * stddev1, 1e9 * max1, + 1e6 * freq_error2, 1e9 * stddev2, 1e9 * max2); + + if (fabs(freq_error2) > MAX_FREQ_ERROR || stddev2 > MAX_STDDEV) { + printf("[FAIL]\n"); + return 1; + } + + printf("[OK]\n"); + return 0; +} + +static void init_test(void) +{ + struct timespec ts; + struct sample sample; + + if (clock_gettime(CLOCK_MONOTONIC_RAW, &ts)) { + perror("[FAIL] clock_gettime(CLOCK_MONOTONIC_RAW)"); + ksft_exit_fail(); + } + + mono_raw_base = ts.tv_sec; + + if (clock_gettime(CLOCK_MONOTONIC, &ts)) { + perror("[FAIL] clock_gettime(CLOCK_MONOTONIC)"); + ksft_exit_fail(); + } + + mono_base = ts.tv_sec; + + user_hz = sysconf(_SC_CLK_TCK); + + precision = get_sample(&sample) / 2.0; + printf("CLOCK_MONOTONIC_RAW+CLOCK_MONOTONIC precision: %.0f ns\t\t", + 1e9 * precision); + + if (precision > MAX_PRECISION) { + printf("[SKIP]\n"); + ksft_exit_skip(); + } + + printf("[OK]\n"); + srand(ts.tv_sec ^ ts.tv_nsec); + + run_test(1, 0.0, 0.0); +} + +int main(int argc, char **argv) +{ + double freq_base, freq_step; + int i, j, fails = 0; + + init_test(); + + printf("Checking response to frequency step:\n"); + printf(" Step 1st interval 2nd interval\n"); + printf(" Freq Dev Max Freq Dev Max\n"); + + for (i = 2; i >= 0; i--) { + for (j = 0; j < 5; j++) { + freq_base = (rand() % (1 << 24) - (1 << 23)) / 65536e6; + freq_step = 10e-6 * (1 << (6 * i)); + fails += run_test(0, freq_base, freq_step); + } + } + + set_frequency(0.0); + + if (fails) + ksft_exit_fail(); + + ksft_exit_pass(); +}