riscv: Fix feenvupdate with FE_DFL_ENV (BZ 31022)
[glibc.git] / sysdeps / x86 / cacheinfo.c
blob3d5e77d6eef0a6d2117717b6c90c4613224b4fa7
1 /* x86 cache info.
2 Copyright (C) 2003-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #if IS_IN (libc)
21 #include <unistd.h>
22 #include <ldsodefs.h>
24 /* Get the value of the system variable NAME. */
25 long int
26 attribute_hidden
27 __cache_sysconf (int name)
29 const struct cpu_features *cpu_features = __get_cpu_features ();
30 switch (name)
32 case _SC_LEVEL1_ICACHE_SIZE:
33 return cpu_features->level1_icache_size;
35 case _SC_LEVEL1_ICACHE_LINESIZE:
36 return cpu_features->level1_icache_linesize;
38 case _SC_LEVEL1_DCACHE_SIZE:
39 return cpu_features->level1_dcache_size;
41 case _SC_LEVEL1_DCACHE_ASSOC:
42 return cpu_features->level1_dcache_assoc;
44 case _SC_LEVEL1_DCACHE_LINESIZE:
45 return cpu_features->level1_dcache_linesize;
47 case _SC_LEVEL2_CACHE_SIZE:
48 return cpu_features->level2_cache_size;
50 case _SC_LEVEL2_CACHE_ASSOC:
51 return cpu_features->level2_cache_assoc;
53 case _SC_LEVEL2_CACHE_LINESIZE:
54 return cpu_features->level2_cache_linesize;
56 case _SC_LEVEL3_CACHE_SIZE:
57 return cpu_features->level3_cache_size;
59 case _SC_LEVEL3_CACHE_ASSOC:
60 return cpu_features->level3_cache_assoc;
62 case _SC_LEVEL3_CACHE_LINESIZE:
63 return cpu_features->level3_cache_linesize;
65 case _SC_LEVEL4_CACHE_SIZE:
66 return cpu_features->level4_cache_size;
68 default:
69 break;
71 return -1;
74 # ifdef SHARED
75 /* NB: In libc.a, cacheinfo.h is included in libc-start.c. In libc.so,
76 cacheinfo.h is included here and call init_cacheinfo by initializing
77 a dummy function pointer via IFUNC relocation after CPU features in
78 ld.so have been initialized by DL_PLATFORM_INIT or IFUNC relocation. */
79 # include <cacheinfo.h>
80 # include <ifunc-init.h>
82 extern void __x86_cacheinfo (void) attribute_hidden;
83 void (*const __x86_cacheinfo_p) (void) attribute_hidden
84 = __x86_cacheinfo;
86 __ifunc (__x86_cacheinfo, __x86_cacheinfo, NULL, void, init_cacheinfo);
87 # endif
88 #endif