fujita / libbpf-async

BPF library for Async Rust, complementary for libbpf-rs.
BSD 2-Clause "Simplified" License
18 stars 5 forks source link

Bump libbpf-rs version. #13

Closed jsoo1 closed 7 months ago

jsoo1 commented 1 year ago

Well... this panics...

jsoo1 commented 1 year ago

... now it doesn't, but a lifetime annotation was required.

jsoo1 commented 1 year ago

What is ProfilerSkelBuilder? I can't seem to find the definition. profiler is failing here.

fujita commented 1 year ago

It's automatically generated.

jsoo1 commented 1 year ago

It's automatically generated.

I see. This error is what originally got me working on this. Somewhere libbpf_rs::map::Map should be replaced with libbpf_rs::Map

jsoo1 commented 1 year ago

The lifetime makes this very hard to work with. I think the association between the Map's and the Ringbuffer's lifetimes is a good change though. It might require a bit of an api change.

jsoo1 commented 1 year ago

Actually this internal reference to the map fd is very problematic: https://github.com/fujita/libbpf-async/blob/052f78c9e05ed6863534efe0508c98791573cc37/libbpf-async/src/ringbuf.rs#L60

Because the fd's lifetime is tied to the Map's (and subsequently the libbpf_rs::Object's lifetime). The new explicit borrow in libbpf_rs (as BorrowedFd) makes this explicit, which is good. But I am not sure how to even work with the libbpf_async::RingBuffer now, since the libbpf_rs::Object (nor any other libbpf_rs type) is not Send or Sync.

You can try to clone the fd using try_clone_to_owned on the borrowed fd but this panics.

jsoo1 commented 1 year ago

See this: https://github.com/libbpf/libbpf-rs/issues/245

jsoo1 commented 1 year ago

Well this still panics using MapHandle. I'm not sure what to do. The panic is on a memmap UnknownErrno

jsoo1 commented 1 year ago

Without the unsafe impl Send for RingBuffer {} even the simple example from the readme won't compile https://github.com/fujita/libbpf-async#example

jsoo1 commented 1 year ago

I still have a panic but i'm not sure what to do about it

fujita commented 1 year ago

Both examples work fine on my env with https://github.com/fujita/libbpf-async/commit/6a57dd65218501f07a39ab83e09c027070868390

jsoo1 commented 1 year ago
$ rustc --version 
rustc 1.69.0 (84c898d65 2023-04-16) (built from a source tarball)

$ cargo tree
trace-locks v0.1.0 (/home/john/projects/trace-locks)
├── anyhow v1.0.71
├── clap v4.3.11
│   ├── clap_builder v4.3.11
│   │   ├── anstream v0.3.2
│   │   │   ├── anstyle v1.0.1
│   │   │   ├── anstyle-parse v0.2.1
│   │   │   │   └── utf8parse v0.2.1
│   │   │   ├── anstyle-query v1.0.0
│   │   │   ├── colorchoice v1.0.0
│   │   │   ├── is-terminal v0.4.9
│   │   │   │   └── rustix v0.38.3
│   │   │   │       ├── bitflags v2.3.3
│   │   │   │       └── linux-raw-sys v0.4.3
│   │   │   └── utf8parse v0.2.1
│   │   ├── anstyle v1.0.1
│   │   ├── clap_lex v0.5.0
│   │   └── strsim v0.10.0
│   ├── clap_derive v4.3.2 (proc-macro)
│   │   ├── heck v0.4.1
│   │   ├── proc-macro2 v1.0.64
│   │   │   └── unicode-ident v1.0.10
│   │   ├── quote v1.0.29
│   │   │   └── proc-macro2 v1.0.64 (*)
│   │   └── syn v2.0.25
│   │       ├── proc-macro2 v1.0.64 (*)
│   │       ├── quote v1.0.29 (*)
│   │       └── unicode-ident v1.0.10
│   └── once_cell v1.18.0
├── env_logger v0.10.0
│   ├── humantime v2.1.0
│   ├── is-terminal v0.4.9 (*)
│   ├── log v0.4.19
│   ├── regex v1.9.1
│   │   ├── aho-corasick v1.0.2
│   │   │   └── memchr v2.5.0
│   │   ├── memchr v2.5.0
│   │   ├── regex-automata v0.3.2
│   │   │   ├── aho-corasick v1.0.2 (*)
│   │   │   ├── memchr v2.5.0
│   │   │   └── regex-syntax v0.7.3
│   │   └── regex-syntax v0.7.3
│   └── termcolor v1.2.0
├── libbpf-async v0.1.0 (/home/john/projects/libbpf-async/libbpf-async)
│   ├── futures v0.3.28
│   │   ├── futures-channel v0.3.28
│   │   │   ├── futures-core v0.3.28
│   │   │   └── futures-sink v0.3.28
│   │   ├── futures-core v0.3.28
│   │   ├── futures-executor v0.3.28
│   │   │   ├── futures-core v0.3.28
│   │   │   ├── futures-task v0.3.28
│   │   │   └── futures-util v0.3.28
│   │   │       ├── futures-channel v0.3.28 (*)
│   │   │       ├── futures-core v0.3.28
│   │   │       ├── futures-io v0.3.28
│   │   │       ├── futures-macro v0.3.28 (proc-macro)
│   │   │       │   ├── proc-macro2 v1.0.64 (*)
│   │   │       │   ├── quote v1.0.29 (*)
│   │   │       │   └── syn v2.0.25 (*)
│   │   │       ├── futures-sink v0.3.28
│   │   │       ├── futures-task v0.3.28
│   │   │       ├── memchr v2.5.0
│   │   │       ├── pin-project-lite v0.2.10
│   │   │       ├── pin-utils v0.1.0
│   │   │       └── slab v0.4.8
│   │   │           [build-dependencies]
│   │   │           └── autocfg v1.1.0
│   │   ├── futures-io v0.3.28
│   │   ├── futures-sink v0.3.28
│   │   ├── futures-task v0.3.28
│   │   └── futures-util v0.3.28 (*)
│   ├── libbpf-rs v0.21.1
│   │   ├── bitflags v1.3.2
│   │   ├── lazy_static v1.4.0
│   │   ├── libbpf-sys v1.2.1+v1.2.0
│   │   │   [build-dependencies]
│   │   │   ├── cc v1.0.79
│   │   │   ├── nix v0.26.2
│   │   │   │   ├── bitflags v1.3.2
│   │   │   │   ├── cfg-if v1.0.0
│   │   │   │   ├── libc v0.2.147
│   │   │   │   ├── memoffset v0.7.1
│   │   │   │   │   [build-dependencies]
│   │   │   │   │   └── autocfg v1.1.0
│   │   │   │   ├── pin-utils v0.1.0
│   │   │   │   └── static_assertions v1.1.0
│   │   │   ├── num_cpus v1.16.0
│   │   │   │   └── libc v0.2.147
│   │   │   └── pkg-config v0.3.27
│   │   ├── libc v0.2.147
│   │   ├── nix v0.26.2 (*)
│   │   ├── num_enum v0.5.11
│   │   │   └── num_enum_derive v0.5.11 (proc-macro)
│   │   │       ├── proc-macro-crate v1.3.1
│   │   │       │   ├── once_cell v1.18.0
│   │   │       │   └── toml_edit v0.19.12
│   │   │       │       ├── indexmap v2.0.0
│   │   │       │       │   ├── equivalent v1.0.0
│   │   │       │       │   └── hashbrown v0.14.0
│   │   │       │       ├── toml_datetime v0.6.3
│   │   │       │       └── winnow v0.4.9
│   │   │       ├── proc-macro2 v1.0.64 (*)
│   │   │       ├── quote v1.0.29 (*)
│   │   │       └── syn v1.0.109
│   │   │           ├── proc-macro2 v1.0.64 (*)
│   │   │           ├── quote v1.0.29 (*)
│   │   │           └── unicode-ident v1.0.10
│   │   ├── strum_macros v0.24.3 (proc-macro)
│   │   │   ├── heck v0.4.1
│   │   │   ├── proc-macro2 v1.0.64 (*)
│   │   │   ├── quote v1.0.29 (*)
│   │   │   ├── rustversion v1.0.13 (proc-macro)
│   │   │   └── syn v1.0.109 (*)
│   │   ├── thiserror v1.0.43
│   │   │   └── thiserror-impl v1.0.43 (proc-macro)
│   │   │       ├── proc-macro2 v1.0.64 (*)
│   │   │       ├── quote v1.0.29 (*)
│   │   │       └── syn v2.0.25 (*)
│   │   └── vsprintf v2.0.0
│   │       └── libc v0.2.147
│   │       [build-dependencies]
│   │       └── cc v1.0.79
│   ├── nix v0.26.2 (*)
│   ├── page_size v0.5.0
│   │   └── libc v0.2.147
│   └── tokio v1.29.1
│       ├── bytes v1.4.0
│       ├── libc v0.2.147
│       ├── mio v0.8.8
│       │   └── libc v0.2.147
│       ├── num_cpus v1.16.0 (*)
│       ├── parking_lot v0.12.1
│       │   ├── lock_api v0.4.10
│       │   │   └── scopeguard v1.1.0
│       │   │   [build-dependencies]
│       │   │   └── autocfg v1.1.0
│       │   └── parking_lot_core v0.9.8
│       │       ├── cfg-if v1.0.0
│       │       ├── libc v0.2.147
│       │       └── smallvec v1.11.0
│       ├── pin-project-lite v0.2.10
│       ├── signal-hook-registry v1.4.1
│       │   └── libc v0.2.147
│       ├── socket2 v0.4.9
│       │   └── libc v0.2.147
│       └── tokio-macros v2.1.0 (proc-macro)
│           ├── proc-macro2 v1.0.64 (*)
│           ├── quote v1.0.29 (*)
│           └── syn v2.0.25 (*)
│       [build-dependencies]
│       └── autocfg v1.1.0
├── libbpf-rs v0.21.1 (*)
├── libc v0.2.147
├── log v0.4.19
├── opentelemetry v0.19.0
│   ├── opentelemetry_api v0.19.0
│   │   ├── fnv v1.0.7
│   │   ├── futures-channel v0.3.28 (*)
│   │   ├── futures-util v0.3.28 (*)
│   │   ├── indexmap v1.9.3
│   │   │   └── hashbrown v0.12.3
│   │   │   [build-dependencies]
│   │   │   └── autocfg v1.1.0
│   │   ├── once_cell v1.18.0
│   │   ├── pin-project-lite v0.2.10
│   │   ├── thiserror v1.0.43 (*)
│   │   └── urlencoding v2.1.2
│   └── opentelemetry_sdk v0.19.0
│       ├── async-trait v0.1.71 (proc-macro)
│       │   ├── proc-macro2 v1.0.64 (*)
│       │   ├── quote v1.0.29 (*)
│       │   └── syn v2.0.25 (*)
│       ├── crossbeam-channel v0.5.8
│       │   ├── cfg-if v1.0.0
│       │   └── crossbeam-utils v0.8.16
│       │       └── cfg-if v1.0.0
│       ├── dashmap v5.4.0
│       │   ├── cfg-if v1.0.0
│       │   ├── hashbrown v0.12.3
│       │   ├── lock_api v0.4.10 (*)
│       │   ├── once_cell v1.18.0
│       │   └── parking_lot_core v0.9.8 (*)
│       ├── fnv v1.0.7
│       ├── futures-channel v0.3.28 (*)
│       ├── futures-executor v0.3.28 (*)
│       ├── futures-util v0.3.28 (*)
│       ├── once_cell v1.18.0
│       ├── opentelemetry_api v0.19.0 (*)
│       ├── percent-encoding v2.3.0
│       ├── rand v0.8.5
│       │   ├── libc v0.2.147
│       │   ├── rand_chacha v0.3.1
│       │   │   ├── ppv-lite86 v0.2.17
│       │   │   └── rand_core v0.6.4
│       │   │       └── getrandom v0.2.10
│       │   │           ├── cfg-if v1.0.0
│       │   │           └── libc v0.2.147
│       │   └── rand_core v0.6.4 (*)
│       ├── thiserror v1.0.43 (*)
│       ├── tokio v1.29.1 (*)
│       └── tokio-stream v0.1.14
│           ├── futures-core v0.3.28
│           ├── pin-project-lite v0.2.10
│           └── tokio v1.29.1 (*)
├── opentelemetry-otlp v0.12.0
│   ├── async-trait v0.1.71 (proc-macro) (*)
│   ├── futures v0.3.28 (*)
│   ├── futures-util v0.3.28 (*)
│   ├── http v0.2.9
│   │   ├── bytes v1.4.0
│   │   ├── fnv v1.0.7
│   │   └── itoa v1.0.8
│   ├── opentelemetry v0.19.0 (*)
│   ├── opentelemetry-proto v0.2.0
│   │   ├── futures v0.3.28 (*)
│   │   ├── futures-util v0.3.28 (*)
│   │   ├── opentelemetry v0.19.0 (*)
│   │   ├── prost v0.11.9
│   │   │   ├── bytes v1.4.0
│   │   │   └── prost-derive v0.11.9 (proc-macro)
│   │   │       ├── anyhow v1.0.71
│   │   │       ├── itertools v0.10.5
│   │   │       │   └── either v1.8.1
│   │   │       ├── proc-macro2 v1.0.64 (*)
│   │   │       ├── quote v1.0.29 (*)
│   │   │       └── syn v1.0.109 (*)
│   │   └── tonic v0.8.3
│   │       ├── async-stream v0.3.5
│   │       │   ├── async-stream-impl v0.3.5 (proc-macro)
│   │       │   │   ├── proc-macro2 v1.0.64 (*)
│   │       │   │   ├── quote v1.0.29 (*)
│   │       │   │   └── syn v2.0.25 (*)
│   │       │   ├── futures-core v0.3.28
│   │       │   └── pin-project-lite v0.2.10
│   │       ├── async-trait v0.1.71 (proc-macro) (*)
│   │       ├── axum v0.6.18
│   │       │   ├── async-trait v0.1.71 (proc-macro) (*)
│   │       │   ├── axum-core v0.3.4
│   │       │   │   ├── async-trait v0.1.71 (proc-macro) (*)
│   │       │   │   ├── bytes v1.4.0
│   │       │   │   ├── futures-util v0.3.28 (*)
│   │       │   │   ├── http v0.2.9 (*)
│   │       │   │   ├── http-body v0.4.5
│   │       │   │   │   ├── bytes v1.4.0
│   │       │   │   │   ├── http v0.2.9 (*)
│   │       │   │   │   └── pin-project-lite v0.2.10
│   │       │   │   ├── mime v0.3.17
│   │       │   │   ├── tower-layer v0.3.2
│   │       │   │   └── tower-service v0.3.2
│   │       │   │   [build-dependencies]
│   │       │   │   └── rustversion v1.0.13 (proc-macro)
│   │       │   ├── bitflags v1.3.2
│   │       │   ├── bytes v1.4.0
│   │       │   ├── futures-util v0.3.28 (*)
│   │       │   ├── http v0.2.9 (*)
│   │       │   ├── http-body v0.4.5 (*)
│   │       │   ├── hyper v0.14.27
│   │       │   │   ├── bytes v1.4.0
│   │       │   │   ├── futures-channel v0.3.28 (*)
│   │       │   │   ├── futures-core v0.3.28
│   │       │   │   ├── futures-util v0.3.28 (*)
│   │       │   │   ├── h2 v0.3.20
│   │       │   │   │   ├── bytes v1.4.0
│   │       │   │   │   ├── fnv v1.0.7
│   │       │   │   │   ├── futures-core v0.3.28
│   │       │   │   │   ├── futures-sink v0.3.28
│   │       │   │   │   ├── futures-util v0.3.28 (*)
│   │       │   │   │   ├── http v0.2.9 (*)
│   │       │   │   │   ├── indexmap v1.9.3 (*)
│   │       │   │   │   ├── slab v0.4.8 (*)
│   │       │   │   │   ├── tokio v1.29.1 (*)
│   │       │   │   │   ├── tokio-util v0.7.8
│   │       │   │   │   │   ├── bytes v1.4.0
│   │       │   │   │   │   ├── futures-core v0.3.28
│   │       │   │   │   │   ├── futures-sink v0.3.28
│   │       │   │   │   │   ├── pin-project-lite v0.2.10
│   │       │   │   │   │   ├── tokio v1.29.1 (*)
│   │       │   │   │   │   └── tracing v0.1.37
│   │       │   │   │   │       ├── cfg-if v1.0.0
│   │       │   │   │   │       ├── pin-project-lite v0.2.10
│   │       │   │   │   │       ├── tracing-attributes v0.1.26 (proc-macro)
│   │       │   │   │   │       │   ├── proc-macro2 v1.0.64 (*)
│   │       │   │   │   │       │   ├── quote v1.0.29 (*)
│   │       │   │   │   │       │   └── syn v2.0.25 (*)
│   │       │   │   │   │       └── tracing-core v0.1.31
│   │       │   │   │   │           └── once_cell v1.18.0
│   │       │   │   │   └── tracing v0.1.37 (*)
│   │       │   │   ├── http v0.2.9 (*)
│   │       │   │   ├── http-body v0.4.5 (*)
│   │       │   │   ├── httparse v1.8.0
│   │       │   │   ├── httpdate v1.0.2
│   │       │   │   ├── itoa v1.0.8
│   │       │   │   ├── pin-project-lite v0.2.10
│   │       │   │   ├── socket2 v0.4.9 (*)
│   │       │   │   ├── tokio v1.29.1 (*)
│   │       │   │   ├── tower-service v0.3.2
│   │       │   │   ├── tracing v0.1.37 (*)
│   │       │   │   └── want v0.3.1
│   │       │   │       └── try-lock v0.2.4
│   │       │   ├── itoa v1.0.8
│   │       │   ├── matchit v0.7.0
│   │       │   ├── memchr v2.5.0
│   │       │   ├── mime v0.3.17
│   │       │   ├── percent-encoding v2.3.0
│   │       │   ├── pin-project-lite v0.2.10
│   │       │   ├── serde v1.0.170
│   │       │   │   └── serde_derive v1.0.170 (proc-macro)
│   │       │   │       ├── proc-macro2 v1.0.64 (*)
│   │       │   │       ├── quote v1.0.29 (*)
│   │       │   │       └── syn v2.0.25 (*)
│   │       │   ├── sync_wrapper v0.1.2
│   │       │   ├── tower v0.4.13
│   │       │   │   ├── futures-core v0.3.28
│   │       │   │   ├── futures-util v0.3.28 (*)
│   │       │   │   ├── indexmap v1.9.3 (*)
│   │       │   │   ├── pin-project v1.1.2
│   │       │   │   │   └── pin-project-internal v1.1.2 (proc-macro)
│   │       │   │   │       ├── proc-macro2 v1.0.64 (*)
│   │       │   │   │       ├── quote v1.0.29 (*)
│   │       │   │   │       └── syn v2.0.25 (*)
│   │       │   │   ├── pin-project-lite v0.2.10
│   │       │   │   ├── rand v0.8.5 (*)
│   │       │   │   ├── slab v0.4.8 (*)
│   │       │   │   ├── tokio v1.29.1 (*)
│   │       │   │   ├── tokio-util v0.7.8 (*)
│   │       │   │   ├── tower-layer v0.3.2
│   │       │   │   ├── tower-service v0.3.2
│   │       │   │   └── tracing v0.1.37 (*)
│   │       │   ├── tower-layer v0.3.2
│   │       │   └── tower-service v0.3.2
│   │       │   [build-dependencies]
│   │       │   └── rustversion v1.0.13 (proc-macro)
│   │       ├── base64 v0.13.1
│   │       ├── bytes v1.4.0
│   │       ├── futures-core v0.3.28
│   │       ├── futures-util v0.3.28 (*)
│   │       ├── h2 v0.3.20 (*)
│   │       ├── http v0.2.9 (*)
│   │       ├── http-body v0.4.5 (*)
│   │       ├── hyper v0.14.27 (*)
│   │       ├── hyper-timeout v0.4.1
│   │       │   ├── hyper v0.14.27 (*)
│   │       │   ├── pin-project-lite v0.2.10
│   │       │   ├── tokio v1.29.1 (*)
│   │       │   └── tokio-io-timeout v1.2.0
│   │       │       ├── pin-project-lite v0.2.10
│   │       │       └── tokio v1.29.1 (*)
│   │       ├── percent-encoding v2.3.0
│   │       ├── pin-project v1.1.2 (*)
│   │       ├── prost v0.11.9 (*)
│   │       ├── prost-derive v0.11.9 (proc-macro) (*)
│   │       ├── tokio v1.29.1 (*)
│   │       ├── tokio-stream v0.1.14 (*)
│   │       ├── tokio-util v0.7.8 (*)
│   │       ├── tower v0.4.13 (*)
│   │       ├── tower-layer v0.3.2
│   │       ├── tower-service v0.3.2
│   │       ├── tracing v0.1.37 (*)
│   │       └── tracing-futures v0.2.5
│   │           ├── pin-project v1.1.2 (*)
│   │           └── tracing v0.1.37 (*)
│   ├── prost v0.11.9 (*)
│   ├── thiserror v1.0.43 (*)
│   ├── tokio v1.29.1 (*)
│   └── tonic v0.8.3 (*)
├── pod v0.5.0
│   ├── packed v0.4.2
│   ├── read_exact v0.0.1
│   └── uninitialized v0.0.2
├── serde v1.0.170 (*)
├── serde_json v1.0.100
│   ├── itoa v1.0.8
│   ├── ryu v1.0.14
│   └── serde v1.0.170 (*)
├── thiserror v1.0.43 (*)
├── tokio v1.29.1 (*)
└── url v2.4.0
    ├── form_urlencoded v1.2.0
    │   └── percent-encoding v2.3.0
    ├── idna v0.4.0
    │   ├── unicode-bidi v0.3.13
    │   └── unicode-normalization v0.1.22
    │       └── tinyvec v1.6.0
    │           └── tinyvec_macros v0.1.1
    └── percent-encoding v2.3.0
[build-dependencies]
└── bindgen v0.66.1
    ├── bitflags v2.3.3
    ├── cexpr v0.6.0
    │   └── nom v7.1.3
    │       ├── memchr v2.5.0
    │       └── minimal-lexical v0.2.1
    ├── clang-sys v1.6.1
    │   ├── glob v0.3.1
    │   ├── libc v0.2.147
    │   └── libloading v0.7.4
    │       └── cfg-if v1.0.0
    │   [build-dependencies]
    │   └── glob v0.3.1
    ├── lazy_static v1.4.0
    ├── lazycell v1.3.0
    ├── log v0.4.19
    ├── peeking_take_while v0.1.2
    ├── prettyplease v0.2.10
    │   ├── proc-macro2 v1.0.64 (*)
    │   └── syn v2.0.25 (*)
    ├── proc-macro2 v1.0.64 (*)
    ├── quote v1.0.29 (*)
    ├── regex v1.9.1
    │   ├── regex-automata v0.3.2
    │   │   └── regex-syntax v0.7.3
    │   └── regex-syntax v0.7.3
    ├── rustc-hash v1.1.0
    ├── shlex v1.1.0
    ├── syn v2.0.25 (*)
    └── which v4.4.0
        ├── either v1.8.1
        └── libc v0.2.147
jsoo1 commented 1 year ago

Here's the trouble I have: https://github.com/jsoo1/trace-locks/blob/bbe95b776daf896e616246eedf69cb60d8086207/src/bpf.rs#L63

jsoo1 commented 1 year ago

But otherwise the bump of libbpf-rs seems to have worked, if it works for you.

jsoo1 commented 1 year ago

Both examples work fine on my env with 6a57dd6

Hm. It could be me.

jsoo1 commented 1 year ago

Does it also work for bashreadline with multi-threaded runtime?

fujita commented 1 year ago

Does it also work for bashreadline with multi-threaded runtime?

bashreadline works with normal Tokio runtime so I think that we can say so. However, libbpf ring buffer isn't designed to be accessed by multiple threads in parallel.

jsoo1 commented 1 year ago

Does it also work for bashreadline with multi-threaded runtime?

bashreadline works with normal Tokio runtime so I think that we can say so. However, libbpf ring buffer isn't designed to be accessed by multiple threads in parallel.

I'm only trying to use it in one thread in a multi-threaded application. I think the problem with it is the NxM model where the execution can be scheduled on any number of underlying threads and might be moved

fujita commented 1 year ago

I guess that it's necessary to understand how a runtime handles threads to use bpf ring buffer. libbpf-async can't do anything about it because bpf ring buffer is designed in that way.