This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH 02/20] libcpu-rt-c/x86: Add cacheinfo
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: libc-alpha at sourceware dot org
- Date: Tue, 12 Jun 2018 15:19:21 -0700
- Subject: [PATCH 02/20] libcpu-rt-c/x86: Add cacheinfo
- References: <20180612221939.19545-1-hjl.tools@gmail.com>
Add cacheinfo to libcpu-rt-c, excluding __cache_sysconf. Don't drag
in <assert.h> in libcpu-rt-c. We want to keep libcpu-rt-c as lean as
possible and still have access to CPU cache information.
* sysdeps/x86/Makefile (libcpu-rt-c-sysdep_routines): Add
cacheinfo.
* sysdeps/x86/cacheinfo.c: Include <assert.h> only for libc.
(assert): [IS_IN (libcpu_rt_c)]: New function.
(__cache_sysconf): Make it libc only.
---
sysdeps/x86/Makefile | 4 ++++
sysdeps/x86/cacheinfo.c | 19 +++++++++++++++++--
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
index d25d6f0ae4..63ddaf03da 100644
--- a/sysdeps/x86/Makefile
+++ b/sysdeps/x86/Makefile
@@ -1,3 +1,7 @@
+ifeq ($(subdir),cpu-rt-c)
+libcpu-rt-c-sysdep_routines += cacheinfo
+endif
+
ifeq ($(subdir),csu)
gen-as-const-headers += cpu-features-offsets.sym
endif
diff --git a/sysdeps/x86/cacheinfo.c b/sysdeps/x86/cacheinfo.c
index b9444ddd52..b23d2791b4 100644
--- a/sysdeps/x86/cacheinfo.c
+++ b/sysdeps/x86/cacheinfo.c
@@ -16,9 +16,22 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
-#if IS_IN (libc)
+#if IS_IN (libc) || IS_IN (libcpu_rt_c)
-#include <assert.h>
+#if IS_IN (libcpu_rt_c)
+# include <abort-instr.h>
+
+__attribute__ ((__noreturn__))
+static inline void
+assert (int expr __attribute__ ((unused)))
+{
+ /* This shouldn't happen in the CPU run-time library. */
+ ABORT_INSTRUCTION;
+ __builtin_unreachable ();
+}
+#else
+# include <assert.h>
+#endif
#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
@@ -436,6 +449,7 @@ handle_amd (int name)
}
+# if IS_IN (libc)
/* Get the value of the system variable NAME. */
long int
attribute_hidden
@@ -454,6 +468,7 @@ __cache_sysconf (int name)
/* CPU not known, we have no information. */
return 0;
}
+# endif
/* Data cache size for use in memory and string routines, typically
--
2.17.1