Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add btf support for maps #2192

Merged
merged 1 commit into from
Feb 11, 2019
Merged

add btf support for maps #2192

merged 1 commit into from
Feb 11, 2019

Conversation

yonghong-song
Copy link
Collaborator

Added bpf support for maps so map key/value types can be
retrieved by user space introspection tool to pretty
print map key/values.

To associate maps with its key/value types, the below macro

  BPF_ANNOTATE_KV_PAIR(name, type_key, type_val)

is used, similar to usage in kernel tools/testing/selftests/bpf
and tools/lib/bpf. Currently, some map types (e.g, PERF_EVENT_ARRAY)
do not support pretty print. But common [per_cpu] hash/array maps
are supported.

Currently, bcc create maps before llvm compilation.
To support pretty printing of maps, map creation
needs have key/value type id's which can only be
obtained after compilation. Therefore, during rewriting,
fake map fd is used. After compilation, btf is first
loaded and maps are created.

With latest bpf-next and latest trunk llvm,
bpftool is able to pretty print bcc tool map key/values
as below:

  ; running tcptop.py in one window
  $ tcptop.py
  ; running bpftool in another window
  $ bpftool m s
  ...
  343: hash  name ipv4_send_bytes  flags 0x0
          key 16B  value 8B  max_entries 10240  memlock 1003520B
  344: hash  name ipv4_recv_bytes  flags 0x0
          key 16B  value 8B  max_entries 10240  memlock 1003520B
  345: hash  name ipv6_send_bytes  flags 0x0
          key 64B  value 8B  max_entries 10240  memlock 1495040B
  346: hash  name ipv6_recv_bytes  flags 0x0
          key 64B  value 8B  max_entries 10240  memlock 1495040B
  $ bpftool m d id 345
  ...
    },{
        "key": {
            "pid": 5511,
            "saddr": 0x100007fffff00000000000000000000,
            "daddr": 0x100007fffff00000000000000000000,
            "lport": 2378,
            "dport": 52602
        },
        "value": 49
    },{
        "key": {
            "pid": 2823,
            "saddr": 0x4e000000cefa7bb0300000db0124,
            "daddr": 0x60000000cefa7bb0300000db0124,
            "lport": 2406,
            "dport": 49348
        },
        "value": 36
    }
   ...

Signed-off-by: Yonghong Song yhs@fb.com

@yonghong-song
Copy link
Collaborator Author

The tests involving "b" frontends failed. Will add proper support in this round.

Added bpf support for maps so map key/value types can be
retrieved by user space introspection tool to pretty
print map key/values.

To associate maps with its key/value types, the below macro
  BPF_ANNOTATE_KV_PAIR(name, type_key, type_val)
is used, similar to usage in kernel tools/testing/selftests/bpf
and tools/lib/bpf. Currently, some map types (e.g, PERF_EVENT_ARRAY)
do not support pretty print. But common [per_cpu] hash/array maps
are supported.

Currently, bcc create maps before llvm compilation.
To support pretty printing of maps, map creation
needs have key/value type id's which can only be
obtained after compilation. Therefore, during rewriting,
fake map fd is used. After compilation, btf is first
loaded and maps are created.

With latest bpf-next and latest trunk llvm,
bpftool is able to pretty print bcc tool map key/values
as below:
  ; running tcptop.py in one window
  $ tcptop.py
  ; running bpftool in another window
  $ bpftool m s
  ...
  343: hash  name ipv4_send_bytes  flags 0x0
          key 16B  value 8B  max_entries 10240  memlock 1003520B
  344: hash  name ipv4_recv_bytes  flags 0x0
          key 16B  value 8B  max_entries 10240  memlock 1003520B
  345: hash  name ipv6_send_bytes  flags 0x0
          key 64B  value 8B  max_entries 10240  memlock 1495040B
  346: hash  name ipv6_recv_bytes  flags 0x0
          key 64B  value 8B  max_entries 10240  memlock 1495040B
  $ bpftool m d id 345
  ...
    },{
        "key": {
            "pid": 5511,
            "saddr": 0x100007fffff00000000000000000000,
            "daddr": 0x100007fffff00000000000000000000,
            "lport": 2378,
            "dport": 52602
        },
        "value": 49
    },{
        "key": {
            "pid": 2823,
            "saddr": 0x4e000000cefa7bb0300000db0124,
            "daddr": 0x60000000cefa7bb0300000db0124,
            "lport": 2406,
            "dport": 49348
        },
        "value": 36
    }
   ...

Signed-off-by: Yonghong Song <yhs@fb.com>
@yonghong-song yonghong-song merged commit 8300c7b into master Feb 11, 2019
palexster pushed a commit to palexster/bcc that referenced this pull request Jul 7, 2019
Added bpf support for maps so map key/value types can be
retrieved by user space introspection tool to pretty
print map key/values.

To associate maps with its key/value types, the below macro
  BPF_ANNOTATE_KV_PAIR(name, type_key, type_val)
is used, similar to usage in kernel tools/testing/selftests/bpf
and tools/lib/bpf. Currently, some map types (e.g, PERF_EVENT_ARRAY)
do not support pretty print. But common [per_cpu] hash/array maps
are supported.

Currently, bcc create maps before llvm compilation.
To support pretty printing of maps, map creation
needs have key/value type id's which can only be
obtained after compilation. Therefore, during rewriting,
fake map fd is used. After compilation, btf is first
loaded and maps are created.

With latest bpf-next and latest trunk llvm,
bpftool is able to pretty print bcc tool map key/values
as below:
  ; running tcptop.py in one window
  $ tcptop.py
  ; running bpftool in another window
  $ bpftool m s
  ...
  343: hash  name ipv4_send_bytes  flags 0x0
          key 16B  value 8B  max_entries 10240  memlock 1003520B
  344: hash  name ipv4_recv_bytes  flags 0x0
          key 16B  value 8B  max_entries 10240  memlock 1003520B
  345: hash  name ipv6_send_bytes  flags 0x0
          key 64B  value 8B  max_entries 10240  memlock 1495040B
  346: hash  name ipv6_recv_bytes  flags 0x0
          key 64B  value 8B  max_entries 10240  memlock 1495040B
  $ bpftool m d id 345
  ...
    },{
        "key": {
            "pid": 5511,
            "saddr": 0x100007fffff00000000000000000000,
            "daddr": 0x100007fffff00000000000000000000,
            "lport": 2378,
            "dport": 52602
        },
        "value": 49
    },{
        "key": {
            "pid": 2823,
            "saddr": 0x4e000000cefa7bb0300000db0124,
            "daddr": 0x60000000cefa7bb0300000db0124,
            "lport": 2406,
            "dport": 49348
        },
        "value": 36
    }
   ...

Signed-off-by: Yonghong Song <yhs@fb.com>
CrackerCat pushed a commit to CrackerCat/bcc that referenced this pull request Jul 31, 2024
Added bpf support for maps so map key/value types can be
retrieved by user space introspection tool to pretty
print map key/values.

To associate maps with its key/value types, the below macro
  BPF_ANNOTATE_KV_PAIR(name, type_key, type_val)
is used, similar to usage in kernel tools/testing/selftests/bpf
and tools/lib/bpf. Currently, some map types (e.g, PERF_EVENT_ARRAY)
do not support pretty print. But common [per_cpu] hash/array maps
are supported.

Currently, bcc create maps before llvm compilation.
To support pretty printing of maps, map creation
needs have key/value type id's which can only be
obtained after compilation. Therefore, during rewriting,
fake map fd is used. After compilation, btf is first
loaded and maps are created.

With latest bpf-next and latest trunk llvm,
bpftool is able to pretty print bcc tool map key/values
as below:
  ; running tcptop.py in one window
  $ tcptop.py
  ; running bpftool in another window
  $ bpftool m s
  ...
  343: hash  name ipv4_send_bytes  flags 0x0
          key 16B  value 8B  max_entries 10240  memlock 1003520B
  344: hash  name ipv4_recv_bytes  flags 0x0
          key 16B  value 8B  max_entries 10240  memlock 1003520B
  345: hash  name ipv6_send_bytes  flags 0x0
          key 64B  value 8B  max_entries 10240  memlock 1495040B
  346: hash  name ipv6_recv_bytes  flags 0x0
          key 64B  value 8B  max_entries 10240  memlock 1495040B
  $ bpftool m d id 345
  ...
    },{
        "key": {
            "pid": 5511,
            "saddr": 0x100007fffff00000000000000000000,
            "daddr": 0x100007fffff00000000000000000000,
            "lport": 2378,
            "dport": 52602
        },
        "value": 49
    },{
        "key": {
            "pid": 2823,
            "saddr": 0x4e000000cefa7bb0300000db0124,
            "daddr": 0x60000000cefa7bb0300000db0124,
            "lport": 2406,
            "dport": 49348
        },
        "value": 36
    }
   ...

Signed-off-by: Yonghong Song <yhs@fb.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants