[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJ8uoz25gK68+uPjKhDm6z32HWR2ZB5oJLSS95+fA3a=vEXkSA@mail.gmail.com>
Date: Wed, 25 Apr 2018 12:50:36 +0200
From: Magnus Karlsson <magnus.karlsson@...il.com>
To: Willem de Bruijn <willemdebruijn.kernel@...il.com>
Cc: Björn Töpel <bjorn.topel@...il.com>,
"Karlsson, Magnus" <magnus.karlsson@...el.com>,
Alexander Duyck <alexander.h.duyck@...el.com>,
Alexander Duyck <alexander.duyck@...il.com>,
John Fastabend <john.fastabend@...il.com>,
Alexei Starovoitov <ast@...com>,
Jesper Dangaard Brouer <brouer@...hat.com>,
Daniel Borkmann <daniel@...earbox.net>,
"Michael S. Tsirkin" <mst@...hat.com>,
Network Development <netdev@...r.kernel.org>,
michael.lundkvist@...csson.com,
"Brandeburg, Jesse" <jesse.brandeburg@...el.com>,
"Singhai, Anjali" <anjali.singhai@...el.com>,
"Zhang, Qi Z" <qi.z.zhang@...el.com>
Subject: Re: [PATCH bpf-next 14/15] xsk: statistics support
On Tue, Apr 24, 2018 at 6:58 PM, Willem de Bruijn
<willemdebruijn.kernel@...il.com> wrote:
> On Mon, Apr 23, 2018 at 9:56 AM, Björn Töpel <bjorn.topel@...il.com> wrote:
>> From: Magnus Karlsson <magnus.karlsson@...el.com>
>>
>> In this commit, a new getsockopt is added: XDP_STATISTICS. This is
>> used to obtain stats from the sockets.
>>
>> Signed-off-by: Magnus Karlsson <magnus.karlsson@...el.com>
>
>> +static int xsk_getsockopt(struct socket *sock, int level, int optname,
>> + char __user *optval, int __user *optlen)
>> +{
>> + struct sock *sk = sock->sk;
>> + struct xdp_sock *xs = xdp_sk(sk);
>> + int len;
>> +
>> + if (level != SOL_XDP)
>> + return -ENOPROTOOPT;
>> +
>> + if (get_user(len, optlen))
>> + return -EFAULT;
>> + if (len < 0)
>> + return -EINVAL;
>> +
>> + switch (optname) {
>> + case XDP_STATISTICS:
>> + {
>> + struct xdp_statistics stats;
>> +
>> + if (len != sizeof(stats))
>> + return -EINVAL;
>> +
>> + mutex_lock(&xs->mutex);
>> + stats.rx_dropped = xs->rx_dropped;
>> + stats.rx_invalid_descs = xskq_nb_invalid_descs(xs->rx);
>> + stats.tx_invalid_descs = xskq_nb_invalid_descs(xs->tx);
>> + mutex_unlock(&xs->mutex);
>> +
>> + if (copy_to_user(optval, &stats, sizeof(stats)))
>> + return -EFAULT;
>> + return 0;
>
> For forward compatibility, could allow caller to pass a struct larger
> than stats and return the number of bytes filled in.
Yes definitely. Will fix right away.
> The lock can also be elided with something like gnet_stats, but it is probably
> taken rarely enough that that is not worth the effort, at least right now.
Will put this on the ever expanding todo list for future patches ;-).
Thanks: Magnus
Powered by blists - more mailing lists