Skip to content

Commit 8e8f0d3

Browse files
committed
Addressed comments: put the AIX code to before Linux's.
1 parent 9ba206e commit 8e8f0d3

File tree

3 files changed

+166
-167
lines changed

3 files changed

+166
-167
lines changed

openmp/runtime/src/kmp_affinity.cpp

Lines changed: 99 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -2915,7 +2915,9 @@ static bool __kmp_affinity_create_cpuinfo_map(int *line,
29152915
kmp_i18n_id_t *const msg_id) {
29162916
*msg_id = kmp_i18n_null;
29172917

2918-
#ifndef KMP_OS_AIX
2918+
#if KMP_OS_AIX
2919+
unsigned num_records = __kmp_xproc;
2920+
#else
29192921
const char *filename = __kmp_cpuinfo_get_filename();
29202922
const char *envvar = __kmp_cpuinfo_get_envvar();
29212923

@@ -2976,9 +2978,7 @@ static bool __kmp_affinity_create_cpuinfo_map(int *line,
29762978
*msg_id = kmp_i18n_str_CantRewindCpuinfo;
29772979
return false;
29782980
}
2979-
#else // KMP_OS_AIX
2980-
unsigned num_records = __kmp_xproc;
2981-
#endif
2981+
#endif // KMP_OS_AIX
29822982

29832983
// Allocate the array of records to store the proc info in. The dummy
29842984
// element at the end makes the logic in filling them out easier to code.
@@ -3008,7 +3008,99 @@ static bool __kmp_affinity_create_cpuinfo_map(int *line,
30083008
INIT_PROC_INFO(threadInfo[i]);
30093009
}
30103010

3011-
#ifndef KMP_OS_AIX
3011+
#if KMP_OS_AIX
3012+
int smt_threads;
3013+
lpar_info_format1_t cpuinfo;
3014+
unsigned num_avail = __kmp_xproc;
3015+
3016+
if (__kmp_affinity.flags.verbose)
3017+
KMP_INFORM(AffParseFilename, "KMP_AFFINITY", "system info for topology");
3018+
3019+
// Get the number of SMT threads per core.
3020+
int retval =
3021+
lpar_get_info(LPAR_INFO_FORMAT1, &cpuinfo, sizeof(lpar_info_format1_t));
3022+
if (!retval)
3023+
smt_threads = cpuinfo.smt_threads;
3024+
else {
3025+
CLEANUP_THREAD_INFO;
3026+
*msg_id = kmp_i18n_str_UnknownTopology;
3027+
return false;
3028+
}
3029+
3030+
// Allocate a resource set containing available system resourses.
3031+
rsethandle_t sys_rset = rs_alloc(RS_SYSTEM);
3032+
if (sys_rset == NULL) {
3033+
CLEANUP_THREAD_INFO;
3034+
*msg_id = kmp_i18n_str_UnknownTopology;
3035+
return false;
3036+
}
3037+
// Allocate a resource set for the SRAD info.
3038+
rsethandle_t srad = rs_alloc(RS_EMPTY);
3039+
if (srad == NULL) {
3040+
rs_free(sys_rset);
3041+
CLEANUP_THREAD_INFO;
3042+
*msg_id = kmp_i18n_str_UnknownTopology;
3043+
return false;
3044+
}
3045+
3046+
// Get the SRAD system detail level.
3047+
int sradsdl = rs_getinfo(NULL, R_SRADSDL, 0);
3048+
if (sradsdl < 0) {
3049+
rs_free(sys_rset);
3050+
rs_free(srad);
3051+
CLEANUP_THREAD_INFO;
3052+
*msg_id = kmp_i18n_str_UnknownTopology;
3053+
return false;
3054+
}
3055+
// Get the number of RADs at that SRAD SDL.
3056+
int num_rads = rs_numrads(sys_rset, sradsdl, 0);
3057+
if (num_rads < 0) {
3058+
rs_free(sys_rset);
3059+
rs_free(srad);
3060+
CLEANUP_THREAD_INFO;
3061+
*msg_id = kmp_i18n_str_UnknownTopology;
3062+
return false;
3063+
}
3064+
3065+
// Get the maximum number of procs that may be contained in a resource set.
3066+
int max_procs = rs_getinfo(NULL, R_MAXPROCS, 0);
3067+
if (max_procs < 0) {
3068+
rs_free(sys_rset);
3069+
rs_free(srad);
3070+
CLEANUP_THREAD_INFO;
3071+
*msg_id = kmp_i18n_str_UnknownTopology;
3072+
return false;
3073+
}
3074+
3075+
int cur_rad = 0;
3076+
int num_set = 0;
3077+
for (int srad_idx = 0; cur_rad < num_rads && srad_idx < VMI_MAXRADS;
3078+
++srad_idx) {
3079+
// Check if the SRAD is available in the RSET.
3080+
if (rs_getrad(sys_rset, srad, sradsdl, srad_idx, 0) < 0)
3081+
continue;
3082+
3083+
for (int cpu = 0; cpu < max_procs; cpu++) {
3084+
// Set the info for the cpu if it is in the SRAD.
3085+
if (rs_op(RS_TESTRESOURCE, srad, NULL, R_PROCS, cpu)) {
3086+
threadInfo[cpu][osIdIndex] = cpu;
3087+
threadInfo[cpu][pkgIdIndex] = cur_rad;
3088+
threadInfo[cpu][coreIdIndex] = cpu / smt_threads;
3089+
++num_set;
3090+
if (num_set >= num_avail) {
3091+
// Done if all available CPUs have been set.
3092+
break;
3093+
}
3094+
}
3095+
}
3096+
++cur_rad;
3097+
}
3098+
rs_free(sys_rset);
3099+
rs_free(srad);
3100+
3101+
// The topology is already sorted.
3102+
3103+
#else // !KMP_OS_AIX
30123104
unsigned num_avail = 0;
30133105
*line = 0;
30143106
#if KMP_ARCH_S390X
@@ -3256,98 +3348,6 @@ static bool __kmp_affinity_create_cpuinfo_map(int *line,
32563348
qsort(threadInfo, num_avail, sizeof(*threadInfo),
32573349
__kmp_affinity_cmp_ProcCpuInfo_phys_id);
32583350

3259-
#else // KMP_OS_AIX
3260-
int smt_threads;
3261-
lpar_info_format1_t cpuinfo;
3262-
unsigned num_avail = __kmp_xproc;
3263-
3264-
if (__kmp_affinity.flags.verbose)
3265-
KMP_INFORM(AffParseFilename, "KMP_AFFINITY", "system info for topology");
3266-
3267-
// Get the number of SMT threads per core.
3268-
int retval =
3269-
lpar_get_info(LPAR_INFO_FORMAT1, &cpuinfo, sizeof(lpar_info_format1_t));
3270-
if (!retval)
3271-
smt_threads = cpuinfo.smt_threads;
3272-
else {
3273-
CLEANUP_THREAD_INFO;
3274-
*msg_id = kmp_i18n_str_UnknownTopology;
3275-
return false;
3276-
}
3277-
3278-
// Allocate a resource set containing available system resourses.
3279-
rsethandle_t sys_rset = rs_alloc(RS_SYSTEM);
3280-
if (sys_rset == NULL) {
3281-
CLEANUP_THREAD_INFO;
3282-
*msg_id = kmp_i18n_str_UnknownTopology;
3283-
return false;
3284-
}
3285-
// Allocate a resource set for the SRAD info.
3286-
rsethandle_t srad = rs_alloc(RS_EMPTY);
3287-
if (srad == NULL) {
3288-
rs_free(sys_rset);
3289-
CLEANUP_THREAD_INFO;
3290-
*msg_id = kmp_i18n_str_UnknownTopology;
3291-
return false;
3292-
}
3293-
3294-
// Get the SRAD system detail level.
3295-
int sradsdl = rs_getinfo(NULL, R_SRADSDL, 0);
3296-
if (sradsdl < 0) {
3297-
rs_free(sys_rset);
3298-
rs_free(srad);
3299-
CLEANUP_THREAD_INFO;
3300-
*msg_id = kmp_i18n_str_UnknownTopology;
3301-
return false;
3302-
}
3303-
// Get the number of RADs at that SRAD SDL.
3304-
int num_rads = rs_numrads(sys_rset, sradsdl, 0);
3305-
if (num_rads < 0) {
3306-
rs_free(sys_rset);
3307-
rs_free(srad);
3308-
CLEANUP_THREAD_INFO;
3309-
*msg_id = kmp_i18n_str_UnknownTopology;
3310-
return false;
3311-
}
3312-
3313-
// Get the maximum number of procs that may be contained in a resource set.
3314-
int max_procs = rs_getinfo(NULL, R_MAXPROCS, 0);
3315-
if (max_procs < 0) {
3316-
rs_free(sys_rset);
3317-
rs_free(srad);
3318-
CLEANUP_THREAD_INFO;
3319-
*msg_id = kmp_i18n_str_UnknownTopology;
3320-
return false;
3321-
}
3322-
3323-
int cur_rad = 0;
3324-
int num_set = 0;
3325-
for (int srad_idx = 0; cur_rad < num_rads && srad_idx < VMI_MAXRADS;
3326-
++srad_idx) {
3327-
// Check if the SRAD is available in the RSET.
3328-
if (rs_getrad(sys_rset, srad, sradsdl, srad_idx, 0) < 0)
3329-
continue;
3330-
3331-
for (int cpu = 0; cpu < max_procs; cpu++) {
3332-
// Set the info for the cpu if it is in the SRAD.
3333-
if (rs_op(RS_TESTRESOURCE, srad, NULL, R_PROCS, cpu)) {
3334-
threadInfo[cpu][osIdIndex] = cpu;
3335-
threadInfo[cpu][pkgIdIndex] = cur_rad;
3336-
threadInfo[cpu][coreIdIndex] = cpu / smt_threads;
3337-
++num_set;
3338-
if (num_set >= num_avail) {
3339-
// Done if all available CPUs have been set.
3340-
break;
3341-
}
3342-
}
3343-
}
3344-
++cur_rad;
3345-
}
3346-
rs_free(sys_rset);
3347-
rs_free(srad);
3348-
3349-
// The topology is already sorted.
3350-
33513351
#endif // KMP_OS_AIX
33523352

33533353
// The table is now sorted by pkgId / coreId / threadId, but we really don't
@@ -4941,7 +4941,7 @@ void __kmp_affinity_uninitialize(void) {
49414941
}
49424942
if (__kmp_affin_origMask != NULL) {
49434943
if (KMP_AFFINITY_CAPABLE()) {
4944-
#ifdef KMP_OS_AIX
4944+
#if KMP_OS_AIX
49454945
// Uninitialize by unbinding the thread.
49464946
bindprocessor(BINDTHREAD, thread_self(), PROCESSOR_CLASS_ANY);
49474947
#else
@@ -5705,7 +5705,7 @@ extern "C"
57055705
"set full mask for thread %d\n",
57065706
gtid));
57075707
KMP_DEBUG_ASSERT(__kmp_affin_fullMask != NULL);
5708-
#ifdef KMP_OS_AIX
5708+
#if KMP_OS_AIX
57095709
return bindprocessor(BINDTHREAD, thread_self(), PROCESSOR_CLASS_ANY);
57105710
#else
57115711
return __kmp_set_system_affinity(__kmp_affin_fullMask, FALSE);

openmp/runtime/src/kmp_affinity.h

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -409,50 +409,7 @@ class KMPNativeAffinity : public KMPAffinity {
409409
++retval;
410410
return retval;
411411
}
412-
#ifndef KMP_OS_AIX
413-
int get_system_affinity(bool abort_on_error) override {
414-
KMP_ASSERT2(KMP_AFFINITY_CAPABLE(),
415-
"Illegal get affinity operation when not capable");
416-
#if KMP_OS_LINUX
417-
long retval =
418-
syscall(__NR_sched_getaffinity, 0, __kmp_affin_mask_size, mask);
419-
#elif KMP_OS_FREEBSD || KMP_OS_NETBSD || KMP_OS_DRAGONFLY
420-
int r = pthread_getaffinity_np(pthread_self(), __kmp_affin_mask_size,
421-
reinterpret_cast<cpuset_t *>(mask));
422-
int retval = (r == 0 ? 0 : -1);
423-
#endif
424-
if (retval >= 0) {
425-
return 0;
426-
}
427-
int error = errno;
428-
if (abort_on_error) {
429-
__kmp_fatal(KMP_MSG(FunctionError, "pthread_getaffinity_np()"),
430-
KMP_ERR(error), __kmp_msg_null);
431-
}
432-
return error;
433-
}
434-
int set_system_affinity(bool abort_on_error) const override {
435-
KMP_ASSERT2(KMP_AFFINITY_CAPABLE(),
436-
"Illegal set affinity operation when not capable");
437-
#if KMP_OS_LINUX
438-
long retval =
439-
syscall(__NR_sched_setaffinity, 0, __kmp_affin_mask_size, mask);
440-
#elif KMP_OS_FREEBSD || KMP_OS_NETBSD || KMP_OS_DRAGONFLY
441-
int r = pthread_setaffinity_np(pthread_self(), __kmp_affin_mask_size,
442-
reinterpret_cast<cpuset_t *>(mask));
443-
int retval = (r == 0 ? 0 : -1);
444-
#endif
445-
if (retval >= 0) {
446-
return 0;
447-
}
448-
int error = errno;
449-
if (abort_on_error) {
450-
__kmp_fatal(KMP_MSG(FunctionError, "pthread_setaffinity_np()"),
451-
KMP_ERR(error), __kmp_msg_null);
452-
}
453-
return error;
454-
}
455-
#elif KMP_OS_AIX
412+
#if KMP_OS_AIX
456413
// On AIX, we don't have a way to get CPU(s) a thread is bound to.
457414
// This routine is only used to get the full mask.
458415
int get_system_affinity(bool abort_on_error) override {
@@ -513,7 +470,50 @@ class KMPNativeAffinity : public KMPAffinity {
513470
}
514471
return 0;
515472
}
516-
#endif // !KMP_OS_AIX
473+
#else // !KMP_OS_AIX
474+
int get_system_affinity(bool abort_on_error) override {
475+
KMP_ASSERT2(KMP_AFFINITY_CAPABLE(),
476+
"Illegal get affinity operation when not capable");
477+
#if KMP_OS_LINUX
478+
long retval =
479+
syscall(__NR_sched_getaffinity, 0, __kmp_affin_mask_size, mask);
480+
#elif KMP_OS_FREEBSD || KMP_OS_NETBSD || KMP_OS_DRAGONFLY
481+
int r = pthread_getaffinity_np(pthread_self(), __kmp_affin_mask_size,
482+
reinterpret_cast<cpuset_t *>(mask));
483+
int retval = (r == 0 ? 0 : -1);
484+
#endif
485+
if (retval >= 0) {
486+
return 0;
487+
}
488+
int error = errno;
489+
if (abort_on_error) {
490+
__kmp_fatal(KMP_MSG(FunctionError, "pthread_getaffinity_np()"),
491+
KMP_ERR(error), __kmp_msg_null);
492+
}
493+
return error;
494+
}
495+
int set_system_affinity(bool abort_on_error) const override {
496+
KMP_ASSERT2(KMP_AFFINITY_CAPABLE(),
497+
"Illegal set affinity operation when not capable");
498+
#if KMP_OS_LINUX
499+
long retval =
500+
syscall(__NR_sched_setaffinity, 0, __kmp_affin_mask_size, mask);
501+
#elif KMP_OS_FREEBSD || KMP_OS_NETBSD || KMP_OS_DRAGONFLY
502+
int r = pthread_setaffinity_np(pthread_self(), __kmp_affin_mask_size,
503+
reinterpret_cast<cpuset_t *>(mask));
504+
int retval = (r == 0 ? 0 : -1);
505+
#endif
506+
if (retval >= 0) {
507+
return 0;
508+
}
509+
int error = errno;
510+
if (abort_on_error) {
511+
__kmp_fatal(KMP_MSG(FunctionError, "pthread_setaffinity_np()"),
512+
KMP_ERR(error), __kmp_msg_null);
513+
}
514+
return error;
515+
}
516+
#endif // KMP_OS_AIX
517517
};
518518
void determine_capable(const char *env_var) override {
519519
__kmp_affinity_determine_capable(env_var);

0 commit comments

Comments
 (0)