Add device mutual exclusion tests and related fixes

* Added a new test to verify mutual exclusion of access to device
  resources
* Added some missing acquiring of mutexes to some RSMI calls, as
  well as try-catch blocks.

Change-Id: I87aac009878a0b2d1f975e1d5b794d887bb23ff9


[ROCm/amdsmi commit: f8b57c3b16]
Šī revīzija ir iekļauta:
Chris Freehill
2020-04-07 17:13:50 -05:00
vecāks 8ecf004060
revīzija d592203ff5
10 mainīti faili ar 429 papildinājumiem un 38 dzēšanām
@@ -118,9 +118,10 @@ typedef enum {
//!< input
RSMI_STATUS_UNEXPECTED_DATA, //!< The data read or provided to
//!< function is not what was expected
RSMI_STATUS_RESOURCE_BUSY, //!< A function timed out trying to
//!< a resource. This could be a
//!< mutex time-out.
RSMI_STATUS_BUSY, //!< A resource or mutex could not be
//!< acquired because it is already
//!< being used
RSMI_STATUS_UNKNOWN_ERROR = 0xFFFFFFFF, //!< An unknown error occurred
} rsmi_status_t;
@@ -131,12 +132,13 @@ typedef enum {
*/
typedef enum {
RSMI_INIT_FLAG_ALL_GPUS = 0x1, //!< Attempt to add all GPUs found
RSMI_INIT_FLAG_ALL_GPUS = 0x1, //!< Attempt to add all GPUs found
//!< (including non-AMD) to the list
//!< of devices from which SMI
//!< information can be retrieved. By
//!< default, only AMD devices are
//!< ennumerated by RSMI.
RSMI_INIT_FLAG_RESRV_TEST1 = 0x800000000000000, //!< Reserved for test
} rsmi_init_flags_t;
/**
@@ -75,23 +75,35 @@ struct pthread_wrap {
public:
explicit pthread_wrap(pthread_mutex_t &p_mut) : mutex_(p_mut) {}
void Acquire() { pthread_mutex_lock(&mutex_); }
void Release() { pthread_mutex_unlock(&mutex_); }
void Acquire() {pthread_mutex_lock(&mutex_);}
int AcquireNB() {return pthread_mutex_trylock(&mutex_);}
void Release() {pthread_mutex_unlock(&mutex_);}
private:
pthread_mutex_t& mutex_;
};
struct ScopedPthread {
explicit ScopedPthread(pthread_wrap& mutex) : pthrd_ref_(mutex) {
pthrd_ref_.Acquire();
explicit ScopedPthread(pthread_wrap& mutex, bool blocking = true) : //NOLINT
pthrd_ref_(mutex), mutex_not_acquired_(false) {
if (blocking) {
pthrd_ref_.Acquire();
} else {
int ret = pthrd_ref_.AcquireNB();
if (ret == EBUSY) {
mutex_not_acquired_ = true;
}
}
}
~ScopedPthread() {
pthrd_ref_.Release();
}
bool mutex_not_acquired() {return mutex_not_acquired_;}
private:
ScopedPthread(const ScopedPthread&);
pthread_wrap& pthrd_ref_;
bool mutex_not_acquired_; // Use for AcquireNB (not for Aquire())
};
} // namespace smi
} // namespace amd