Skip to content

Commit

Permalink
rusty: Remove explicit padding
Browse files Browse the repository at this point in the history
As of libbpf-rs 0.23.0 (which contains commit
libbpf/libbpf-rs@9d9e979),
libbpf-rs now generates rust structs that honor padding. We can
therefore remove the custom padding in scx_rusty's struct pcpu_ctx.

For example, here is the generated pub struct pcpu_ctx:

pub struct pcpu_ctx {
    pub dom_rr_cur: u32,
    pub dom_id: u32,
    pub nr_node_doms: u32,
    pub node_doms: [u32; 64],
    pub __pad_268: [u8; 52],
}

And here is the matching struct in the BPF object file:

struct pcpu_ctx {
        u32                        dom_rr_cur;           /*     0     4 */
        u32                        dom_id;               /*     4     4 */
        u32                        nr_node_doms;         /*     8     4 */
        u32                        node_doms[64];        /*    12   256 */

        /* size: 320, cachelines: 5, members: 4 */
        /* padding: 52 */
} __attribute__((__aligned__(64)));

Signed-off-by: David Vernet <void@manifault.com>
  • Loading branch information
Byte-Lab committed Apr 12, 2024
1 parent 5404303 commit ffced1f
Showing 1 changed file with 0 additions and 3 deletions.
3 changes: 0 additions & 3 deletions scheds/rust/scx_rusty/src/bpf/main.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ struct pcpu_ctx {
u32 dom_id;
u32 nr_node_doms;
u32 node_doms[MAX_DOMS];

/* libbpf-rs does not respect the alignment, so pad out the struct explicitly */
u8 _padding[CACHELINE_SIZE - ((3 + MAX_DOMS) * sizeof(u32) % CACHELINE_SIZE)];
} __attribute__((aligned(CACHELINE_SIZE)));

struct pcpu_ctx pcpu_ctx[MAX_CPUS];
Expand Down

0 comments on commit ffced1f

Please sign in to comment.