Merge amd-staging into amd-master 20221124

Signed-off-by: Hao Zhou <Hao.Zhou@amd.com>
Change-Id: Iff6f3f5c66a33f703588b2afbf767777564c178b
Αυτή η υποβολή περιλαμβάνεται σε:
Hao Zhou
2022-11-24 17:18:44 +08:00
γονέας dcebccffb2 76b5528feb
υποβολή 3a5765fbcf
3 αρχεία άλλαξαν με 67 προσθήκες και 3 διαγραφές
@@ -57,7 +57,20 @@ function(create_header_template)
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/\n\n#ifndef @include_guard@\n#define @include_guard@ \n\n#pragma message(\"This file is deprecated. Use file from include path /opt/rocm-ver/include/ and prefix with @prefix_name@\")\n@include_statements@ \n\n#endif")
*/
#ifndef @include_guard@
#define @include_guard@
#if defined(__GNUC__)
#warning \"This file is deprecated. Use file from include path /opt/rocm-ver/include/ and prefix with @prefix_name@\"
#else
#pragma message(\"This file is deprecated. Use file from include path /opt/rocm-ver/include/ and prefix with @prefix_name@\")
#endif
@include_statements@
#endif")
endfunction()
#use header template file and generate wrapper header files
+1 -1
Προβολή Αρχείου
@@ -41,10 +41,10 @@
*
*/
#include <pthread.h>
#include <unistd.h>
#include <sys/types.h>
#include <assert.h>
#include <sys/stat.h>
#include <stdint.h>
+52 -1
Προβολή Αρχείου
@@ -1,5 +1,5 @@
/*
Modifications Copyright © 2019 2020 Advanced Micro Devices, Inc. All Rights
Modifications Copyright 2019 - 2022 Advanced Micro Devices, Inc. All Rights
Reserved.
Copyright (c) 2018 Oleg Yamnikov
@@ -34,8 +34,50 @@ THE SOFTWARE.
#include <time.h> // clock_gettime
#include <assert.h>
#include <sys/types.h>
#include <dirent.h>
#include <algorithm>
#include <string>
#include <vector>
#include "rocm_smi/rocm_smi_exception.h"
// find which processes are using the file by searching /proc/*/fd
static std::vector<std::string> lsof(const char* filename) {
struct dirent *entry = nullptr;
DIR *dp = nullptr;
std::vector<std::string> process_id;
dp = opendir("/proc");
if (dp != nullptr) {
while ((entry = readdir(dp))) {
std::string id(entry->d_name);
// the process id should be a number
if (std::all_of(id.begin(), id.end(), ::isdigit)) {
process_id.push_back(entry->d_name);
}
}
closedir(dp);
}
std::vector<std::string> matched_process;
for (unsigned int i=0; i < process_id.size(); i++) {
std::string folder_name("/proc/");
folder_name += process_id[i]+"/fd/";
dp = opendir(folder_name.c_str());
if (dp == nullptr) continue;
while ((entry = readdir(dp))) {
std::string p(folder_name+entry->d_name);
char buf[512];
memset(buf, 0, 512);
if (readlink(p.c_str(), buf, sizeof(buf)-1) < 0) continue;
if (!strcmp(filename, buf)) matched_process.push_back(process_id[i]);
}
closedir(dp);
}
return matched_process;
}
shared_mutex_t shared_mutex_init(const char *name, mode_t mode) {
shared_mutex_t mutex = {NULL, 0, NULL, 0};
errno = 0;
@@ -81,6 +123,15 @@ shared_mutex_t shared_mutex_init(const char *name, mode_t mode) {
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;