@@ -2990,6 +2990,9 @@ static bool __kmp_affinity_create_cpuinfo_map(int *line,
2990
2990
2991
2991
unsigned num_avail = 0 ;
2992
2992
*line = 0 ;
2993
+ #if KMP_ARCH_S390X
2994
+ bool reading_s390x_sys_info = true ;
2995
+ #endif
2993
2996
while (!feof (f)) {
2994
2997
// Create an inner scoping level, so that all the goto targets at the end of
2995
2998
// 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,
3036
3039
continue ;
3037
3040
#endif
3038
3041
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
3039
3055
char s1[] = " processor" ;
3056
+ #endif
3040
3057
if (strncmp (buf, s1, sizeof (s1) - 1 ) == 0 ) {
3041
3058
CHECK_LINE;
3042
3059
char *p = strchr (buf + sizeof (s1) - 1 , ' :' );
@@ -3062,6 +3079,23 @@ static bool __kmp_affinity_create_cpuinfo_map(int *line,
3062
3079
threadInfo[num_avail][osIdIndex]);
3063
3080
__kmp_read_from_file (path, " %u" , &threadInfo[num_avail][pkgIdIndex]);
3064
3081
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
+
3065
3099
KMP_SNPRINTF (path, sizeof (path),
3066
3100
" /sys/devices/system/cpu/cpu%u/topology/core_id" ,
3067
3101
threadInfo[num_avail][osIdIndex]);
0 commit comments