Skip to content

Conversation

@MinhPhan8803
Copy link
Member

@MinhPhan8803 MinhPhan8803 commented Apr 28, 2025

Because #6 is getting quite bloated.

Add support for PERF_EVENT_ARRAY. No test yet, ideally Harpoon port will test this new map type.

Remaining question: is it safe to stick a raw pointer into a program type and just implement Sync for that program?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should include the uprobe support in this PR since it is not about uprobe. Moreover, the change on the compiler is not included here so it cannot be used anyway.

impl rex_prog for tracepoint {
fn prog_run(&self, ctx: *mut ()) -> u32 {
fn prog_run(&mut self, ctx: *mut ()) -> u32 {
self.ctx_ptr = ctx as *const ();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah apparently this is one thing I missed in our previous discussions --- writing to the program object is not safe since it lives in the global data section, and we cannot synchronize this across multiple instances of the program running on different CPUs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. It looks like we need the enum then.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually is there another way to load the context pointer into the program object, say at compile time?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are referring to the address of the context, it is only available at runtime.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the reason we cannot associate the ctx type with the program is because __rex_entry_tracepoint is an extern "C" function. Maybe we can completely bypass this layer of indirection by generating all the needed code in rex-macros?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would the case where the user has multiple tracepoint programs to different hooks work then? Because then we will need to associate multiple context types with the tracepoint program type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are going generate individual entry functions for each of the tp programs. The good thing is that each tp program can only associate with one hookpoint (forget about programs without hookpoints for now)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of messing with the macro and while avoiding duplicating code in an Enum, I think we can add a trait:

trait TracepointContext

and a newtype:

struct TpCtxWrapper<C: TracepointContext> {
      ref: &'static C
}

and then associate this newtype with the tracepoint program.

Would this be better?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But can this workaround the problem of extern "C" __rex_entry_tracepoint? That function cannot be generic.

@MinhPhan8803 MinhPhan8803 force-pushed the perf_array_map_impl branch 3 times, most recently from 645680b to ebbd5d1 Compare April 28, 2025 23:19
@MinhPhan8803 MinhPhan8803 force-pushed the perf_array_map_impl branch 2 times, most recently from d8ad0b0 to f0e4c33 Compare May 9, 2025 03:08
rex/src/utils.rs Outdated
/// Programs that can stream data through a
/// RexPerfEventArray will implement this trait
pub trait PerfEventStreamer {
type Context: ?Sized;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: do we have any cases where the context is not Sized?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, I'm just putting it there just in case. We can remove the bound for now.

@MinhPhan8803 MinhPhan8803 force-pushed the perf_array_map_impl branch from f0e4c33 to 8bcc72b Compare May 9, 2025 19:15
@MinhPhan8803 MinhPhan8803 force-pushed the perf_array_map_impl branch from 8bcc72b to 80a2b48 Compare May 9, 2025 19:17
@jinghao-jia jinghao-jia enabled auto-merge May 9, 2025 20:03
@jinghao-jia jinghao-jia merged commit 9468272 into main May 9, 2025
10 checks passed
@jinghao-jia jinghao-jia deleted the perf_array_map_impl branch May 9, 2025 20:03
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.

3 participants