Skip to contentSkip to conversation

Thread-Local Storage (TLS) support for Linux, 2.5.28

PATCH Oleg Nesterov 2 participants 7 messages Jul 28, 2002

lore
Share & tools
lore
#0 lore raw

Hello.

I thought, that gdt entry consulted only while
loading its index into the segment register.

So load_TLS_desc(next, cpu) must be called before
loading next->fs,next->gs in __switch_to() ?

arch/i386/kernel/process.c renamed from arch/i386/kernel/process.c~ +8 -8
@@ -675,6 +675,14 @@
 	tss->esp0 = next->esp0;
 
 	/*
+	 * Load the per-thread Thread-Local Storage descriptor.
+	 *
+	 * NOTE: it's faster to do the two stores unconditionally
+	 * than to branch away.
+	 */
+	load_TLS_desc(next, cpu);
+
+	/*
 	 * Save away %fs and %gs. No need to save %es and %ds, as
 	 * those are always kernel segments while inside the kernel.
 	 */
@@ -688,14 +696,6 @@
 		loadsegment(fs, next->fs);
 		loadsegment(gs, next->gs);
 	}
-
-	/*
-	 * Load the per-thread Thread-Local Storage descriptor.
-	 *
-	 * NOTE: it's faster to do the two stores unconditionally
-	 * than to branch away.
-	 */
-	load_TLS_desc(next, cpu);
 
 	/*
 	 * Now maybe reload the debug registers

Oleg.

#1 lore raw
Quoted 5 lines · Oleg Nesterov

I thought, that gdt entry consulted only while
loading its index into the segment register.

So load_TLS_desc(next, cpu) must be called before
loading next->fs,next->gs in __switch_to() ?

hm, right. I'm wondering, why did the tls_test code still work?

Ingo

#4 lore raw
In reply to Oleg Nesterov

arch/i386/kernel/process.c line 686

Quoted 9 lines · Oleg Nesterov
arch/i386/kernel/process.c renamed from arch/i386/kernel/process.c~ +8 -0
+	 * Load the per-thread Thread-Local Storage descriptor.
+	 *
+	 * NOTE: it's faster to do the two stores unconditionally
+	 * than to branch away.
+	 */
+	load_TLS_desc(next, cpu);
+
+	/*
 	 * Save away %fs and %gs. No need to save %es and %ds, as

actually, shouldnt this be done after saving the current %fs and %gs, and before loading the next %fs and %gs?

Ingo

#2 lore raw
In reply to Ingo Molnar
Quoted 4 lines · Ingo Molnar
Quoted 2 lines

So load_TLS_desc(next, cpu) must be called before
loading next->fs,next->gs in __switch_to() ?

hm, right. I'm wondering, why did the tls_test code still work?

okay, the tls_test.c code worked only because the code didnt context-switch after installing the TLS.

Ingo

#3 lore raw

Re: [announce, patch] Thread-Local Storage (TLS) support for Linux,2.5.28

In reply to Ingo Molnar

Hello.

Quoted 9 lines
Quoted 5 lines

I thought, that gdt entry consulted only while
loading its index into the segment register.

So load_TLS_desc(next, cpu) must be called before
loading next->fs,next->gs in __switch_to() ?

hm, right. I'm wondering, why did the tls_test code still work?

Ingo

Because that code reloads %fs before every time in {read,write}seg.

Oleg.

#5 lore raw

Re: [announce, patch] Thread-Local Storage (TLS) support for Linux,2.5.28

In reply to Ingo Molnar

Hello.

Quoted 13 lines · Ingo Molnar

arch/i386/kernel/process.c line 686

Quoted 9 lines · Oleg Nesterov
arch/i386/kernel/process.c renamed from arch/i386/kernel/process.c~ +8 -0
+      * Load the per-thread Thread-Local Storage descriptor.
+      *
+      * NOTE: it's faster to do the two stores unconditionally
+      * than to branch away.
+      */
+     load_TLS_desc(next, cpu);
+
+     /*
       * Save away %fs and %gs. No need to save %es and %ds, as
Quoted 4 lines

actually, shouldnt this be done after saving the current %fs and %gs, and before loading the next %fs and %gs?

Ingo

Well, load_TLS() and saving current %fs,%gs are just mem stores, no? I can't see any difference in terms of correctness.

Oleg.

#6 lore raw

Re: [announce, patch] Thread-Local Storage (TLS) support for Linux,2.5.28

Quoted 2 lines · Oleg Nesterov

Well, load_TLS() and saving current %fs,%gs are just mem stores, no? I can't see any difference in terms of correctness.

yes, your patch is fine.

Ingo