mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] AF_UNIX: Implement SO_TIMESTAMP and SO_TIMETAMPNS on Unix sockets
@ 2010-10-04 15:38 Alban Crequy
  2010-10-04 16:41 ` Eric Dumazet
  0 siblings, 1 reply; 9+ messages in thread
From: Alban Crequy @ 2010-10-04 15:38 UTC (permalink / raw)
  Cc: Lennart Poettering, Alban Crequy, David S. Miller,
	Stephen Hemminger, Eric Dumazet, Cyrill Gorcunov,
	Alexey Dobriyan, linux-kernel, netdev

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);
-- 
1.7.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] AF_UNIX: Implement SO_TIMESTAMP and SO_TIMETAMPNS on Unix sockets
  2010-10-04 15:38 [PATCH] AF_UNIX: Implement SO_TIMESTAMP and SO_TIMETAMPNS on Unix sockets Alban Crequy
@ 2010-10-04 16:41 ` Eric Dumazet
  2010-10-04 18:00   ` Alban Crequy
  0 siblings, 1 reply; 9+ messages in thread
From: Eric Dumazet @ 2010-10-04 16:41 UTC (permalink / raw)
  To: Alban Crequy
  Cc: Lennart Poettering, David S. Miller, Stephen Hemminger,
	Cyrill Gorcunov, Alexey Dobriyan, linux-kernel, netdev

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



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] AF_UNIX: Implement SO_TIMESTAMP and SO_TIMETAMPNS on  Unix sockets
  2010-10-04 16:41 ` Eric Dumazet
@ 2010-10-04 18:00   ` Alban Crequy
  2010-10-04 18:01     ` Alban Crequy
  0 siblings, 1 reply; 9+ messages in thread
From: Alban Crequy @ 2010-10-04 18:00 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Lennart Poettering, David S. Miller, Stephen Hemminger,
	Cyrill Gorcunov, Alexey Dobriyan, linux-kernel, netdev,
	Alban Crequy

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).

-- 
Alban

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] AF_UNIX: Implement SO_TIMESTAMP and SO_TIMETAMPNS on Unix sockets
  2010-10-04 18:00   ` Alban Crequy
@ 2010-10-04 18:01     ` Alban Crequy
  2010-10-04 18:09       ` Eric Dumazet
  0 siblings, 1 reply; 9+ messages in thread
From: Alban Crequy @ 2010-10-04 18:01 UTC (permalink / raw)
  Cc: Lennart Poettering, Alban Crequy, David S. Miller,
	Stephen Hemminger, Eric Dumazet, Cyrill Gorcunov,
	Alexey Dobriyan, linux-kernel, netdev

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 on SOCK_DGRAM and SOCK_SEQPACKET Unix
sockets.

Signed-off-by: Alban Crequy <alban.crequy@collabora.co.uk>
---
 net/unix/af_unix.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 617bea4..bca0c1e 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -1697,6 +1697,9 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
 	if (err)
 		goto out_free;
 
+	if (sock_flag(sk, SOCK_RCVTSTAMP))
+		__sock_recv_timestamp(msg, sk, skb);
+
 	if (!siocb->scm) {
 		siocb->scm = &tmp_scm;
 		memset(&tmp_scm, 0, sizeof(tmp_scm));
-- 
1.7.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] AF_UNIX: Implement SO_TIMESTAMP and SO_TIMETAMPNS on Unix sockets
  2010-10-04 18:01     ` Alban Crequy
@ 2010-10-04 18:09       ` Eric Dumazet
  2010-10-04 18:47         ` Alban Crequy
  0 siblings, 1 reply; 9+ messages in thread
From: Eric Dumazet @ 2010-10-04 18:09 UTC (permalink / raw)
  To: Alban Crequy
  Cc: Lennart Poettering, David S. Miller, Stephen Hemminger,
	Cyrill Gorcunov, Alexey Dobriyan, linux-kernel, netdev

Le lundi 04 octobre 2010 à 19:01 +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 on SOCK_DGRAM and SOCK_SEQPACKET Unix
> sockets.
> 
> Signed-off-by: Alban Crequy <alban.crequy@collabora.co.uk>
> ---
>  net/unix/af_unix.c |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)
> 
> diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
> index 617bea4..bca0c1e 100644
> --- a/net/unix/af_unix.c
> +++ b/net/unix/af_unix.c
> @@ -1697,6 +1697,9 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
>  	if (err)
>  		goto out_free;
>  
> +	if (sock_flag(sk, SOCK_RCVTSTAMP))
> +		__sock_recv_timestamp(msg, sk, skb);
> +
>  	if (!siocb->scm) {
>  		siocb->scm = &tmp_scm;
>  		memset(&tmp_scm, 0, sizeof(tmp_scm));

Hmm, but how is set skb->tstamp ?

I think its zero at this point, so __sock_recv_timestamp() use current
time, not time of send().

gettimeofday() might be better/cheaper :)




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] AF_UNIX: Implement SO_TIMESTAMP and SO_TIMETAMPNS on  Unix sockets
  2010-10-04 18:09       ` Eric Dumazet
@ 2010-10-04 18:47         ` Alban Crequy
  2010-10-04 18:48           ` Alban Crequy
  0 siblings, 1 reply; 9+ messages in thread
From: Alban Crequy @ 2010-10-04 18:47 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Lennart Poettering, David S. Miller, Stephen Hemminger,
	Cyrill Gorcunov, Alexey Dobriyan, linux-kernel, netdev,
	Alban Crequy

Le Mon, 04 Oct 2010 20:09:49 +0200,
Eric Dumazet <eric.dumazet@gmail.com> a écrit :

> Le lundi 04 octobre 2010 à 19:01 +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 on SOCK_DGRAM
> > and SOCK_SEQPACKET Unix sockets.
> > 
> > Signed-off-by: Alban Crequy <alban.crequy@collabora.co.uk>
> > ---
> >  net/unix/af_unix.c |    3 +++
> >  1 files changed, 3 insertions(+), 0 deletions(-)
> > 
> > diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
> > index 617bea4..bca0c1e 100644
> > --- a/net/unix/af_unix.c
> > +++ b/net/unix/af_unix.c
> > @@ -1697,6 +1697,9 @@ static int unix_dgram_recvmsg(struct kiocb
> > *iocb, struct socket *sock, if (err)
> >  		goto out_free;
> >  
> > +	if (sock_flag(sk, SOCK_RCVTSTAMP))
> > +		__sock_recv_timestamp(msg, sk, skb);
> > +
> >  	if (!siocb->scm) {
> >  		siocb->scm = &tmp_scm;
> >  		memset(&tmp_scm, 0, sizeof(tmp_scm));
> 
> Hmm, but how is set skb->tstamp ?
> 
> I think its zero at this point, so __sock_recv_timestamp() use current
> time, not time of send().
> 
> gettimeofday() might be better/cheaper :)

You're right, I just tested it and it was the time of reception. Thanks
for the review.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] AF_UNIX: Implement SO_TIMESTAMP and SO_TIMETAMPNS on Unix sockets
  2010-10-04 18:47         ` Alban Crequy
@ 2010-10-04 18:48           ` Alban Crequy
  2010-10-04 19:20             ` Eric Dumazet
  0 siblings, 1 reply; 9+ messages in thread
From: Alban Crequy @ 2010-10-04 18:48 UTC (permalink / raw)
  Cc: Lennart Poettering, Alban Crequy, David S. Miller,
	Stephen Hemminger, Eric Dumazet, Cyrill Gorcunov,
	Alexey Dobriyan, linux-kernel, netdev

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 on SOCK_DGRAM and SOCK_SEQPACKET Unix
sockets.

Signed-off-by: Alban Crequy <alban.crequy@collabora.co.uk>
---
 net/unix/af_unix.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 617bea4..b03baa8 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -1484,6 +1484,8 @@ restart:
 		goto restart;
 	}
 
+	if (sock_flag(other, SOCK_RCVTSTAMP))
+		__net_timestamp(skb);
 	skb_queue_tail(&other->sk_receive_queue, skb);
 	unix_state_unlock(other);
 	other->sk_data_ready(other, len);
@@ -1697,6 +1699,9 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
 	if (err)
 		goto out_free;
 
+	if (sock_flag(sk, SOCK_RCVTSTAMP))
+		__sock_recv_timestamp(msg, sk, skb);
+
 	if (!siocb->scm) {
 		siocb->scm = &tmp_scm;
 		memset(&tmp_scm, 0, sizeof(tmp_scm));
-- 
1.7.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] AF_UNIX: Implement SO_TIMESTAMP and SO_TIMETAMPNS on Unix sockets
  2010-10-04 18:48           ` Alban Crequy
@ 2010-10-04 19:20             ` Eric Dumazet
  2010-10-05 21:55               ` David Miller
  0 siblings, 1 reply; 9+ messages in thread
From: Eric Dumazet @ 2010-10-04 19:20 UTC (permalink / raw)
  To: Alban Crequy
  Cc: Lennart Poettering, David S. Miller, Stephen Hemminger,
	Cyrill Gorcunov, Alexey Dobriyan, linux-kernel, netdev

Le lundi 04 octobre 2010 à 19:48 +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 on SOCK_DGRAM and SOCK_SEQPACKET Unix
> sockets.
> 
> Signed-off-by: Alban Crequy <alban.crequy@collabora.co.uk>

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>

Note: tstamp is sampled at the time of skb queueing, _after_ eventual
sleep in sock_alloc_send_skb() or memcpy_fromiovec()




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] AF_UNIX: Implement SO_TIMESTAMP and SO_TIMETAMPNS on Unix sockets
  2010-10-04 19:20             ` Eric Dumazet
@ 2010-10-05 21:55               ` David Miller
  0 siblings, 0 replies; 9+ messages in thread
From: David Miller @ 2010-10-05 21:55 UTC (permalink / raw)
  To: eric.dumazet
  Cc: alban.crequy, lennart, shemminger, gorcunov, adobriyan,
	linux-kernel, netdev

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Mon, 04 Oct 2010 21:20:52 +0200

> Le lundi 04 octobre 2010 à 19:48 +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 on SOCK_DGRAM and SOCK_SEQPACKET Unix
>> sockets.
>> 
>> Signed-off-by: Alban Crequy <alban.crequy@collabora.co.uk>
> 
> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>

Applied.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-10-05 21:55 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-04 15:38 [PATCH] AF_UNIX: Implement SO_TIMESTAMP and SO_TIMETAMPNS on Unix sockets Alban Crequy
2010-10-04 16:41 ` Eric Dumazet
2010-10-04 18:00   ` Alban Crequy
2010-10-04 18:01     ` Alban Crequy
2010-10-04 18:09       ` Eric Dumazet
2010-10-04 18:47         ` Alban Crequy
2010-10-04 18:48           ` Alban Crequy
2010-10-04 19:20             ` Eric Dumazet
2010-10-05 21:55               ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®