]>
Commit | Line | Data |
---|---|---|
0f09154c | 1 | /* x86 cache info. |
581c785b | 2 | Copyright (C) 2003-2022 Free Software Foundation, Inc. |
bfe6f5fa UD |
3 | This file is part of the GNU C Library. |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
bfe6f5fa | 18 | |
9c450f6f L |
19 | #if IS_IN (libc) |
20 | ||
bfe6f5fa | 21 | #include <unistd.h> |
0f09154c | 22 | #include <ldsodefs.h> |
a98dc92d | 23 | |
bfe6f5fa UD |
24 | /* Get the value of the system variable NAME. */ |
25 | long int | |
26 | attribute_hidden | |
27 | __cache_sysconf (int name) | |
28 | { | |
7c1d7225 | 29 | const struct cpu_features *cpu_features = __get_cpu_features (); |
2d651eb9 L |
30 | switch (name) |
31 | { | |
32 | case _SC_LEVEL1_ICACHE_SIZE: | |
33 | return cpu_features->level1_icache_size; | |
7c1d7225 | 34 | |
f53ffc9b L |
35 | case _SC_LEVEL1_ICACHE_LINESIZE: |
36 | return cpu_features->level1_icache_linesize; | |
37 | ||
2d651eb9 L |
38 | case _SC_LEVEL1_DCACHE_SIZE: |
39 | return cpu_features->level1_dcache_size; | |
bfe6f5fa | 40 | |
2d651eb9 L |
41 | case _SC_LEVEL1_DCACHE_ASSOC: |
42 | return cpu_features->level1_dcache_assoc; | |
bfe6f5fa | 43 | |
2d651eb9 L |
44 | case _SC_LEVEL1_DCACHE_LINESIZE: |
45 | return cpu_features->level1_dcache_linesize; | |
a98dc92d | 46 | |
2d651eb9 L |
47 | case _SC_LEVEL2_CACHE_SIZE: |
48 | return cpu_features->level2_cache_size; | |
bfe6f5fa | 49 | |
2d651eb9 L |
50 | case _SC_LEVEL2_CACHE_ASSOC: |
51 | return cpu_features->level2_cache_assoc; | |
52 | ||
53 | case _SC_LEVEL2_CACHE_LINESIZE: | |
54 | return cpu_features->level2_cache_linesize; | |
55 | ||
56 | case _SC_LEVEL3_CACHE_SIZE: | |
57 | return cpu_features->level3_cache_size; | |
58 | ||
59 | case _SC_LEVEL3_CACHE_ASSOC: | |
60 | return cpu_features->level3_cache_assoc; | |
61 | ||
62 | case _SC_LEVEL3_CACHE_LINESIZE: | |
63 | return cpu_features->level3_cache_linesize; | |
64 | ||
65 | case _SC_LEVEL4_CACHE_SIZE: | |
66 | return cpu_features->level4_cache_size; | |
67 | ||
68 | default: | |
69 | break; | |
70 | } | |
71 | return -1; | |
bfe6f5fa UD |
72 | } |
73 | ||
0f09154c L |
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> | |
bfe6f5fa | 81 | |
0f09154c | 82 | extern void __x86_cacheinfo (void) attribute_hidden; |
31f64887 | 83 | void (*const __x86_cacheinfo_p) (void) attribute_hidden |
0f09154c | 84 | = __x86_cacheinfo; |
a98dc92d | 85 | |
0f09154c | 86 | __ifunc (__x86_cacheinfo, __x86_cacheinfo, NULL, void, init_cacheinfo); |
3f4b61a0 | 87 | # endif |
9c450f6f | 88 | #endif |