[Cake] [PATCH v2] Split tin stats to its own structure to decrease size of tc_cake_xstats

Toke Høiland-Jørgensen toke at toke.dk
Sat Jan 27 08:05:42 EST 2018


This splits out the tin stats from tc_cake_xstats, which seems like the
least intrusive way of decreasing the size of the stats structure. This
way, we can send only the statistics corresponding to the actual number of
allocated tins, rather than having the xstats structure always be allocated
for the full number of tins.

Signed-off-by: Toke Høiland-Jørgensen <toke at toke.dk>
---
v2:
- If we want to be able to extend the tc_cake_tin_stats at a later date
  (and if we don't the 'version' field is sort of meaningless), its size
  need to be included somewhere so userspace can skip over unknown
  fields. So add the tin stats size to struct tc_cake_xstats.

 pkt_sched.h | 50 ++++++++++++++++++++++++++++----------------------
 sch_cake.c  | 56 ++++++++++++++++++++++++++++++--------------------------
 2 files changed, 58 insertions(+), 48 deletions(-)

diff --git a/pkt_sched.h b/pkt_sched.h
index ed7c111..096642e 100644
--- a/pkt_sched.h
+++ b/pkt_sched.h
@@ -964,33 +964,39 @@ struct tc_cake_traffic_stats {
 };
 
 #define TC_CAKE_MAX_TINS (8)
+struct tc_cake_tin_stats {
+
+	__u32 threshold_rate;
+	__u32 target_us;
+	struct tc_cake_traffic_stats sent;
+	struct tc_cake_traffic_stats dropped;
+	struct tc_cake_traffic_stats ecn_marked;
+	struct tc_cake_traffic_stats backlog;
+	__u32 interval_us;
+	__u32 way_indirect_hits;
+	__u32 way_misses;
+	__u32 way_collisions;
+	__u32 peak_delay_us; /* ~= bulk flow delay */
+	__u32 avge_delay_us;
+	__u32 base_delay_us; /* ~= sparse flows delay */
+	__u16 sparse_flows;
+	__u16 bulk_flows;
+	__u16 unresponse_flows; /* v4 - was u32 last_len */
+	__u16 spare; /* v4 - split last_len */
+	__u32 max_skblen;
+	struct tc_cake_traffic_stats ack_drops; /* v5 */
+};
+
 struct tc_cake_xstats {
-	__u16 version;  /* == 5, increments when struct extended */
-	__u8  max_tins; /* == TC_CAKE_MAX_TINS */
+	__u16 tin_stats_size; /* == sizeof(struct tc_cake_tin_stats) */
 	__u8  tin_cnt;  /* <= TC_CAKE_MAX_TINS */
-
-	__u32 threshold_rate[TC_CAKE_MAX_TINS];
-	__u32 target_us[TC_CAKE_MAX_TINS];
-	struct tc_cake_traffic_stats sent[TC_CAKE_MAX_TINS];
-	struct tc_cake_traffic_stats dropped[TC_CAKE_MAX_TINS];
-	struct tc_cake_traffic_stats ecn_marked[TC_CAKE_MAX_TINS];
-	struct tc_cake_traffic_stats backlog[TC_CAKE_MAX_TINS];
-	__u32 interval_us[TC_CAKE_MAX_TINS];
-	__u32 way_indirect_hits[TC_CAKE_MAX_TINS];
-	__u32 way_misses[TC_CAKE_MAX_TINS];
-	__u32 way_collisions[TC_CAKE_MAX_TINS];
-	__u32 peak_delay_us[TC_CAKE_MAX_TINS]; /* ~= bulk flow delay */
-	__u32 avge_delay_us[TC_CAKE_MAX_TINS];
-	__u32 base_delay_us[TC_CAKE_MAX_TINS]; /* ~= sparse flows delay */
-	__u16 sparse_flows[TC_CAKE_MAX_TINS];
-	__u16 bulk_flows[TC_CAKE_MAX_TINS];
-	__u16 unresponse_flows[TC_CAKE_MAX_TINS]; /* v4 - was u32 last_len */
-	__u16 spare[TC_CAKE_MAX_TINS]; /* v4 - split last_len */
-	__u32 max_skblen[TC_CAKE_MAX_TINS];
+	__u8  version;  /* == 5, increments when struct extended */
 	__u32 capacity_estimate;  /* version 2 */
 	__u32 memory_limit;       /* version 3 */
 	__u32 memory_used;	  /* version 3 */
-	struct tc_cake_traffic_stats ack_drops[TC_CAKE_MAX_TINS]; /* v5 */
+
+	struct tc_cake_tin_stats tin_stats[0]; /* keep last */
 };
 
+
 #endif
diff --git a/sch_cake.c b/sch_cake.c
index 7f6ff8e..ba316a7 100644
--- a/sch_cake.c
+++ b/sch_cake.c
@@ -2478,51 +2478,55 @@ nla_put_failure:
 static int cake_dump_stats(struct Qdisc *sch, struct gnet_dump *d)
 {
 	struct cake_sched_data *q = qdisc_priv(sch);
-	struct tc_cake_xstats *st = kvzalloc(sizeof(*st), GFP_KERNEL);
+	struct tc_cake_xstats *st;
+	size_t size = sizeof(*st) + sizeof(struct tc_cake_tin_stats) * q->tin_cnt;
 	int i;
 
+	st = kvzalloc(size, GFP_KERNEL);
+
 	if (!st)
 		return -ENOMEM;
 
 	st->version = 5;
-	st->max_tins = TC_CAKE_MAX_TINS;
+	st->tin_stats_size = sizeof(struct tc_cake_tin_stats);
 	st->tin_cnt = q->tin_cnt;
 
 	for (i = 0; i < q->tin_cnt; i++) {
 		struct cake_tin_data *b = &q->tins[q->tin_order[i]];
+		struct tc_cake_tin_stats *tstat = &st->tin_stats[i];
 
-		st->threshold_rate[i] = b->tin_rate_bps;
-		st->target_us[i]      = cobalt_time_to_us(b->cparams.target);
-		st->interval_us[i]    = cobalt_time_to_us(b->cparams.interval);
+		tstat->threshold_rate = b->tin_rate_bps;
+		tstat->target_us      = cobalt_time_to_us(b->cparams.target);
+		tstat->interval_us    = cobalt_time_to_us(b->cparams.interval);
 
 		/* TODO FIXME: add missing aspects of these composite stats */
-		st->sent[i].packets       = b->packets;
-		st->sent[i].bytes	  = b->bytes;
-		st->dropped[i].packets    = b->tin_dropped;
-		st->ecn_marked[i].packets = b->tin_ecn_mark;
-		st->backlog[i].bytes      = b->tin_backlog;
-		st->ack_drops[i].packets  = b->ack_drops;
-
-		st->peak_delay_us[i] = cobalt_time_to_us(b->peak_delay);
-		st->avge_delay_us[i] = cobalt_time_to_us(b->avge_delay);
-		st->base_delay_us[i] = cobalt_time_to_us(b->base_delay);
-
-		st->way_indirect_hits[i] = b->way_hits;
-		st->way_misses[i]	 = b->way_misses;
-		st->way_collisions[i]    = b->way_collisions;
-
-		st->sparse_flows[i]      = b->sparse_flow_count +
+		tstat->sent.packets       = b->packets;
+		tstat->sent.bytes	  = b->bytes;
+		tstat->dropped.packets    = b->tin_dropped;
+		tstat->ecn_marked.packets = b->tin_ecn_mark;
+		tstat->backlog.bytes      = b->tin_backlog;
+		tstat->ack_drops.packets  = b->ack_drops;
+
+		tstat->peak_delay_us = cobalt_time_to_us(b->peak_delay);
+		tstat->avge_delay_us = cobalt_time_to_us(b->avge_delay);
+		tstat->base_delay_us = cobalt_time_to_us(b->base_delay);
+
+		tstat->way_indirect_hits = b->way_hits;
+		tstat->way_misses	 = b->way_misses;
+		tstat->way_collisions    = b->way_collisions;
+
+		tstat->sparse_flows      = b->sparse_flow_count +
 					   b->decaying_flow_count;
-		st->bulk_flows[i]	 = b->bulk_flow_count;
-		st->unresponse_flows[i]  = b->unresponsive_flow_count;
-		st->spare[i]		 = 0;
-		st->max_skblen[i]	 = b->max_skblen;
+		tstat->bulk_flows	 = b->bulk_flow_count;
+		tstat->unresponse_flows  = b->unresponsive_flow_count;
+		tstat->spare		 = 0;
+		tstat->max_skblen	 = b->max_skblen;
 	}
 	st->capacity_estimate = q->avg_peak_bandwidth;
 	st->memory_limit      = q->buffer_limit;
 	st->memory_used       = q->buffer_max_used;
 
-	i = gnet_stats_copy_app(d, st, sizeof(*st));
+	i = gnet_stats_copy_app(d, st, size);
 	cake_free(st);
 	return i;
 }
-- 
2.16.1



More information about the Cake mailing list