From 83e04215a22dbed0415f8b60d998033f165558ee Mon Sep 17 00:00:00 2001 From: Harry Yu Date: Fri, 14 Feb 2020 16:25:12 -0500 Subject: [PATCH] Add omrsysinfo_processor_disable_feature API This API is used for disabling features in OMRProcessorDesc. Issue: #4339 Signed-off-by: Harry Yu --- include_core/omrport.h | 7 +++++-- port/common/omrport.c | 1 + port/common/omrport.tdf | 9 ++++++--- port/common/omrsysinfo.c | 20 +++++++++++++++++++- port/unix/omrsysinfo.c | 20 ++++++++++++++++++++ port/win32/omrsysinfo.c | 20 ++++++++++++++++++++ 6 files changed, 71 insertions(+), 6 deletions(-) diff --git a/include_core/omrport.h b/include_core/omrport.h index 86a34c3c268..c6ca2c70e4c 100644 --- a/include_core/omrport.h +++ b/include_core/omrport.h @@ -1226,8 +1226,8 @@ typedef enum OMRProcessorArchitecture { } OMRProcessorArchitecture; -/* Holds processor type and features used with j9sysinfo_get_processor_description - * and j9sysinfo_processor_has_feature +/* Holds processor type and features used with omrsysinfo_get_processor_description, + * omrsysinfo_processor_has_feature and omrsysinfo_processor_disable_feature */ #define OMRPORT_SYSINFO_FEATURES_SIZE 5 typedef struct OMRProcessorDesc { @@ -1560,6 +1560,8 @@ typedef struct OMRPortLibrary { intptr_t ( *sysinfo_get_processor_description)(struct OMRPortLibrary *portLibrary, OMRProcessorDesc *desc) ; /** see @ref omrsysinfo.c::omrsysinfo_processor_has_feature "omrsysinfo_processor_has_feature"*/ BOOLEAN ( *sysinfo_processor_has_feature)(struct OMRPortLibrary *portLibrary, OMRProcessorDesc *desc, uint32_t feature) ; + /** see @ref omrsysinfo.c::omrsysinfo_processor_disable_feature "omrsysinfo_processor_disable_feature"*/ + intptr_t ( *sysinfo_processor_disable_feature)(struct OMRPortLibrary *portLibrary, OMRProcessorDesc *desc, uint32_t feature) ; /** see @ref omrsysinfo.c::omrsysinfo_get_OS_type "omrsysinfo_get_OS_type"*/ const char *(*sysinfo_get_OS_type)(struct OMRPortLibrary *portLibrary) ; /** see @ref omrsysinfo.c::omrsysinfo_get_executable_name "omrsysinfo_get_executable_name"*/ @@ -2267,6 +2269,7 @@ extern J9_CFUNC int32_t omrport_getVersion(struct OMRPortLibrary *portLibrary); #define omrsysinfo_get_CPU_architecture() privateOmrPortLibrary->sysinfo_get_CPU_architecture(privateOmrPortLibrary) #define omrsysinfo_get_processor_description(param1) privateOmrPortLibrary->sysinfo_get_processor_description(privateOmrPortLibrary,param1) #define omrsysinfo_processor_has_feature(param1,param2) privateOmrPortLibrary->sysinfo_processor_has_feature(privateOmrPortLibrary,param1,param2) +#define omrsysinfo_processor_disable_feature(param1,param2) privateOmrPortLibrary->sysinfo_processor_disable_feature(privateOmrPortLibrary,param1,param2) #define omrsysinfo_get_OS_type() privateOmrPortLibrary->sysinfo_get_OS_type(privateOmrPortLibrary) #define omrsysinfo_get_executable_name(param1,param2) privateOmrPortLibrary->sysinfo_get_executable_name(privateOmrPortLibrary, (param1), (param2)) #define omrsysinfo_get_username(param1,param2) privateOmrPortLibrary->sysinfo_get_username(privateOmrPortLibrary, (param1), (param2)) diff --git a/port/common/omrport.c b/port/common/omrport.c index 6f1862ab49c..8f05ef5f243 100644 --- a/port/common/omrport.c +++ b/port/common/omrport.c @@ -74,6 +74,7 @@ static OMRPortLibrary MasterPortLibraryTable = { omrsysinfo_get_CPU_architecture, /* sysinfo_get_CPU_architecture */ omrsysinfo_get_processor_description, /* omrsysinfo_get_processor_description */ omrsysinfo_processor_has_feature, /* omrsysinfo_processor_has_feature */ + omrsysinfo_processor_disable_feature, /* omrsysinfo_processor_disable_feature */ omrsysinfo_get_OS_type, /* sysinfo_get_OS_type */ omrsysinfo_get_executable_name, /* sysinfo_get_executable_name */ omrsysinfo_get_username, /* sysinfo_get_username */ diff --git a/port/common/omrport.tdf b/port/common/omrport.tdf index 1cbe385988a..d79a27b32a9 100644 --- a/port/common/omrport.tdf +++ b/port/common/omrport.tdf @@ -1102,8 +1102,11 @@ TraceException=Trc_PRT_vmem_omrvmem_findAvailableMemoryBlockNoMalloc_parseDashFa TraceException=Trc_PRT_vmem_omrvmem_findAvailableMemoryBlockNoMalloc_parseSecondAddressFailed Group=mem Overhead=1 Level=5 NoEnv Template="findAvailableMemoryBlockNoMalloc parser failed to get second address from line (%s)" TraceException=Trc_PRT_vmem_omrvmem_findAvailableMemoryBlockNoMalloc_addressesMismatch Group=mem Overhead=1 Level=5 NoEnv Template="findAvailableMemoryBlockNoMalloc parser found addresses mismatch from line (%s)" -TraceEntry=Trc_PRT_sysinfo_get_processor_description_Entered Group=j9sysinfo Overhead=1 Level=5 NoEnv Template="sysinfo_get_processor_description: desc = %p" -TraceExit=Trc_PRT_sysinfo_get_processor_description_Exit Group=j9sysinfo Overhead=1 Level=5 NoEnv Template="sysinfo_get_processor_description: returning with %zd" +TraceEntry=Trc_PRT_sysinfo_get_processor_description_Entered Group=sysinfo Overhead=1 Level=5 NoEnv Template="sysinfo_get_processor_description: desc = %p" +TraceExit=Trc_PRT_sysinfo_get_processor_description_Exit Group=sysinfo Overhead=1 Level=5 NoEnv Template="sysinfo_get_processor_description: returning with %zd" TraceEntry=Trc_PRT_sysinfo_processor_has_feature_Entered Group=sysinfo Overhead=1 Level=5 NoEnv Template="sysinfo_processor_has_feature: desc = %p, feature = %d" -TraceExit=Trc_PRT_sysinfo_processor_has_feature_Exit Group=sysinfo Overhead=1 Level=5 NoEnv Template="sysinfo_processor_has_feature: returning with %zu." +TraceExit=Trc_PRT_sysinfo_processor_has_feature_Exit Group=sysinfo Overhead=1 Level=5 NoEnv Template="sysinfo_processor_has_feature: returning with %zu" + +TraceEntry=Trc_PRT_sysinfo_processor_disable_feature_Entered Group=sysinfo Overhead=1 Level=5 NoEnv Template="sysinfo_processor_disable_feature: desc = %p, feature = %d" +TraceExit=Trc_PRT_sysinfo_processor_disable_feature_Exit Group=sysinfo Overhead=1 Level=5 NoEnv Template="sysinfo_processor_disable_feature: returning with %zd" diff --git a/port/common/omrsysinfo.c b/port/common/omrsysinfo.c index bbb647a247e..8e2b5c458cb 100644 --- a/port/common/omrsysinfo.c +++ b/port/common/omrsysinfo.c @@ -115,7 +115,7 @@ omrsysinfo_get_processor_description(struct OMRPortLibrary *portLibrary, OMRProc * * @param[in] portLibrary The port library. * @param[in] desc The struct that will contain the CPU type and features. - * @param[in] feature The feature to check (see j9port.h for list of features J9PORT_{PPC,S390,PPC}_FEATURE_*) + * @param[in] feature The feature to check (see omrport.h for list of features OMRPORT_FEATURE_{PPC,S390,PPC}_*) * * @return TRUE if feature is present, FALSE otherwise. */ @@ -127,6 +127,24 @@ omrsysinfo_processor_has_feature(struct OMRPortLibrary *portLibrary, OMRProcesso Trc_PRT_sysinfo_processor_has_feature_Exit((uintptr_t)rc); return rc; } + +/** + * Disable provided CPU feature. + * + * @param[in] portLibrary The port library. + * @param[in] desc The struct that will contain the CPU type and features. + * @param[in] feature The feature to check (see omrport.h for list of features OMRPORT_FEATURE_{PPC,S390,PPC}_*) + * + * @return 0 on success, -1 on failure + */ +intptr_t +omrsysinfo_processor_disable_feature(struct OMRPortLibrary *portLibrary, OMRProcessorDesc *desc, uint32_t feature) +{ + Trc_PRT_sysinfo_processor_disable_feature_Entered(desc, feature); + intptr_t rc = OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM; + Trc_PRT_sysinfo_processor_disable_feature_Exit(rc); + return rc; +} /** * Query the operating system for environment variables. * diff --git a/port/unix/omrsysinfo.c b/port/unix/omrsysinfo.c index 5bbf90dfc17..eb06a5e2701 100644 --- a/port/unix/omrsysinfo.c +++ b/port/unix/omrsysinfo.c @@ -654,6 +654,26 @@ omrsysinfo_processor_has_feature(struct OMRPortLibrary *portLibrary, OMRProcesso return rc; } +intptr_t +omrsysinfo_processor_disable_feature(struct OMRPortLibrary *portLibrary, OMRProcessorDesc *desc, uint32_t feature) +{ + intptr_t rc = -1; + Trc_PRT_sysinfo_processor_disable_feature_Entered(desc, feature); + + if ((NULL != desc) && (feature < (OMRPORT_SYSINFO_OS_FEATURES_SIZE * 32))) { + uint32_t featureIndex = feature / 32; + uint32_t featureShift = feature % 32; + + if (OMR_ARE_ALL_BITS_SET(desc->features[featureIndex], 1 << featureShift)) { + desc->features[featureIndex] -= (1 << featureShift); + rc = 0; + } + } + + Trc_PRT_sysinfo_processor_disable_feature_Exit(rc); + return rc; +} + #if (defined(AIXPPC) || defined(S390) || defined(J9ZOS390)) /** * @internal diff --git a/port/win32/omrsysinfo.c b/port/win32/omrsysinfo.c index dd8e827f8ff..f4c27e5ba01 100644 --- a/port/win32/omrsysinfo.c +++ b/port/win32/omrsysinfo.c @@ -123,6 +123,26 @@ omrsysinfo_processor_has_feature(struct OMRPortLibrary *portLibrary, OMRProcesso return rc; } +intptr_t +omrsysinfo_processor_disable_feature(struct OMRPortLibrary *portLibrary, OMRProcessorDesc *desc, uint32_t feature) +{ + intptr_t rc = -1; + Trc_PRT_sysinfo_processor_disable_feature_Entered(desc, feature); + + if ((NULL != desc) && (feature < (OMRPORT_SYSINFO_OS_FEATURES_SIZE * 32))) { + uint32_t featureIndex = feature / 32; + uint32_t featureShift = feature % 32; + + if (OMR_ARE_ALL_BITS_SET(desc->features[featureIndex], 1 << featureShift)) { + desc->features[featureIndex] -= (1 << featureShift); + rc = 0; + } + } + + Trc_PRT_sysinfo_processor_disable_feature_Exit(rc); + return rc; +} + #define ENVVAR_VALUE_BUFFER_LENGTH 512 #define ENVVAR_NAME_BUFFER_LENGTH 128 intptr_t