@cryptotaxi247 / netdata-1 / commits / 19c7ffc05

code cleanup and commenting

Costa Tsaousis (ktsaou) committed Jan 29, 2017 at 09:10 UTC 19c7ffc053db632f4e0fd62e44d323f018895921
1 file changed +42 -15
src/plugin_tc.c
+42 -15
@@ -230,17 +230,20 @@ static inline void tc_device_commit(struct tc_device *d) {
230 int active_nodes = 0, updated_classes = 0, updated_qdiscs = 0;
231
232 // prepare all classes
233 + // we set reasonable defaults for the rest of the code below
234 +
235 for(c = d->classes ; c ; c = c->next) {
234 - c->render = 0;
236 + c->render = 0; // do not render this class
237
236 - c->isleaf = 1;
237 - c->hasparent = 0;
238 + c->isleaf = 1; // this is a leaf class
239 + c->hasparent = 0; // without a parent
240
241 if(unlikely(!c->updated))
240 - c->unupdated++;
242 + c->unupdated++; // increase its unupdated counter
243 else {
242 - c->unupdated = 0;
244 + c->unupdated = 0; // reset its unupdated counter
245
246 + // count how many of each kind
247 if(c->isqdisc)
248 updated_qdiscs++;
249 else
@@ -256,6 +259,8 @@ static inline void tc_device_commit(struct tc_device *d) {
259
260 if(unlikely(updated_classes && updated_qdiscs)) {
261 error("TC: device '%s' has active both classes (%d) and qdiscs (%d). Will render only qdiscs.", d->id, updated_classes, updated_qdiscs);
262 +
263 + // set all classes to !updated
264 for(c = d->classes ; c ; c = c->next)
265 if(unlikely(!c->isqdisc && c->updated))
266 c->updated = 0;
@@ -264,6 +269,20 @@ static inline void tc_device_commit(struct tc_device *d) {
269 }
270
271 // mark the classes as leafs and parents
272 + //
273 + // TC is hierarchical:
274 + // - classes can have other classes in them
275 + // - the same is true for qdiscs (i.e. qdiscs have classes, that have other qdiscs)
276 + //
277 + // we need to present a chart with leaf nodes only, so that the sum
278 + // of all dimensions of the chart, will be the total utilization
279 + // of the interface.
280 + //
281 + // here we try to find the ones we need to report
282 + // by default all nodes are marked with: isleaf = 1 (see above)
283 + //
284 + // so, here we remove the isleaf flag from nodes in the middle
285 + // and we add the hasparent flag to leaf nodes we found their parent
286 for(c = d->classes; c; c = c->next) {
287 if(unlikely(!c->updated)) continue;
288
@@ -278,6 +297,10 @@ static inline void tc_device_commit(struct tc_device *d) {
297 for(x = d->classes; x; x = x->next) {
298 if(unlikely(!x->updated || c == x || !x->parentid)) continue;
299
300 + // classes have both parentid and leafid
301 + // qdiscs have only parentid
302 + // the following works for both (it is an OR)
303 +
304 if( (c->hash == x->parent_hash && strcmp(c->id, x->parentid) == 0) ||
305 (c->leafid && c->leaf_hash == x->parent_hash && strcmp(c->leafid, x->parentid) == 0)) {
306 // debug(D_TC_LOOP, "TC: In device '%s', %s '%s' (leafid: '%s') has as leaf %s '%s' (parentid: '%s').", d->name?d->name:d->id, c->isqdisc?"qdisc":"class", c->name?c->name:c->id, c->leafid?c->leafid:c->id, x->isqdisc?"qdisc":"class", x->name?x->name:x->id, x->parentid?x->parentid:x->id);
@@ -287,16 +310,6 @@ static inline void tc_device_commit(struct tc_device *d) {
310 }
311 }
312
290 - // debugging only
291 - /*
292 - if(unlikely(debug_flags & D_TC_LOOP)) {
293 - for(c = d->classes ; c ; c = c->next) {
294 - if((c->isleaf && c->hasparent) || d->enabled_all_classes_qdiscs) debug(D_TC_LOOP, "TC: final nodes dump for '%s': class %s, OK", d->name, c->id);
295 - else debug(D_TC_LOOP, "TC: final nodes dump for '%s': class %s, IGNORE (isleaf: %d, hasparent: %d, parent: %s)", d->name?d->name:d->id, c->id, c->isleaf, c->hasparent, c->parentid?c->parentid:"(unset)");
296 - }
297 - }
298 - */
299 -
313 for(c = d->classes ; c ; c = c->next) {
314 if(unlikely(!c->updated)) continue;
315
@@ -319,6 +332,17 @@ static inline void tc_device_commit(struct tc_device *d) {
332 //}
333 }
334
335 +#ifdef NETDATA_INTERNAL_CHECKS
336 + // dump all the list to see what we know
337 +
338 + if(unlikely(debug_flags & D_TC_LOOP)) {
339 + for(c = d->classes ; c ; c = c->next) {
340 + if(c->render) debug(D_TC_LOOP, "TC: final nodes dump for '%s': class %s, OK", d->name, c->id);
341 + else debug(D_TC_LOOP, "TC: final nodes dump for '%s': class %s, IGNORE (updated: %d, isleaf: %d, hasparent: %d, parent: %s)", d->name?d->name:d->id, c->id, c->updated, c->isleaf, c->hasparent, c->parentid?c->parentid:"(unset)");
342 + }
343 + }
344 +#endif
345 +
346 if(unlikely(!active_nodes)) {
347 debug(D_TC_LOOP, "TC: Ignoring TC device '%s'. No useful classes/qdiscs.", d->name?d->name:d->id);
348 tc_device_classes_cleanup(d);
@@ -826,6 +850,9 @@ void *tc_main(void *ptr) {
850
851 if(parent_is_parent && parentid) {
852 // eliminate the minor number from parentid
853 + // why: parentid is the id of the parent class
854 + // but major: is also the id of the parent qdisc
855 +
856 char *s = parentid;
857 while(*s && *s != ':') s++;
858 if(*s == ':') s[1] = '\0';