Commit 5711f8b3 authored by santosh.shilimkar@oracle.com's avatar santosh.shilimkar@oracle.com Committed by David S. Miller

RDS: Add support for SO_TIMESTAMP for incoming messages

The SO_TIMESTAMP generates time stamp for each incoming RDS messages
User app can enable it by using SO_TIMESTAMP setsocketopt() at
SOL_SOCKET level. CMSG data of cmsg type SO_TIMESTAMP contains the
time stamp in struct timeval format.
Reviewed-by: default avatarSowmini Varadhan <sowmini.varadhan@oracle.com>
Signed-off-by: default avatarSantosh Shilimkar <ssantosh@kernel.org>
Signed-off-by: default avatarSantosh Shilimkar <santosh.shilimkar@oracle.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent dcdede04
...@@ -277,6 +277,27 @@ static int rds_set_transport(struct rds_sock *rs, char __user *optval, ...@@ -277,6 +277,27 @@ static int rds_set_transport(struct rds_sock *rs, char __user *optval,
return rs->rs_transport ? 0 : -ENOPROTOOPT; return rs->rs_transport ? 0 : -ENOPROTOOPT;
} }
static int rds_enable_recvtstamp(struct sock *sk, char __user *optval,
int optlen)
{
int val, valbool;
if (optlen != sizeof(int))
return -EFAULT;
if (get_user(val, (int __user *)optval))
return -EFAULT;
valbool = val ? 1 : 0;
if (valbool)
sock_set_flag(sk, SOCK_RCVTSTAMP);
else
sock_reset_flag(sk, SOCK_RCVTSTAMP);
return 0;
}
static int rds_setsockopt(struct socket *sock, int level, int optname, static int rds_setsockopt(struct socket *sock, int level, int optname,
char __user *optval, unsigned int optlen) char __user *optval, unsigned int optlen)
{ {
...@@ -312,6 +333,11 @@ static int rds_setsockopt(struct socket *sock, int level, int optname, ...@@ -312,6 +333,11 @@ static int rds_setsockopt(struct socket *sock, int level, int optname,
ret = rds_set_transport(rs, optval, optlen); ret = rds_set_transport(rs, optval, optlen);
release_sock(sock->sk); release_sock(sock->sk);
break; break;
case SO_TIMESTAMP:
lock_sock(sock->sk);
ret = rds_enable_recvtstamp(sock->sk, optval, optlen);
release_sock(sock->sk);
break;
default: default:
ret = -ENOPROTOOPT; ret = -ENOPROTOOPT;
} }
......
...@@ -222,6 +222,7 @@ struct rds_incoming { ...@@ -222,6 +222,7 @@ struct rds_incoming {
__be32 i_saddr; __be32 i_saddr;
rds_rdma_cookie_t i_rdma_cookie; rds_rdma_cookie_t i_rdma_cookie;
struct timeval i_rx_tstamp;
}; };
struct rds_mr { struct rds_mr {
......
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
#include <net/sock.h> #include <net/sock.h>
#include <linux/in.h> #include <linux/in.h>
#include <linux/export.h> #include <linux/export.h>
#include <linux/time.h>
#include <linux/rds.h>
#include "rds.h" #include "rds.h"
...@@ -46,6 +48,8 @@ void rds_inc_init(struct rds_incoming *inc, struct rds_connection *conn, ...@@ -46,6 +48,8 @@ void rds_inc_init(struct rds_incoming *inc, struct rds_connection *conn,
inc->i_conn = conn; inc->i_conn = conn;
inc->i_saddr = saddr; inc->i_saddr = saddr;
inc->i_rdma_cookie = 0; inc->i_rdma_cookie = 0;
inc->i_rx_tstamp.tv_sec = 0;
inc->i_rx_tstamp.tv_usec = 0;
} }
EXPORT_SYMBOL_GPL(rds_inc_init); EXPORT_SYMBOL_GPL(rds_inc_init);
...@@ -228,6 +232,8 @@ void rds_recv_incoming(struct rds_connection *conn, __be32 saddr, __be32 daddr, ...@@ -228,6 +232,8 @@ void rds_recv_incoming(struct rds_connection *conn, __be32 saddr, __be32 daddr,
rds_recv_rcvbuf_delta(rs, sk, inc->i_conn->c_lcong, rds_recv_rcvbuf_delta(rs, sk, inc->i_conn->c_lcong,
be32_to_cpu(inc->i_hdr.h_len), be32_to_cpu(inc->i_hdr.h_len),
inc->i_hdr.h_dport); inc->i_hdr.h_dport);
if (sock_flag(sk, SOCK_RCVTSTAMP))
do_gettimeofday(&inc->i_rx_tstamp);
rds_inc_addref(inc); rds_inc_addref(inc);
list_add_tail(&inc->i_item, &rs->rs_recv_queue); list_add_tail(&inc->i_item, &rs->rs_recv_queue);
__rds_wake_sk_sleep(sk); __rds_wake_sk_sleep(sk);
...@@ -381,7 +387,8 @@ static int rds_notify_cong(struct rds_sock *rs, struct msghdr *msghdr) ...@@ -381,7 +387,8 @@ static int rds_notify_cong(struct rds_sock *rs, struct msghdr *msghdr)
/* /*
* Receive any control messages. * Receive any control messages.
*/ */
static int rds_cmsg_recv(struct rds_incoming *inc, struct msghdr *msg) static int rds_cmsg_recv(struct rds_incoming *inc, struct msghdr *msg,
struct rds_sock *rs)
{ {
int ret = 0; int ret = 0;
...@@ -392,6 +399,15 @@ static int rds_cmsg_recv(struct rds_incoming *inc, struct msghdr *msg) ...@@ -392,6 +399,15 @@ static int rds_cmsg_recv(struct rds_incoming *inc, struct msghdr *msg)
return ret; return ret;
} }
if ((inc->i_rx_tstamp.tv_sec != 0) &&
sock_flag(rds_rs_to_sk(rs), SOCK_RCVTSTAMP)) {
ret = put_cmsg(msg, SOL_SOCKET, SCM_TIMESTAMP,
sizeof(struct timeval),
&inc->i_rx_tstamp);
if (ret)
return ret;
}
return 0; return 0;
} }
...@@ -474,7 +490,7 @@ int rds_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, ...@@ -474,7 +490,7 @@ int rds_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
msg->msg_flags |= MSG_TRUNC; msg->msg_flags |= MSG_TRUNC;
} }
if (rds_cmsg_recv(inc, msg)) { if (rds_cmsg_recv(inc, msg, rs)) {
ret = -EFAULT; ret = -EFAULT;
goto out; goto out;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment