Skip to contentSkip to conversation

Demo patch - no interactivity 2.6

PATCH Con Kolivas 2 participants 2 messages Nov 23, 2003 – Nov 26, 2003

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

I created this patch for demonstration purposes.

People have raised concerns about the overhead of the interactivity estimator in 2.6 and it's effect on throughput. Some anecdotes report wild accusations of 20% loss (without hard data). While others believe there is no need for interactivity estimation in the kernel with modern cpus.

The work put in by myself to fine tune the estimator was carefully checked to ensure there were no regressions to performance and there have actually been minor improvements along the way. Beyond this is the interactivity estimator infrastructure already in place.

The estimator should not somehow make your cpu 20% slower unless something is horribly wrong. It simply reorders which tasks go first, and if they do get to go first they round robin more frequently. Overall within a larger timespace the amount of time taken to do the work is the same (or slightly better in some settings). Delaying the cpu bound tasks and then letting them run for a longer timeslice when there is a larger cpu window allows them to benefit more from cpu cache. While the code looks complicated, the overhead is miniscule.

So to demonstrate this more clearly, here is a patch that removes the interactivity estimator entirely, leaving the scheduler mechanism otherwise unchanged. No tasks get dynamic priority changes, and all tasks are allowed to run out their full timeslice and will then expire. There is no selective reinsertion into the active array. This deletes about 350 lines of code.

I have benchmarked this patch in a range of different benchmarks, and tried using it in real world settings. There is no demonstrable performance benefit to this patch. Cpu throughput is the same in my testing (up to 16x). Not surprisingly, interactivity of this is also quite appalling. At rest it is fine, but as any load is placed on the system, X stutters and jerks. Audio is not too bad actually as a consequence of the fact that audio threads go to sleep before they expire so they always wake up in the active array and will not have too long a scheduling latency from there.

I do not recommend you use this patch in any real world setting as it is mildly DOS exploitable by repeated waking tasks, but otherwise works fine. I guess there are some embedded devices or specific one-use settings for the kernel where this would be ok to use. The only other setting I could think of is as a base patch for re-writing a new interactivity estimator from scratch.

Con

arch/i386/kernel/timers/timer_tsc.c +0 -24
diff -Naurp linux-2.6.0-test9/arch/i386/kernel/timers/timer_tsc.c linux-2.6.0-test9-noint/arch/i386/kernel/timers/timer_tsc.c
@@ -127,30 +127,6 @@ static unsigned long long monotonic_cloc
 	return base + cycles_2_ns(this_offset - last_offset);
 }
 
-/*
- * Scheduler clock - returns current time in nanosec units.
- */
-unsigned long long sched_clock(void)
-{
-	unsigned long long this_offset;
-
-	/*
-	 * In the NUMA case we dont use the TSC as they are not
-	 * synchronized across all CPUs.
-	 */
-#ifndef CONFIG_NUMA
-	if (unlikely(!cpu_has_tsc))
-#endif
-		return (unsigned long long)jiffies * (1000000000 / HZ);
-
-	/* Read the Time Stamp Counter */
-	rdtscll(this_offset);
-
-	/* return the value in ns */
-	return cycles_2_ns(this_offset);
-}
-
-
 static void mark_offset_tsc(void)
 {
 	unsigned long lost,delay;
fs/proc/array.c +0 -2
diff -Naurp linux-2.6.0-test9/fs/proc/array.c linux-2.6.0-test9-noint/fs/proc/array.c
@@ -154,7 +154,6 @@ static inline char * task_state(struct t
 	read_lock(&tasklist_lock);
 	buffer += sprintf(buffer,
 		"State:\t%s\n"
-		"SleepAVG:\t%lu%%\n"
 		"Tgid:\t%d\n"
 		"Pid:\t%d\n"
 		"PPid:\t%d\n"
@@ -162,7 +161,6 @@ static inline char * task_state(struct t
 		"Uid:\t%d\t%d\t%d\t%d\n"
 		"Gid:\t%d\t%d\t%d\t%d\n",
 		get_task_state(p),
-		(p->sleep_avg/1024)*100/(1000000000/1024),
 	       	p->tgid,
 		p->pid, p->pid ? p->real_parent->pid : 0,
 		p->pid && p->ptrace ? p->parent->pid : 0,
include/linux/sched.h +0 -5
diff -Naurp linux-2.6.0-test9/include/linux/sched.h linux-2.6.0-test9-noint/include/linux/sched.h
@@ -343,11 +343,6 @@ struct task_struct {
 	struct list_head run_list;
 	prio_array_t *array;
 
-	unsigned long sleep_avg;
-	long interactive_credit;
-	unsigned long long timestamp;
-	int activated;
-
 	unsigned long policy;
 	cpumask_t cpus_allowed;
 	unsigned int time_slice, first_time_slice;
kernel/fork.c +0 -1
diff -Naurp linux-2.6.0-test9/kernel/fork.c linux-2.6.0-test9-noint/kernel/fork.c
@@ -960,7 +960,6 @@ struct task_struct *copy_process(unsigne
 	 */
 	p->first_time_slice = 1;
 	current->time_slice >>= 1;
-	p->timestamp = sched_clock();
 	if (!current->time_slice) {
 		/*
 	 	 * This case is rare, it happens when the parent has only
kernel/sched.c +24 -342

500 lines not on this page · raw message

#1 lore raw
Quoted 5 lines · Con Kolivas

I created this patch for demonstration purposes.

People have raised concerns about the overhead of the interactivity estimator in 2.6 and it's effect on throughput. Some anecdotes report wild accusations of 20% loss (without hard data). [...]

this claim is nonsense, agreed. The only small change in performance should be for microbenchmark things like lmbench's lat_ctx. But this cost is well worth it.

Ingo