The test helps to validate clamping and mount behaviors
according to supported file system timestamp ranges.
Note that the test can fail on 32-bit systems for a
few file systems. This will be corrected when vfs is
transitioned to use 64-bit timestamps.
Signed-off-by: Deepa Dinamani <deepa.kernel(a)gmail.com>
---
The branch of the kernel tree can be located at
https://github.com/deepa-hub/vfs refs/heads/vfs_timestamp_policy
The xfs_io patch to add utimes is at
https://www.spinics.net/lists/linux-xfs/msg02952.html
Changes since v2:
* Refactored notrun handling
* Updated comments
Changes since v1:
* Use xfs_io utimes command
* Updated error handling
* Reorganized code according to review comments
common/rc | 48 +++++++++++++
tests/generic/390 | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++
tests/generic/390.out | 2 +
tests/generic/group | 1 +
4 files changed, 243 insertions(+)
create mode 100755 tests/generic/390
create mode 100644 tests/generic/390.out
diff --git a/common/rc b/common/rc
index e3b54ec..17f025e 100644
--- a/common/rc
+++ b/common/rc
@@ -1960,6 +1960,51 @@ _run_aiodio()
return $status
}
+# this test requires y2038 sysfs switch and filesystem
+# timestamp ranges support.
+_require_y2038()
+{
+ local device=${1:-$TEST_DEV}
+ local sysfsdir=/proc/sys/fs/fs-timestamp-check-on
+
+ if [ ! -e $sysfsdir ]; then
+ _notrun "no kernel support for y2038 sysfs switch"
+ fi
+
+ local tsmin tsmax
+ read tsmin tsmax <<<$(_filesystem_timestamp_range $device)
+ if [ $tsmin -eq -1 -a $tsmax -eq -1 ]; then
+ _notrun "filesystem $FSTYP timestamp bounds are unknown"
+ fi
+}
+
+_filesystem_timestamp_range()
+{
+ device=${1:-$TEST_DEV}
+ case $FSTYP in
+ ext4)
+ if [ $(dumpe2fs -h $device 2>/dev/null | grep "Inode size:" | cut -d: -f2) -gt 128 ]; then
+ echo "-2147483648 15032385535"
+ else
+ echo "-2147483648 2147483647"
+ fi
+ ;;
+
+ xfs)
+ echo "-2147483648 2147483647"
+ ;;
+ jfs)
+ echo "0 4294967295"
+ ;;
+ f2fs)
+ echo "-2147483648 2147483647"
+ ;;
+ *)
+ echo "-1 -1"
+ ;;
+ esac
+}
+
# indicate whether YP/NIS is active or not
#
_yp_active()
@@ -2070,6 +2115,9 @@ _require_xfs_io_command()
echo $testio | egrep -q "Inappropriate ioctl" && \
_notrun "xfs_io $command support is missing"
;;
+ "utimes" )
+ testio=`$XFS_IO_PROG -f -c "utimes" 0 0 0 0 $testfile 2>&1`
+ ;;
*)
testio=`$XFS_IO_PROG -c "$command help" 2>&1`
esac
diff --git a/tests/generic/390 b/tests/generic/390
new file mode 100755
index 0000000..f68b931
--- /dev/null
+++ b/tests/generic/390
@@ -0,0 +1,192 @@
+#! /bin/bash
+# FS QA Test 390
+#
+# Tests to verify policy for filesystem timestamps for
+# supported ranges:
+# 1. Verify filesystem rw mount according to sysctl
+# timestamp_supported.
+# 2. Verify timestamp clamping for timestamps beyond max
+# timestamp supported.
+#
+# Exit status 1: either or both tests above fail.
+# Exit status 0: both the above tests pass.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2016 Deepa Dinamani. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#-----------------------------------------------------------------------
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1 # failure is the default!
+trap "exit \$status" 0 1 2 3 15
+
+# Get standard environment, filters and checks.
+. ./common/rc
+. ./common/filter
+. ./common/attr
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# Prerequisites for the test run.
+_supported_fs generic
+_supported_os Linux
+_require_scratch
+_require_xfs_io_command utimes
+
+# Compare file timestamps obtained from stat
+# with a given timestamp.
+check_stat()
+{
+ file=$1
+ timestamp=$2
+
+ stat_timestamp=`stat -c"%X;%Y" $file`
+
+ prev_timestamp="$timestamp;$timestamp"
+ if [ $prev_timestamp != $stat_timestamp ]; then
+ echo "$prev_timestamp != $stat_timestamp" | tee -a $seqres.full
+ fi
+}
+
+run_test_individual()
+{
+ file=$1
+ timestamp=$2
+ update_time=$3
+
+ #check if the time needs update
+ if [ $update_time -eq 1 ]; then
+ echo "Updating file: $file to timestamp `date -d @$timestamp`" >> $seqres.full
+ $XFS_IO_PROG -f -c "utimes $timestamp 0 $timestamp 0" $file
+ if [ $? -ne 0 ]; then
+ echo "Failed to update times on $file" | tee -a $seqres.full
+ fi
+ fi
+
+ tsclamp=$(($timestamp>$tsmax?$tsmax:$timestamp))
+ echo "Checking file: $file Updated timestamp is `date -d @$tsclamp`" >> $seqres.full
+ check_stat $file $tsclamp
+}
+
+run_test()
+{
+ update_time=$1
+
+ n=1
+
+ for TIME in "${TIMESTAMPS[@]}"
+ do
+ #Run the test
+ run_test_individual ${SCRATCH_MNT}/test_$n $TIME $update_time
+
+ #update iterator
+ ((n++))
+ done
+}
+
+_scratch_mkfs &>> $seqres.full 2>&1 || _fail "mkfs failed"
+_require_y2038 $SCRATCH_DEV
+
+read tsmin tsmax <<<$(_filesystem_timestamp_range $SCRATCH_DEV)
+echo min supported timestamp $tsmin $(date --date=@$tsmin) >> $seqres.full
+echo max supported timestamp $tsmax $(date --date=@$tsmax) >> $seqres.full
+
+# Test timestamps array
+
+declare -a TIMESTAMPS=(
+ $tsmin
+ 0
+ $tsmax
+ $((tsmax+1))
+ 4294967295
+ 8589934591
+ 34359738367
+)
+
+# Max timestamp is hardcoded to Mon Jan 18 19:14:07 PST 2038
+sys_tsmax=2147483647
+echo "max timestamp that needs to be supported by fs for rw mount is" \
+ "$((sys_tsmax+1)) $(date --date=@$((sys_tsmax+1)))" >> $seqres.full
+
+read ts_check <<<$(cat /proc/sys/fs/fs-timestamp-check-on)
+
+_scratch_mount
+result=$?
+
+if [ $ts_check -ne 0 ]; then
+ echo "sysctl filesystem timestamp check is on" >> $seqres.full
+ # check for mount failure if the minimum requirement for max timestamp
+ # supported is not met.
+ if [ $sys_tsmax -ge $tsmax ]; then
+ if [ $result -eq 0 ]; then
+ echo "mount test failed" | tee -a $seqres.full
+ exit
+ fi
+ else
+ if [ $result -ne 0 ]; then
+ echo "failed to mount $SCRATCH_DEV" | tee -a $seqres.full
+ exit
+ fi
+ fi
+else
+ # if sysctl switch is off then mount should succeed always.
+ echo "sysctl filesystem timestamp check is off" >> $seqres.full
+ if [ $result -ne 0 ]; then
+ echo "failed to mount $SCRATCH_DEV and timestamp check is off" >> $seqres.full
+ exit
+ fi
+fi
+
+# Begin test case 1
+echo "In memory timestamps update test start" >> $seqres.full
+
+# update time on the file
+update_time=1
+
+run_test $update_time
+
+echo "In memory timestamps update complete" >> $seqres.full
+
+echo "Unmounting and mounting scratch $SCRATCH_MNT" >> $seqres.full
+
+# unmount and remount $SCRATCH_DEV
+_scratch_cycle_mount
+
+# Begin test case 2
+
+n=1
+
+# Do not update time on the file this time, just read from disk
+update_time=0
+
+echo "On disk timestamps update test start" >> $seqres.full
+
+# Re-run test
+run_test $update_time
+
+echo "On disk timestamps update test complete" >> $seqres.full
+
+echo "y2038 inode timestamp tests completed successfully"
+
+# success, all done
+status=0
+exit
diff --git a/tests/generic/390.out b/tests/generic/390.out
new file mode 100644
index 0000000..82bd4eb
--- /dev/null
+++ b/tests/generic/390.out
@@ -0,0 +1,2 @@
+QA output created by 390
+y2038 inode timestamp tests completed successfully
diff --git a/tests/generic/group b/tests/generic/group
index 08007d7..d137d01 100644
--- a/tests/generic/group
+++ b/tests/generic/group
@@ -392,3 +392,4 @@
387 auto clone
388 auto log metadata
389 auto quick acl
+390 auto quick rw
--
2.7.4
The series is a preparation series for individual architectures
to use 64 bit time_t syscalls in compat and 32 bit emulation modes.
This is a follow up to the series Arnd Bergmann posted:
https://sourceware.org/ml/libc-alpha/2015-05/msg00070.html [1]
Big picture is as per the lwn article:
https://lwn.net/Articles/643234/ [2]
The series is directed at converting posix clock syscalls:
clock_gettime, clock_settime, clock_getres and clock_nanosleep
to use a new data structure __kernel_timespec at syscall boundaries.
__kernel_timespec maintains 64 bit time_t across all execution modes.
vdso will be handled as part of each architecture when they enable
support for 64 bit time_t.
The compat syscalls are repurposed to provide backward compatibility
by using them as native syscalls as well for 32 bit architectures.
They will continue to use timespec at syscall boundaries.
CONFIG_64_BIT_TIME controls whether the syscalls use __kernel_timespec
or timespec at syscall boundaries.
The series does the following:
1. Enable compat syscalls on 32 bit architectures.
2. Add a new __kernel_timespec type to be used as the data structure
for all the new syscalls.
3. Add new config CONFIG_64BIT_TIME(intead of the CONFIG_COMPAT_TIME in
[1] and [2] to switch to new definition of __kernel_timespec. It is
the same as struct timespec otherwise.
4. Add new CONFIG_32BIT_TIME to conditionally compile compat syscalls.
* Changes since v2:
* Dropped the ARCH_HAS_64BIT_TIME config.
* Fixed zeroing out of higher order bits of tv_nsec for real.
* Addressed minor review comments from v1.
* Changes since v1:
* Introduce CONFIG_32BIT_TIME
* Fixed zeroing out of higher order bits of tv_nsec
* Included Arnd's changes to fix up use of compat headers
I decided against using LEGACY_TIME_SYSCALLS to conditionally compile
legacy time syscalls such as sys_nanosleep because this will need to
enclose compat_sys_nanosleep as well. So, defining it as
config LEGACY_TIME_SYSCALLS
def_bool 64BIT || !64BIT_TIME
will not include compat_sys_nanosleep. We will instead need a new config to
exclusively mark legacy syscalls.
Deepa Dinamani (10):
compat: Make compat helpers independent of CONFIG_COMPAT
include: Move compat_timespec/ timeval to compat_time.h
compat: enable compat_get/put_timespec64 always
arch: introduce CONFIG_64BIT_TIME
arch: Introduce CONFIG_COMPAT_32BIT_TIME
posix-clocks: Make compat syscalls depend on CONFIG_COMPAT_32BIT_TIME
include: Add new y2038 safe __kernel_timespec
fix get_timespec64() for y2038 safe compat interfaces
change time types to new y2038 safe __kernel_* types
nanosleep: change time types to safe __kernel_* types
arch/Kconfig | 15 +++++++++
arch/arm64/include/asm/compat.h | 11 -------
arch/arm64/include/asm/stat.h | 1 +
arch/arm64/kernel/hw_breakpoint.c | 1 -
arch/arm64/kernel/perf_regs.c | 2 +-
arch/arm64/kernel/process.c | 1 -
arch/mips/include/asm/compat.h | 11 -------
arch/mips/kernel/signal32.c | 2 +-
arch/parisc/include/asm/compat.h | 11 -------
arch/powerpc/include/asm/compat.h | 11 -------
arch/powerpc/kernel/asm-offsets.c | 2 +-
arch/powerpc/oprofile/backtrace.c | 2 +-
arch/s390/hypfs/hypfs_sprp.c | 1 -
arch/s390/include/asm/compat.h | 11 -------
arch/s390/include/asm/elf.h | 3 +-
arch/s390/kvm/priv.c | 1 -
arch/s390/pci/pci_clp.c | 1 -
arch/sparc/include/asm/compat.h | 11 -------
arch/tile/include/asm/compat.h | 11 -------
arch/x86/events/core.c | 2 +-
arch/x86/include/asm/compat.h | 11 -------
arch/x86/include/asm/ftrace.h | 2 +-
arch/x86/include/asm/sys_ia32.h | 2 +-
arch/x86/kernel/sys_x86_64.c | 2 +-
drivers/s390/block/dasd_ioctl.c | 1 -
drivers/s390/char/fs3270.c | 1 -
drivers/s390/char/sclp_ctl.c | 1 -
drivers/s390/char/vmcp.c | 1 -
drivers/s390/cio/chsc_sch.c | 1 -
drivers/s390/net/qeth_core_main.c | 2 +-
include/linux/compat.h | 11 ++++---
include/linux/compat_time.h | 23 ++++++++++++++
include/linux/restart_block.h | 7 ++--
include/linux/syscalls.h | 12 +++----
include/linux/time.h | 4 +--
include/linux/time64.h | 10 +++++-
include/uapi/asm-generic/posix_types.h | 1 +
include/uapi/linux/time.h | 7 ++++
kernel/compat.c | 52 +++++-------------------------
kernel/time/hrtimer.c | 10 ++++--
kernel/time/posix-stubs.c | 12 ++++---
kernel/time/posix-timers.c | 24 ++++++++++----
kernel/time/time.c | 58 +++++++++++++++++++++++++++++++---
43 files changed, 176 insertions(+), 190 deletions(-)
create mode 100644 include/linux/compat_time.h
base-commit: 8418f88764046d0e8ca6a3c04a69a0e57189aa1e
--
2.14.1
Cc: acme(a)kernel.org
Cc: benh(a)kernel.crashing.org
Cc: borntraeger(a)de.ibm.com
Cc: catalin.marinas(a)arm.com
Cc: cmetcalf(a)mellanox.com
Cc: cohuck(a)redhat.com
Cc: davem(a)davemloft.net
Cc: deller(a)gmx.de
Cc: devel(a)driverdev.osuosl.org
Cc: gerald.schaefer(a)de.ibm.com
Cc: gregkh(a)linuxfoundation.org
Cc: heiko.carstens(a)de.ibm.com
Cc: hoeppner(a)linux.vnet.ibm.com
Cc: hpa(a)zytor.com
Cc: jejb(a)parisc-linux.org
Cc: jwi(a)linux.vnet.ibm.com
Cc: linux-api(a)vger.kernel.org
Cc: linux-arch(a)vger.kernel.org
Cc: linux-kernel(a)vger.kernel.org
Cc: linux-mips(a)linux-mips.org
Cc: linux-parisc(a)vger.kernel.org
Cc: linuxppc-dev(a)lists.ozlabs.org
Cc: linux-s390(a)vger.kernel.org
Cc: mark.rutland(a)arm.com
Cc: mingo(a)redhat.com
Cc: mpe(a)ellerman.id.au
Cc: oberpar(a)linux.vnet.ibm.com
Cc: oprofile-list(a)lists.sf.net
Cc: paulus(a)samba.org
Cc: peterz(a)infradead.org
Cc: ralf(a)linux-mips.org
Cc: rostedt(a)goodmis.org
Cc: rric(a)kernel.org
Cc: schwidefsky(a)de.ibm.com
Cc: sebott(a)linux.vnet.ibm.com
Cc: sparclinux(a)vger.kernel.org
Cc: sth(a)linux.vnet.ibm.com
Cc: ubraun(a)linux.vnet.ibm.com
Cc: will.deacon(a)arm.com
Cc: x86(a)kernel.org
The series is aimed at adding support to maintain individual
timestamp ranges for filesystems. This helps futimens, utimensat
and utimes syscalls to conform to POSIX defined behavior when
the time being set is outside of the corresponding filesystem's
supported limits.
The series was developed with discussions and guidance from
Arnd Bergmann.
The original thread is at https://lkml.org/lkml/2016/11/2/294
I will be submitting follow up kernel patches to update all
filesystems.
Currently ext4 is the only filesystem that reflects correct limits.
The branch is available at
https://github.com/deepa-hub/vfs.git refs/heads/range
Changes since v5:
* Dropped y2038-specific changes
Changes since v4:
* Added documentation for boot param
Changes since v3:
* Remove redundant initializations in libfs.c
* Change early_param to __setup similar to other root mount options.
* Fix documentation warning
Changes since v2:
* Introduce early boot param override for checks.
* Drop afs patch for timestamp limits.
Changes since v1:
* return EROFS on mount errors
* fix mtime copy/paste error in utimes
Deepa Dinamani (4):
vfs: Add file timestamp range support
ext4: Initialize timestamps limits
vfs: Add timestamp_truncate() api
utimes: Clamp the timestamps before update
fs/ext4/ext4.h | 4 ++++
fs/ext4/super.c | 7 ++++++-
fs/inode.c | 32 +++++++++++++++++++++++++++++++-
fs/super.c | 2 ++
fs/utimes.c | 17 +++++++++++++----
include/linux/fs.h | 3 +++
include/linux/time64.h | 2 ++
7 files changed, 61 insertions(+), 6 deletions(-)
--
2.14.1
Cc: "Theodore Ts'o" <tytso(a)mit.edu>
Cc: Andreas Dilger <adilger.kernel(a)dilger.ca>
Cc: linux-ext4(a)vger.kernel.org
The arcmsr uses its own implementation of time_to_tm(), along with do_gettimeofday()
to read the current time. While the algoritm used here is fine in principle, it
suffers from two problems:
- it assigns the seconds portion of the timeval to a 32-bit unsigned integer that
overflows in 2106 even on 64-bit architectures.
- do_gettimeofday() returns a time_t that overflows in 2038 on all 32-bit systems.
This changes the time retrieval function to ktime_get_real_seconds(), which returns
a proper 64-bit value, and replaces the open-coded time_to_tm() algorithm with
a call to the safe time64_to_tm().
I checked way all numbers are indexed and found that months are given in range
0..11 while the days are in range 1..31, same as 'struct tm', but the year value
that the firmware expects starts in 2000 while 'struct tm' is based on year 1900,
so it needs a small adjustment.
Fixes: b416c099472a ("scsi: arcmsr: Add a function to set date and time to firmware")
Signed-off-by: Arnd Bergmann <arnd(a)arndb.de>
---
drivers/scsi/arcmsr/arcmsr_hba.c | 37 ++++++++++---------------------------
1 file changed, 10 insertions(+), 27 deletions(-)
diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index 47745592cff4..75e828bd30e3 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -3489,8 +3489,9 @@ static int arcmsr_polling_ccbdone(struct AdapterControlBlock *acb,
static void arcmsr_set_iop_datetime(struct timer_list *t)
{
struct AdapterControlBlock *pacb = from_timer(pacb, t, refresh_timer);
- unsigned int days, j, i, a, b, c, d, e, m, year, mon, day, hour, min, sec, secs, next_time;
- struct timeval tv;
+ unsigned int next_time;
+ struct tm tm;
+
union {
struct {
uint16_t signature;
@@ -3506,33 +3507,15 @@ static void arcmsr_set_iop_datetime(struct timer_list *t)
} b;
} datetime;
- do_gettimeofday(&tv);
- secs = (u32)(tv.tv_sec - (sys_tz.tz_minuteswest * 60));
- days = secs / 86400;
- secs = secs - 86400 * days;
- j = days / 146097;
- i = days - 146097 * j;
- a = i + 719468;
- b = ( 4 * a + 3 ) / 146097;
- c = a - ( 146097 * b ) / 4;
- d = ( 4 * c + 3 ) / 1461 ;
- e = c - ( 1461 * d ) / 4 ;
- m = ( 5 * e + 2 ) / 153 ;
- year = 400 * j + 100 * b + d + m / 10 - 2000;
- mon = m + 3 - 12 * ( m /10 );
- day = e - ( 153 * m + 2 ) / 5 + 1;
- hour = secs / 3600;
- secs = secs - 3600 * hour;
- min = secs / 60;
- sec = secs - 60 * min;
+ time64_to_tm(ktime_get_real_seconds(), -sys_tz.tz_minuteswest * 60, &tm);
datetime.a.signature = 0x55AA;
- datetime.a.year = year;
- datetime.a.month = mon;
- datetime.a.date = day;
- datetime.a.hour = hour;
- datetime.a.minute = min;
- datetime.a.second = sec;
+ datetime.a.year = tm.tm_year - 100; /* base 2000 instead of 1900 */
+ datetime.a.month = tm.tm_mon;
+ datetime.a.date = tm.tm_mday;
+ datetime.a.hour = tm.tm_hour;
+ datetime.a.minute = tm.tm_min;
+ datetime.a.second = tm.tm_sec;
switch (pacb->adapter_type) {
case ACB_ADAPTER_TYPE_A: {
--
2.9.0
DRM_VMW_EVENT_FENCE_SIGNALED (struct drm_vmw_event_fence) and
DRM_EVENT_VBLANK (struct drm_event_vblank) pass timestamps in 32-bit
seconds/microseconds format.
As of commit c61eef726a78 ("drm: add support for monotonic vblank
timestamps"), other DRM drivers use monotonic times for drm_event_vblank,
but vmwgfx still uses CLOCK_REALTIME for both events, which suffers from
the y2038/y2106 overflow as well as time jumps.
For consistency, this changes vmwgfx to use ktime_get_ts64 as well,
which solves those problems and avoids the deprecated do_gettimeofday()
function.
This should be transparent to to user space, as long as it doesn't
compare the time against the result of gettimeofday().
Link: https://patchwork.kernel.org/patch/10076599/
Signed-off-by: Arnd Bergmann <arnd(a)arndb.de>
---
Originally sent on Nov 27. Sinclair Yeh said he'd pick it up
for the next pull request, but it's not in linux-next yet.
Resending the unchanged patch, please pick it up when you have time,
or feel free to ignore this email in case it's already in some tree
that just isn't part of linux-next but will be sent during the
next merge window.
---
drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
index 6c5c75cf5e6c..9ed544f8958f 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
@@ -901,11 +901,12 @@ static void vmw_event_fence_action_seq_passed(struct vmw_fence_action *action)
spin_lock_irq(&dev->event_lock);
if (likely(eaction->tv_sec != NULL)) {
- struct timeval tv;
+ struct timespec64 ts;
- do_gettimeofday(&tv);
- *eaction->tv_sec = tv.tv_sec;
- *eaction->tv_usec = tv.tv_usec;
+ ktime_get_ts64(&ts);
+ /* monotonic time, so no y2038 overflow */
+ *eaction->tv_sec = ts.tv_sec;
+ *eaction->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
}
drm_send_event_locked(dev, eaction->event);
--
2.9.0
getnstimeofday() is deprecated, so I'm converting this to use
ktime_get_real_ts64() as a safe replacement. I considered using
ktime_get_real() instead, but since the algorithm here depends
on the exact timing, I decided to introduce fewer changes
and leave the code that determines the nanoseconds since the
last seconds wrap untouched.
It's not entirely clear to me whether we should also change the
time base to CLOCK_BOOTTIME or CLOCK_TAI. With boottime, we
would be independent of changes due to settimeofday() and only
see the speed adjustment from the upstream clock source, with
the downside of having the signal be at an arbirary offset
from the start of the UTC second signal. With CLOCK_TAI, we
would use the same offset from the UTC second as before and
still suffer from settimeofday() adjustments, but would be
less confused during leap seconds.
Both boottime and tai only offer usable (i.e. avoiding ktime_t
to timespec64 conversion) interfaces for ktime_t though, so
either way, changing it wouldn't take significantly more work.
CLOCK_MONOTONIC could be used with ktime_get_ts64(), but would
lose synchronization across a suspend/resume cycle, which seems
worse.
Acked-by: Rodolfo Giometti <giometti(a)enneenne.com>
Signed-off-by: Arnd Bergmann <arnd(a)arndb.de>
---
Sent on Nov 28 originally, got an Ack, but nobody picked it up.
Andrew, it seems you handled some pps generator patches
in the past, can you take this one through -mm?
---
drivers/pps/generators/pps_gen_parport.c | 40 ++++++++++++++++----------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/drivers/pps/generators/pps_gen_parport.c b/drivers/pps/generators/pps_gen_parport.c
index dcd39fba6ddd..51cfde6afffd 100644
--- a/drivers/pps/generators/pps_gen_parport.c
+++ b/drivers/pps/generators/pps_gen_parport.c
@@ -70,7 +70,7 @@ static long hrtimer_error = SAFETY_INTERVAL;
/* the kernel hrtimer event */
static enum hrtimer_restart hrtimer_event(struct hrtimer *timer)
{
- struct timespec expire_time, ts1, ts2, ts3, dts;
+ struct timespec64 expire_time, ts1, ts2, ts3, dts;
struct pps_generator_pp *dev;
struct parport *port;
long lim, delta;
@@ -78,7 +78,7 @@ static enum hrtimer_restart hrtimer_event(struct hrtimer *timer)
/* We have to disable interrupts here. The idea is to prevent
* other interrupts on the same processor to introduce random
- * lags while polling the clock. getnstimeofday() takes <1us on
+ * lags while polling the clock. ktime_get_real_ts64() takes <1us on
* most machines while other interrupt handlers can take much
* more potentially.
*
@@ -88,22 +88,22 @@ static enum hrtimer_restart hrtimer_event(struct hrtimer *timer)
local_irq_save(flags);
/* first of all we get the time stamp... */
- getnstimeofday(&ts1);
- expire_time = ktime_to_timespec(hrtimer_get_softexpires(timer));
+ ktime_get_real_ts64(&ts1);
+ expire_time = ktime_to_timespec64(hrtimer_get_softexpires(timer));
dev = container_of(timer, struct pps_generator_pp, timer);
lim = NSEC_PER_SEC - send_delay - dev->port_write_time;
/* check if we are late */
if (expire_time.tv_sec != ts1.tv_sec || ts1.tv_nsec > lim) {
local_irq_restore(flags);
- pr_err("we are late this time %ld.%09ld\n",
- ts1.tv_sec, ts1.tv_nsec);
+ pr_err("we are late this time %lld.%09ld\n",
+ (s64)ts1.tv_sec, ts1.tv_nsec);
goto done;
}
/* busy loop until the time is right for an assert edge */
do {
- getnstimeofday(&ts2);
+ ktime_get_real_ts64(&ts2);
} while (expire_time.tv_sec == ts2.tv_sec && ts2.tv_nsec < lim);
/* set the signal */
@@ -113,25 +113,25 @@ static enum hrtimer_restart hrtimer_event(struct hrtimer *timer)
/* busy loop until the time is right for a clear edge */
lim = NSEC_PER_SEC - dev->port_write_time;
do {
- getnstimeofday(&ts2);
+ ktime_get_real_ts64(&ts2);
} while (expire_time.tv_sec == ts2.tv_sec && ts2.tv_nsec < lim);
/* unset the signal */
port->ops->write_control(port, NO_SIGNAL);
- getnstimeofday(&ts3);
+ ktime_get_real_ts64(&ts3);
local_irq_restore(flags);
/* update calibrated port write time */
- dts = timespec_sub(ts3, ts2);
+ dts = timespec64_sub(ts3, ts2);
dev->port_write_time =
- (dev->port_write_time + timespec_to_ns(&dts)) >> 1;
+ (dev->port_write_time + timespec64_to_ns(&dts)) >> 1;
done:
/* update calibrated hrtimer error */
- dts = timespec_sub(ts1, expire_time);
- delta = timespec_to_ns(&dts);
+ dts = timespec64_sub(ts1, expire_time);
+ delta = timespec64_to_ns(&dts);
/* If the new error value is bigger then the old, use the new
* value, if not then slowly move towards the new value. This
* way it should be safe in bad conditions and efficient in
@@ -161,17 +161,17 @@ static void calibrate_port(struct pps_generator_pp *dev)
long acc = 0;
for (i = 0; i < (1 << PORT_NTESTS_SHIFT); i++) {
- struct timespec a, b;
+ struct timespec64 a, b;
unsigned long irq_flags;
local_irq_save(irq_flags);
- getnstimeofday(&a);
+ ktime_get_real_ts64(&a);
port->ops->write_control(port, NO_SIGNAL);
- getnstimeofday(&b);
+ ktime_get_real_ts64(&b);
local_irq_restore(irq_flags);
- b = timespec_sub(b, a);
- acc += timespec_to_ns(&b);
+ b = timespec64_sub(b, a);
+ acc += timespec64_to_ns(&b);
}
dev->port_write_time = acc >> PORT_NTESTS_SHIFT;
@@ -180,9 +180,9 @@ static void calibrate_port(struct pps_generator_pp *dev)
static inline ktime_t next_intr_time(struct pps_generator_pp *dev)
{
- struct timespec ts;
+ struct timespec64 ts;
- getnstimeofday(&ts);
+ ktime_get_real_ts64(&ts);
return ktime_set(ts.tv_sec +
((ts.tv_nsec > 990 * NSEC_PER_MSEC) ? 1 : 0),
--
2.9.0