Port: Add Solaris getcpu support
authorMichael Jeanson <mjeanson@efficios.com>
Fri, 2 Oct 2015 19:37:55 +0000 (15:37 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 6 Oct 2015 16:57:36 +0000 (12:57 -0400)
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Makefile.am
compat-getcpu.h [new file with mode: 0644]
configure.ac
rculfhash.c
urcu-call-rcu-impl.h

index f41e3358ad1c4b788e14685a32216f3b60428be5..672beecad0176a848ab31d5258c97bee668e4747 100644 (file)
@@ -27,7 +27,7 @@ nobase_dist_include_HEADERS = urcu/compiler.h urcu/hlist.h urcu/list.h \
                urcu/tls-compat.h urcu/debug.h
 nobase_nodist_include_HEADERS = urcu/arch.h urcu/uatomic.h urcu/config.h
 
-dist_noinst_HEADERS = urcu-die.h urcu-wait.h
+dist_noinst_HEADERS = urcu-die.h urcu-wait.h compat-getcpu.h
 
 EXTRA_DIST = $(top_srcdir)/urcu/arch/*.h $(top_srcdir)/urcu/uatomic/*.h \
                gpl-2.0.txt lgpl-2.1.txt lgpl-relicensing.txt \
diff --git a/compat-getcpu.h b/compat-getcpu.h
new file mode 100644 (file)
index 0000000..863c80a
--- /dev/null
@@ -0,0 +1,51 @@
+#ifndef _COMPAT_GETCPU_H
+#define _COMPAT_GETCPU_H
+
+/*
+ * compat-getcpu.h
+ *
+ * Copyright (c) 2015 Michael Jeanson <mjeanson@efficios.com>
+ *
+ * This 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.
+ *
+ * This 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 this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <config.h>
+
+#if defined(HAVE_SCHED_GETCPU)
+#include <sched.h>
+
+static inline
+int urcu_sched_getcpu(void)
+{
+       return sched_getcpu();
+}
+#elif defined(HAVE_GETCPUID)
+#include <sys/processor.h>
+
+static inline
+int urcu_sched_getcpu(void)
+{
+       return (int) getcpuid();
+}
+#else
+
+static inline
+int urcu_sched_getcpu(void)
+{
+        return -1;
+}
+#endif
+
+#endif /* _COMPAT_GETCPU_H */
index 93631d036ac69d321289cae75e6ae610db8bb546..c2f8c84983858c70513f5e234a79382d6dd42377 100644 (file)
@@ -74,7 +74,7 @@ CC="$PTHREAD_CC"
 AC_FUNC_MALLOC
 AC_FUNC_MMAP
 AC_CHECK_FUNCS(
-       [memset gettimeofday munmap sched_getcpu strtoul sysconf gettid memeset strerror]
+       [memset gettimeofday munmap sched_getcpu getcpuid strtoul sysconf gettid memeset strerror]
 )
 
 # Check for headers
index 19767096d20b0f3e840059596a7ea0ec4673c30f..6a41b92fa5fb11e3630e56f47ef161c0e4e6ca0f 100644 (file)
 #include <sched.h>
 
 #include "config.h"
+#include "compat-getcpu.h"
 #include <urcu.h>
 #include <urcu-call-rcu.h>
 #include <urcu-flavor.h>
@@ -619,26 +620,18 @@ void free_split_items_count(struct cds_lfht *ht)
        poison_free(ht->split_count);
 }
 
-#if defined(HAVE_SCHED_GETCPU)
 static
 int ht_get_split_count_index(unsigned long hash)
 {
        int cpu;
 
        assert(split_count_mask >= 0);
-       cpu = sched_getcpu();
+       cpu = urcu_sched_getcpu();
        if (caa_unlikely(cpu < 0))
                return hash & split_count_mask;
        else
                return cpu & split_count_mask;
 }
-#else /* #if defined(HAVE_SCHED_GETCPU) */
-static
-int ht_get_split_count_index(unsigned long hash)
-{
-       return hash & split_count_mask;
-}
-#endif /* #else #if defined(HAVE_SCHED_GETCPU) */
 
 static
 void ht_count_add(struct cds_lfht *ht, unsigned long size, unsigned long hash)
index d33c731ad1e9eae6437ae95595ecf0c825f3e6e8..65f63ee51670ae73b9c8ead9869554e4f8f35a82 100644 (file)
@@ -36,6 +36,7 @@
 #include <sched.h>
 
 #include "config.h"
+#include "compat-getcpu.h"
 #include "urcu/wfcqueue.h"
 #include "urcu-call-rcu.h"
 #include "urcu-pointer.h"
@@ -106,23 +107,7 @@ static struct call_rcu_data *default_call_rcu_data;
  * CPUs rather than only to specific threads.
  */
 
-#ifdef HAVE_SCHED_GETCPU
-
-static int urcu_sched_getcpu(void)
-{
-       return sched_getcpu();
-}
-
-#else /* #ifdef HAVE_SCHED_GETCPU */
-
-static int urcu_sched_getcpu(void)
-{
-       return -1;
-}
-
-#endif /* #else #ifdef HAVE_SCHED_GETCPU */
-
-#if defined(HAVE_SYSCONF) && defined(HAVE_SCHED_GETCPU)
+#if defined(HAVE_SYSCONF) && (defined(HAVE_SCHED_GETCPU) || defined(HAVE_GETCPUID))
 
 /*
  * Pointer to array of pointers to per-CPU call_rcu_data structures
This page took 0.029491 seconds and 4 git commands to generate.