aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/uipc_usrreq.c
diff options
context:
space:
mode:
authorMaxim Sobolev <sobomax@FreeBSD.org>2017-01-16 17:46:38 +0000
committerMaxim Sobolev <sobomax@FreeBSD.org>2017-01-16 17:46:38 +0000
commit339efd75a49379707b8f8f578d0814a194047b5b (patch)
tree250aca065db174079d41caaf6f1a46a17cd315d0 /sys/kern/uipc_usrreq.c
parent227743cad4bb24d407c88d6286d80e795828d829 (diff)
downloadsrc-339efd75a49379707b8f8f578d0814a194047b5b.tar.gz
src-339efd75a49379707b8f8f578d0814a194047b5b.zip
Add a new socket option SO_TS_CLOCK to pick from several different clock
sources to return timestamps when SO_TIMESTAMP is enabled. Two additional clock sources are: o nanosecond resolution realtime clock (equivalent of CLOCK_REALTIME); o nanosecond resolution monotonic clock (equivalent of CLOCK_MONOTONIC). In addition to this, this option provides unified interface to get bintime (equivalent of using SO_BINTIME), except it also supported with IPv6 where SO_BINTIME has never been supported. The long term plan is to depreciate SO_BINTIME and move everything to using SO_TS_CLOCK. Idea for this enhancement has been briefly discussed on the Net session during dev summit in Ottawa last June and the general input was positive. This change is believed to benefit network benchmarks/profiling as well as other scenarios where precise time of arrival measurement is necessary. There are two regression test cases as part of this commit: one extends unix domain test code (unix_cmsg) to test new SCM_XXX types and another one implementis totally new test case which exchanges UDP packets between two processes using both conventional methods (i.e. calling clock_gettime(2) before recv(2) and after send(2)), as well as using setsockopt()+recv() in receive path. The resulting delays are checked for sanity for all supported clock types. Reviewed by: adrian, gnn Differential Revision: https://reviews.freebsd.org/D9171
Notes
Notes: svn path=/head/; revision=312296
Diffstat (limited to 'sys/kern/uipc_usrreq.c')
-rw-r--r--sys/kern/uipc_usrreq.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c
index a4ca27455a35..10f3ac2b88f3 100644
--- a/sys/kern/uipc_usrreq.c
+++ b/sys/kern/uipc_usrreq.c
@@ -1899,6 +1899,7 @@ unp_internalize(struct mbuf **controlp, struct thread *td)
struct filedescent *fde, **fdep, *fdev;
struct file *fp;
struct timeval *tv;
+ struct timespec *ts;
int i, *fdp;
void *data;
socklen_t clen = control->m_len, datalen;
@@ -2019,6 +2020,30 @@ unp_internalize(struct mbuf **controlp, struct thread *td)
bintime(bt);
break;
+ case SCM_REALTIME:
+ *controlp = sbcreatecontrol(NULL, sizeof(*ts),
+ SCM_REALTIME, SOL_SOCKET);
+ if (*controlp == NULL) {
+ error = ENOBUFS;
+ goto out;
+ }
+ ts = (struct timespec *)
+ CMSG_DATA(mtod(*controlp, struct cmsghdr *));
+ nanotime(ts);
+ break;
+
+ case SCM_MONOTONIC:
+ *controlp = sbcreatecontrol(NULL, sizeof(*ts),
+ SCM_MONOTONIC, SOL_SOCKET);
+ if (*controlp == NULL) {
+ error = ENOBUFS;
+ goto out;
+ }
+ ts = (struct timespec *)
+ CMSG_DATA(mtod(*controlp, struct cmsghdr *));
+ nanouptime(ts);
+ break;
+
default:
error = EINVAL;
goto out;