All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Networking <netdev@vger.kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Kernel Team <kernel-team@fb.com>, Martin KaFai Lau <kafai@fb.com>
Subject: Re: [PATCH bpf-next v3 13/15] tools/bpf: selftests: implement sample tcp/tcp6 bpf_iter programs
Date: Tue, 23 Jun 2020 08:03:09 -0700	[thread overview]
Message-ID: <6ff28837-63b1-754d-17aa-fd5877409b64@fb.com> (raw)
In-Reply-To: <CAEf4BzatNEOJSuM2t-1eLQuT4E8gcRLB38B=rqZU3G=vVGkizQ@mail.gmail.com>



On 6/22/20 11:56 PM, Andrii Nakryiko wrote:
> On Mon, Jun 22, 2020 at 5:38 PM Yonghong Song <yhs@fb.com> wrote:
>>
>> In my VM, I got identical result compared to /proc/net/{tcp,tcp6}.
>> For tcp6:
>>    $ cat /proc/net/tcp6
>>      sl  local_address                         remote_address                        st tx_queue rx_queue tr tm->when retrnsmt   uid  timeout inode
>>       0: 00000000000000000000000000000000:0016 00000000000000000000000000000000:0000 0A 00000000:00000000 00:00000001 00000000     0        0 17955 1 000000003eb3102e 100 0 0 10 0
>>
>>    $ cat /sys/fs/bpf/p1
>>      sl  local_address                         remote_address                        st tx_queue rx_queue tr tm->when retrnsmt   uid  timeout inode
>>       0: 00000000000000000000000000000000:0016 00000000000000000000000000000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 17955 1 000000003eb3102e 100 0 0 10 0
>>
>> For tcp:
>>    $ cat /proc/net/tcp
>>    sl  local_address rem_address   st tx_queue rx_queue tr tm->when retrnsmt   uid  timeout inode
>>     0: 00000000:0016 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 2666 1 000000007152e43f 100 0 0 10 0
>>    $ cat /sys/fs/bpf/p2
>>    sl  local_address                         remote_address                        st tx_queue rx_queue tr tm->when retrnsmt   uid  timeout inode
>>     1: 00000000:0016 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 2666 1 000000007152e43f 100 0 0 10 0
>>
>> Signed-off-by: Yonghong Song <yhs@fb.com>
>> ---
> 
> Looks reasonable, to the extent possible ;)
> 
> Acked-by: Andrii Nakryiko <andriin@fb.com>
> 
>>   tools/testing/selftests/bpf/progs/bpf_iter.h  |  15 ++
>>   .../selftests/bpf/progs/bpf_iter_tcp4.c       | 235 ++++++++++++++++
>>   .../selftests/bpf/progs/bpf_iter_tcp6.c       | 250 ++++++++++++++++++
>>   3 files changed, 500 insertions(+)
>>   create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_tcp4.c
>>   create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_tcp6.c
>>
> 
> [...]
> 
>> +static int hlist_unhashed_lockless(const struct hlist_node *h)
>> +{
>> +        return !(h->pprev);
>> +}
>> +
>> +static int timer_pending(const struct timer_list * timer)
>> +{
>> +       return !hlist_unhashed_lockless(&timer->entry);
>> +}
>> +
>> +extern unsigned CONFIG_HZ __kconfig __weak;
> 
> Why the __weak? We expect to have /proc/kconfig.gz in other tests
> anyway? __weak will make CONFIG_HZ to be a zero and you'll get a bunch
> of divisions by zero.

Make sense. Will change.

> 
>> +
>> +#define USER_HZ                100
>> +#define NSEC_PER_SEC   1000000000ULL
>> +static clock_t jiffies_to_clock_t(unsigned long x)
>> +{
>> +       /* The implementation here tailored to a particular
>> +        * setting of USER_HZ.
>> +        */
>> +       u64 tick_nsec = (NSEC_PER_SEC + CONFIG_HZ/2) / CONFIG_HZ;
>> +       u64 user_hz_nsec = NSEC_PER_SEC / USER_HZ;
>> +
>> +       if ((tick_nsec % user_hz_nsec) == 0) {
>> +               if (CONFIG_HZ < USER_HZ)
>> +                       return x * (USER_HZ / CONFIG_HZ);
>> +               else
>> +                       return x / (CONFIG_HZ / USER_HZ);
>> +       }
>> +       return x * tick_nsec/user_hz_nsec;
>> +}
>> +
> 
> [...]
> 
>> +       if (sk_common->skc_family != AF_INET)
>> +               return 0;
>> +
>> +       tp = bpf_skc_to_tcp_sock(sk_common);
>> +       if (tp) {
>> +               return dump_tcp_sock(seq, tp, uid, seq_num);
>> +       }
> 
> nit: unnecessary {}
> 
>> +
>> +       tw = bpf_skc_to_tcp_timewait_sock(sk_common);
>> +       if (tw)
>> +               return dump_tw_sock(seq, tw, uid, seq_num);
>> +
>> +       req = bpf_skc_to_tcp_request_sock(sk_common);
>> +       if (req)
>> +               return dump_req_sock(seq, req, uid, seq_num);
>> +
>> +       return 0;
>> +}
> 
> [...]
> 
>> +static int timer_pending(const struct timer_list * timer)
>> +{
>> +       return !hlist_unhashed_lockless(&timer->entry);
>> +}
>> +
>> +extern unsigned CONFIG_HZ __kconfig __weak;
> 
> same about __weak here
> 
>> +
>> +#define USER_HZ                100
>> +#define NSEC_PER_SEC   1000000000ULL
>> +static clock_t jiffies_to_clock_t(unsigned long x)
>> +{
>> +       /* The implementation here tailored to a particular
>> +        * setting of USER_HZ.
>> +        */
>> +       u64 tick_nsec = (NSEC_PER_SEC + CONFIG_HZ/2) / CONFIG_HZ;
>> +       u64 user_hz_nsec = NSEC_PER_SEC / USER_HZ;
>> +
>> +       if ((tick_nsec % user_hz_nsec) == 0) {
>> +               if (CONFIG_HZ < USER_HZ)
>> +                       return x * (USER_HZ / CONFIG_HZ);
>> +               else
>> +                       return x / (CONFIG_HZ / USER_HZ);
>> +       }
>> +       return x * tick_nsec/user_hz_nsec;
>> +}
> 
> nit: jiffies_to_clock_t() implementation looks like an overkill for
> this use case... Would it be just `x / CONFIG_HZ * NSEC_PER_SEC` with
> some potential rounding error?

We really want to have the output the same as /proc/net/{tcp,tcp6}.
Otherwise, it may cause confusion when comparing bpf_iter_tcp[6] outputs
vs. /proc/net/tcp[6] outputs.

> 
>> +
>> +static clock_t jiffies_delta_to_clock_t(long delta)
>> +{
>> +       if (delta <= 0)
>> +               return 0;
>> +
>> +       return jiffies_to_clock_t(delta);
>> +}
>> +
> 
> [...]
> 

  reply	other threads:[~2020-06-23 15:03 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-23  0:36 [PATCH bpf-next v3 00/15] implement bpf iterator for tcp and udp sockets Yonghong Song
2020-06-23  0:36 ` [PATCH bpf-next v3 01/15] net: bpf: add bpf_seq_afinfo in tcp_iter_state Yonghong Song
2020-06-23  0:36 ` [PATCH bpf-next v3 02/15] net: bpf: implement bpf iterator for tcp Yonghong Song
2020-06-23  0:36 ` [PATCH bpf-next v3 03/15] bpf: support 'X' in bpf_seq_printf() helper Yonghong Song
2020-06-23  0:36 ` [PATCH bpf-next v3 04/15] bpf: allow tracing programs to use bpf_jiffies64() helper Yonghong Song
2020-06-23  0:36 ` [PATCH bpf-next v3 05/15] bpf: add bpf_skc_to_tcp6_sock() helper Yonghong Song
2020-06-23  5:46   ` kernel test robot
2020-06-23  5:46     ` kernel test robot
2020-06-23  5:53   ` kernel test robot
2020-06-23  5:53     ` kernel test robot
2020-06-23  6:39   ` Andrii Nakryiko
2020-06-23 14:52     ` Yonghong Song
2020-06-23 18:23       ` Andrii Nakryiko
2020-06-23 19:45         ` Yonghong Song
2020-06-23 20:11           ` Andrii Nakryiko
2020-06-23 20:46             ` Yonghong Song
2020-06-23  0:36 ` [PATCH bpf-next v3 06/15] bpf: add bpf_skc_to_{tcp,tcp_timewait,tcp_request}_sock() helpers Yonghong Song
2020-06-23  5:18   ` kernel test robot
2020-06-23  5:18     ` [PATCH bpf-next v3 06/15] bpf: add bpf_skc_to_{tcp, tcp_timewait, tcp_request}_sock() helpers kernel test robot
2020-06-23  6:39   ` [PATCH bpf-next v3 06/15] bpf: add bpf_skc_to_{tcp,tcp_timewait,tcp_request}_sock() helpers kernel test robot
2020-06-23  6:39     ` [PATCH bpf-next v3 06/15] bpf: add bpf_skc_to_{tcp, tcp_timewait, tcp_request}_sock() helpers kernel test robot
2020-06-23  0:36 ` [PATCH bpf-next v3 07/15] net: bpf: add bpf_seq_afinfo in udp_iter_state Yonghong Song
2020-06-23  0:36 ` [PATCH bpf-next v3 08/15] net: bpf: implement bpf iterator for udp Yonghong Song
2020-06-23  0:36 ` [PATCH bpf-next v3 09/15] bpf: add bpf_skc_to_udp6_sock() helper Yonghong Song
2020-06-23  1:47   ` Eric Dumazet
2020-06-23  2:22     ` Yonghong Song
2020-06-23 16:27       ` Eric Dumazet
2020-06-23 17:03         ` Yonghong Song
2020-06-23 22:11           ` Eric Dumazet
2020-06-23 22:44             ` Yonghong Song
2020-06-23  0:36 ` [PATCH bpf-next v3 10/15] bpf/selftests: move newer bpf_iter_* type redefining to a new header file Yonghong Song
2020-06-23  0:36 ` [PATCH bpf-next v3 11/15] tools/bpf: refactor some net macros to libbpf bpf_tracing_net.h Yonghong Song
2020-06-23  6:45   ` Andrii Nakryiko
2020-06-23 14:56     ` Yonghong Song
2020-06-23  0:36 ` [PATCH bpf-next v3 12/15] tools/libbpf: add more common macros to bpf_tracing_net.h Yonghong Song
2020-06-23  0:36 ` [PATCH bpf-next v3 13/15] tools/bpf: selftests: implement sample tcp/tcp6 bpf_iter programs Yonghong Song
2020-06-23  6:56   ` Andrii Nakryiko
2020-06-23 15:03     ` Yonghong Song [this message]
2020-06-23  0:36 ` [PATCH bpf-next v3 14/15] tools/bpf: add udp4/udp6 bpf iterator Yonghong Song
2020-06-23  6:57   ` Andrii Nakryiko
2020-06-23 15:03     ` Yonghong Song
2020-06-23  0:36 ` [PATCH bpf-next v3 15/15] bpf/selftests: add tcp/udp iterator programs to selftests Yonghong Song
2020-06-23  6:59   ` Andrii Nakryiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6ff28837-63b1-754d-17aa-fd5877409b64@fb.com \
    --to=yhs@fb.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kafai@fb.com \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.