[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[commits] r1887 - in /fsf/trunk/libc: ChangeLog posix/Makefile posix/Versions posix/sched_cpucount.c posix/tst-cpucount.c



Author: eglibc
Date: Wed Apr  4 00:01:50 2007
New Revision: 1887

Log:
Import glibc-mainline for 2007-04-04

Added:
    fsf/trunk/libc/posix/sched_cpucount.c
    fsf/trunk/libc/posix/tst-cpucount.c
Modified:
    fsf/trunk/libc/ChangeLog
    fsf/trunk/libc/posix/Makefile
    fsf/trunk/libc/posix/Versions

Modified: fsf/trunk/libc/ChangeLog
==============================================================================
--- fsf/trunk/libc/ChangeLog (original)
+++ fsf/trunk/libc/ChangeLog Wed Apr  4 00:01:50 2007
@@ -1,3 +1,11 @@
+2007-04-03  Ulrich Drepper  <drepper@xxxxxxxxxx>
+
+	* posix/Makefile (routines): Add sched_cpucount.
+	(tests): Add tst-cpucount.
+	* posix/sched_cpucount.c: New file.
+	* posix/tst-cpucount.c: New file.
+	* posix/Versions: Export __sched_cpucount with version GLIBC_2.6.
+
 2007-03-27  Jakub Jelinek  <jakub@xxxxxxxxxx>
 
 	* posix/fnmatch.c (STRUCT): Define.

Modified: fsf/trunk/libc/posix/Makefile
==============================================================================
--- fsf/trunk/libc/posix/Makefile (original)
+++ fsf/trunk/libc/posix/Makefile Wed Apr  4 00:01:50 2007
@@ -66,7 +66,7 @@
 	spawnattr_getsigmask spawnattr_getschedpolicy spawnattr_getschedparam \
 	spawnattr_setsigmask spawnattr_setschedpolicy spawnattr_setschedparam \
 	posix_madvise							      \
-	get_child_max
+	get_child_max sched_cpucount
 
 include ../Makeconfig
 
@@ -90,7 +90,7 @@
 		   tst-execv1 tst-execv2 tst-execl1 tst-execl2 \
 		   tst-execve1 tst-execve2 tst-execle1 tst-execle2 \
 		   tst-execvp3 tst-execvp4 tst-rfc3484 tst-rfc3484-2 \
-		   tst-getaddrinfo3 tst-fnmatch2
+		   tst-getaddrinfo3 tst-fnmatch2 tst-cpucount
 xtests		:= bug-ga2
 ifeq (yes,$(build-shared))
 test-srcs	:= globtest

Modified: fsf/trunk/libc/posix/Versions
==============================================================================
--- fsf/trunk/libc/posix/Versions (original)
+++ fsf/trunk/libc/posix/Versions Wed Apr  4 00:01:50 2007
@@ -122,6 +122,9 @@
   GLIBC_2.3.4 {
     regexec;
   }
+  GLIBC_2.6 {
+    __sched_cpucount;
+  }
   GLIBC_PRIVATE {
     __libc_fork; __libc_pwrite;
   }

Added: fsf/trunk/libc/posix/sched_cpucount.c
==============================================================================
--- fsf/trunk/libc/posix/sched_cpucount.c (added)
+++ fsf/trunk/libc/posix/sched_cpucount.c Wed Apr  4 00:01:50 2007
@@ -1,0 +1,52 @@
+/* Copyright (C) 2007 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <limits.h>
+#include <sched.h>
+
+
+int
+__sched_cpucount (cpu_set_t *setp)
+{
+  int s = 0;
+  for (unsigned int j = 0; j < __CPU_SETSIZE / __NCPUBITS; ++j)
+    {
+      __cpu_mask l = setp->__bits[j];
+      if (l == 0)
+	continue;
+
+#if LONG_BIT > 32
+      l = (l & 0x5555555555555555ul) + ((l >> 1) & 0x5555555555555555ul);
+      l = (l & 0x3333333333333333ul) + ((l >> 2) & 0x3333333333333333ul);
+      l = (l & 0x0f0f0f0f0f0f0f0ful) + ((l >> 4) & 0x0f0f0f0f0f0f0f0ful);
+      l = (l & 0x00ff00ff00ff00fful) + ((l >> 8) & 0x00ff00ff00ff00fful);
+      l = (l & 0x0000ffff0000fffful) + ((l >> 16) & 0x0000ffff0000fffful);
+      l = (l & 0x00000000fffffffful) + ((l >> 32) & 0x00000000fffffffful);
+#else
+      l = (l & 0x55555555ul) + ((l >> 1) & 0x55555555ul);
+      l = (l & 0x33333333ul) + ((l >> 2) & 0x33333333ul);
+      l = (l & 0x0f0f0f0ful) + ((l >> 4) & 0x0f0f0f0ful);
+      l = (l & 0x00ff00fful) + ((l >> 8) & 0x00ff00fful);
+      l = (l & 0x0000fffful) + ((l >> 16) & 0x0000fffful);
+#endif
+
+      s += l;
+    }
+
+  return s;
+}

Added: fsf/trunk/libc/posix/tst-cpucount.c
==============================================================================
--- fsf/trunk/libc/posix/tst-cpucount.c (added)
+++ fsf/trunk/libc/posix/tst-cpucount.c Wed Apr  4 00:01:50 2007
@@ -1,0 +1,27 @@
+#include <sched.h>
+#include <stdio.h>
+
+static int
+do_test (void)
+{
+  cpu_set_t c;
+
+  CPU_ZERO (&c);
+
+  for (int cnt = 0; cnt < 130; ++cnt)
+    {
+      int n = CPU_COUNT (&c);
+      if (n != cnt)
+	{
+	  printf ("expected %d, not %d\n", cnt, n);
+	  return 1;
+	}
+
+      CPU_SET (cnt, &c);
+    }
+
+  return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"