]>
Commit | Line | Data |
---|---|---|
0f09154c | 1 | /* x86 cache info. |
dff8da6b | 2 | Copyright (C) 2020-2024 Free Software Foundation, Inc. |
0f09154c L |
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 | |
16 | License along with the GNU C Library; if not, see | |
17 | <https://www.gnu.org/licenses/>. */ | |
18 | ||
19 | #include <assert.h> | |
20 | #include <unistd.h> | |
2d651eb9 L |
21 | #include <cpuid.h> |
22 | #include <cpu-features.h> | |
0f09154c | 23 | |
33237fe8 AZN |
24 | #define TUNABLE_NAMESPACE cpu |
25 | #include <unistd.h> /* Get STDOUT_FILENO for _dl_printf. */ | |
26 | #include <elf/dl-tunables.h> | |
2d651eb9 L |
27 | |
28 | #if IS_IN (libc) | |
0f09154c L |
29 | /* Data cache size for use in memory and string routines, typically |
30 | L1 size, rounded to multiple of 256 bytes. */ | |
31 | long int __x86_data_cache_size_half attribute_hidden = 32 * 1024 / 2; | |
32 | long int __x86_data_cache_size attribute_hidden = 32 * 1024; | |
0f09154c L |
33 | /* Shared cache size for use in memory and string routines, typically |
34 | L2 or L3 size, rounded to multiple of 256 bytes. */ | |
35 | long int __x86_shared_cache_size_half attribute_hidden = 1024 * 1024 / 2; | |
36 | long int __x86_shared_cache_size attribute_hidden = 1024 * 1024; | |
0f09154c L |
37 | |
38 | /* Threshold to use non temporal store. */ | |
39 | long int __x86_shared_non_temporal_threshold attribute_hidden; | |
40 | ||
41 | /* Threshold to use Enhanced REP MOVSB. */ | |
42 | long int __x86_rep_movsb_threshold attribute_hidden = 2048; | |
43 | ||
44 | /* Threshold to use Enhanced REP STOSB. */ | |
45 | long int __x86_rep_stosb_threshold attribute_hidden = 2048; | |
46 | ||
6e02b3e9 SK |
47 | /* Threshold to stop using Enhanced REP MOVSB. */ |
48 | long int __x86_rep_movsb_stop_threshold attribute_hidden; | |
49 | ||
91cc803d L |
50 | /* A bit-wise OR of string/memory requirements for optimal performance |
51 | e.g. X86_STRING_CONTROL_AVOID_SHORT_DISTANCE_REP_MOVSB. These bits | |
52 | are used at runtime to tune implementation behavior. */ | |
53 | int __x86_string_control attribute_hidden; | |
54 | ||
0f09154c L |
55 | static void |
56 | init_cacheinfo (void) | |
57 | { | |
0f09154c | 58 | const struct cpu_features *cpu_features = __get_cpu_features (); |
2d651eb9 | 59 | long int data = cpu_features->data_cache_size; |
2d651eb9 L |
60 | /* Round data cache size to multiple of 256 bytes. */ |
61 | data = data & ~255L; | |
c242fcce AJ |
62 | if (data > 0) |
63 | { | |
64 | __x86_data_cache_size_half = data / 2; | |
65 | __x86_data_cache_size = data; | |
66 | } | |
2d651eb9 L |
67 | |
68 | long int shared = cpu_features->shared_cache_size; | |
2d651eb9 L |
69 | /* Round shared cache size to multiple of 256 bytes. */ |
70 | shared = shared & ~255L; | |
c242fcce AJ |
71 | if (shared > 0) |
72 | { | |
73 | __x86_shared_cache_size_half = shared / 2; | |
74 | __x86_shared_cache_size = shared; | |
75 | } | |
0f09154c | 76 | |
0f09154c | 77 | __x86_shared_non_temporal_threshold |
2d651eb9 | 78 | = cpu_features->non_temporal_threshold; |
0f09154c | 79 | |
2d651eb9 | 80 | __x86_rep_movsb_threshold = cpu_features->rep_movsb_threshold; |
0f09154c | 81 | __x86_rep_stosb_threshold = cpu_features->rep_stosb_threshold; |
6e02b3e9 | 82 | __x86_rep_movsb_stop_threshold = cpu_features->rep_movsb_stop_threshold; |
91cc803d L |
83 | |
84 | if (CPU_FEATURES_ARCH_P (cpu_features, Avoid_Short_Distance_REP_MOVSB)) | |
85 | __x86_string_control | |
86 | |= X86_STRING_CONTROL_AVOID_SHORT_DISTANCE_REP_MOVSB; | |
0f09154c | 87 | } |
2d651eb9 | 88 | #endif |