2.9
[glibc/nacl-glibc.git] / sysdeps / unix / sysv / linux / alpha / sysconf.c
blob3e5b4ee85ff0283f91c53bcd73a7448e77c8b34f
1 /* Copyright (C) 2004 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
19 #include <assert.h>
20 #include <stdbool.h>
21 #include <stdlib.h>
22 #include <unistd.h>
25 static long int linux_sysconf (int name);
27 #define CSHAPE(totalsize, linesize, assoc) \
28 ((totalsize & ~0xff) | (linesize << 4) | assoc)
30 extern long __libc_alpha_cache_shape[4];
32 static inline unsigned long
33 implver (void)
35 unsigned long i;
36 #if __GNUC_PREREQ(3,3)
37 i = __builtin_alpha_implver ();
38 #else
39 asm ("implver %0" : "=r" (i));
40 #endif
41 return i;
44 static inline unsigned long
45 amask (unsigned long x)
47 unsigned long r;
48 #if __GNUC_PREREQ(3,3)
49 r = __builtin_alpha_amask (x);
50 #else
51 asm ("amask %1,%0" : "=r"(r) : "Ir"(x));
52 #endif
53 return r;
56 /* Get the value of the system variable NAME. */
57 long int
58 __sysconf (int name)
60 long shape, index;
62 /* We only handle the cache information here (for now). */
63 if (name < _SC_LEVEL1_ICACHE_SIZE || name > _SC_LEVEL4_CACHE_LINESIZE)
64 return linux_sysconf (name);
66 /* No Alpha has L4 caches. */
67 if (name >= _SC_LEVEL4_CACHE_SIZE)
68 return -1;
70 index = (name - _SC_LEVEL1_ICACHE_SIZE) / 3;
71 shape = __libc_alpha_cache_shape[index];
72 if (shape == -2)
74 long shape_l1i, shape_l1d, shape_l2, shape_l3 = -1;
76 /* ??? In the cases below for which we do not know L1 cache sizes,
77 we could do timings to measure sizes. But for the Bcache, it's
78 generally big enough that (without additional help) TLB effects
79 get in the way. We'd either need to be able to allocate large
80 pages or have the kernel do the timings from KSEG. Fortunately,
81 kernels beginning with 2.6.5 will pass us this info in auxvec. */
83 switch (implver())
85 case 0: /* EV4 */
86 /* EV4/LCA45 had 8k L1 caches; EV45 had 16k L1 caches. */
87 /* EV4/EV45 had 128k to 16M 32-byte direct Bcache. LCA45
88 had 64k to 8M 8-byte direct Bcache. Can't tell. */
89 shape_l1i = shape_l1d = shape_l2 = CSHAPE (0, 5, 1);
90 break;
92 case 1: /* EV5 */
93 if (amask (1 << 8))
95 /* MAX insns not present; either EV5 or EV56. */
96 shape_l1i = shape_l1d = CSHAPE(8*1024, 5, 1);
97 /* ??? L2 and L3 *can* be configured as 32-byte line. */
98 shape_l2 = CSHAPE (96*1024, 6, 3);
99 /* EV5/EV56 has 1M to 16M Bcache. */
100 shape_l3 = CSHAPE (0, 6, 1);
102 else
104 /* MAX insns present; either PCA56 or PCA57. */
105 /* PCA56 had 16k 64-byte cache; PCA57 had 32k Icache. */
106 /* PCA56 had 8k 64-byte cache; PCA57 had 16k Dcache. */
107 /* PCA5[67] had 512k to 4M Bcache. */
108 shape_l1i = shape_l1d = shape_l2 = CSHAPE (0, 6, 1);
110 break;
112 case 2: /* EV6 */
113 shape_l1i = shape_l1d = CSHAPE(64*1024, 6, 2);
114 /* EV6/EV67/EV68* had 1M to 16M Bcache. */
115 shape_l2 = CSHAPE (0, 6, 1);
116 break;
118 case 3: /* EV7 */
119 shape_l1i = shape_l1d = CSHAPE(64*1024, 6, 2);
120 shape_l2 = CSHAPE(7*1024*1024/4, 6, 7);
121 break;
123 default:
124 shape_l1i = shape_l1d = shape_l2 = 0;
125 break;
128 __libc_alpha_cache_shape[0] = shape_l1i;
129 __libc_alpha_cache_shape[1] = shape_l1d;
130 __libc_alpha_cache_shape[2] = shape_l2;
131 __libc_alpha_cache_shape[3] = shape_l3;
132 shape = __libc_alpha_cache_shape[index];
135 if (shape <= 0)
136 return shape;
138 switch (name % 3)
140 case 0: /* total size */
141 return shape & -0x100;
142 case 1: /* associativity */
143 return shape & 0xf;
144 default: /* line size */
145 return 1L << ((shape >> 4) & 0xf);
149 /* Now the generic Linux version. */
150 #undef __sysconf
151 #define __sysconf static linux_sysconf
152 #include "../sysconf.c"