1. 16 7月, 2019 1 次提交
  2. 03 7月, 2019 3 次提交
    • S
      samples/bpf: fix tcp_bpf.readme detach command · d78e3f06
      Stanislav Fomichev 提交于
      Copy-paste, should be detach, not attach.
      Signed-off-by: NStanislav Fomichev <sdf@google.com>
      Acked-by: NSoheil Hassas Yeganeh <soheil@google.com>
      Acked-by: NYuchung Cheng <ycheng@google.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      d78e3f06
    • S
      samples/bpf: add sample program that periodically dumps TCP stats · 39533884
      Stanislav Fomichev 提交于
      Uses new RTT callback to dump stats every second.
      
      $ mkdir -p /tmp/cgroupv2
      $ mount -t cgroup2 none /tmp/cgroupv2
      $ mkdir -p /tmp/cgroupv2/foo
      $ echo $$ >> /tmp/cgroupv2/foo/cgroup.procs
      $ bpftool prog load ./tcp_dumpstats_kern.o /sys/fs/bpf/tcp_prog
      $ bpftool cgroup attach /tmp/cgroupv2/foo sock_ops pinned /sys/fs/bpf/tcp_prog
      $ bpftool prog tracelog
      $ # run neper/netperf/etc
      
      Used neper to compare performance with and without this program attached
      and didn't see any noticeable performance impact.
      
      Sample output:
        <idle>-0     [015] ..s.  2074.128800: 0: dsack_dups=0 delivered=242526
        <idle>-0     [015] ..s.  2074.128808: 0: delivered_ce=0 icsk_retransmits=0
        <idle>-0     [015] ..s.  2075.130133: 0: dsack_dups=0 delivered=323599
        <idle>-0     [015] ..s.  2075.130138: 0: delivered_ce=0 icsk_retransmits=0
        <idle>-0     [005] .Ns.  2076.131440: 0: dsack_dups=0 delivered=404648
        <idle>-0     [005] .Ns.  2076.131447: 0: delivered_ce=0 icsk_retransmits=0
      
      Cc: Eric Dumazet <edumazet@google.com>
      Cc: Priyaranjan Jha <priyarjha@google.com>
      Cc: Yuchung Cheng <ycheng@google.com>
      Cc: Soheil Hassas Yeganeh <soheil@google.com>
      Acked-by: NSoheil Hassas Yeganeh <soheil@google.com>
      Acked-by: NYuchung Cheng <ycheng@google.com>
      Signed-off-by: NStanislav Fomichev <sdf@google.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      39533884
    • B
      bpf: Add support for fq's EDT to HBM · 71634d7f
      brakmo 提交于
      Adds support for fq's Earliest Departure Time to HBM (Host Bandwidth
      Manager). Includes a new BPF program supporting EDT, and also updates
      corresponding programs.
      
      It will drop packets with an EDT of more than 500us in the future
      unless the packet belongs to a flow with less than 2 packets in flight.
      This is done so each flow has at least 2 packets in flight, so they
      will not starve, and also to help prevent delayed ACK timeouts.
      
      It will also work with ECN enabled traffic, where the packets will be
      CE marked if their EDT is more than 50us in the future.
      
      The table below shows some performance numbers. The flows are back to
      back RPCS. One server sending to another, either 2 or 4 flows.
      One flow is a 10KB RPC, the rest are 1MB RPCs. When there are more
      than one flow of a given RPC size, the numbers represent averages.
      
      The rate limit applies to all flows (they are in the same cgroup).
      Tests ending with "-edt" ran with the new BPF program supporting EDT.
      Tests ending with "-hbt" ran on top HBT qdisc with the specified rate
      (i.e. no HBM). The other tests ran with the HBM BPF program included
      in the HBM patch-set.
      
      EDT has limited value when using DCTCP, but it helps in many cases when
      using Cubic. It usually achieves larger link utilization and lower
      99% latencies for the 1MB RPCs.
      HBM ends up queueing a lot of packets with its default parameter values,
      reducing the goodput of the 10KB RPCs and increasing their latency. Also,
      the RTTs seen by the flows are quite large.
      
                               Aggr              10K  10K  10K   1MB  1MB  1MB
               Limit           rate drops  RTT  rate  P90  P99  rate  P90  P99
      Test      rate  Flows    Mbps   %     us  Mbps   us   us  Mbps   ms   ms
      --------  ----  -----    ---- -----  ---  ---- ---- ----  ---- ---- ----
      cubic       1G    2       904  0.02  108   257  511  539   647 13.4 24.5
      cubic-edt   1G    2       982  0.01  156   239  656  967   743 14.0 17.2
      dctcp       1G    2       977  0.00  105   324  408  744   653 14.5 15.9
      dctcp-edt   1G    2       981  0.01  142   321  417  811   660 15.7 17.0
      cubic-htb   1G    2       919  0.00 1825    40 2822 4140   879  9.7  9.9
      
      cubic     200M    2       155  0.30  220    81  532  655    74  283  450
      cubic-edt 200M    2       188  0.02  222    87 1035 1095   101   84   85
      dctcp     200M    2       188  0.03  111    77  912  939   111   76  325
      dctcp-edt 200M    2       188  0.03  217    74 1416 1738   114   76   79
      cubic-htb 200M    2       188  0.00 5015     8 14ms 15ms   180   48   50
      
      cubic       1G    4       952  0.03  110   165  516  546   262   38  154
      cubic-edt   1G    4       973  0.01  190   111 1034 1314   287   65   79
      dctcp       1G    4       951  0.00  103   180  617  905   257   37   38
      dctcp-edt   1G    4       967  0.00  163   151  732 1126   272   43   55
      cubic-htb   1G    4       914  0.00 3249    13  7ms  8ms   300   29   34
      
      cubic       5G    4      4236  0.00  134   305  490  624  1310   10   17
      cubic-edt   5G    4      4865  0.00  156   306  425  759  1520   10   16
      dctcp       5G    4      4936  0.00  128   485  221  409  1484    7    9
      dctcp-edt   5G    4      4924  0.00  148   390  392  623  1508   11   26
      
      v1 -> v2: Incorporated Andrii's suggestions
      v2 -> v3: Incorporated Yonghong's suggestions
      v3 -> v4: Removed credit update that is not needed
      Signed-off-by: NLawrence Brakmo <brakmo@fb.com>
      Acked-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      71634d7f
  3. 28 6月, 2019 1 次提交
  4. 26 6月, 2019 1 次提交
  5. 25 6月, 2019 1 次提交
  6. 24 6月, 2019 1 次提交
  7. 19 6月, 2019 1 次提交
  8. 18 6月, 2019 2 次提交
  9. 15 6月, 2019 1 次提交
  10. 11 6月, 2019 1 次提交
  11. 06 6月, 2019 1 次提交
  12. 05 6月, 2019 1 次提交
  13. 04 6月, 2019 1 次提交
  14. 01 6月, 2019 2 次提交
  15. 31 5月, 2019 1 次提交
  16. 29 5月, 2019 1 次提交
  17. 28 5月, 2019 1 次提交
  18. 25 5月, 2019 2 次提交
  19. 21 5月, 2019 2 次提交
    • M
      samples, bpf: suppress compiler warning · a195ceff
      Matteo Croce 提交于
      GCC 9 fails to calculate the size of local constant strings and produces a
      false positive:
      
      samples/bpf/task_fd_query_user.c: In function ‘test_debug_fs_uprobe’:
      samples/bpf/task_fd_query_user.c:242:67: warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 215 [-Wformat-truncation=]
        242 |  snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/events/%ss/%s/id",
            |                                                                   ^~
        243 |    event_type, event_alias);
            |                ~~~~~~~~~~~
      samples/bpf/task_fd_query_user.c:242:2: note: ‘snprintf’ output between 45 and 300 bytes into a destination of size 256
        242 |  snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/events/%ss/%s/id",
            |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        243 |    event_type, event_alias);
            |    ~~~~~~~~~~~~~~~~~~~~~~~~
      
      Workaround this by lowering the buffer size to a reasonable value.
      Related GCC Bugzilla: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83431Signed-off-by: NMatteo Croce <mcroce@redhat.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      a195ceff
    • C
      samples, bpf: fix to change the buffer size for read() · f7c2d64b
      Chang-Hsien Tsai 提交于
      If the trace for read is larger than 4096, the return
      value sz will be 4096. This results in off-by-one error
      on buf:
      
          static char buf[4096];
          ssize_t sz;
      
          sz = read(trace_fd, buf, sizeof(buf));
          if (sz > 0) {
              buf[sz] = 0;
              puts(buf);
          }
      Signed-off-by: NChang-Hsien Tsai <luke.tw@gmail.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      f7c2d64b
  20. 26 4月, 2019 1 次提交
  21. 05 4月, 2019 1 次提交
    • A
      samples/bpf: fix build with new clang · 636e78b1
      Alexei Starovoitov 提交于
      clang started to error on invalid asm clobber usage in x86 headers
      and many bpf program samples failed to build with the message:
      
        CLANG-bpf  /data/users/ast/bpf-next/samples/bpf/xdp_redirect_kern.o
      In file included from /data/users/ast/bpf-next/samples/bpf/xdp_redirect_kern.c:14:
      In file included from ../include/linux/in.h:23:
      In file included from ../include/uapi/linux/in.h:24:
      In file included from ../include/linux/socket.h:8:
      In file included from ../include/linux/uio.h:14:
      In file included from ../include/crypto/hash.h:16:
      In file included from ../include/linux/crypto.h:26:
      In file included from ../include/linux/uaccess.h:5:
      In file included from ../include/linux/sched.h:15:
      In file included from ../include/linux/sem.h:5:
      In file included from ../include/uapi/linux/sem.h:5:
      In file included from ../include/linux/ipc.h:9:
      In file included from ../include/linux/refcount.h:72:
      ../arch/x86/include/asm/refcount.h:72:36: error: asm-specifier for input or output variable conflicts with asm clobber list
                                               r->refs.counter, e, "er", i, "cx");
                                                                            ^
      ../arch/x86/include/asm/refcount.h:86:27: error: asm-specifier for input or output variable conflicts with asm clobber list
                                               r->refs.counter, e, "cx");
                                                                   ^
      2 errors generated.
      
      Override volatile() to workaround the problem.
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      636e78b1
  22. 04 4月, 2019 1 次提交
  23. 28 3月, 2019 1 次提交
  24. 22 3月, 2019 1 次提交
  25. 07 3月, 2019 1 次提交
  26. 03 3月, 2019 3 次提交
    • B
      bpf: HBM test script · 4ffd44cf
      brakmo 提交于
      Script for testing HBM (Host Bandwidth Manager) framework.
      It creates a cgroup to use for testing and load a BPF program to limit
      egress bandwidht. It then uses iperf3 or netperf to create
      loads. The output is the goodput in Mbps (unless -D is used).
      
      It can work on a single host using loopback or among two hosts (with netperf).
      When using loopback, it is recommended to also introduce a delay of at least
      1ms (-d=1), otherwise the assigned bandwidth is likely to be underutilized.
      
      USAGE: $name [out] [-b=<prog>|--bpf=<prog>] [-c=<cc>|--cc=<cc>] [-D]
                   [-d=<delay>|--delay=<delay>] [--debug] [-E]
                   [-f=<#flows>|--flows=<#flows>] [-h] [-i=<id>|--id=<id >] [-l]
      	     [-N] [-p=<port>|--port=<port>] [-P] [-q=<qdisc>]
                   [-R] [-s=<server>|--server=<server] [--stats]
      	     [-t=<time>|--time=<time>] [-w] [cubic|dctcp]
        Where:
          out               Egress (default egress)
          -b or --bpf       BPF program filename to load and attach.
                            Default is nrm_out_kern.o for egress,
          -c or -cc         TCP congestion control (cubic or dctcp)
          -d or --delay     Add a delay in ms using netem
          -D                In addition to the goodput in Mbps, it also outputs
                            other detailed information. This information is
                            test dependent (i.e. iperf3 or netperf).
          --debug           Print BPF trace buffer
          -E                Enable ECN (not required for dctcp)
          -f or --flows     Number of concurrent flows (default=1)
          -i or --id        cgroup id (an integer, default is 1)
          -l                Do not limit flows using loopback
          -N                Use netperf instead of iperf3
          -h                Help
          -p or --port      iperf3 port (default is 5201)
          -P                Use an iperf3 instance for each flow
          -q                Use the specified qdisc.
          -r or --rate      Rate in Mbps (default 1s 1Gbps)
          -R                Use TCP_RR for netperf. 1st flow has req
                            size of 10KB, rest of 1MB. Reply in all
                            cases is 1 byte.
                            More detailed output for each flow can be found
                            in the files netperf.<cg>.<flow>, where <cg> is the
                            cgroup id as specified with the -i flag, and <flow>
                            is the flow id starting at 1 and increasing by 1 for
                            flow (as specified by -f).
          -s or --server    hostname of netperf server. Used to create netperf
                            test traffic between to hosts (default is within host)
                            netserver must be running on the host.
          --stats           Get HBM stats (marked, dropped, etc.)
          -t or --time      duration of iperf3 in seconds (default=5)
          -w                Work conserving flag. cgroup can increase its
                            bandwidth beyond the rate limit specified
                            while there is available bandwidth. Current
                            implementation assumes there is only one NIC
                            (eth0), but can be extended to support multiple
                            NICs. This is just a proof of concept.
          cubic or dctcp    specify TCP CC to use
      
      Examples:
       ./do_hbm_test.sh -l -d=1 -D --stats
           Runs a 5 second test, using a single iperf3 flow and with the default
           rate limit of 1Gbps and a delay of 1ms (using netem) using the default
           TCP congestion control on the loopback device (hence we use "-l" to
           enforce bandwidth limit on loopback device). Since no direction is
           specified, it defaults to egress. Since no TCP CC algorithm is
           specified it uses the system default (Cubic for this test).
           With no -D flag, only the value of the AGGREGATE OUTPUT would show.
           id refers to the cgroup id and is useful when running multi cgroup
           tests (supported by a future patch).
           This patchset does not support calling TCP's congesion window
           reduction, even when packets are dropped by the BPF program, resulting
           in a large number of packets dropped. It is recommended that the  current
           HBM implemenation only be used with ECN enabled flows. A future patch
           will add support for reducing TCP's cwnd and will increase the
           performance of non-ECN enabled flows.
         Output:
           Details for HBM in cgroup 1
           id:1
           rate_mbps:493
           duration:4.8 secs
           packets:11355
           bytes_MB:590
           pkts_dropped:4497
           bytes_dropped_MB:292
           pkts_marked_percent: 39.60
           bytes_marked_percent: 49.49
           pkts_dropped_percent: 39.60
           bytes_dropped_percent: 49.49
           PING AVG DELAY:2.075
           AGGREGATE_GOODPUT:505
      
      ./do_nrm_test.sh -l -d=1 -D --stats dctcp
           Same as above but using dctcp. Note that fewer bytes are dropped
           (0.01% vs. 49%).
         Output:
           Details for HBM in cgroup 1
           id:1
           rate_mbps:945
           duration:4.9 secs
           packets:16859
           bytes_MB:578
           pkts_dropped:1
           bytes_dropped_MB:0
           pkts_marked_percent: 28.74
           bytes_marked_percent: 45.15
           pkts_dropped_percent:  0.01
           bytes_dropped_percent:  0.01
           PING AVG DELAY:2.083
           AGGREGATE_GOODPUT:965
      
      ./do_nrm_test.sh -d=1 -D --stats
           As first example, but without limiting loopback device (i.e. no
           "-l" flag). Since there is no bandwidth limiting, no details for
           HBM are printed out.
         Output:
           Details for HBM in cgroup 1
           PING AVG DELAY:2.019
           AGGREGATE_GOODPUT:42655
      
      ./do_hbm.sh -l -d=1 -D --stats -f=2
           Uses iper3 and does 2 flows
      ./do_hbm.sh -l -d=1 -D --stats -f=4 -P
           Uses iperf3 and does 4 flows, each flow as a separate process.
      ./do_hbm.sh -l -d=1 -D --stats -f=4 -N
           Uses netperf, 4 flows
      ./do_hbm.sh -f=1 -r=2000 -t=5 -N -D --stats dctcp -s=<server-name>
           Uses netperf between two hosts. The remote host name is specified
           with -s= and you need to start the program netserver manually on
           the remote host. It will use 1 flow, a rate limit of 2Gbps and dctcp.
      ./do_hbm.sh -f=1 -r=2000 -t=5 -N -D --stats -w dctcp \
           -s=<server-name>
           As previous, but allows use of extra bandwidth. For this test the
           rate is 8Gbps vs. 1Gbps of the previous test.
      Signed-off-by: NLawrence Brakmo <brakmo@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      4ffd44cf
    • B
      bpf: User program for testing HBM · a1270fe9
      brakmo 提交于
      The program nrm creates a cgroup and attaches a BPF program to the
      cgroup for testing HBM (Host Bandwidth Manager) for egress traffic.
      One still needs to create network traffic. This can be done through
      netesto, netperf or iperf3.
      A follow-up patch contains a script to create traffic.
      
      USAGE: hbm [-d] [-l] [-n <id>] [-r <rate>] [-s] [-t <secs>]
                 [-w] [-h] [prog]
        Where:
         -d        Print BPF trace debug buffer
         -l        Also limit flows doing loopback
         -n <#>    To create cgroup "/hbm#" and attach prog. Default is /nrm1
                   This is convenient when testing HBM in more than 1 cgroup
         -r <rate> Rate limit in Mbps
         -s        Get HBM stats (marked, dropped, etc.)
         -t <time> Exit after specified seconds (deault is 0)
         -w        Work conserving flag. cgroup can increase its bandwidth
                   beyond the rate limit specified while there is available
                   bandwidth. Current implementation assumes there is only
                   NIC (eth0), but can be extended to support multiple NICs.
                   Currrently only supported for egress. Note, this is just
      	     a proof of concept.
         -h        Print this info
         prog      BPF program file name. Name defaults to hbm_out_kern.o
      
      More information about HBM can be found in the paper "BPF Host Resource
      Management" presented at the 2018 Linux Plumbers Conference, Networking Track
      (http://vger.kernel.org/lpc_net2018_talks/LPC%20BPF%20Network%20Resource%20Paper.pdf)
      Signed-off-by: NLawrence Brakmo <brakmo@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      a1270fe9
    • B
      bpf: Sample HBM BPF program to limit egress bw · 187d0738
      brakmo 提交于
      A cgroup skb BPF program to limit cgroup output bandwidth.
      It uses a modified virtual token bucket queue to limit average
      egress bandwidth. The implementation uses credits instead of tokens.
      Negative credits imply that queueing would have happened (this is
      a virtual queue, so no queueing is done by it. However, queueing may
      occur at the actual qdisc (which is not used for rate limiting).
      
      This implementation uses 3 thresholds, one to start marking packets and
      the other two to drop packets:
                                       CREDIT
             - <--------------------------|------------------------> +
                   |    |          |      0
                   |  Large pkt    |
                   |  drop thresh  |
        Small pkt drop             Mark threshold
            thresh
      
      The effect of marking depends on the type of packet:
      a) If the packet is ECN enabled, then the packet is ECN ce marked.
         The current mark threshold is tuned for DCTCP.
      c) Else, it is dropped if it is a large packet.
      
      If the credit is below the drop threshold, the packet is dropped.
      Note that dropping a packet through the BPF program does not trigger CWR
      (Congestion Window Reduction) in TCP packets. A future patch will add
      support for triggering CWR.
      
      This BPF program actually uses 2 drop thresholds, one threshold
      for larger packets (>= 120 bytes) and another for smaller packets. This
      protects smaller packets such as SYNs, ACKs, etc.
      
      The default bandwidth limit is set at 1Gbps but this can be changed by
      a user program through a shared BPF map. In addition, by default this BPF
      program does not limit connections using loopback. This behavior can be
      overwritten by the user program. There is also an option to calculate
      some statistics, such as percent of packets marked or dropped, which
      the user program can access.
      
      A latter patch provides such a program (hbm.c)
      Signed-off-by: NLawrence Brakmo <brakmo@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      187d0738
  27. 02 3月, 2019 1 次提交
    • Y
      samples/bpf: silence compiler warning for xdpsock_user.c · b74e21ab
      Yonghong Song 提交于
      Compiling xdpsock_user.c with 4.8.5, I hit the following
      compilation warning:
          HOSTCC  samples/bpf/xdpsock_user.o
        /data/users/yhs/work/net-next/samples/bpf/xdpsock_user.c: In function ‘main’:
        /data/users/yhs/work/net-next/samples/bpf/xdpsock_user.c:449:6: warning: ‘idx_cq’ may be used unini
        tialized in this function [-Wmaybe-uninitialized]
          u32 idx_cq, idx_fq;
              ^
        /data/users/yhs/work/net-next/samples/bpf/xdpsock_user.c:606:7: warning: ‘idx_rx’ may be used unini
        tialized in this function [-Wmaybe-uninitialized]
           u32 idx_rx, idx_tx = 0;
               ^
        /data/users/yhs/work/net-next/samples/bpf/xdpsock_user.c:506:6: warning: ‘idx_rx’ may be used unini
        tialized in this function [-Wmaybe-uninitialized]
          u32 idx_rx, idx_fq = 0;
      
      As an example, the code pattern looks like:
          u32 idx_cq;
          ...
          ret = xsk_ring_prod__reserve(&xsk->umem->fq, rcvd, &idx_fq);
          if (ret) {
            ...
          }
          ... idx_fq ...
      The compiler warns since it does not know whether &idx_fq is assigned
      or not inside the library function xsk_ring_prod__reserve().
      
      Let us assign an initial value 0 to such auto variables to silence
      compiler warning.
      
      Fixes: 248c7f9c ("samples/bpf: convert xdpsock to use libbpf for AF_XDP access")
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Acked-by: NJonathan Lemon <jonathan.lemon@gmail.com>
      Acked-by: NSong Liu <songliubraving@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      b74e21ab
  28. 01 3月, 2019 3 次提交
  29. 28 2月, 2019 1 次提交
  30. 26 2月, 2019 1 次提交