Patchwork AF_UNIX: Implement SO_TIMESTAMP and SO_TIMETAMPNS on Unix sockets

login
register
mail settings
Submitter Alban Crequy
Date Oct. 4, 2010, 3:38 p.m.
Message ID <1286206706-25733-1-git-send-email-alban.crequy@collabora.co.uk>
Download mbox | patch
Permalink /patch/66705/
State Superseded
Delegated to: David Miller
Headers show

Comments

Alban Crequy - Oct. 4, 2010, 3:38 p.m.
Userspace applications can already request to receive timestamps with:
setsockopt(sockfd, SOL_SOCKET, SO_TIMESTAMP, ...)

Although setsockopt() returns zero (success), timestamps are not added to the
ancillary data. This patch fixes that.

Signed-off-by: Alban Crequy <alban.crequy@collabora.co.uk>
---
 net/unix/af_unix.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
Eric Dumazet - Oct. 4, 2010, 4:41 p.m.
Le lundi 04 octobre 2010 à 16:38 +0100, Alban Crequy a écrit :
> Userspace applications can already request to receive timestamps with:
> setsockopt(sockfd, SOL_SOCKET, SO_TIMESTAMP, ...)
> 
> Although setsockopt() returns zero (success), timestamps are not added to the
> ancillary data. This patch fixes that.
> 
> Signed-off-by: Alban Crequy <alban.crequy@collabora.co.uk>
> ---
>  net/unix/af_unix.c |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
> index 617bea4..142ccea 100644
> --- a/net/unix/af_unix.c
> +++ b/net/unix/af_unix.c
> @@ -1697,6 +1697,8 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
>  	if (err)
>  		goto out_free;
>  
> +	sock_recv_timestamp(msg, sk, skb);
> +
>  	if (!siocb->scm) {
>  		siocb->scm = &tmp_scm;
>  		memset(&tmp_scm, 0, sizeof(tmp_scm));
> @@ -1877,6 +1879,8 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
>  		copied += chunk;
>  		size -= chunk;
>  
> +		sock_recv_timestamp(msg, sk, skb);
> +
>  		/* Mark read part of skb as used */
>  		if (!(flags & MSG_PEEK)) {
>  			skb_pull(skb, chunk);

Are you sure its needed for unix_stream case ?

We dont do this for TCP for example, only for datagrams.

As shown in the past, sock_recv_timestamp() is a bit expensive because
it takes care of many possible options.

It would be better to use in AF_UNIX case (only software timestamps) :

Solution 1) 
if (sock_flag(sk, SOCK_RCVTSTAMP))
	__sock_recv_timestamp(msg, sk, skb);

Solution 2) 
Or something already used elsewhere since 2.6.35 and commit
767dd03369ac1 (net: speedup sock_recv_ts_and_drops()) :

sock_recv_ts_and_drops(msg, sk, skb);


I would vote for the 1) solution


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alban Crequy - Oct. 4, 2010, 6 p.m.
Le Mon, 04 Oct 2010 18:41:44 +0200,
Eric Dumazet <eric.dumazet@gmail.com> a écrit :

> Le lundi 04 octobre 2010 à 16:38 +0100, Alban Crequy a écrit :
> > Userspace applications can already request to receive timestamps
> > with: setsockopt(sockfd, SOL_SOCKET, SO_TIMESTAMP, ...)
> > 
> > Although setsockopt() returns zero (success), timestamps are not
> > added to the ancillary data. This patch fixes that.
> > 
> > Signed-off-by: Alban Crequy <alban.crequy@collabora.co.uk>
> > ---
> >  net/unix/af_unix.c |    4 ++++
> >  1 files changed, 4 insertions(+), 0 deletions(-)
> > 
> > diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
> > index 617bea4..142ccea 100644
> > --- a/net/unix/af_unix.c
> > +++ b/net/unix/af_unix.c
> > @@ -1697,6 +1697,8 @@ static int unix_dgram_recvmsg(struct kiocb
> > *iocb, struct socket *sock, if (err)
> >  		goto out_free;
> >  
> > +	sock_recv_timestamp(msg, sk, skb);
> > +
> >  	if (!siocb->scm) {
> >  		siocb->scm = &tmp_scm;
> >  		memset(&tmp_scm, 0, sizeof(tmp_scm));
> > @@ -1877,6 +1879,8 @@ static int unix_stream_recvmsg(struct kiocb
> > *iocb, struct socket *sock, copied += chunk;
> >  		size -= chunk;
> >  
> > +		sock_recv_timestamp(msg, sk, skb);
> > +
> >  		/* Mark read part of skb as used */
> >  		if (!(flags & MSG_PEEK)) {
> >  			skb_pull(skb, chunk);
> 
> Are you sure its needed for unix_stream case ?

I was about to say it does not cost anything to add it...

> We dont do this for TCP for example, only for datagrams.
> 
> As shown in the past, sock_recv_timestamp() is a bit expensive because
> it takes care of many possible options.

Is it really expensive? It looks like a few flag checks in an inline
function to me.

> It would be better to use in AF_UNIX case (only software timestamps) :
> 
> Solution 1) 
> if (sock_flag(sk, SOCK_RCVTSTAMP))
> 	__sock_recv_timestamp(msg, sk, skb);
> 
> Solution 2) 
> Or something already used elsewhere since 2.6.35 and commit
> 767dd03369ac1 (net: speedup sock_recv_ts_and_drops()) :
> 
> sock_recv_ts_and_drops(msg, sk, skb);
> 
> 
> I would vote for the 1) solution

The patch in the next email implements the 1) solution on SOCK_DGRAM and
SOCK_SEQPACKET (without SOCK_STREAM).

Patch

diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 617bea4..142ccea 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -1697,6 +1697,8 @@  static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
 	if (err)
 		goto out_free;
 
+	sock_recv_timestamp(msg, sk, skb);
+
 	if (!siocb->scm) {
 		siocb->scm = &tmp_scm;
 		memset(&tmp_scm, 0, sizeof(tmp_scm));
@@ -1877,6 +1879,8 @@  static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
 		copied += chunk;
 		size -= chunk;
 
+		sock_recv_timestamp(msg, sk, skb);
+
 		/* Mark read part of skb as used */
 		if (!(flags & MSG_PEEK)) {
 			skb_pull(skb, chunk);