Skip to contentSkip to conversation

i386 TIF flags for debug regs and io bitmap in ctxsw

PATCH Chuck Ebbert 3 participants 4 messages Jul 4, 2006

lore
Share & tools
lore
#0 lore raw

In-Reply-To: <[email protected]>

Quoted 4 lines · Stephane Eranian

Following my discussion with Andi. Here is a patch that introduces two new TIF flags to simplify the context switch code in __switch_to(). The idea is to minimize the number of cache lines accessed in the common case, i.e., when neither the debug registers nor the I/O bitmap are used.

I get a 5-10% speedup in task switch times with this patch. Some very minor comments:

Quoted 1 line

<signed-off-by>: [email protected]

Should be: Signed-off-by: Stephane Eranian <[email protected]>

Review

Quoted 1 line
(quoted diff) +1 -0
+	if (test_tsk_thread_flag(next_p, TIF_IO_BITMAP) == 0) {

preferred:

	if (!test_tsk_thread_flag(next_p, TIF_IO_BITMAP)) {

Review struct task_struct fastcall * __switch_t · line 694

Quoted 4 lines
(quoted diff) +0 -0
@@ -674,18 +692,9 @@ struct task_struct fastcall * __switch_t
 	/*
 	 * Now maybe reload the debug registers
 	 */

/*
* Now maybe reload the debug registers and/or IO bitmap */

And this should be added to the patch:

arch/i386/kernel/process.c +3 -4
@@ -360,13 +360,12 @@ EXPORT_SYMBOL(kernel_thread);
  */
 void exit_thread(void)
 {
-	struct task_struct *tsk = current;
-	struct thread_struct *t = &tsk->thread;
-
 	/* The process may have allocated an io port bitmap... nuke it. */
-	if (unlikely(NULL != t->io_bitmap_ptr)) {
+	if (unlikely(test_thread_flag(TIF_IO_BITMAP))) {
 		int cpu = get_cpu();
 		struct tss_struct *tss = &per_cpu(init_tss, cpu);
+		struct task_struct *tsk = current;
+		struct thread_struct *t = &tsk->thread;
 
 		kfree(t->io_bitmap_ptr);
 		t->io_bitmap_ptr = NULL;
Signature · 2 lines
Chuck
 "You can't read a newspaper if you can't read."  --George W. Bush
#1 lore raw
Quoted 9 lines · Chuck Ebbert

In-Reply-To: <[email protected]>

Quoted 4 lines · Stephane Eranian

Following my discussion with Andi. Here is a patch that introduces two new TIF flags to simplify the context switch code in __switch_to(). The idea is to minimize the number of cache lines accessed in the common case, i.e., when neither the debug registers nor the I/O bitmap are used.

I get a 5-10% speedup in task switch times with this patch.

That sounds too much. How did you measure it?

Note that lmbench tends to be unstable for this.

-Andi

#2 lore raw
Quoted 9 lines · Andi Kleen
Quoted 8 lines · Chuck Ebbert

In-Reply-To: <[email protected]>

Quoted 4 lines · Stephane Eranian

Following my discussion with Andi. Here is a patch that introduces two new TIF flags to simplify the context switch code in __switch_to(). The idea is to minimize the number of cache lines accessed in the common case, i.e., when neither the debug registers nor the I/O bitmap are used.

Quoted 6 lines
Quoted 1 line

I get a 5-10% speedup in task switch times with this patch.

That sounds too much. How did you measure it?

Note that lmbench tends to be unstable for this.

Yes, that is my observation as well. Anybody knows of a better benchmark for ctxsw?

Signature · 1 line
-Stephane
#3 lore raw
In reply to Chuck Ebbert

Chuck,

Quoted 7 lines · Chuck Ebbert

Review

Quoted 2 lines
(quoted diff) +1 -0
+	if (test_tsk_thread_flag(next_p, TIF_IO_BITMAP) == 0) {

preferred:

	if (!test_tsk_thread_flag(next_p, TIF_IO_BITMAP)) {

Ok, I will fix that.

Quoted 11 lines

And this should be added to the patch:

arch/i386/kernel/process.c +0 -3
@@ -360,13 +360,12 @@ EXPORT_SYMBOL(kernel_thread);
  */
 void exit_thread(void)
 {
-	struct task_struct *tsk = current;
-	struct thread_struct *t = &tsk->thread;
-

arch/i386/kernel/process.c EXPORT_SYMBOL(kernel_thread); · line 371

Quoted 10 lines
arch/i386/kernel/process.c +3 -1
 	/* The process may have allocated an io port bitmap... nuke it. */
-	if (unlikely(NULL != t->io_bitmap_ptr)) {
+	if (unlikely(test_thread_flag(TIF_IO_BITMAP))) {
 		int cpu = get_cpu();
 		struct tss_struct *tss = &per_cpu(init_tss, cpu);
+		struct task_struct *tsk = current;
+		struct thread_struct *t = &tsk->thread;
 
 		kfree(t->io_bitmap_ptr);
 		t->io_bitmap_ptr = NULL;

Yes, I missed that test. Thanks for catching it.

Signature · 1 line
-Stephane