Skip to content

Commit

Permalink
Add only required subsystems to PPG_cgroupEntryList
Browse files Browse the repository at this point in the history
Added an anonymous struct instance 'supportedSubsystems' that contains
information about subsystems supported by JVM.
Updated addCgroupEntry() to add only the required subsystems and also
set PPG_cgroupSubsystemsAvailable.
Removed getAvailableSubsystems().

Issue: #1281
Signed-off-by: Ashutosh Mehra <asmehra1@in.ibm.com>
  • Loading branch information
Ashutosh Mehra committed Sep 11, 2017
1 parent 129fed2 commit 175daad
Showing 1 changed file with 44 additions and 73 deletions.
117 changes: 44 additions & 73 deletions port/unix/omrsysinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,14 @@ const char *subsystemNames[NUM_SUBSYSTEMS] = {
"pids",
};

struct {
const char *name;
uint64_t flag;
} supportedSubsystems[] = {
{ "cpu", OMR_CGROUP_SUBSYSTEM_CPU },
{ "memory", OMR_CGROUP_SUBSYSTEM_MEMORY }
};

static uint32_t attachedPortLibraries;
static omrthread_monitor_t cgroupEntryListMonitor;

Expand Down Expand Up @@ -320,7 +328,6 @@ static uint16_t getPhysicalMemory();

#if defined(LINUX) && !defined(OMRZTPF)
static void freeCgroupEntries(struct OMRPortLibrary *portLibrary, OMRCgroupEntry *cgEntryList);
static uint64_t getAvailableSubsystems(struct OMRPortLibrary *portLibrary, OMRCgroupEntry *cgEntryList);
static char * getCgroupNameForSubsystem(struct OMRPortLibrary *portLibrary, OMRCgroupEntry *cgEntryList, const char *subsystem);
static int32_t addCgroupEntry(struct OMRPortLibrary *portLibrary, OMRCgroupEntry **cgEntryList, int32_t hierId, const char *subsystem, const char *cgroupName);
static int32_t readCgroupFile(struct OMRPortLibrary *portLibrary, int pid, OMRCgroupEntry **cgroupEntryList);
Expand Down Expand Up @@ -3291,40 +3298,6 @@ freeCgroupEntries(struct OMRPortLibrary *portLibrary, OMRCgroupEntry *cgEntryLis
} while (cgEntry != cgEntryList);
}

/**
* Returns cgroup subsystems available for port library to use based on the
* subsystem entries in cgEntryList
*
* @param[in] portLibrary pointer to OMRPortLibrary
* @param[in] cgEntryList pointer to OMRCgroupEntry representing a circular list
* containing entry for each subsystem
*
* @return bitwise-OR of flags of type OMR_CGROUP_SUBSYSTEM_* indicating the
* subsystems that are available
*/
static uint64_t
getAvailableSubsystems(struct OMRPortLibrary *portLibrary, OMRCgroupEntry *cgEntryList)
{
OMRCgroupEntry *cgEntry = cgEntryList;
uint64_t availableSubsystems = 0;

if (NULL == cgEntry) {
goto _end;
}

do {
if (!strcmp(cgEntry->subsystem, subsystemNames[CPU])) {
availableSubsystems |= OMR_CGROUP_SUBSYSTEM_CPU;
} else if (!strcmp(cgEntry->subsystem, subsystemNames[MEMORY])) {
availableSubsystems |= OMR_CGROUP_SUBSYSTEM_MEMORY;
}
cgEntry = cgEntry->next;
} while (cgEntry!= cgEntryList);

_end:
return availableSubsystems;
}

/**
* Returns cgroup name for the subsystem/resource controller using the circular
* linked list pointed by cgEntryList.
Expand Down Expand Up @@ -3372,31 +3345,41 @@ getCgroupNameForSubsystem(struct OMRPortLibrary *portLibrary, OMRCgroupEntry *cg
static int32_t
addCgroupEntry(struct OMRPortLibrary *portLibrary, OMRCgroupEntry **cgEntryList, int32_t hierId, const char *subsystem, const char *cgroupName)
{
OMRCgroupEntry *cgEntry = NULL;
int32_t cgEntrySize = sizeof(OMRCgroupEntry) + strlen(subsystem) + 1 + strlen(cgroupName) + 1;
int32_t rc = 0;
int32_t i = 0;

cgEntry = portLibrary->mem_allocate_memory(portLibrary, cgEntrySize, OMR_GET_CALLSITE(), OMRMEM_CATEGORY_PORT_LIBRARY);
if (NULL == cgEntry) {
rc = portLibrary->error_set_last_error_with_message(portLibrary, OMRPORT_ERROR_SYSINFO_MEMORY_ALLOC_FAILED, "memory allocation for cgroup entry failed");
goto _end;
}
cgEntry->hierarchyId = hierId;
cgEntry->subsystem = (char *)(cgEntry + 1);
strcpy(cgEntry->subsystem, subsystem);
cgEntry->cgroup = cgEntry->subsystem + strlen(subsystem) + 1;
strcpy(cgEntry->cgroup, cgroupName);
for (i = 0; i < sizeof(supportedSubsystems) / sizeof(supportedSubsystems[0]); i++) {
if (J9_ARE_NO_BITS_SET(PPG_cgroupSubsystemsAvailable, supportedSubsystems[i].flag)
&& !strcmp(subsystem, supportedSubsystems[i].name)
) {
int32_t cgEntrySize = sizeof(OMRCgroupEntry) + strlen(subsystem) + 1 + strlen(cgroupName) + 1;
OMRCgroupEntry *cgEntry = portLibrary->mem_allocate_memory(portLibrary, cgEntrySize, OMR_GET_CALLSITE(), OMRMEM_CATEGORY_PORT_LIBRARY);

if (NULL == *cgEntryList) {
*cgEntryList = cgEntry;
cgEntry->next = cgEntry; /* create a circular list */
} else {
OMRCgroupEntry *first = *cgEntryList;
*cgEntryList = cgEntry;
cgEntry->next = first->next;
first->next = cgEntry;
}
if (NULL == cgEntry) {
rc = portLibrary->error_set_last_error_with_message(portLibrary, OMRPORT_ERROR_SYSINFO_MEMORY_ALLOC_FAILED, "memory allocation for cgroup entry failed");
goto _end;
}
cgEntry->hierarchyId = hierId;
cgEntry->subsystem = (char *)(cgEntry + 1);
strcpy(cgEntry->subsystem, subsystem);
cgEntry->cgroup = cgEntry->subsystem + strlen(subsystem) + 1;
strcpy(cgEntry->cgroup, cgroupName);

if (NULL == *cgEntryList) {
*cgEntryList = cgEntry;
cgEntry->next = cgEntry; /* create a circular list */
} else {
OMRCgroupEntry *first = *cgEntryList;
*cgEntryList = cgEntry;
cgEntry->next = first->next;
first->next = cgEntry;
}

PPG_cgroupSubsystemsAvailable |= supportedSubsystems[i].flag;

break;
}
}
_end:
return rc;
}
Expand Down Expand Up @@ -3463,24 +3446,14 @@ readCgroupFile(struct OMRPortLibrary *portLibrary, int pid, OMRCgroupEntry **cgr
}
cursor = subsystems;
do {
const char *cgName = NULL;

separator = strchr(cursor, ',');
if (NULL != separator) {
*separator = '\0';
}

cgName = getCgroupNameForSubsystem(portLibrary, cgEntryList, cursor);

if (NULL == cgName) {
rc = addCgroupEntry(portLibrary, &cgEntryList, hierId, cursor, cgroup);
if (0 != rc) {
goto _end;
}
} else {
rc = portLibrary->error_set_last_error_with_message_format(portLibrary, OMRPORT_ERROR_SYSINFO_PROCESS_CGROUP_FILE_DUPLICATE_SUBSYSTEM_ENTRIES, "multiple entries for subsystem %s found in process cgroup file", cursor);
rc = addCgroupEntry(portLibrary, &cgEntryList, hierId, cursor, cgroup);
if (0 != rc) {
goto _end;

}
if (NULL != separator) {
cursor = separator + 1;
Expand Down Expand Up @@ -3606,19 +3579,18 @@ omrsysinfo_cgroup_is_system_available(struct OMRPortLibrary *portLibrary)
{
BOOLEAN result = FALSE;
int32_t rc = OMRPORT_ERROR_SYSINFO_CGROUP_UNSUPPORTED_PLATFORM;
#if defined(LINUX) && !defined(OMRZTPF)
struct statfs buf = {0};

#if defined(LINUX) && !defined(OMRZTPF)
if (NULL == PPG_cgroupEntryList) {
struct statfs buf = {0};

/* If tmpfs is mounted on /sys/fs/cgroup, then it indicates cgroup v1 system is available */
rc = statfs(OMR_CGROUP_V1_MOUNT_POINT, &buf);
if (0 != rc) {
rc = portLibrary->error_set_last_error(portLibrary, errno, OMRPORT_ERROR_SYSINFO_CGROUP_STATFS_FAILED);
rc = portLibrary->error_set_last_error(portLibrary, errno, OMRPORT_ERROR_SYSINFO_SYS_FS_CGROUP_STATFS_FAILED);
goto _end;
} else if (TMPFS_MAGIC != buf.f_type) {
rc = portLibrary->error_set_last_error_with_message_format(portLibrary, OMRPORT_ERROR_SYSINFO_CGROUP_TMPFS_NOT_MOUNTED, "tmpfs is not mounted on " OMR_CGROUP_V1_MOUNT_POINT);
rc = portLibrary->error_set_last_error_with_message_format(portLibrary, OMRPORT_ERROR_SYSINFO_SYS_FS_CGROUP_TMPFS_NOT_MOUNTED, "tmpfs is not mounted on " OMR_CGROUP_V1_MOUNT_POINT);
goto _end;
}

Expand All @@ -3628,7 +3600,6 @@ omrsysinfo_cgroup_is_system_available(struct OMRPortLibrary *portLibrary)
if (0 != rc) {
goto _end;
}
PPG_cgroupSubsystemsAvailable = getAvailableSubsystems(portLibrary, PPG_cgroupEntryList);
} else {
rc = 0;
}
Expand Down

0 comments on commit 175daad

Please sign in to comment.