Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/bin/ergo_i586.c
32285 views
/*1* Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include "ergo.h"2627static unsigned long physical_processors(void);2829#ifdef __solaris__3031/*32* A utility method for asking the CPU about itself.33* There's a corresponding version of linux-i58634* because the compilers are different.35*/36static void37get_cpuid(uint32_t arg,38uint32_t* eaxp,39uint32_t* ebxp,40uint32_t* ecxp,41uint32_t* edxp) {42#ifdef _LP6443asm(44/* rbx is a callee-saved register */45" movq %rbx, %r11 \n"46/* rdx and rcx are 3rd and 4th argument registers */47" movq %rdx, %r10 \n"48" movq %rcx, %r9 \n"49" movl %edi, %eax \n"50" cpuid \n"51" movl %eax, (%rsi)\n"52" movl %ebx, (%r10)\n"53" movl %ecx, (%r9) \n"54" movl %edx, (%r8) \n"55/* Restore rbx */56" movq %r11, %rbx");57#else58/* EBX is a callee-saved register */59asm(" pushl %ebx");60/* Need ESI for storing through arguments */61asm(" pushl %esi");62asm(" movl 8(%ebp), %eax \n"63" cpuid \n"64" movl 12(%ebp), %esi \n"65" movl %eax, (%esi) \n"66" movl 16(%ebp), %esi \n"67" movl %ebx, (%esi) \n"68" movl 20(%ebp), %esi \n"69" movl %ecx, (%esi) \n"70" movl 24(%ebp), %esi \n"71" movl %edx, (%esi) ");72/* Restore ESI and EBX */73asm(" popl %esi");74/* Restore EBX */75asm(" popl %ebx");76#endif /* LP64 */77}7879/* The definition of a server-class machine for solaris-i586/amd64 */80jboolean81ServerClassMachineImpl(void) {82jboolean result = JNI_FALSE;83/* How big is a server class machine? */84const unsigned long server_processors = 2UL;85const uint64_t server_memory = 2UL * GB;86/*87* We seem not to get our full complement of memory.88* We allow some part (1/8?) of the memory to be "missing",89* based on the sizes of DIMMs, and maybe graphics cards.90*/91const uint64_t missing_memory = 256UL * MB;92const uint64_t actual_memory = physical_memory();9394/* Is this a server class machine? */95if (actual_memory >= (server_memory - missing_memory)) {96const unsigned long actual_processors = physical_processors();97if (actual_processors >= server_processors) {98result = JNI_TRUE;99}100}101JLI_TraceLauncher("solaris_" LIBARCHNAME "_ServerClassMachine: %s\n",102(result == JNI_TRUE ? "true" : "false"));103return result;104}105106#endif /* __solaris__ */107108#ifdef __linux__109110/*111* A utility method for asking the CPU about itself.112* There's a corresponding version of solaris-i586113* because the compilers are different.114*/115static void116get_cpuid(uint32_t arg,117uint32_t* eaxp,118uint32_t* ebxp,119uint32_t* ecxp,120uint32_t* edxp) {121#ifdef _LP64122__asm__ volatile (/* Instructions */123" movl %4, %%eax \n"124" cpuid \n"125" movl %%eax, (%0)\n"126" movl %%ebx, (%1)\n"127" movl %%ecx, (%2)\n"128" movl %%edx, (%3)\n"129: /* Outputs */130: /* Inputs */131"r" (eaxp),132"r" (ebxp),133"r" (ecxp),134"r" (edxp),135"r" (arg)136: /* Clobbers */137"%rax", "%rbx", "%rcx", "%rdx", "memory"138);139#else /* _LP64 */140uint32_t value_of_eax = 0;141uint32_t value_of_ebx = 0;142uint32_t value_of_ecx = 0;143uint32_t value_of_edx = 0;144__asm__ volatile (/* Instructions */145/* ebx is callee-save, so push it */146" pushl %%ebx \n"147" movl %4, %%eax \n"148" cpuid \n"149" movl %%eax, %0 \n"150" movl %%ebx, %1 \n"151" movl %%ecx, %2 \n"152" movl %%edx, %3 \n"153/* restore ebx */154" popl %%ebx \n"155156: /* Outputs */157"=m" (value_of_eax),158"=m" (value_of_ebx),159"=m" (value_of_ecx),160"=m" (value_of_edx)161: /* Inputs */162"m" (arg)163: /* Clobbers */164"%eax", "%ecx", "%edx"165);166*eaxp = value_of_eax;167*ebxp = value_of_ebx;168*ecxp = value_of_ecx;169*edxp = value_of_edx;170#endif /* _LP64 */171}172173/* The definition of a server-class machine for linux-i586 */174jboolean175ServerClassMachineImpl(void) {176jboolean result = JNI_FALSE;177/* How big is a server class machine? */178const unsigned long server_processors = 2UL;179const uint64_t server_memory = 2UL * GB;180/*181* We seem not to get our full complement of memory.182* We allow some part (1/8?) of the memory to be "missing",183* based on the sizes of DIMMs, and maybe graphics cards.184*/185const uint64_t missing_memory = 256UL * MB;186const uint64_t actual_memory = physical_memory();187188/* Is this a server class machine? */189if (actual_memory >= (server_memory - missing_memory)) {190const unsigned long actual_processors = physical_processors();191if (actual_processors >= server_processors) {192result = JNI_TRUE;193}194}195JLI_TraceLauncher("linux_" LIBARCHNAME "_ServerClassMachine: %s\n",196(result == JNI_TRUE ? "true" : "false"));197return result;198}199#endif /* __linux__ */200201/*202* Routines shared by solaris-i586 and linux-i586.203*/204205enum HyperThreadingSupport_enum {206hts_supported = 1,207hts_too_soon_to_tell = 0,208hts_not_supported = -1,209hts_not_pentium4 = -2,210hts_not_intel = -3211};212typedef enum HyperThreadingSupport_enum HyperThreadingSupport;213214/* Determine if hyperthreading is supported */215static HyperThreadingSupport216hyperthreading_support(void) {217HyperThreadingSupport result = hts_too_soon_to_tell;218/* Bits 11 through 8 is family processor id */219# define FAMILY_ID_SHIFT 8220# define FAMILY_ID_MASK 0xf221/* Bits 23 through 20 is extended family processor id */222# define EXT_FAMILY_ID_SHIFT 20223# define EXT_FAMILY_ID_MASK 0xf224/* Pentium 4 family processor id */225# define PENTIUM4_FAMILY_ID 0xf226/* Bit 28 indicates Hyper-Threading Technology support */227# define HT_BIT_SHIFT 28228# define HT_BIT_MASK 1229uint32_t vendor_id[3] = { 0U, 0U, 0U };230uint32_t value_of_eax = 0U;231uint32_t value_of_edx = 0U;232uint32_t dummy = 0U;233234/* Yes, this is supposed to be [0], [2], [1] */235get_cpuid(0, &dummy, &vendor_id[0], &vendor_id[2], &vendor_id[1]);236JLI_TraceLauncher("vendor: %c %c %c %c %c %c %c %c %c %c %c %c \n",237((vendor_id[0] >> 0) & 0xff),238((vendor_id[0] >> 8) & 0xff),239((vendor_id[0] >> 16) & 0xff),240((vendor_id[0] >> 24) & 0xff),241((vendor_id[1] >> 0) & 0xff),242((vendor_id[1] >> 8) & 0xff),243((vendor_id[1] >> 16) & 0xff),244((vendor_id[1] >> 24) & 0xff),245((vendor_id[2] >> 0) & 0xff),246((vendor_id[2] >> 8) & 0xff),247((vendor_id[2] >> 16) & 0xff),248((vendor_id[2] >> 24) & 0xff));249get_cpuid(1, &value_of_eax, &dummy, &dummy, &value_of_edx);250JLI_TraceLauncher("value_of_eax: 0x%x value_of_edx: 0x%x\n",251value_of_eax, value_of_edx);252if ((((value_of_eax >> FAMILY_ID_SHIFT) & FAMILY_ID_MASK) == PENTIUM4_FAMILY_ID) ||253(((value_of_eax >> EXT_FAMILY_ID_SHIFT) & EXT_FAMILY_ID_MASK) != 0)) {254if ((((vendor_id[0] >> 0) & 0xff) == 'G') &&255(((vendor_id[0] >> 8) & 0xff) == 'e') &&256(((vendor_id[0] >> 16) & 0xff) == 'n') &&257(((vendor_id[0] >> 24) & 0xff) == 'u') &&258(((vendor_id[1] >> 0) & 0xff) == 'i') &&259(((vendor_id[1] >> 8) & 0xff) == 'n') &&260(((vendor_id[1] >> 16) & 0xff) == 'e') &&261(((vendor_id[1] >> 24) & 0xff) == 'I') &&262(((vendor_id[2] >> 0) & 0xff) == 'n') &&263(((vendor_id[2] >> 8) & 0xff) == 't') &&264(((vendor_id[2] >> 16) & 0xff) == 'e') &&265(((vendor_id[2] >> 24) & 0xff) == 'l')) {266if (((value_of_edx >> HT_BIT_SHIFT) & HT_BIT_MASK) == HT_BIT_MASK) {267JLI_TraceLauncher("Hyperthreading supported\n");268result = hts_supported;269} else {270JLI_TraceLauncher("Hyperthreading not supported\n");271result = hts_not_supported;272}273} else {274JLI_TraceLauncher("Not GenuineIntel\n");275result = hts_not_intel;276}277} else {278JLI_TraceLauncher("not Pentium 4 or extended\n");279result = hts_not_pentium4;280}281return result;282}283284/* Determine how many logical processors there are per CPU */285static unsigned int286logical_processors_per_package(void) {287/*288* After CPUID with EAX==1, register EBX bits 23 through 16289* indicate the number of logical processors per package290*/291# define NUM_LOGICAL_SHIFT 16292# define NUM_LOGICAL_MASK 0xff293unsigned int result = 1U;294const HyperThreadingSupport hyperthreading = hyperthreading_support();295296if (hyperthreading == hts_supported) {297uint32_t value_of_ebx = 0U;298uint32_t dummy = 0U;299300get_cpuid(1, &dummy, &value_of_ebx, &dummy, &dummy);301result = (value_of_ebx >> NUM_LOGICAL_SHIFT) & NUM_LOGICAL_MASK;302JLI_TraceLauncher("logical processors per package: %u\n", result);303}304return result;305}306307/* Compute the number of physical processors, not logical processors */308static unsigned long309physical_processors(void) {310const long sys_processors = sysconf(_SC_NPROCESSORS_CONF);311unsigned long result = sys_processors;312313JLI_TraceLauncher("sysconf(_SC_NPROCESSORS_CONF): %lu\n", sys_processors);314if (sys_processors > 1) {315unsigned int logical_processors = logical_processors_per_package();316if (logical_processors > 1) {317result = (unsigned long) sys_processors / logical_processors;318}319}320JLI_TraceLauncher("physical processors: %lu\n", result);321return result;322}323324325