Skip to contentSkip to conversation

sched: change the fairness model of the CFS group scheduler

RFC PATCH J.C. Pizarro 1 participant 1 message Feb 29, 2008

lore
Share & tools
lore
#0 lore raw

http://lkml.org/lkml/2008/2/28/313 has a lot of new bugs.

Review

Quoted 8 lines

+++ linux-2.6.25-rc2/kernel/sched_fair.c

(quoted diff) +5 -0
+	struct sched_entity *se = tg->se[cpu], *top_se;
 
+
+	for_each_sched_entity(se)
+		top_se = se;
+

It does unnecesary code execution.
Why don't do once "top_se = se;" instead for each?

Review

Quoted 10 lines
(quoted diff) +10 -0
+static inline int depth_se(struct sched_entity *se)
+{
+	int depth = 0;
+
+	for_each_sched_entity(se)
+		depth++;
+
+	return depth;
+}
+

It does unnecesary code execution.
Why don't do "depth = the count of sched entities" instead of ++?

Review

Quoted 13 lines
(quoted diff) +13 -0
+	/* First walk up until both entities are at same depth */
+	se_depth = depth_se(se);
+	pse_depth = depth_se(pse);
+
+	while (se_depth > pse_depth) {
+		se_depth--;
+		se = parent_entity(se);
+	}
+
+	while (pse_depth > se_depth) {
+		pse_depth--;
+		pse = parent_entity(pse);
+	}

It does unnecesary code execution.
Exiting the 1st while asserts "se_depth == pse_depth", the 2nd while never is entered.

Review

Quoted 9 lines

__load_balance_iterator(struct cfs_rq *cfs_rq, struct rb_node *curr)

(quoted diff) +5 -2
-	p = rb_entry(curr, struct task_struct, se.run_node);
-	cfs_rq->rb_load_balance_curr = rb_next(curr);
+	/* Skip over entities that are not tasks */
+	do {
+		se = rb_entry(curr, struct sched_entity, run_node);
+		curr = rb_next(curr);
+	} while (curr && !entity_is_task(se));

It's wrong, it says that curr is next to the first found entity that is task.

I think that the correct code could be
curr = rb_next(curr);
while (curr) {
se = rb_entry(curr, struct sched_entity, run_node); if (entity_is_task(se)) break;
curr = rb_next(curr);
} /* se is next to curr and first entity that is task skipping non-task entities */

Review

Quoted 6 lines
(quoted diff) +4 -0
+	cfs_rq->rb_load_balance_curr = curr;
+
+	if (entity_is_task(se))
+		p = task_of(se);
 
 	return p;

You forgot if (unlikely(curr == NULL)) { ... }

Quoted 6 lines
(quoted diff) +1 -1
@@ -1210,21 +1267,28 @@ load_balance_fair(struct rq *this_rq, in
 
 		unsigned long maxload, task_load, group_weight;
 
-		group_weight = se->load.weight;
+		if (!task_load)

Review load_balance_fair(struct rq *this_rq, in · line 1279

Quoted 10 lines
(quoted diff) +4 -1
+			continue;
+
+		group_weight = group_cpu_load(tg, busiest->cpu);
 
-		 * 'group_weight' is contributed by tasks of total weight
+		 * 'group_weight' is contributed by entities of total weight
 
 		 * 	maxload = (remload / group_weight) * task_load;
 		 */
 		maxload = (rem_load_move * task_load) / group_weight;

The unsigned long division IS SLOW!!! Use multiplication and shift stupid!!! Be careful with zerodiv exception of "/ group_weight"!!!

Quoted 27 lines
(quoted diff) +10 -15
-		/*
-		 * load_moved holds the task load that was moved. The
-		 * effective (group) weight moved would be:
-		 * 	load_moved_eff = load_moved/task_load * group_weight;
-		 */
-		load_moved = (group_weight * load_moved) / task_load;
-
 		/* Adjust shares on both cpus to reflect load_moved */
-		group_weight -= load_moved;
-		set_se_shares(se, group_weight);
+		if (likely(se)) {
+			unsigned long load_moved_eff;
+			unsigned long se_shares;
 
-		se = busy_cfs_rq->tg->se[this_cpu];
-		if (!thisload)
-			group_weight = load_moved;
-		else
-			group_weight = se->load.weight + load_moved;
-		set_se_shares(se, group_weight);
+			/*
+			 * load_moved holds the task load that was moved. The
+			 * effective (group) weight moved would be:
+			 *	load_moved_eff = load_moved/task_load *
+			 *					group_weight;
+			 */
+			load_moved_eff = (se->load.weight *

Review load_balance_fair(struct rq *this_rq, in

Quoted 10 lines
(quoted diff) +10 -0
+						 load_moved) / task_load;
+
+			set_se_shares(se, se->load.weight - load_moved_eff);
+			if (!thisload)
+				se_shares = load_moved_eff;
+			else
+				se_shares = this_se->load.weight +
+							load_moved_eff;
+			set_se_shares(this_se, se_shares);
+		}

The unsigned long division IS SLOW!!! Use multiplication and shift stupid!!! Be careful with zerodiv exception of "/ task_load"!!!

J.C.Pizarro