mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 01:55:51 +02:00
net/sched: netem: add per-impairment extended statistics
Add 64-bit counters for each impairment netem applies (delay, loss, ECN marking, corruption, duplication, reordering) and for skb allocation failures during enqueue. Exposed through TCA_STATS_APP as struct tc_netem_xstats. Counters increment when an impairment is occurs, independent of later events that may mask its on-wire effect. Added allocation_errors (similar to sch_fq) to account for when impairment could not be applied due to memory pressure, etc. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Link: https://patch.msgid.link/20260509171123.307549-6-stephen@networkplumber.org Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
parent
e8be7cdedc
commit
a2f6ed7b48
|
|
@ -569,6 +569,16 @@ struct tc_netem_gemodel {
|
||||||
#define NETEM_DIST_SCALE 8192
|
#define NETEM_DIST_SCALE 8192
|
||||||
#define NETEM_DIST_MAX 16384
|
#define NETEM_DIST_MAX 16384
|
||||||
|
|
||||||
|
struct tc_netem_xstats {
|
||||||
|
__u64 delayed; /* packets delayed */
|
||||||
|
__u64 dropped; /* packets dropped by loss model */
|
||||||
|
__u64 corrupted; /* packets with bit errors injected */
|
||||||
|
__u64 duplicated; /* duplicate packets generated */
|
||||||
|
__u64 reordered; /* packets sent out of order */
|
||||||
|
__u64 ecn_marked; /* packets ECN CE-marked (not dropped)*/
|
||||||
|
__u64 allocation_errors;
|
||||||
|
};
|
||||||
|
|
||||||
/* DRR */
|
/* DRR */
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
|
|
||||||
|
|
@ -152,6 +152,15 @@ struct netem_sched_data {
|
||||||
u8 state;
|
u8 state;
|
||||||
} clg;
|
} clg;
|
||||||
|
|
||||||
|
/* Impairment counters */
|
||||||
|
u64 delayed;
|
||||||
|
u64 dropped;
|
||||||
|
u64 corrupted;
|
||||||
|
u64 duplicated;
|
||||||
|
u64 ecn_marked;
|
||||||
|
u64 reordered;
|
||||||
|
u64 allocation_errors;
|
||||||
|
|
||||||
/* Cold tail: slot reschedule config and the watchdog timer. */
|
/* Cold tail: slot reschedule config and the watchdog timer. */
|
||||||
struct tc_netem_slot slot_config;
|
struct tc_netem_slot slot_config;
|
||||||
struct qdisc_watchdog watchdog;
|
struct qdisc_watchdog watchdog;
|
||||||
|
|
@ -462,16 +471,21 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,
|
||||||
skb->prev = NULL;
|
skb->prev = NULL;
|
||||||
|
|
||||||
/* Random duplication */
|
/* Random duplication */
|
||||||
if (q->duplicate && q->duplicate >= get_crandom(&q->dup_cor, &q->prng))
|
if (q->duplicate && q->duplicate >= get_crandom(&q->dup_cor, &q->prng)) {
|
||||||
++count;
|
++count;
|
||||||
|
WRITE_ONCE(q->duplicated, q->duplicated + 1);
|
||||||
|
}
|
||||||
|
|
||||||
/* Drop packet? */
|
/* Drop packet? */
|
||||||
if (loss_event(q)) {
|
if (loss_event(q)) {
|
||||||
if (q->ecn && INET_ECN_set_ce(skb))
|
if (q->ecn && INET_ECN_set_ce(skb)) {
|
||||||
qdisc_qstats_drop(sch); /* mark packet */
|
WRITE_ONCE(q->ecn_marked, q->ecn_marked + 1);
|
||||||
else
|
} else {
|
||||||
|
WRITE_ONCE(q->dropped, q->dropped + 1);
|
||||||
--count;
|
--count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
qdisc_qstats_drop(sch);
|
qdisc_qstats_drop(sch);
|
||||||
__qdisc_drop(skb, to_free);
|
__qdisc_drop(skb, to_free);
|
||||||
|
|
@ -488,8 +502,11 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,
|
||||||
* If we need to duplicate packet, then clone it before
|
* If we need to duplicate packet, then clone it before
|
||||||
* original is modified.
|
* original is modified.
|
||||||
*/
|
*/
|
||||||
if (count > 1)
|
if (count > 1) {
|
||||||
skb2 = skb_clone(skb, GFP_ATOMIC);
|
skb2 = skb_clone(skb, GFP_ATOMIC);
|
||||||
|
if (!skb2)
|
||||||
|
WRITE_ONCE(q->allocation_errors, q->allocation_errors + 1);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Randomized packet corruption.
|
* Randomized packet corruption.
|
||||||
|
|
@ -500,8 +517,10 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,
|
||||||
if (q->corrupt && q->corrupt >= get_crandom(&q->corrupt_cor, &q->prng)) {
|
if (q->corrupt && q->corrupt >= get_crandom(&q->corrupt_cor, &q->prng)) {
|
||||||
if (skb_is_gso(skb)) {
|
if (skb_is_gso(skb)) {
|
||||||
skb = netem_segment(skb, sch, to_free);
|
skb = netem_segment(skb, sch, to_free);
|
||||||
if (!skb)
|
if (!skb) {
|
||||||
|
WRITE_ONCE(q->allocation_errors, q->allocation_errors + 1);
|
||||||
goto finish_segs;
|
goto finish_segs;
|
||||||
|
}
|
||||||
|
|
||||||
segs = skb->next;
|
segs = skb->next;
|
||||||
skb_mark_not_on_list(skb);
|
skb_mark_not_on_list(skb);
|
||||||
|
|
@ -510,11 +529,13 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,
|
||||||
|
|
||||||
skb = skb_unshare(skb, GFP_ATOMIC);
|
skb = skb_unshare(skb, GFP_ATOMIC);
|
||||||
if (unlikely(!skb)) {
|
if (unlikely(!skb)) {
|
||||||
|
WRITE_ONCE(q->allocation_errors, q->allocation_errors + 1);
|
||||||
qdisc_qstats_drop(sch);
|
qdisc_qstats_drop(sch);
|
||||||
goto finish_segs;
|
goto finish_segs;
|
||||||
}
|
}
|
||||||
if (skb_linearize(skb) ||
|
if (skb_linearize(skb) ||
|
||||||
(skb->ip_summed == CHECKSUM_PARTIAL && skb_checksum_help(skb))) {
|
(skb->ip_summed == CHECKSUM_PARTIAL && skb_checksum_help(skb))) {
|
||||||
|
WRITE_ONCE(q->allocation_errors, q->allocation_errors + 1);
|
||||||
qdisc_drop(skb, sch, to_free);
|
qdisc_drop(skb, sch, to_free);
|
||||||
skb = NULL;
|
skb = NULL;
|
||||||
goto finish_segs;
|
goto finish_segs;
|
||||||
|
|
@ -523,6 +544,7 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,
|
||||||
if (skb->len) {
|
if (skb->len) {
|
||||||
u32 offset = get_random_u32_below(skb->len);
|
u32 offset = get_random_u32_below(skb->len);
|
||||||
skb->data[offset] ^= 1 << get_random_u32_below(8);
|
skb->data[offset] ^= 1 << get_random_u32_below(8);
|
||||||
|
WRITE_ONCE(q->corrupted, q->corrupted + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -604,12 +626,16 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,
|
||||||
|
|
||||||
cb->time_to_send = now + delay;
|
cb->time_to_send = now + delay;
|
||||||
++q->counter;
|
++q->counter;
|
||||||
|
if (delay)
|
||||||
|
WRITE_ONCE(q->delayed, q->delayed + 1);
|
||||||
|
|
||||||
tfifo_enqueue(skb, sch);
|
tfifo_enqueue(skb, sch);
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* Do re-ordering by putting one out of N packets at the front
|
* Do re-ordering by putting one out of N packets at the front
|
||||||
* of the queue.
|
* of the queue.
|
||||||
*/
|
*/
|
||||||
|
WRITE_ONCE(q->reordered, q->reordered + 1);
|
||||||
cb->time_to_send = ktime_get_ns();
|
cb->time_to_send = ktime_get_ns();
|
||||||
q->counter = 0;
|
q->counter = 0;
|
||||||
|
|
||||||
|
|
@ -1348,6 +1374,22 @@ static int netem_dump(struct Qdisc *sch, struct sk_buff *skb)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int netem_dump_stats(struct Qdisc *sch, struct gnet_dump *d)
|
||||||
|
{
|
||||||
|
struct netem_sched_data *q = qdisc_priv(sch);
|
||||||
|
struct tc_netem_xstats st = {
|
||||||
|
.delayed = READ_ONCE(q->delayed),
|
||||||
|
.dropped = READ_ONCE(q->dropped),
|
||||||
|
.corrupted = READ_ONCE(q->corrupted),
|
||||||
|
.duplicated = READ_ONCE(q->duplicated),
|
||||||
|
.reordered = READ_ONCE(q->reordered),
|
||||||
|
.ecn_marked = READ_ONCE(q->ecn_marked),
|
||||||
|
.allocation_errors = READ_ONCE(q->allocation_errors),
|
||||||
|
};
|
||||||
|
|
||||||
|
return gnet_stats_copy_app(d, &st, sizeof(st));
|
||||||
|
}
|
||||||
|
|
||||||
static int netem_dump_class(struct Qdisc *sch, unsigned long cl,
|
static int netem_dump_class(struct Qdisc *sch, unsigned long cl,
|
||||||
struct sk_buff *skb, struct tcmsg *tcm)
|
struct sk_buff *skb, struct tcmsg *tcm)
|
||||||
{
|
{
|
||||||
|
|
@ -1410,6 +1452,7 @@ static struct Qdisc_ops netem_qdisc_ops __read_mostly = {
|
||||||
.destroy = netem_destroy,
|
.destroy = netem_destroy,
|
||||||
.change = netem_change,
|
.change = netem_change,
|
||||||
.dump = netem_dump,
|
.dump = netem_dump,
|
||||||
|
.dump_stats = netem_dump_stats,
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
};
|
};
|
||||||
MODULE_ALIAS_NET_SCH("netem");
|
MODULE_ALIAS_NET_SCH("netem");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user