jdk/src/solaris/bin/ergo_i586.c
author ksrini
Fri, 27 Sep 2013 16:29:44 -0700
changeset 20201 50cc2d25a60b
parent 5506 202f599c92aa
permissions -rw-r--r--
8020552: [launcher] changes to support removal of Solaris 32-bit distribution 8023495: [infra] create 64-bit solaris bits with symlinks Reviewed-by: ihse, tbell, dholmes, darcy, alanb, erikj, sla, martin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include "ergo.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
static unsigned long physical_processors(void);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#ifdef __solaris__
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * A utility method for asking the CPU about itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * There's a corresponding version of linux-i586
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * because the compilers are different.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
get_cpuid(uint32_t arg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
          uint32_t* eaxp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
          uint32_t* ebxp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
          uint32_t* ecxp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
          uint32_t* edxp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#ifdef _LP64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
  asm(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
  /* rbx is a callee-saved register */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
      " movq    %rbx, %r11  \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
  /* rdx and rcx are 3rd and 4th argument registers */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
      " movq    %rdx, %r10  \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
      " movq    %rcx, %r9   \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
      " movl    %edi, %eax  \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
      " cpuid               \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
      " movl    %eax, (%rsi)\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
      " movl    %ebx, (%r10)\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
      " movl    %ecx, (%r9) \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
      " movl    %edx, (%r8) \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
  /* Restore rbx */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
      " movq    %r11, %rbx");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
  /* EBX is a callee-saved register */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
  asm(" pushl   %ebx");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
  /* Need ESI for storing through arguments */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
  asm(" pushl   %esi");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
  asm(" movl    8(%ebp), %eax   \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
      " cpuid                   \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
      " movl    12(%ebp), %esi  \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
      " movl    %eax, (%esi)    \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
      " movl    16(%ebp), %esi  \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
      " movl    %ebx, (%esi)    \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
      " movl    20(%ebp), %esi  \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
      " movl    %ecx, (%esi)    \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
      " movl    24(%ebp), %esi  \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
      " movl    %edx, (%esi)      ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
  /* Restore ESI and EBX */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
  asm(" popl    %esi");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
  /* Restore EBX */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
  asm(" popl    %ebx");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
#endif /* LP64 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
/* The definition of a server-class machine for solaris-i586/amd64 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
ServerClassMachineImpl(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
  jboolean            result            = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
  /* How big is a server class machine? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
  const unsigned long server_processors = 2UL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
  const uint64_t      server_memory     = 2UL * GB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
  /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
   * We seem not to get our full complement of memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
   *     We allow some part (1/8?) of the memory to be "missing",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
   *     based on the sizes of DIMMs, and maybe graphics cards.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
  const uint64_t      missing_memory    = 256UL * MB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
  const uint64_t      actual_memory     = physical_memory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
  /* Is this a server class machine? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
  if (actual_memory >= (server_memory - missing_memory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    const unsigned long actual_processors = physical_processors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    if (actual_processors >= server_processors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
      result = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
  JLI_TraceLauncher("solaris_" LIBARCHNAME "_ServerClassMachine: %s\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
           (result == JNI_TRUE ? "true" : "false"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
  return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
#endif /* __solaris__ */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * A utility method for asking the CPU about itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * There's a corresponding version of solaris-i586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * because the compilers are different.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
get_cpuid(uint32_t arg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
          uint32_t* eaxp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
          uint32_t* ebxp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
          uint32_t* ecxp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
          uint32_t* edxp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
#ifdef _LP64
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
  __asm__ volatile (/* Instructions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                    "   movl    %4, %%eax  \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    "   cpuid              \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    "   movl    %%eax, (%0)\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                    "   movl    %%ebx, (%1)\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    "   movl    %%ecx, (%2)\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                    "   movl    %%edx, (%3)\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                    : /* Outputs */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                    : /* Inputs */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                    "r" (eaxp),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                    "r" (ebxp),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    "r" (ecxp),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    "r" (edxp),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                    "r" (arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                    : /* Clobbers */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                    "%rax", "%rbx", "%rcx", "%rdx", "memory"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                    );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
#else /* _LP64 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
  uint32_t value_of_eax = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
  uint32_t value_of_ebx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
  uint32_t value_of_ecx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
  uint32_t value_of_edx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
  __asm__ volatile (/* Instructions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                        /* ebx is callee-save, so push it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                    "   pushl   %%ebx      \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                    "   movl    %4, %%eax  \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                    "   cpuid              \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                    "   movl    %%eax, %0  \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                    "   movl    %%ebx, %1  \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                    "   movl    %%ecx, %2  \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    "   movl    %%edx, %3  \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                        /* restore ebx */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                    "   popl    %%ebx      \n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                    : /* Outputs */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                    "=m" (value_of_eax),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                    "=m" (value_of_ebx),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                    "=m" (value_of_ecx),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                    "=m" (value_of_edx)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                    : /* Inputs */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                    "m" (arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    : /* Clobbers */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    "%eax", "%ecx", "%edx"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
  *eaxp = value_of_eax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
  *ebxp = value_of_ebx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
  *ecxp = value_of_ecx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
  *edxp = value_of_edx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
#endif /* _LP64 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
/* The definition of a server-class machine for linux-i586 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
ServerClassMachineImpl(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
  jboolean            result            = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
  /* How big is a server class machine? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
  const unsigned long server_processors = 2UL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
  const uint64_t      server_memory     = 2UL * GB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
  /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
   * We seem not to get our full complement of memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
   *     We allow some part (1/8?) of the memory to be "missing",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
   *     based on the sizes of DIMMs, and maybe graphics cards.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
  const uint64_t      missing_memory    = 256UL * MB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
  const uint64_t      actual_memory     = physical_memory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
  /* Is this a server class machine? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
  if (actual_memory >= (server_memory - missing_memory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    const unsigned long actual_processors = physical_processors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    if (actual_processors >= server_processors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
      result = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
  JLI_TraceLauncher("linux_" LIBARCHNAME "_ServerClassMachine: %s\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
           (result == JNI_TRUE ? "true" : "false"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
  return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
#endif /* __linux__ */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 * Routines shared by solaris-i586 and linux-i586.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
enum HyperThreadingSupport_enum {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
  hts_supported        =  1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
  hts_too_soon_to_tell =  0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
  hts_not_supported    = -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
  hts_not_pentium4     = -2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
  hts_not_intel        = -3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
typedef enum HyperThreadingSupport_enum HyperThreadingSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
/* Determine if hyperthreading is supported */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
static HyperThreadingSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
hyperthreading_support(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
  HyperThreadingSupport result = hts_too_soon_to_tell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
  /* Bits 11 through 8 is family processor id */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
# define FAMILY_ID_SHIFT 8
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
# define FAMILY_ID_MASK 0xf
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
  /* Bits 23 through 20 is extended family processor id */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
# define EXT_FAMILY_ID_SHIFT 20
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
# define EXT_FAMILY_ID_MASK 0xf
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
  /* Pentium 4 family processor id */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
# define PENTIUM4_FAMILY_ID 0xf
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
  /* Bit 28 indicates Hyper-Threading Technology support */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
# define HT_BIT_SHIFT 28
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
# define HT_BIT_MASK 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
  uint32_t vendor_id[3] = { 0U, 0U, 0U };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
  uint32_t value_of_eax = 0U;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
  uint32_t value_of_edx = 0U;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
  uint32_t dummy        = 0U;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
  /* Yes, this is supposed to be [0], [2], [1] */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
  get_cpuid(0, &dummy, &vendor_id[0], &vendor_id[2], &vendor_id[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
  JLI_TraceLauncher("vendor: %c %c %c %c %c %c %c %c %c %c %c %c \n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
           ((vendor_id[0] >>  0) & 0xff),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
           ((vendor_id[0] >>  8) & 0xff),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
           ((vendor_id[0] >> 16) & 0xff),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
           ((vendor_id[0] >> 24) & 0xff),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
           ((vendor_id[1] >>  0) & 0xff),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
           ((vendor_id[1] >>  8) & 0xff),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
           ((vendor_id[1] >> 16) & 0xff),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
           ((vendor_id[1] >> 24) & 0xff),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
           ((vendor_id[2] >>  0) & 0xff),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
           ((vendor_id[2] >>  8) & 0xff),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
           ((vendor_id[2] >> 16) & 0xff),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
           ((vendor_id[2] >> 24) & 0xff));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
  get_cpuid(1, &value_of_eax, &dummy, &dummy, &value_of_edx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
  JLI_TraceLauncher("value_of_eax: 0x%x  value_of_edx: 0x%x\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
           value_of_eax, value_of_edx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
  if ((((value_of_eax >> FAMILY_ID_SHIFT) & FAMILY_ID_MASK) == PENTIUM4_FAMILY_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
      (((value_of_eax >> EXT_FAMILY_ID_SHIFT) & EXT_FAMILY_ID_MASK) != 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    if ((((vendor_id[0] >>  0) & 0xff) == 'G') &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        (((vendor_id[0] >>  8) & 0xff) == 'e') &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        (((vendor_id[0] >> 16) & 0xff) == 'n') &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        (((vendor_id[0] >> 24) & 0xff) == 'u') &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        (((vendor_id[1] >>  0) & 0xff) == 'i') &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        (((vendor_id[1] >>  8) & 0xff) == 'n') &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        (((vendor_id[1] >> 16) & 0xff) == 'e') &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        (((vendor_id[1] >> 24) & 0xff) == 'I') &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        (((vendor_id[2] >>  0) & 0xff) == 'n') &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        (((vendor_id[2] >>  8) & 0xff) == 't') &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        (((vendor_id[2] >> 16) & 0xff) == 'e') &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        (((vendor_id[2] >> 24) & 0xff) == 'l')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
      if (((value_of_edx >> HT_BIT_SHIFT) & HT_BIT_MASK) == HT_BIT_MASK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        JLI_TraceLauncher("Hyperthreading supported\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        result = hts_supported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
      } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        JLI_TraceLauncher("Hyperthreading not supported\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        result = hts_not_supported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
      JLI_TraceLauncher("Not GenuineIntel\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
      result = hts_not_intel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    JLI_TraceLauncher("not Pentium 4 or extended\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    result = hts_not_pentium4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
  return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
/* Determine how many logical processors there are per CPU */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
static unsigned int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
logical_processors_per_package(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
  /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
   * After CPUID with EAX==1, register EBX bits 23 through 16
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
   * indicate the number of logical processors per package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
# define NUM_LOGICAL_SHIFT 16
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
# define NUM_LOGICAL_MASK 0xff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
  unsigned int result                        = 1U;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
  const HyperThreadingSupport hyperthreading = hyperthreading_support();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
  if (hyperthreading == hts_supported) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    uint32_t value_of_ebx = 0U;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    uint32_t dummy        = 0U;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    get_cpuid(1, &dummy, &value_of_ebx, &dummy, &dummy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    result = (value_of_ebx >> NUM_LOGICAL_SHIFT) & NUM_LOGICAL_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    JLI_TraceLauncher("logical processors per package: %u\n", result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
  return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
/* Compute the number of physical processors, not logical processors */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
static unsigned long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
physical_processors(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
  const long sys_processors = sysconf(_SC_NPROCESSORS_CONF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
  unsigned long result      = sys_processors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
  JLI_TraceLauncher("sysconf(_SC_NPROCESSORS_CONF): %lu\n", sys_processors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
  if (sys_processors > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    unsigned int logical_processors = logical_processors_per_package();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    if (logical_processors > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
      result = (unsigned long) sys_processors / logical_processors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
  JLI_TraceLauncher("physical processors: %lu\n", result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
  return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
}