linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] de-xchg fork.c
  2002-09-23  1:06 [PATCH] de-xchg fork.c Rusty Russell
@ 2002-09-22  0:48 ` Pavel Machek
  2002-09-23 18:31 ` Ingo Molnar
  1 sibling, 0 replies; 5+ messages in thread
From: Pavel Machek @ 2002-09-22  0:48 UTC (permalink / raw)
  To: Rusty Russell; +Cc: torvalds, akpm, ingo, linux-kernel, trivial

Hi!

> Don't know who put this in for 2.5.38.
> 
> I realize that using xchg() makes you 'leet.  But doing an atomic op
> where none is required is suboptimal and confusing.

Well, atomic op is also more expensive. i think ingo did this. Ingo, is
patch below safe? It is faster *and* it works on 386.
								Pavel 

> diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.38/kernel/fork.c working-2.5.38-unxchg/kernel/fork.c
> --- linux-2.5.38/kernel/fork.c	2002-09-21 13:55:19.000000000 +1000
> +++ working-2.5.38-unxchg/kernel/fork.c	2002-09-23 11:00:31.000000000 +1000
> @@ -64,11 +64,12 @@ void __put_task_struct(struct task_struc
>  	} else {
>  		int cpu = smp_processor_id();
>  
> -		tsk = xchg(task_cache + cpu, tsk);
> +		tsk = task_cache[cpu];
>  		if (tsk) {
>  			free_thread_info(tsk->thread_info);
>  			kmem_cache_free(task_struct_cachep,tsk);
>  		}
> +		task_cache[cpu] = current;
>  	}
>  }

-- 
Philips Velo 1: 1"x4"x8", 300gram, 60, 12MB, 40bogomips, linux, mutt,
details at http://atrey.karlin.mff.cuni.cz/~pavel/velo/index.html.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] de-xchg fork.c
@ 2002-09-23  1:06 Rusty Russell
  2002-09-22  0:48 ` Pavel Machek
  2002-09-23 18:31 ` Ingo Molnar
  0 siblings, 2 replies; 5+ messages in thread
From: Rusty Russell @ 2002-09-23  1:06 UTC (permalink / raw)
  To: torvalds; +Cc: akpm, ingo, linux-kernel, trivial

Don't know who put this in for 2.5.38.

I realize that using xchg() makes you 'leet.  But doing an atomic op
where none is required is suboptimal and confusing.

Hey, at least it wasn't:
	if (likely(tsk = xchg(task_cache + cpu, tsk))) {

Cheers,
Rusty.

diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.38/kernel/fork.c working-2.5.38-unxchg/kernel/fork.c
--- linux-2.5.38/kernel/fork.c	2002-09-21 13:55:19.000000000 +1000
+++ working-2.5.38-unxchg/kernel/fork.c	2002-09-23 11:00:31.000000000 +1000
@@ -64,11 +64,12 @@ void __put_task_struct(struct task_struc
 	} else {
 		int cpu = smp_processor_id();
 
-		tsk = xchg(task_cache + cpu, tsk);
+		tsk = task_cache[cpu];
 		if (tsk) {
 			free_thread_info(tsk->thread_info);
 			kmem_cache_free(task_struct_cachep,tsk);
 		}
+		task_cache[cpu] = current;
 	}
 }
 

--
  Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] de-xchg fork.c
  2002-09-23 18:31 ` Ingo Molnar
@ 2002-09-23 18:30   ` Robert Love
  2002-09-23 18:56     ` Ingo Molnar
  0 siblings, 1 reply; 5+ messages in thread
From: Robert Love @ 2002-09-23 18:30 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Rusty Russell, torvalds, akpm, ingo, linux-kernel, trivial

On Mon, 2002-09-23 at 14:31, Ingo Molnar wrote:

> the attached patch (against BK-curr) fixes all xchg()'s and a preemption
> bug.

Thanks, Ingo.

> --- linux/kernel/fork.c.orig	Mon Sep 23 20:28:36 2002
> +++ linux/kernel/fork.c	Mon Sep 23 20:30:02 2002
> @@ -64,11 +64,12 @@
>  	} else {
>  		int cpu = smp_processor_id();
>  
> -		tsk = xchg(task_cache + cpu, tsk);
> +		tsk = task_cache[cpu];
>  		if (tsk) {
>  			free_thread_info(tsk->thread_info);
>  			kmem_cache_free(task_struct_cachep,tsk);
>  		}
> +		task_cache[cpu] = current;
>  	}
>  }

I think you need get/put_cpu() here, too?

	Robert Love


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] de-xchg fork.c
  2002-09-23  1:06 [PATCH] de-xchg fork.c Rusty Russell
  2002-09-22  0:48 ` Pavel Machek
@ 2002-09-23 18:31 ` Ingo Molnar
  2002-09-23 18:30   ` Robert Love
  1 sibling, 1 reply; 5+ messages in thread
From: Ingo Molnar @ 2002-09-23 18:31 UTC (permalink / raw)
  To: Rusty Russell; +Cc: torvalds, akpm, ingo, linux-kernel, trivial


On Mon, 23 Sep 2002, Rusty Russell wrote:

> -		tsk = xchg(task_cache + cpu, tsk);
> +		tsk = task_cache[cpu];

this was me - i forgot that this are per-CPU fields. (hey and i wrote the
original task_cache code so there's no excuse :-)

the attached patch (against BK-curr) fixes all xchg()'s and a preemption
bug.

	Ingo

--- linux/kernel/fork.c.orig	Mon Sep 23 20:28:36 2002
+++ linux/kernel/fork.c	Mon Sep 23 20:30:02 2002
@@ -64,11 +64,12 @@
 	} else {
 		int cpu = smp_processor_id();
 
-		tsk = xchg(task_cache + cpu, tsk);
+		tsk = task_cache[cpu];
 		if (tsk) {
 			free_thread_info(tsk->thread_info);
 			kmem_cache_free(task_struct_cachep,tsk);
 		}
+		task_cache[cpu] = current;
 	}
 }
 
@@ -126,8 +127,11 @@
 {
 	struct task_struct *tsk;
 	struct thread_info *ti;
+	int cpu = get_cpu();
 
-	tsk = xchg(task_cache + smp_processor_id(), NULL);
+	tsk = task_cache[cpu];
+	task_cache[cpu] = NULL;
+	put_cpu();
 	if (!tsk) {
 		ti = alloc_thread_info();
 		if (!ti)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] de-xchg fork.c
  2002-09-23 18:30   ` Robert Love
@ 2002-09-23 18:56     ` Ingo Molnar
  0 siblings, 0 replies; 5+ messages in thread
From: Ingo Molnar @ 2002-09-23 18:56 UTC (permalink / raw)
  To: Robert Love
  Cc: Rusty Russell, Linus Torvalds, Andrew Morton, ingo, linux-kernel,
	trivial


On 23 Sep 2002, Robert Love wrote:

> > +		task_cache[cpu] = current;
> >  	}
> >  }
> 
> I think you need get/put_cpu() here, too?

you are right - new patch attached.

	Ingo

--- linux/kernel/fork.c.orig	Mon Sep 23 20:28:36 2002
+++ linux/kernel/fork.c	Mon Sep 23 20:55:08 2002
@@ -62,13 +62,15 @@
 		free_thread_info(tsk->thread_info);
 		kmem_cache_free(task_struct_cachep,tsk);
 	} else {
-		int cpu = smp_processor_id();
+		int cpu = get_cpu();
 
-		tsk = xchg(task_cache + cpu, tsk);
+		tsk = task_cache[cpu];
 		if (tsk) {
 			free_thread_info(tsk->thread_info);
 			kmem_cache_free(task_struct_cachep,tsk);
 		}
+		task_cache[cpu] = current;
+		put_cpu();
 	}
 }
 
@@ -126,8 +128,11 @@
 {
 	struct task_struct *tsk;
 	struct thread_info *ti;
+	int cpu = get_cpu();
 
-	tsk = xchg(task_cache + smp_processor_id(), NULL);
+	tsk = task_cache[cpu];
+	task_cache[cpu] = NULL;
+	put_cpu();
 	if (!tsk) {
 		ti = alloc_thread_info();
 		if (!ti)


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-09-24 20:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-23  1:06 [PATCH] de-xchg fork.c Rusty Russell
2002-09-22  0:48 ` Pavel Machek
2002-09-23 18:31 ` Ingo Molnar
2002-09-23 18:30   ` Robert Love
2002-09-23 18:56     ` Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).