Skip to content

Commit fea80ba

Browse files
committed
Stash the active backend in quark_queue_stats{}
The whole idea of "the user should not even know which backend is being used", worked a bit too much. This was prompted by a bug in beats where seccomp was blocking a syscall needed for EBPF, and so it fell back to kprobe all the time and the user had no proper way to notice this. Related to elastic/beats#41297 Purposedly stashed this into stats to make it hard to retrieve from quark.c, if we start doing `if (qq->backend == QQ_EBPF)` we lost the war.
1 parent b6beeea commit fea80ba

File tree

9 files changed

+45
-7
lines changed

9 files changed

+45
-7
lines changed

CHANGES

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Quark Breaking Changes
2+
~~~~~~~~~~~~~~~~~~~~~~
3+
This file documents breaking and/or other changes that might require
4+
user interaction. Examples include: a user facing structure change; a
5+
new library call; a change in behaviour.
6+
7+
Changes from 0.1 to 0.2
8+
~~~~~~~~~~~~~~~~~~~~~~~
9+
o quark_queue_stats{} got a "backend" member.

bpf_queue.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ bpf_queue_open(struct quark_queue *qq)
292292
goto fail;
293293

294294
qq->queue_ops = &queue_ops_bpf;
295+
qq->stats.backend = QQ_EBPF;
295296

296297
return (0);
297298
fail:

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ <h1 class="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1
387387
</div>
388388
<table class="foot">
389389
<tr>
390-
<td class="foot-date">October 15, 2024</td>
390+
<td class="foot-date">October 18, 2024</td>
391391
<td class="foot-os">Linux</td>
392392
</tr>
393393
</table>

docs/quark.7.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ <h1 class="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1
387387
</div>
388388
<table class="foot">
389389
<tr>
390-
<td class="foot-date">October 15, 2024</td>
390+
<td class="foot-date">October 18, 2024</td>
391391
<td class="foot-os">Linux</td>
392392
</tr>
393393
</table>

docs/quark_queue_get_stats.3.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ <h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIP
4141
u64 aggregations;
4242
u64 non_aggregations;
4343
u64 lost;
44+
int backend;
4445
};</pre>
4546
</div>
4647
<dl class="Bl-tag">
@@ -67,6 +68,9 @@ <h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIP
6768
simply can't handle the load, the former is way more likely. It is a state
6869
counter representing total loss, the user should compare to an old reading
6970
to know if it increased.</dd>
71+
<dt id="backend"><a class="permalink" href="#backend"><i class="Em">backend</i></a></dt>
72+
<dd>Active queue backend, either <code class="Dv">QQ_EBPF</code> or
73+
<code class="Dv">QQ_KPROBE</code>.</dd>
7074
</dl>
7175
<section class="Sh">
7276
<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
@@ -85,7 +89,7 @@ <h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
8589
</div>
8690
<table class="foot">
8791
<tr>
88-
<td class="foot-date">September 19, 2024</td>
92+
<td class="foot-date">October 18, 2024</td>
8993
<td class="foot-os">Linux</td>
9094
</tr>
9195
</table>

kprobe_queue.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,7 @@ kprobe_queue_open(struct quark_queue *qq)
12681268
}
12691269

12701270
qq->queue_ops = &queue_ops_kprobe;
1271+
qq->stats.backend = QQ_KPROBE;
12711272

12721273
return (0);
12731274

quark-mon.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
static int gotsigint;
1818

1919
static void
20-
quark_queue_dump_stats(struct quark_queue *qq)
20+
dump_stats(struct quark_queue *qq)
2121
{
22-
struct quark_queue_stats s;
22+
struct quark_queue_stats s;
2323

2424
quark_queue_get_stats(qq, &s);
2525
printf("%8llu insertions %8llu removals %8llu aggregations "
@@ -28,6 +28,18 @@ quark_queue_dump_stats(struct quark_queue *qq)
2828
s.non_aggregations, s.lost);
2929
}
3030

31+
static const char *
32+
fetch_backend(struct quark_queue *qq)
33+
{
34+
struct quark_queue_stats s;
35+
36+
quark_queue_get_stats(qq, &s);
37+
38+
return (s.backend == QQ_EBPF ? "ebpf" :
39+
s.backend == QQ_KPROBE ? "kprobe" :
40+
"invalid");
41+
}
42+
3143
static void
3244
sigint_handler(int sig)
3345
{
@@ -179,6 +191,9 @@ main(int argc, char *argv[])
179191
if ((qevs = calloc(nqevs, sizeof(*qevs))) == NULL)
180192
err(1, "calloc");
181193

194+
if (quark_verbose)
195+
printf("using %s for backend\n", fetch_backend(qq));
196+
182197
/* From now on we will be nobody */
183198
if (do_priv_drop)
184199
priv_drop();
@@ -204,7 +219,8 @@ main(int argc, char *argv[])
204219
quark_event_dump(qev, stdout);
205220
/* No events, just block */
206221
if (n == 0) {
207-
quark_queue_block(qq);
222+
if (quark_queue_block(qq) == -1 && errno != EINTR)
223+
err(1, "quark_queue_block");
208224
continue;
209225
}
210226
}
@@ -225,7 +241,7 @@ main(int argc, char *argv[])
225241
}
226242

227243
free(qevs);
228-
quark_queue_dump_stats(qq);
244+
dump_stats(qq);
229245
quark_queue_close(qq);
230246
free(qq);
231247

quark.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ struct quark_queue_stats {
335335
u64 aggregations;
336336
u64 non_aggregations;
337337
u64 lost;
338+
int backend; /* active backend, QQ_EBPF or QQ_KPROBE */
338339
/* TODO u64 peak_nodes; */
339340
};
340341

quark_queue_get_stats.3

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct quark_queue_stats {
2323
u64 aggregations;
2424
u64 non_aggregations;
2525
u64 lost;
26+
int backend;
2627
};
2728
.Ed
2829
.Bl -tag -width "non_aggregations"
@@ -50,6 +51,11 @@ fast enough or if
5051
simply can't handle the load, the former is way more likely.
5152
It is a state counter representing total loss, the user should compare to an old
5253
reading to know if it increased.
54+
.It Em backend
55+
Active queue backend, either
56+
.Dv QQ_EBPF
57+
or
58+
.Dv QQ_KPROBE .
5359
.El
5460
.Sh SEE ALSO
5561
.Xr quark_event_dump 3 ,

0 commit comments

Comments
 (0)