diff options
| author | jdolecek <jdolecek@NetBSD.org> | 2021-02-04 21:07:06 +0000 |
|---|---|---|
| committer | jdolecek <jdolecek@NetBSD.org> | 2021-02-04 21:07:06 +0000 |
| commit | dd4157ea8bf4ac0b3e75e10f2c10eb5d9bae3679 (patch) | |
| tree | 71c636f1c10c7cfab77844c962facfc31fbe0c31 /sys | |
| parent | a1b3946ce5c624bb6253bcaa14900efb0bb003c3 (diff) | |
introduce vfs.generic.timestamp_precision sysctl to control precision
of the timer used for vfs_timestamp(); default stays the same
to use nanotime(9), but option is there to use the faster, albeit
less precise methods
code taken from FreeBSD
suggested by Mateusz Guzik in:
http://mail-index.netbsd.org/tech-kern/2020/07/19/msg026620.html
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/kern/vfs_init.c | 12 | ||||
| -rw-r--r-- | sys/kern/vfs_subr.c | 39 | ||||
| -rw-r--r-- | sys/sys/mount.h | 3 |
3 files changed, 46 insertions, 8 deletions
diff --git a/sys/kern/vfs_init.c b/sys/kern/vfs_init.c index 0b19f8ee2c6..b279cdc2cf8 100644 --- a/sys/kern/vfs_init.c +++ b/sys/kern/vfs_init.c @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_init.c,v 1.51 2020/05/16 18:31:50 christos Exp $ */ +/* $NetBSD: vfs_init.c,v 1.52 2021/02/04 21:07:06 jdolecek Exp $ */ /*- * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc. @@ -67,7 +67,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: vfs_init.c,v 1.51 2020/05/16 18:31:50 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_init.c,v 1.52 2021/02/04 21:07:06 jdolecek Exp $"); #include <sys/param.h> #include <sys/mount.h> @@ -151,6 +151,7 @@ static void sysctl_vfs_setup(void) { extern int vfs_magiclinks; + extern int vfs_timestamp_precision; sysctl_createv(&vfs_sysctllog, 0, NULL, NULL, CTLFLAG_PERMANENT, @@ -170,6 +171,13 @@ sysctl_vfs_setup(void) SYSCTL_DESCR("Whether \"magic\" symlinks are expanded"), NULL, 0, &vfs_magiclinks, 0, CTL_VFS, VFS_GENERIC, VFS_MAGICLINKS, CTL_EOL); + sysctl_createv(&vfs_sysctllog, 0, NULL, NULL, + CTLFLAG_PERMANENT|CTLFLAG_READWRITE, + CTLTYPE_INT, "timestamp_precision", + SYSCTL_DESCR("File timestamp precision"), + NULL, 0, &vfs_timestamp_precision, 0, + CTL_VFS, VFS_GENERIC, VFS_TIMESTAMP_PRECISION, + CTL_EOL); } diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index cf6679abda4..94d2bcdd2a4 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_subr.c,v 1.489 2020/07/26 21:28:33 christos Exp $ */ +/* $NetBSD: vfs_subr.c,v 1.490 2021/02/04 21:07:06 jdolecek Exp $ */ /*- * Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008, 2019, 2020 @@ -69,7 +69,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.489 2020/07/26 21:28:33 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.490 2021/02/04 21:07:06 jdolecek Exp $"); #ifdef _KERNEL_OPT #include "opt_ddb.h" @@ -1253,11 +1253,40 @@ set_statvfs_info(const char *onp, int ukon, const char *fromp, int ukfrom, return 0; } +/* + * Knob to control the precision of file timestamps: + * + * 0 = seconds only; nanoseconds zeroed. + * 1 = seconds and nanoseconds, accurate within 1/HZ. + * 2 = seconds and nanoseconds, truncated to microseconds. + * >=3 = seconds and nanoseconds, maximum precision. + */ +enum { TSP_SEC, TSP_HZ, TSP_USEC, TSP_NSEC }; + +int vfs_timestamp_precision __read_mostly = TSP_NSEC; + void -vfs_timestamp(struct timespec *ts) +vfs_timestamp(struct timespec *tsp) { - - nanotime(ts); + struct timeval tv; + + switch (vfs_timestamp_precision) { + case TSP_SEC: + tsp->tv_sec = time_second; + tsp->tv_nsec = 0; + break; + case TSP_HZ: + getnanotime(tsp); + break; + case TSP_USEC: + microtime(&tv); + TIMEVAL_TO_TIMESPEC(&tv, tsp); + break; + case TSP_NSEC: + default: + nanotime(tsp); + break; + } } /* diff --git a/sys/sys/mount.h b/sys/sys/mount.h index 2d8c623f187..2e984c6dbc9 100644 --- a/sys/sys/mount.h +++ b/sys/sys/mount.h @@ -1,4 +1,4 @@ -/* $NetBSD: mount.h,v 1.236 2020/01/17 20:08:10 ad Exp $ */ +/* $NetBSD: mount.h,v 1.237 2021/02/04 21:07:06 jdolecek Exp $ */ /* * Copyright (c) 1989, 1991, 1993 @@ -115,6 +115,7 @@ as next argument */ #define VFS_USERMOUNT 3 /* enable/disable fs mnt by non-root */ #define VFS_MAGICLINKS 4 /* expand 'magic' symlinks */ +#define VFS_TIMESTAMP_PRECISION 5 /* file timestamp precision */ /* vfsquery flags for kqueue(2) */ #define VQ_MOUNT 0x0001 /* new filesystem arrived */ |
