Skip to content

Commit

Permalink
Merge pull request #4900 from harryyu1994/portEnableFeature
Browse files Browse the repository at this point in the history
Add omrsysinfo_processor_set_feature API
  • Loading branch information
youngar authored Mar 10, 2020
2 parents b5206bd + cb7e3d8 commit b03105e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 22 deletions.
8 changes: 4 additions & 4 deletions include_core/omrport.h
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ typedef enum OMRProcessorArchitecture {
} OMRProcessorArchitecture;

/* Holds processor type and features used with omrsysinfo_get_processor_description,
* omrsysinfo_processor_has_feature and omrsysinfo_processor_disable_feature
* omrsysinfo_processor_has_feature and omrsysinfo_processor_set_feature
*/
#define OMRPORT_SYSINFO_FEATURES_SIZE 5
typedef struct OMRProcessorDesc {
Expand Down Expand Up @@ -1660,8 +1660,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_processor_set_feature "omrsysinfo_processor_set_feature"*/
intptr_t ( *sysinfo_processor_set_feature)(struct OMRPortLibrary *portLibrary, OMRProcessorDesc *desc, uint32_t feature, BOOLEAN enable) ;
/** 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"*/
Expand Down Expand Up @@ -2375,7 +2375,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_processor_set_feature(param1,param2,param3) privateOmrPortLibrary->sysinfo_processor_set_feature(privateOmrPortLibrary,param1,param2,param3)
#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))
Expand Down
2 changes: 1 addition & 1 deletion port/common/omrport.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +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_processor_set_feature, /* omrsysinfo_processor_set_feature */
omrsysinfo_get_OS_type, /* sysinfo_get_OS_type */
omrsysinfo_get_executable_name, /* sysinfo_get_executable_name */
omrsysinfo_get_username, /* sysinfo_get_username */
Expand Down
3 changes: 3 additions & 0 deletions port/common/omrport.tdf
Original file line number Diff line number Diff line change
Expand Up @@ -1110,3 +1110,6 @@ TraceExit=Trc_PRT_sysinfo_processor_has_feature_Exit Group=sysinfo Overhead=1 Le

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"

TraceEntry=Trc_PRT_sysinfo_processor_set_feature_Entered Group=sysinfo Overhead=1 Level=5 NoEnv Template="sysinfo_processor_set_feature: desc = %p, feature = %d, enable = %d"
TraceExit=Trc_PRT_sysinfo_processor_set_feature_Exit Group=sysinfo Overhead=1 Level=5 NoEnv Template="sysinfo_processor_set_feature: returning with %zd"
9 changes: 5 additions & 4 deletions port/common/omrsysinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ omrsysinfo_processor_has_feature(struct OMRPortLibrary *portLibrary, OMRProcesso
}

/**
* Disable provided CPU feature.
* Enable or disable provided CPU feature.
*
* @param[in] portLibrary The port library.
* @param[in] desc The struct that will contain the CPU type and features.
Expand All @@ -138,13 +138,14 @@ omrsysinfo_processor_has_feature(struct OMRPortLibrary *portLibrary, OMRProcesso
* @return 0 on success, -1 on failure
*/
intptr_t
omrsysinfo_processor_disable_feature(struct OMRPortLibrary *portLibrary, OMRProcessorDesc *desc, uint32_t feature)
omrsysinfo_processor_set_feature(struct OMRPortLibrary *portLibrary, OMRProcessorDesc *desc, uint32_t feature, BOOLEAN enable)
{
Trc_PRT_sysinfo_processor_disable_feature_Entered(desc, feature);
Trc_PRT_sysinfo_processor_set_feature_Entered(desc, feature, enable);
intptr_t rc = OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
Trc_PRT_sysinfo_processor_disable_feature_Exit(rc);
Trc_PRT_sysinfo_processor_set_feature_Exit(rc);
return rc;
}

/**
* Query the operating system for environment variables.
*
Expand Down
2 changes: 1 addition & 1 deletion port/omrportpriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ omrsysinfo_get_processor_description(struct OMRPortLibrary *portLibrary, OMRProc
extern J9_CFUNC BOOLEAN
omrsysinfo_processor_has_feature(struct OMRPortLibrary *portLibrary, OMRProcessorDesc *desc, uint32_t feature);
extern J9_CFUNC intptr_t
omrsysinfo_processor_disable_feature(struct OMRPortLibrary *portLibrary, OMRProcessorDesc *desc, uint32_t feature);
omrsysinfo_processor_set_feature(struct OMRPortLibrary *portLibrary, OMRProcessorDesc *desc, uint32_t feature, BOOLEAN enable);
extern J9_CFUNC const char *
omrsysinfo_get_OS_version(struct OMRPortLibrary *portLibrary);
extern J9_CFUNC int32_t
Expand Down
15 changes: 9 additions & 6 deletions port/unix/omrsysinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,22 +657,25 @@ omrsysinfo_processor_has_feature(struct OMRPortLibrary *portLibrary, OMRProcesso
}

intptr_t
omrsysinfo_processor_disable_feature(struct OMRPortLibrary *portLibrary, OMRProcessorDesc *desc, uint32_t feature)
omrsysinfo_processor_set_feature(struct OMRPortLibrary *portLibrary, OMRProcessorDesc *desc, uint32_t feature, BOOLEAN enable)
{
intptr_t rc = -1;
Trc_PRT_sysinfo_processor_disable_feature_Entered(desc, feature);
Trc_PRT_sysinfo_processor_set_feature_Entered(desc, feature, enable);

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], 1u << featureShift)) {
desc->features[featureIndex] -= (1u << featureShift);
rc = 0;
if (enable) {
desc->features[featureIndex] |= (1u << featureShift);
}
else {
desc->features[featureIndex] &= ~(1u << featureShift);
}
rc = 0;
}

Trc_PRT_sysinfo_processor_disable_feature_Exit(rc);
Trc_PRT_sysinfo_processor_set_feature_Exit(rc);
return rc;
}

Expand Down
15 changes: 9 additions & 6 deletions port/win32/omrsysinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,25 @@ omrsysinfo_processor_has_feature(struct OMRPortLibrary *portLibrary, OMRProcesso
}

intptr_t
omrsysinfo_processor_disable_feature(struct OMRPortLibrary *portLibrary, OMRProcessorDesc *desc, uint32_t feature)
omrsysinfo_processor_set_feature(struct OMRPortLibrary *portLibrary, OMRProcessorDesc *desc, uint32_t feature, BOOLEAN enable)
{
intptr_t rc = -1;
Trc_PRT_sysinfo_processor_disable_feature_Entered(desc, feature);
Trc_PRT_sysinfo_processor_set_feature_Entered(desc, feature, enable);

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], 1u << featureShift)) {
desc->features[featureIndex] -= (1u << featureShift);
rc = 0;
if (enable) {
desc->features[featureIndex] |= (1u << featureShift);
}
else {
desc->features[featureIndex] &= ~(1u << featureShift);
}
rc = 0;
}

Trc_PRT_sysinfo_processor_disable_feature_Exit(rc);
Trc_PRT_sysinfo_processor_set_feature_Exit(rc);
return rc;
}

Expand Down

0 comments on commit b03105e

Please sign in to comment.