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 ebpf lost event counter. Issue #38 #48

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions bpf_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@
#include "elastic-ebpf/GPL/Events/EbpfEventProto.h"

struct bpf_queue {
struct bpf_prog *prog;
struct ring_buffer *ringbuf;
struct bpf_prog *prog;
struct ring_buffer *ringbuf;
};

static int bpf_queue_populate(struct quark_queue *);
static int bpf_queue_update_stats(struct quark_queue *);
static void bpf_queue_close(struct quark_queue *);

struct quark_queue_ops queue_ops_bpf = {
.open = bpf_queue_open,
.populate = bpf_queue_populate,
.close = bpf_queue_close,
.open = bpf_queue_open,
.populate = bpf_queue_populate,
.update_stats = bpf_queue_update_stats,
.close = bpf_queue_close,
};

static int
Expand Down Expand Up @@ -262,7 +264,6 @@ bpf_queue_populate(struct quark_queue *qq)
struct bpf_queue *bqq = qq->queue_be;
int npop, space_left;

npop = 0;
space_left = qq->length >= qq->max_length ?
0 : qq->max_length - qq->length;
if (space_left == 0)
Expand All @@ -273,6 +274,24 @@ bpf_queue_populate(struct quark_queue *qq)
return (npop < 0 ? -1 : npop);
}

static int
bpf_queue_update_stats(struct quark_queue *qq)
{
struct bpf_queue *bqq = qq->queue_be;
struct ebpf_event_stats pcpu_ees[libbpf_num_possible_cpus()];
u32 zero = 0;
int i;

if (bpf_map__lookup_elem(bqq->prog->maps.ringbuf_stats, &zero,
sizeof(zero), pcpu_ees, sizeof(pcpu_ees), 0) != 0)
return (-1);

for (i = 0; i < libbpf_num_possible_cpus(); i++)
qq->stats.lost = pcpu_ees[i].lost;
Copy link
Contributor

Choose a reason for hiding this comment

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

don't care about the sent?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

At the moment no, I don't have the statistics for sent yet, I just wanted to get it on the same stage as the kprobes for now.


return (0);
}

static void
bpf_queue_close(struct quark_queue *qq)
{
Expand Down
15 changes: 12 additions & 3 deletions kprobe_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,14 @@ struct kprobe_queue {
};

static int kprobe_queue_populate(struct quark_queue *);
static int kprobe_queue_update_stats(struct quark_queue *);
static void kprobe_queue_close(struct quark_queue *);

struct quark_queue_ops queue_ops_kprobe = {
.open = kprobe_queue_open,
.populate = kprobe_queue_populate,
.close = kprobe_queue_close,
.open = kprobe_queue_open,
.populate = kprobe_queue_populate,
.update_stats = kprobe_queue_update_stats,
.close = kprobe_queue_close,
};

static char *
Expand Down Expand Up @@ -1298,6 +1300,13 @@ kprobe_queue_populate(struct quark_queue *qq)
return (npop);
}

static int
kprobe_queue_update_stats(struct quark_queue *qq)
{
/* NADA */
return (0);
}

static void
kprobe_queue_close(struct quark_queue *qq)
{
Expand Down
1 change: 1 addition & 0 deletions quark.c
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,7 @@ quark_queue_get_epollfd(struct quark_queue *qq)
void
quark_queue_get_stats(struct quark_queue *qq, struct quark_queue_stats *qs)
{
qq->queue_ops->update_stats(qq);
*qs = qq->stats;
}

Expand Down
1 change: 1 addition & 0 deletions quark.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ struct quark_queue_stats {
struct quark_queue_ops {
int (*open)(struct quark_queue *);
int (*populate)(struct quark_queue *);
int (*update_stats)(struct quark_queue *);
void (*close)(struct quark_queue *);
};

Expand Down