
From: Matt Mackall <mpm@selenic.com>

Eep.  cpuset uses bubble sort on a data set that's potentially O(# processes).
Switch to lib/sort.

Signed-off-by: Matt Mackall <mpm@selenic.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/kernel/cpuset.c |   19 ++++---------------
 1 files changed, 4 insertions(+), 15 deletions(-)

diff -puN kernel/cpuset.c~lib-sort-replace-open-coded-opids2-bubblesort-in-cpusets kernel/cpuset.c
--- 25/kernel/cpuset.c~lib-sort-replace-open-coded-opids2-bubblesort-in-cpusets	2005-02-02 15:56:31.556990232 -0800
+++ 25-akpm/kernel/cpuset.c	2005-02-02 15:56:36.404253336 -0800
@@ -47,6 +47,7 @@
 #include <linux/string.h>
 #include <linux/time.h>
 #include <linux/backing-dev.h>
+#include <linux/sort.h>
 
 #include <asm/uaccess.h>
 #include <asm/atomic.h>
@@ -1003,21 +1004,9 @@ array_full:
 	return n;
 }
 
-/*
- * In place bubble sort pidarray of npids pid_t's.
- */
-static inline void pid_array_sort(pid_t *pidarray, int npids)
+static int cmppid(const void *a, const void *b)
 {
-	int i, j;
-
-	for (i = 0; i < npids - 1; i++) {
-		for (j = 0; j < npids - 1 - i; j++)
-			if (pidarray[j + 1] < pidarray[j]) {
-				pid_t tmp = pidarray[j];
-				pidarray[j] = pidarray[j + 1];
-				pidarray[j + 1] = tmp;
-			}
-	}
+	return *(pid_t *)a - *(pid_t *)b;
 }
 
 /*
@@ -1059,7 +1048,7 @@ static inline struct ctr_struct *cpuset_
 		goto err1;
 
 	npids = pid_array_load(pidarray, npids, cs);
-	pid_array_sort(pidarray, npids);
+	sort(pidarray, npids, sizeof(pid_t), cmppid, NULL);
 
 	/* Call pid_array_to_buf() twice, first just to get bufsz */
 	ctr->bufsz = pid_array_to_buf(&c, sizeof(c), pidarray, npids) + 1;
_
