Skip to content

Commit 13bea32

Browse files
committed
fixup! Add openmp support to System z: Implement s390x /proc/cpuinfo parsing
1 parent 91dead1 commit 13bea32

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

openmp/runtime/src/kmp_affinity.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2990,6 +2990,9 @@ static bool __kmp_affinity_create_cpuinfo_map(int *line,
29902990

29912991
unsigned num_avail = 0;
29922992
*line = 0;
2993+
#if KMP_ARCH_S390X
2994+
bool reading_s390x_sys_info = true;
2995+
#endif
29932996
while (!feof(f)) {
29942997
// Create an inner scoping level, so that all the goto targets at the end of
29952998
// the loop appear in an outer scoping level. This avoids warnings about
@@ -3036,7 +3039,21 @@ static bool __kmp_affinity_create_cpuinfo_map(int *line,
30363039
continue;
30373040
#endif
30383041

3042+
#if KMP_ARCH_S390X
3043+
// s390x /proc/cpuinfo starts with a variable number of lines containing
3044+
// the overall system information. Skip them.
3045+
if (reading_s390x_sys_info) {
3046+
if (*buf == '\n')
3047+
reading_s390x_sys_info = false;
3048+
continue;
3049+
}
3050+
#endif
3051+
3052+
#if KMP_ARCH_S390X
3053+
char s1[] = "cpu number";
3054+
#else
30393055
char s1[] = "processor";
3056+
#endif
30403057
if (strncmp(buf, s1, sizeof(s1) - 1) == 0) {
30413058
CHECK_LINE;
30423059
char *p = strchr(buf + sizeof(s1) - 1, ':');
@@ -3062,6 +3079,23 @@ static bool __kmp_affinity_create_cpuinfo_map(int *line,
30623079
threadInfo[num_avail][osIdIndex]);
30633080
__kmp_read_from_file(path, "%u", &threadInfo[num_avail][pkgIdIndex]);
30643081

3082+
#if KMP_ARCH_S390X
3083+
// Disambiguate physical_package_id.
3084+
unsigned book_id;
3085+
KMP_SNPRINTF(path, sizeof(path),
3086+
"/sys/devices/system/cpu/cpu%u/topology/book_id",
3087+
threadInfo[num_avail][osIdIndex]);
3088+
__kmp_read_from_file(path, "%u", &book_id);
3089+
threadInfo[num_avail][pkgIdIndex] |= (book_id << 8);
3090+
3091+
unsigned drawer_id;
3092+
KMP_SNPRINTF(path, sizeof(path),
3093+
"/sys/devices/system/cpu/cpu%u/topology/drawer_id",
3094+
threadInfo[num_avail][osIdIndex]);
3095+
__kmp_read_from_file(path, "%u", &drawer_id);
3096+
threadInfo[num_avail][pkgIdIndex] |= (drawer_id << 16);
3097+
#endif
3098+
30653099
KMP_SNPRINTF(path, sizeof(path),
30663100
"/sys/devices/system/cpu/cpu%u/topology/core_id",
30673101
threadInfo[num_avail][osIdIndex]);

0 commit comments

Comments
 (0)