From a47dd11cc003c264dccfa9541e7974690e724037 Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Fri, 2 Oct 2015 15:37:55 -0400 Subject: [PATCH] Port: Add Solaris getcpu support Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- Makefile.am | 2 +- compat-getcpu.h | 51 ++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 2 +- rculfhash.c | 11 ++-------- urcu-call-rcu-impl.h | 19 ++--------------- 5 files changed, 57 insertions(+), 28 deletions(-) create mode 100644 compat-getcpu.h diff --git a/Makefile.am b/Makefile.am index f41e335..672beec 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 index 0000000..863c80a --- /dev/null +++ b/compat-getcpu.h @@ -0,0 +1,51 @@ +#ifndef _COMPAT_GETCPU_H +#define _COMPAT_GETCPU_H + +/* + * compat-getcpu.h + * + * Copyright (c) 2015 Michael Jeanson + * + * 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 + +#if defined(HAVE_SCHED_GETCPU) +#include + +static inline +int urcu_sched_getcpu(void) +{ + return sched_getcpu(); +} +#elif defined(HAVE_GETCPUID) +#include + +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 */ diff --git a/configure.ac b/configure.ac index 93631d0..c2f8c84 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/rculfhash.c b/rculfhash.c index 1976709..6a41b92 100644 --- a/rculfhash.c +++ b/rculfhash.c @@ -266,6 +266,7 @@ #include #include "config.h" +#include "compat-getcpu.h" #include #include #include @@ -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) diff --git a/urcu-call-rcu-impl.h b/urcu-call-rcu-impl.h index d33c731..65f63ee 100644 --- a/urcu-call-rcu-impl.h +++ b/urcu-call-rcu-impl.h @@ -36,6 +36,7 @@ #include #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 -- 2.34.1