Introduce debug level to Thunk
Existing Thunk has printf/fprintf in the code while normally libraries
don't print any message. This patch introduces a print machenism similar to
how the Linux kernel prints to console based on the log level. The default
is not to print any message, but setting HSAKMT_DEBUG_LEVEL will enable the
prints.
Change-Id: Ic071e122d35a82260218e9914cde4815e69df742
Signed-off-by: Amber Lin <Amber.Lin@amd.com>
[ROCm/ROCR-Runtime commit: ccfe739929]
이 커밋은 다음에 포함됨:
@@ -64,6 +64,24 @@ extern int PAGE_SHIFT;
|
||||
#define BITMASK(n) (((n) < sizeof(1ULL) * CHAR_BIT ? (1ULL << (n)) : 0) - 1ULL)
|
||||
#define ARRAY_LEN(array) (sizeof(array) / sizeof(array[0]))
|
||||
|
||||
/* HSA Thunk logging usage */
|
||||
extern int hsakmt_debug_level;
|
||||
#define hsakmt_print(level, fmt, ...) \
|
||||
do { if (level <= hsakmt_debug_level) fprintf(stderr, fmt, ##__VA_ARGS__); } while (0)
|
||||
#define HSAKMT_DEBUG_LEVEL_DEFAULT -1
|
||||
#define HSAKMT_DEBUG_LEVEL_ERR 3
|
||||
#define HSAKMT_DEBUG_LEVEL_WARNING 4
|
||||
#define HSAKMT_DEBUG_LEVEL_INFO 6
|
||||
#define HSAKMT_DEBUG_LEVEL_DEBUG 7
|
||||
#define pr_err(fmt, ...) \
|
||||
hsakmt_print(HSAKMT_DEBUG_LEVEL_ERR, fmt, ##__VA_ARGS__)
|
||||
#define pr_warn(fmt, ...) \
|
||||
hsakmt_print(HSAKMT_DEBUG_LEVEL_WARNING, fmt, ##__VA_ARGS__)
|
||||
#define pr_info(fmt, ...) \
|
||||
hsakmt_print(HSAKMT_DEBUG_LEVEL_INFO, fmt, ##__VA_ARGS__)
|
||||
#define pr_debug(fmt, ...) \
|
||||
hsakmt_print(HSAKMT_DEBUG_LEVEL_DEBUG, fmt, ##__VA_ARGS__)
|
||||
|
||||
enum asic_family_type {
|
||||
CHIP_KAVERI = 0,
|
||||
CHIP_HAWAII,
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "libhsakmt.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
@@ -38,7 +39,7 @@ static const char kfd_device_name[] = "/dev/kfd";
|
||||
static const char tmp_file[] = "/var/lock/.amd_hsa_thunk_lock";
|
||||
int amd_hsa_thunk_lock_fd;
|
||||
static pid_t parent_pid = -1;
|
||||
|
||||
int hsakmt_debug_level;
|
||||
|
||||
static bool is_forked_child(void)
|
||||
{
|
||||
@@ -76,6 +77,25 @@ static inline void init_page_size(void)
|
||||
PAGE_SHIFT = ffs(PAGE_SIZE) - 1;
|
||||
}
|
||||
|
||||
/* Normally libraries don't print messages. For debugging purpose, we'll
|
||||
* print messages if an environment variable, HSAKMT_DEBUG_LEVEL, is set.
|
||||
*/
|
||||
static void init_debug_level(void)
|
||||
{
|
||||
char *envvar;
|
||||
int debug_level;
|
||||
|
||||
hsakmt_debug_level = HSAKMT_DEBUG_LEVEL_DEFAULT;
|
||||
|
||||
envvar = getenv("HSAKMT_DEBUG_LEVEL");
|
||||
if (envvar) {
|
||||
debug_level = atoi(envvar);
|
||||
if (debug_level >= HSAKMT_DEBUG_LEVEL_ERR &&
|
||||
debug_level <= HSAKMT_DEBUG_LEVEL_DEBUG)
|
||||
hsakmt_debug_level = debug_level;
|
||||
}
|
||||
}
|
||||
|
||||
HSAKMT_STATUS HSAKMTAPI hsaKmtOpenKFD(void)
|
||||
{
|
||||
HSAKMT_STATUS result;
|
||||
@@ -93,6 +113,7 @@ HSAKMT_STATUS HSAKMTAPI hsaKmtOpenKFD(void)
|
||||
clear_after_fork();
|
||||
|
||||
if (kfd_open_count == 0) {
|
||||
init_debug_level();
|
||||
amd_hsa_thunk_lock_fd = 0;
|
||||
|
||||
fd = open(kfd_device_name, O_RDWR | O_CLOEXEC);
|
||||
|
||||
새 이슈에서 참조
사용자 차단