accel/ivpu: Refactor functions in ivpu_fw_log.c

commit 1fc1251149a76d3b75d7f4c94d9c4e081b7df6b4 upstream.

Make function names more consistent and (arguably) readable in
fw log code. Add fw_log_print_all_in_bo() that remove duplicated code in
ivpu_fw_log_print().

Reviewed-by: Tomasz Rusinowicz <tomasz.rusinowicz@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240930195322.461209-5-jacek.lawrynowicz@linux.intel.com
Signed-off-by: Jacek Lawrynowicz <jacek.lawrynowicz@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Jacek Lawrynowicz
2024-09-30 21:52:55 +02:00
committed by Greg Kroah-Hartman
parent 1516c55872
commit 0923a7d55a
3 changed files with 36 additions and 32 deletions
+1 -1
View File
@@ -201,7 +201,7 @@ fw_log_fops_write(struct file *file, const char __user *user_buf, size_t size, l
if (!size) if (!size)
return -EINVAL; return -EINVAL;
ivpu_fw_log_clear(vdev); ivpu_fw_log_mark_read(vdev);
return size; return size;
} }
+34 -30
View File
@@ -26,8 +26,8 @@ MODULE_PARM_DESC(fw_log_level,
" error=" __stringify(IVPU_FW_LOG_ERROR) " error=" __stringify(IVPU_FW_LOG_ERROR)
" fatal=" __stringify(IVPU_FW_LOG_FATAL)); " fatal=" __stringify(IVPU_FW_LOG_FATAL));
static int fw_log_ptr(struct ivpu_device *vdev, struct ivpu_bo *bo, u32 *offset, static int fw_log_from_bo(struct ivpu_device *vdev, struct ivpu_bo *bo, u32 *offset,
struct vpu_tracing_buffer_header **log_header) struct vpu_tracing_buffer_header **out_log)
{ {
struct vpu_tracing_buffer_header *log; struct vpu_tracing_buffer_header *log;
@@ -48,7 +48,7 @@ static int fw_log_ptr(struct ivpu_device *vdev, struct ivpu_bo *bo, u32 *offset,
return -EINVAL; return -EINVAL;
} }
*log_header = log; *out_log = log;
*offset += log->size; *offset += log->size;
ivpu_dbg(vdev, FW_BOOT, ivpu_dbg(vdev, FW_BOOT,
@@ -59,7 +59,7 @@ static int fw_log_ptr(struct ivpu_device *vdev, struct ivpu_bo *bo, u32 *offset,
return 0; return 0;
} }
static void buffer_print(char *buffer, u32 size, struct drm_printer *p) static void fw_log_print_lines(char *buffer, u32 size, struct drm_printer *p)
{ {
char line[IVPU_FW_LOG_LINE_LENGTH]; char line[IVPU_FW_LOG_LINE_LENGTH];
u32 index = 0; u32 index = 0;
@@ -90,11 +90,11 @@ static void buffer_print(char *buffer, u32 size, struct drm_printer *p)
drm_printf(p, "%s\n", line); drm_printf(p, "%s\n", line);
} }
static void fw_log_print_buffer(struct ivpu_device *vdev, struct vpu_tracing_buffer_header *log, static void fw_log_print_buffer(struct vpu_tracing_buffer_header *log, const char *prefix,
const char *prefix, bool only_new_msgs, struct drm_printer *p) bool only_new_msgs, struct drm_printer *p)
{ {
char *log_buffer = (void *)log + log->header_size; char *log_data = (void *)log + log->header_size;
u32 log_size = log->size - log->header_size; u32 data_size = log->size - log->header_size;
u32 log_start = log->read_index; u32 log_start = log->read_index;
u32 log_end = log->write_index; u32 log_end = log->write_index;
@@ -106,51 +106,55 @@ static void fw_log_print_buffer(struct ivpu_device *vdev, struct vpu_tracing_buf
drm_printf(p, "==== %s \"%s\" log start ====\n", prefix, log->name); drm_printf(p, "==== %s \"%s\" log start ====\n", prefix, log->name);
if (log->write_index > log->read_index) { if (log->write_index > log->read_index) {
buffer_print(log_buffer + log_start, log_end - log_start, p); fw_log_print_lines(log_data + log_start, log_end - log_start, p);
} else { } else {
buffer_print(log_buffer + log_end, log_size - log_end, p); fw_log_print_lines(log_data + log_end, data_size - log_end, p);
buffer_print(log_buffer, log_end, p); fw_log_print_lines(log_data, log_end, p);
} }
drm_printf(p, "\x1b[0m"); drm_printf(p, "\x1b[0m");
drm_printf(p, "==== %s \"%s\" log end ====\n", prefix, log->name); drm_printf(p, "==== %s \"%s\" log end ====\n", prefix, log->name);
} }
void ivpu_fw_log_print(struct ivpu_device *vdev, bool only_new_msgs, struct drm_printer *p) static void
fw_log_print_all_in_bo(struct ivpu_device *vdev, const char *name,
struct ivpu_bo *bo, bool only_new_msgs, struct drm_printer *p)
{ {
struct vpu_tracing_buffer_header *log_header; struct vpu_tracing_buffer_header *log;
u32 next = 0; u32 next = 0;
while (fw_log_ptr(vdev, vdev->fw->mem_log_crit, &next, &log_header) == 0) while (fw_log_from_bo(vdev, bo, &next, &log) == 0)
fw_log_print_buffer(vdev, log_header, "NPU critical", only_new_msgs, p); fw_log_print_buffer(log, name, only_new_msgs, p);
next = 0;
while (fw_log_ptr(vdev, vdev->fw->mem_log_verb, &next, &log_header) == 0)
fw_log_print_buffer(vdev, log_header, "NPU verbose", only_new_msgs, p);
} }
void ivpu_fw_log_clear(struct ivpu_device *vdev) void ivpu_fw_log_print(struct ivpu_device *vdev, bool only_new_msgs, struct drm_printer *p)
{ {
struct vpu_tracing_buffer_header *log_header; fw_log_print_all_in_bo(vdev, "NPU critical", vdev->fw->mem_log_crit, only_new_msgs, p);
fw_log_print_all_in_bo(vdev, "NPU verbose", vdev->fw->mem_log_verb, only_new_msgs, p);
}
void ivpu_fw_log_mark_read(struct ivpu_device *vdev)
{
struct vpu_tracing_buffer_header *log;
u32 next = 0; u32 next = 0;
while (fw_log_ptr(vdev, vdev->fw->mem_log_crit, &next, &log_header) == 0) while (fw_log_from_bo(vdev, vdev->fw->mem_log_crit, &next, &log) == 0)
log_header->read_index = log_header->write_index; log->read_index = log->write_index;
next = 0; next = 0;
while (fw_log_ptr(vdev, vdev->fw->mem_log_verb, &next, &log_header) == 0) while (fw_log_from_bo(vdev, vdev->fw->mem_log_verb, &next, &log) == 0)
log_header->read_index = log_header->write_index; log->read_index = log->write_index;
} }
void ivpu_fw_log_reset(struct ivpu_device *vdev) void ivpu_fw_log_reset(struct ivpu_device *vdev)
{ {
struct vpu_tracing_buffer_header *log_header; struct vpu_tracing_buffer_header *log;
u32 next; u32 next;
next = 0; next = 0;
while (fw_log_ptr(vdev, vdev->fw->mem_log_crit, &next, &log_header) == 0) while (fw_log_from_bo(vdev, vdev->fw->mem_log_crit, &next, &log) == 0)
log_header->read_index = 0; log->read_index = 0;
next = 0; next = 0;
while (fw_log_ptr(vdev, vdev->fw->mem_log_verb, &next, &log_header) == 0) while (fw_log_from_bo(vdev, vdev->fw->mem_log_verb, &next, &log) == 0)
log_header->read_index = 0; log->read_index = 0;
} }
+1 -1
View File
@@ -24,7 +24,7 @@
extern unsigned int ivpu_fw_log_level; extern unsigned int ivpu_fw_log_level;
void ivpu_fw_log_print(struct ivpu_device *vdev, bool only_new_msgs, struct drm_printer *p); void ivpu_fw_log_print(struct ivpu_device *vdev, bool only_new_msgs, struct drm_printer *p);
void ivpu_fw_log_clear(struct ivpu_device *vdev); void ivpu_fw_log_mark_read(struct ivpu_device *vdev);
void ivpu_fw_log_reset(struct ivpu_device *vdev); void ivpu_fw_log_reset(struct ivpu_device *vdev);