Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys introduce vfs.generic.timestamp_precision sysctl to cont...
details: https://anonhg.NetBSD.org/src/rev/c577651f0d02
branches: trunk
changeset: 959204:c577651f0d02
user: jdolecek <jdolecek%NetBSD.org@localhost>
date: Thu Feb 04 21:07:06 2021 +0000
description:
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:
sys/kern/vfs_init.c | 12 ++++++++++--
sys/kern/vfs_subr.c | 37 +++++++++++++++++++++++++++++++++----
sys/sys/mount.h | 3 ++-
3 files changed, 45 insertions(+), 7 deletions(-)
diffs (118 lines):
diff -r edd6b3865e5b -r c577651f0d02 sys/kern/vfs_init.c
--- a/sys/kern/vfs_init.c Thu Feb 04 20:19:09 2021 +0000
+++ b/sys/kern/vfs_init.c Thu Feb 04 21:07:06 2021 +0000
@@ -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 @@
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_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 -r edd6b3865e5b -r c577651f0d02 sys/kern/vfs_subr.c
--- a/sys/kern/vfs_subr.c Thu Feb 04 20:19:09 2021 +0000
+++ b/sys/kern/vfs_subr.c Thu Feb 04 21:07:06 2021 +0000
@@ -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 @@
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)
{
+ struct timeval tv;
- nanotime(ts);
+ 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 -r edd6b3865e5b -r c577651f0d02 sys/sys/mount.h
--- a/sys/sys/mount.h Thu Feb 04 20:19:09 2021 +0000
+++ b/sys/sys/mount.h Thu Feb 04 21:07:06 2021 +0000
@@ -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 */
Home |
Main Index |
Thread Index |
Old Index