Blame sysdeps/unix/sysv/linux/alpha/sysconf.c

Packit 6c4009
/* Copyright (C) 2004-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library.  If not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <assert.h>
Packit 6c4009
#include <stdbool.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
#include <unistd.h>
Packit 6c4009
Packit 6c4009
Packit 6c4009
static long int linux_sysconf (int name);
Packit 6c4009
Packit 6c4009
#define CSHAPE(totalsize, linesize, assoc) \
Packit 6c4009
  ((totalsize & ~0xff) | (linesize << 4) | assoc)
Packit 6c4009
Packit 6c4009
extern long __libc_alpha_cache_shape[4];
Packit 6c4009
Packit 6c4009
/* Get the value of the system variable NAME.  */
Packit 6c4009
long int
Packit 6c4009
__sysconf (int name)
Packit 6c4009
{
Packit 6c4009
  long shape, index;
Packit 6c4009
Packit 6c4009
  /* We only handle the cache information here (for now).  */
Packit 6c4009
  if (name < _SC_LEVEL1_ICACHE_SIZE || name > _SC_LEVEL4_CACHE_LINESIZE)
Packit 6c4009
    return linux_sysconf (name);
Packit 6c4009
Packit 6c4009
  /* No Alpha has L4 caches.  */
Packit 6c4009
  if (name >= _SC_LEVEL4_CACHE_SIZE)
Packit 6c4009
    return -1;
Packit 6c4009
Packit 6c4009
  index = (name - _SC_LEVEL1_ICACHE_SIZE) / 3;
Packit 6c4009
  shape = __libc_alpha_cache_shape[index];
Packit 6c4009
  if (shape == -2)
Packit 6c4009
    {
Packit 6c4009
      long shape_l1i, shape_l1d, shape_l2, shape_l3 = -1;
Packit 6c4009
Packit 6c4009
      /* ??? In the cases below for which we do not know L1 cache sizes,
Packit 6c4009
	 we could do timings to measure sizes.  But for the Bcache, it's
Packit 6c4009
	 generally big enough that (without additional help) TLB effects
Packit 6c4009
	 get in the way.  We'd either need to be able to allocate large
Packit 6c4009
	 pages or have the kernel do the timings from KSEG.  Fortunately,
Packit 6c4009
	 kernels beginning with 2.6.5 will pass us this info in auxvec.  */
Packit 6c4009
Packit 6c4009
      switch (__builtin_alpha_implver ())
Packit 6c4009
	{
Packit 6c4009
	case 0: /* EV4 */
Packit 6c4009
	  /* EV4/LCA45 had 8k L1 caches; EV45 had 16k L1 caches.  */
Packit 6c4009
	  /* EV4/EV45 had 128k to 16M 32-byte direct Bcache.  LCA45
Packit 6c4009
	     had 64k to 8M 8-byte direct Bcache.  Can't tell.  */
Packit 6c4009
	  shape_l1i = shape_l1d = shape_l2 = CSHAPE (0, 5, 1);
Packit 6c4009
	  break;
Packit 6c4009
Packit 6c4009
	case 1: /* EV5 */
Packit 6c4009
	  if (__builtin_alpha_amask (1 << 8))
Packit 6c4009
	    {
Packit 6c4009
	      /* MAX insns not present; either EV5 or EV56.  */
Packit 6c4009
	      shape_l1i = shape_l1d = CSHAPE(8*1024, 5, 1);
Packit 6c4009
	      /* ??? L2 and L3 *can* be configured as 32-byte line.  */
Packit 6c4009
	      shape_l2 = CSHAPE (96*1024, 6, 3);
Packit 6c4009
	      /* EV5/EV56 has 1M to 16M Bcache.  */
Packit 6c4009
	      shape_l3 = CSHAPE (0, 6, 1);
Packit 6c4009
	    }
Packit 6c4009
	  else
Packit 6c4009
	    {
Packit 6c4009
	      /* MAX insns present; either PCA56 or PCA57.  */
Packit 6c4009
	      /* PCA56 had 16k 64-byte cache; PCA57 had 32k Icache.  */
Packit 6c4009
	      /* PCA56 had 8k 64-byte cache; PCA57 had 16k Dcache.  */
Packit 6c4009
	      /* PCA5[67] had 512k to 4M Bcache.  */
Packit 6c4009
	      shape_l1i = shape_l1d = shape_l2 = CSHAPE (0, 6, 1);
Packit 6c4009
	    }
Packit 6c4009
	  break;
Packit 6c4009
Packit 6c4009
	case 2: /* EV6 */
Packit 6c4009
	  shape_l1i = shape_l1d = CSHAPE(64*1024, 6, 2);
Packit 6c4009
	  /* EV6/EV67/EV68* had 1M to 16M Bcache.  */
Packit 6c4009
	  shape_l2 = CSHAPE (0, 6, 1);
Packit 6c4009
	  break;
Packit 6c4009
Packit 6c4009
	case 3: /* EV7 */
Packit 6c4009
	  shape_l1i = shape_l1d = CSHAPE(64*1024, 6, 2);
Packit 6c4009
	  shape_l2 = CSHAPE(7*1024*1024/4, 6, 7);
Packit 6c4009
	  break;
Packit 6c4009
Packit 6c4009
	default:
Packit 6c4009
	  shape_l1i = shape_l1d = shape_l2 = 0;
Packit 6c4009
	  break;
Packit 6c4009
	}
Packit 6c4009
Packit 6c4009
      __libc_alpha_cache_shape[0] = shape_l1i;
Packit 6c4009
      __libc_alpha_cache_shape[1] = shape_l1d;
Packit 6c4009
      __libc_alpha_cache_shape[2] = shape_l2;
Packit 6c4009
      __libc_alpha_cache_shape[3] = shape_l3;
Packit 6c4009
      shape = __libc_alpha_cache_shape[index];
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (shape <= 0)
Packit 6c4009
    return shape;
Packit 6c4009
Packit 6c4009
  switch ((name - _SC_LEVEL1_ICACHE_SIZE) % 3)
Packit 6c4009
    {
Packit 6c4009
    case 0: /* total size */
Packit 6c4009
      return shape & -0x100;
Packit 6c4009
    case 1: /* associativity */
Packit 6c4009
      return shape & 0xf;
Packit 6c4009
    default: /* line size */
Packit 6c4009
      return 1L << ((shape >> 4) & 0xf);
Packit 6c4009
    }
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Now the generic Linux version.  */
Packit 6c4009
#undef __sysconf
Packit 6c4009
#define __sysconf static linux_sysconf
Packit 6c4009
#include <sysdeps/unix/sysv/linux/sysconf.c>