Module Name: src
Committed By: jdolecek
Date: Thu Feb 4 21:07:06 UTC 2021
Modified Files:
src/sys/kern: vfs_init.c vfs_subr.c
src/sys/sys: mount.h
Log Message:
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
To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/kern/vfs_init.c
cvs rdiff -u -r1.489 -r1.490 src/sys/kern/vfs_subr.c
cvs rdiff -u -r1.236 -r1.237 src/sys/sys/mount.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/kern/vfs_init.c
diff -u src/sys/kern/vfs_init.c:1.51 src/sys/kern/vfs_init.c:1.52
--- src/sys/kern/vfs_init.c:1.51 Sat May 16 18:31:50 2020
+++ src/sys/kern/vfs_init.c Thu Feb 4 21:07:06 2021
@@ -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);
}
Index: src/sys/kern/vfs_subr.c
diff -u src/sys/kern/vfs_subr.c:1.489 src/sys/kern/vfs_subr.c:1.490
--- src/sys/kern/vfs_subr.c:1.489 Sun Jul 26 21:28:33 2020
+++ src/sys/kern/vfs_subr.c Thu Feb 4 21:07:06 2021
@@ -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 uk
return 0;
}
-void
-vfs_timestamp(struct timespec *ts)
-{
-
- nanotime(ts);
+/*
+ * 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 *tsp)
+{
+ 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;
+ }
}
/*
Index: src/sys/sys/mount.h
diff -u src/sys/sys/mount.h:1.236 src/sys/sys/mount.h:1.237
--- src/sys/sys/mount.h:1.236 Fri Jan 17 20:08:10 2020
+++ src/sys/sys/mount.h Thu Feb 4 21:07:06 2021
@@ -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 */