Revert^2 "Revert "Merge amd-staging into amd-master 20230524""

4e044a1f6c

Change-Id: Ibb44f48a8ea2099de01cf04d31b47f2a2f2473ad
This commit is contained in:
Hao Zhou
2023-06-02 02:12:07 -04:00
parent 5aa94c48d1
commit be41c19d3c
30 changed files with 78 additions and 4302 deletions
+10 -15
View File
@@ -78,7 +78,7 @@ static std::vector<std::string> lsof(const char* filename) {
return matched_process;
}
shared_mutex_t shared_mutex_init(const char *name, mode_t mode, bool retried) {
shared_mutex_t shared_mutex_init(const char *name, mode_t mode) {
shared_mutex_t mutex = {NULL, 0, NULL, 0};
errno = 0;
@@ -123,6 +123,15 @@ shared_mutex_t shared_mutex_init(const char *name, mode_t mode, bool retried) {
pthread_mutex_t *mutex_ptr = reinterpret_cast<pthread_mutex_t *>(addr);
// When process crash before unlock the mutex, the mutex is in bad status.
// reset the mutex if no process is using it
std::vector<std::string> ids = lsof(name);
if (ids.size() == 0) { // no process is using it
memset(mutex_ptr, 0, sizeof(pthread_mutex_t));
// Set mutex.created == 1 so that it can be initialized latter.
mutex.created = 1;
}
// Make sure the mutex wasn't left in a locked state. If we can't
// acquire it in 5 sec., re-do everything.
struct timespec expireTime;
@@ -152,20 +161,6 @@ shared_mutex_t shared_mutex_init(const char *name, mode_t mode, bool retried) {
} else if (ret || (mutex.created == 0 &&
reinterpret_cast<shared_mutex_t *>(addr)->ptr == NULL)) {
// Something is out of sync.
// When process crash before unlock the mutex, the mutex is in bad status.
// reset the mutex if no process is using it, and then retry lock
if (!retried) {
std::vector<std::string> ids = lsof(name);
if (ids.size() == 0) { // no process is using it
memset(mutex_ptr, 0, sizeof(pthread_mutex_t));
// Set mutex.created == 1 so that it can be initialized latter.
mutex.created = 1;
free(mutex.name);
return shared_mutex_init(name, mode, true);
}
}
fprintf(stderr, "pthread_mutex_timedlock() returned %d\n", ret);
perror("Failed to initialize RSMI device mutex after 5 seconds. Previous "
"execution may not have shutdown cleanly. To fix problem, stop all "
+1 -1
View File
@@ -61,7 +61,7 @@ typedef struct shared_mutex_t {
// There is no workaround currently, except to run first
// initialization only before multi-threaded or multi-process
// functionality.
shared_mutex_t shared_mutex_init(const char *name, mode_t mode, bool retried=false);
shared_mutex_t shared_mutex_init(const char *name, mode_t mode);
// Close access to the shared mutex and free all the resources,
// used by the structure.