Skip to content

Commit

Permalink
Clarifications
Browse files Browse the repository at this point in the history
  • Loading branch information
EricYangIBM committed May 11, 2022
1 parent 3bb6769 commit cb26705
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions port/unix/omrsysinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,15 @@ struct {

#define SINGLE_CGROUP_METRIC 1
#define MAX_64BIT_INT_LENGTH 20
/* Indicates a file has multiple space-separated values. */
/* The metricKeyInFile field in an OMRCgroupMetricInfoElement being set to this
* indicates that the file containing this element is in the space-separated format,
* i.e.
* VAL0 VAL1 ...\n
* All 'OMRCgroupMetricInfoElement's corresponding to values in a file of this format
* must have their metricKeyInFile set to CGROUP_METRIC_NO_KEY and OMRCgroupMetricInfoElement
* arrays must list metrics in order of appearance in their file.
* CGROUP_METRIC_NO_KEY does not apply to newline-separated files.
*/
#define CGROUP_METRIC_NO_KEY -1

/* Used for PPG_sysinfoControlFlags global, set bits indicate cgroup v1 availability,
Expand Down Expand Up @@ -476,6 +484,9 @@ static struct OMRCgroupMetricInfoElement cpuStatMetricElementListV1[] = {
{ "Total throttle time", "throttled_time", "nanoseconds", FALSE }
};

/* The cpu.max file contains two space separated values in the format
* $QUOTA $PERIOD
*/
static struct OMRCgroupMetricInfoElement cpuMaxMetricElementListV2[] = {
{ "CPU Quota", (char *)CGROUP_METRIC_NO_KEY, "microseconds", TRUE },
{ "CPU Period", (char *)CGROUP_METRIC_NO_KEY, "microseconds", FALSE }
Expand Down Expand Up @@ -6517,36 +6528,36 @@ getCgroupSubsystemMetricMap(struct OMRPortLibrary *portLibrary, uint64_t subsyst
Assert_PRT_true((NULL != subsystemMetricMap) || (NULL != numElements));
if (OMR_ARE_ANY_BITS_SET(PPG_sysinfoControlFlags, OMRPORT_SYSINFO_CGROUP_V1_AVAILABLE)) {
switch (subsystem) {
case OMR_CGROUP_SUBSYSTEM_MEMORY :
case OMR_CGROUP_SUBSYSTEM_MEMORY:
map = omrCgroupMemoryMetricMapV1;
count = OMR_CGROUP_MEMORY_METRIC_MAP_V1_SIZE;
break;
case OMR_CGROUP_SUBSYSTEM_CPU :
case OMR_CGROUP_SUBSYSTEM_CPU:
map = omrCgroupCpuMetricMapV1;
count = OMR_CGROUP_CPU_METRIC_MAP_V1_SIZE;
break;
case OMR_CGROUP_SUBSYSTEM_CPUSET :
case OMR_CGROUP_SUBSYSTEM_CPUSET:
map = omrCgroupCpusetMetricMapV1;
count = OMR_CGROUP_CPUSET_METRIC_MAP_V1_SIZE;
break;
default :
default:
rc = OMRPORT_ERROR_SYSINFO_CGROUP_SUBSYSTEM_UNAVAILABLE;
}
} else if (OMR_ARE_ANY_BITS_SET(PPG_sysinfoControlFlags, OMRPORT_SYSINFO_CGROUP_V2_AVAILABLE)) {
switch (subsystem) {
case OMR_CGROUP_SUBSYSTEM_MEMORY :
case OMR_CGROUP_SUBSYSTEM_MEMORY:
map = omrCgroupMemoryMetricMapV2;
count = OMR_CGROUP_MEMORY_METRIC_MAP_V2_SIZE;
break;
case OMR_CGROUP_SUBSYSTEM_CPU :
case OMR_CGROUP_SUBSYSTEM_CPU:
map = omrCgroupCpuMetricMapV2;
count = OMR_CGROUP_CPU_METRIC_MAP_V2_SIZE;
break;
case OMR_CGROUP_SUBSYSTEM_CPUSET :
case OMR_CGROUP_SUBSYSTEM_CPUSET:
map = omrCgroupCpusetMetricMapV2;
count = OMR_CGROUP_CPUSET_METRIC_MAP_V2_SIZE;
break;
default :
default:
rc = OMRPORT_ERROR_SYSINFO_CGROUP_SUBSYSTEM_UNAVAILABLE;
}
} else {
Expand Down Expand Up @@ -6894,11 +6905,12 @@ omrsysinfo_cgroup_subsystem_iterator_next(struct OMRPortLibrary *portLibrary, st
metricElement->value[len-1] = '\0';
}
if (currentElement->isValueToBeChecked) {
int64_t result = 0;
BOOLEAN notSet = FALSE;
if ('\n' == metricElement->value[0]) {
/* Empty file, see cpuset.cpus and cpuset.mems in omrCgroupCpusetMetricMapV2. */
result = -1;
notSet = TRUE;
} else if (OMR_ARE_ANY_BITS_SET(PPG_sysinfoControlFlags, OMRPORT_SYSINFO_CGROUP_V1_AVAILABLE)) {
int64_t result = 0;
rc = sscanf(metricElement->value, "%" PRId64, &result);
if (1 != rc) {
rc = portLibrary->error_set_last_error_with_message_format(
Expand All @@ -6908,6 +6920,9 @@ omrsysinfo_cgroup_subsystem_iterator_next(struct OMRPortLibrary *portLibrary, st
metricElement->value,
subsystemMetricMapElement->metricFileName);
} else {
if ((result > MAX_DEFAULT_VALUE_CHECK) || (result < 0)) {
notSet = TRUE;
}
rc = 0;
}
} else if (OMR_ARE_ANY_BITS_SET(PPG_sysinfoControlFlags, OMRPORT_SYSINFO_CGROUP_V2_AVAILABLE)) {
Expand All @@ -6920,16 +6935,15 @@ omrsysinfo_cgroup_subsystem_iterator_next(struct OMRPortLibrary *portLibrary, st
"invalid value %s in file %s",
metricElement->value,
subsystemMetricMapElement->metricFileName);
} else if (UINT64_MAX == uresult) {
result = -1;
} else {
result = (int64_t)uresult;
} else if (uresult > MAX_DEFAULT_VALUE_CHECK) {
/* Assume that the metric is effectively unlimited and can be considered "Not Set". */
notSet = TRUE;
}
} else {
Trc_PRT_Assert_ShouldNeverHappen();
}
/* Check that the metric is set and that it is a reasonable value. */
if ((result > (MAX_DEFAULT_VALUE_CHECK)) || (result < 0)) {
if (notSet) {
metricElement->units = NULL;
strcpy(metricElement->value, "Not Set");
}
Expand Down

0 comments on commit cb26705

Please sign in to comment.