mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-23 14:07:42 +00:00
tools: acrntrace: give user hint when acrn trace devices not found
If module acrn_trace is configured as "m" and we don't insert it before launching acrntrace tool, acrntrace will run normally instead of throw out an error in current implementation. And no trace files are generated. It will cause confusing here. So, this patch throw out an error massage to user about the absence of acrn trace devices. BTW, this patch replaces cpuid/num related concept to devid/cnt which is more suitable for /dev/acrn_trace_xxx. Tracked-On: #1975 Signed-off-by: Kaige Fu <kaige.fu@intel.com> Acked-by: Yan, Like <like.yan@intel.com>
This commit is contained in:
parent
9ea93ce620
commit
d85a0b70ed
@ -36,7 +36,7 @@ static uint32_t flags;
|
||||
static char trace_file_dir[TRACE_FILE_DIR_LEN];
|
||||
|
||||
static reader_struct *reader;
|
||||
static int pcpu_num = 0;
|
||||
static int dev_cnt = 0; /* Count of /dev/acrn_trace_xxx devices */
|
||||
|
||||
static void display_usage(void)
|
||||
{
|
||||
@ -128,10 +128,10 @@ static int parse_opt(int argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_cpu_num(void)
|
||||
static int get_dev_cnt(void)
|
||||
{
|
||||
struct dirent *pdir;
|
||||
int cpu_num = 0;
|
||||
int cnt = 0;
|
||||
char *ret;
|
||||
DIR *dir;
|
||||
|
||||
@ -144,12 +144,12 @@ static int get_cpu_num(void)
|
||||
while ((pdir = readdir(dir)) != NULL) {
|
||||
ret = strstr(pdir->d_name, dev_prefix);
|
||||
if (ret)
|
||||
cpu_num++;
|
||||
cnt++;
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
|
||||
return cpu_num;
|
||||
return cnt;
|
||||
}
|
||||
|
||||
static int create_trace_file_dir(char *dir)
|
||||
@ -229,15 +229,15 @@ static void reader_fn(param_t * param)
|
||||
}
|
||||
}
|
||||
|
||||
static int create_reader(reader_struct * reader, uint32_t cpu)
|
||||
static int create_reader(reader_struct * reader, uint32_t dev_id)
|
||||
{
|
||||
char trace_file_name[TRACE_FILE_NAME_LEN];
|
||||
|
||||
if (snprintf(reader->dev_name, DEV_PATH_LEN, "/dev/%s%u", dev_prefix, cpu)
|
||||
if (snprintf(reader->dev_name, DEV_PATH_LEN, "/dev/%s%u", dev_prefix, dev_id)
|
||||
>= DEV_PATH_LEN)
|
||||
printf("WARN: device name is truncated\n");
|
||||
|
||||
reader->param.cpuid = cpu;
|
||||
reader->param.devid = dev_id;
|
||||
|
||||
reader->dev_fd = open(reader->dev_name, O_RDWR);
|
||||
if (reader->dev_fd < 0) {
|
||||
@ -250,17 +250,17 @@ static int create_reader(reader_struct * reader, uint32_t cpu)
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED, reader->dev_fd, 0);
|
||||
if (reader->param.sbuf == MAP_FAILED) {
|
||||
pr_err("mmap failed for cpu%d, errno %d\n", cpu, errno);
|
||||
pr_err("mmap failed for %s, errno %d\n", reader->dev_name, errno);
|
||||
reader->param.sbuf = NULL;
|
||||
return -2;
|
||||
}
|
||||
|
||||
pr_dbg("sbuf[%d]:\nmagic_num: %lx\nele_num: %u\n ele_size: %u\n",
|
||||
cpu, reader->param.sbuf->magic, reader->param.sbuf->ele_num,
|
||||
dev_id, reader->param.sbuf->magic, reader->param.sbuf->ele_num,
|
||||
reader->param.sbuf->ele_size);
|
||||
|
||||
if(snprintf(trace_file_name, TRACE_FILE_NAME_LEN, "%s/%d", trace_file_dir,
|
||||
cpu) >= TRACE_FILE_NAME_LEN)
|
||||
dev_id) >= TRACE_FILE_NAME_LEN)
|
||||
printf("WARN: trace file name is truncated\n");
|
||||
reader->param.trace_fd = open(trace_file_name,
|
||||
O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
||||
@ -274,7 +274,7 @@ static int create_reader(reader_struct * reader, uint32_t cpu)
|
||||
|
||||
if (pthread_create(&reader->thrd, NULL,
|
||||
(void *)&reader_fn, &reader->param)) {
|
||||
pr_err("failed to create reader thread, %d\n", cpu);
|
||||
pr_err("failed to create reader thread, %d\n", dev_id);
|
||||
return -4;
|
||||
}
|
||||
|
||||
@ -308,7 +308,7 @@ static void destory_reader(reader_struct * reader)
|
||||
|
||||
static void handle_on_exit(void)
|
||||
{
|
||||
uint32_t cpu;
|
||||
uint32_t dev_id;
|
||||
|
||||
/* if nothing to release */
|
||||
if (!(flags & FLAG_TO_REL))
|
||||
@ -316,8 +316,8 @@ static void handle_on_exit(void)
|
||||
|
||||
pr_info("exiting - to release resources...\n");
|
||||
|
||||
foreach_cpu(cpu)
|
||||
destory_reader(&reader[cpu]);
|
||||
foreach_dev(dev_id)
|
||||
destory_reader(&reader[dev_id]);
|
||||
}
|
||||
|
||||
static void signal_exit_handler(int sig)
|
||||
@ -328,16 +328,20 @@ static void signal_exit_handler(int sig)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
uint32_t cpu = 0;
|
||||
uint32_t dev_id = 0;
|
||||
int err;
|
||||
|
||||
/* parse options */
|
||||
if (parse_opt(argc, argv))
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
/* how many cpus */
|
||||
pcpu_num = get_cpu_num();
|
||||
reader = calloc(1, sizeof(reader_struct) * pcpu_num);
|
||||
dev_cnt = get_dev_cnt();
|
||||
if (dev_cnt == 0) {
|
||||
pr_err("Failed to find acrn trace devices, please check whether module acrn_trace is inserted\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
reader = calloc(1, sizeof(reader_struct) * dev_cnt);
|
||||
if (!reader) {
|
||||
pr_err("Failed to allocate reader memory\n");
|
||||
exit(EXIT_FAILURE);
|
||||
@ -362,8 +366,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* acquair res for each trace dev */
|
||||
flags |= FLAG_TO_REL;
|
||||
foreach_cpu(cpu)
|
||||
if (create_reader(&reader[cpu], cpu) < 0)
|
||||
foreach_dev(dev_id)
|
||||
if (create_reader(&reader[dev_id], dev_id) < 0)
|
||||
goto out_free;
|
||||
|
||||
/* for kill exit handling */
|
||||
@ -376,8 +380,8 @@ int main(int argc, char *argv[])
|
||||
printf("q <enter> to quit:\n");
|
||||
|
||||
out_free:
|
||||
foreach_cpu(cpu)
|
||||
destory_reader(&reader[cpu]);
|
||||
foreach_dev(dev_id)
|
||||
destory_reader(&reader[dev_id]);
|
||||
|
||||
free(reader);
|
||||
flags &= ~FLAG_TO_REL;
|
||||
|
@ -42,8 +42,8 @@
|
||||
#define FLAG_TO_REL (1UL << 0)
|
||||
#define FLAG_CLEAR_BUF (1UL << 1)
|
||||
|
||||
#define foreach_cpu(cpu) \
|
||||
for ((cpu) = 0; (cpu) < (pcpu_num); (cpu)++)
|
||||
#define foreach_dev(dev_id) \
|
||||
for ((dev_id) = 0; (dev_id) < (dev_cnt); (dev_id)++)
|
||||
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned int uint32_t;
|
||||
@ -71,7 +71,7 @@ typedef struct {
|
||||
} trace_ev_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t cpuid;
|
||||
uint32_t devid;
|
||||
int exit_flag;
|
||||
int trace_fd;
|
||||
shared_buf_t *sbuf;
|
||||
|
Loading…
Reference in New Issue
Block a user