Skip to content

Commit 6c1a5e0

Browse files
jlawrynojfvogel
authored andcommitted
accel/ivpu: Refactor functions in ivpu_fw_log.c
commit 1fc1251 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 <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Jacek Lawrynowicz <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 0923a7d55a85179744926b7c11768a81679cc4d4) Signed-off-by: Jack Vogel <[email protected]>
1 parent f0ea7e7 commit 6c1a5e0

File tree

3 files changed

+35
-31
lines changed

3 files changed

+35
-31
lines changed

drivers/accel/ivpu/ivpu_debugfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ fw_log_fops_write(struct file *file, const char __user *user_buf, size_t size, l
201201
if (!size)
202202
return -EINVAL;
203203

204-
ivpu_fw_log_clear(vdev);
204+
ivpu_fw_log_mark_read(vdev);
205205
return size;
206206
}
207207

drivers/accel/ivpu/ivpu_fw_log.c

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ MODULE_PARM_DESC(fw_log_level,
2626
" error=" __stringify(IVPU_FW_LOG_ERROR)
2727
" fatal=" __stringify(IVPU_FW_LOG_FATAL));
2828

29-
static int fw_log_ptr(struct ivpu_device *vdev, struct ivpu_bo *bo, u32 *offset,
30-
struct vpu_tracing_buffer_header **log_header)
29+
static int fw_log_from_bo(struct ivpu_device *vdev, struct ivpu_bo *bo, u32 *offset,
30+
struct vpu_tracing_buffer_header **out_log)
3131
{
3232
struct vpu_tracing_buffer_header *log;
3333

@@ -48,7 +48,7 @@ static int fw_log_ptr(struct ivpu_device *vdev, struct ivpu_bo *bo, u32 *offset,
4848
return -EINVAL;
4949
}
5050

51-
*log_header = log;
51+
*out_log = log;
5252
*offset += log->size;
5353

5454
ivpu_dbg(vdev, FW_BOOT,
@@ -59,7 +59,7 @@ static int fw_log_ptr(struct ivpu_device *vdev, struct ivpu_bo *bo, u32 *offset,
5959
return 0;
6060
}
6161

62-
static void buffer_print(char *buffer, u32 size, struct drm_printer *p)
62+
static void fw_log_print_lines(char *buffer, u32 size, struct drm_printer *p)
6363
{
6464
char line[IVPU_FW_LOG_LINE_LENGTH];
6565
u32 index = 0;
@@ -90,11 +90,11 @@ static void buffer_print(char *buffer, u32 size, struct drm_printer *p)
9090
drm_printf(p, "%s\n", line);
9191
}
9292

93-
static void fw_log_print_buffer(struct ivpu_device *vdev, struct vpu_tracing_buffer_header *log,
94-
const char *prefix, bool only_new_msgs, struct drm_printer *p)
93+
static void fw_log_print_buffer(struct vpu_tracing_buffer_header *log, const char *prefix,
94+
bool only_new_msgs, struct drm_printer *p)
9595
{
96-
char *log_buffer = (void *)log + log->header_size;
97-
u32 log_size = log->size - log->header_size;
96+
char *log_data = (void *)log + log->header_size;
97+
u32 data_size = log->size - log->header_size;
9898
u32 log_start = log->read_index;
9999
u32 log_end = log->write_index;
100100

@@ -106,51 +106,55 @@ static void fw_log_print_buffer(struct ivpu_device *vdev, struct vpu_tracing_buf
106106

107107
drm_printf(p, "==== %s \"%s\" log start ====\n", prefix, log->name);
108108
if (log->write_index > log->read_index) {
109-
buffer_print(log_buffer + log_start, log_end - log_start, p);
109+
fw_log_print_lines(log_data + log_start, log_end - log_start, p);
110110
} else {
111-
buffer_print(log_buffer + log_end, log_size - log_end, p);
112-
buffer_print(log_buffer, log_end, p);
111+
fw_log_print_lines(log_data + log_end, data_size - log_end, p);
112+
fw_log_print_lines(log_data, log_end, p);
113113
}
114114
drm_printf(p, "\x1b[0m");
115115
drm_printf(p, "==== %s \"%s\" log end ====\n", prefix, log->name);
116116
}
117117

118-
void ivpu_fw_log_print(struct ivpu_device *vdev, bool only_new_msgs, struct drm_printer *p)
118+
static void
119+
fw_log_print_all_in_bo(struct ivpu_device *vdev, const char *name,
120+
struct ivpu_bo *bo, bool only_new_msgs, struct drm_printer *p)
119121
{
120-
struct vpu_tracing_buffer_header *log_header;
122+
struct vpu_tracing_buffer_header *log;
121123
u32 next = 0;
122124

123-
while (fw_log_ptr(vdev, vdev->fw->mem_log_crit, &next, &log_header) == 0)
124-
fw_log_print_buffer(vdev, log_header, "NPU critical", only_new_msgs, p);
125+
while (fw_log_from_bo(vdev, bo, &next, &log) == 0)
126+
fw_log_print_buffer(log, name, only_new_msgs, p);
127+
}
125128

126-
next = 0;
127-
while (fw_log_ptr(vdev, vdev->fw->mem_log_verb, &next, &log_header) == 0)
128-
fw_log_print_buffer(vdev, log_header, "NPU verbose", only_new_msgs, p);
129+
void ivpu_fw_log_print(struct ivpu_device *vdev, bool only_new_msgs, struct drm_printer *p)
130+
{
131+
fw_log_print_all_in_bo(vdev, "NPU critical", vdev->fw->mem_log_crit, only_new_msgs, p);
132+
fw_log_print_all_in_bo(vdev, "NPU verbose", vdev->fw->mem_log_verb, only_new_msgs, p);
129133
}
130134

131-
void ivpu_fw_log_clear(struct ivpu_device *vdev)
135+
void ivpu_fw_log_mark_read(struct ivpu_device *vdev)
132136
{
133-
struct vpu_tracing_buffer_header *log_header;
137+
struct vpu_tracing_buffer_header *log;
134138
u32 next = 0;
135139

136-
while (fw_log_ptr(vdev, vdev->fw->mem_log_crit, &next, &log_header) == 0)
137-
log_header->read_index = log_header->write_index;
140+
while (fw_log_from_bo(vdev, vdev->fw->mem_log_crit, &next, &log) == 0)
141+
log->read_index = log->write_index;
138142

139143
next = 0;
140-
while (fw_log_ptr(vdev, vdev->fw->mem_log_verb, &next, &log_header) == 0)
141-
log_header->read_index = log_header->write_index;
144+
while (fw_log_from_bo(vdev, vdev->fw->mem_log_verb, &next, &log) == 0)
145+
log->read_index = log->write_index;
142146
}
143147

144148
void ivpu_fw_log_reset(struct ivpu_device *vdev)
145149
{
146-
struct vpu_tracing_buffer_header *log_header;
150+
struct vpu_tracing_buffer_header *log;
147151
u32 next;
148152

149153
next = 0;
150-
while (fw_log_ptr(vdev, vdev->fw->mem_log_crit, &next, &log_header) == 0)
151-
log_header->read_index = 0;
154+
while (fw_log_from_bo(vdev, vdev->fw->mem_log_crit, &next, &log) == 0)
155+
log->read_index = 0;
152156

153157
next = 0;
154-
while (fw_log_ptr(vdev, vdev->fw->mem_log_verb, &next, &log_header) == 0)
155-
log_header->read_index = 0;
158+
while (fw_log_from_bo(vdev, vdev->fw->mem_log_verb, &next, &log) == 0)
159+
log->read_index = 0;
156160
}

drivers/accel/ivpu/ivpu_fw_log.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
extern unsigned int ivpu_fw_log_level;
2525

2626
void ivpu_fw_log_print(struct ivpu_device *vdev, bool only_new_msgs, struct drm_printer *p);
27-
void ivpu_fw_log_clear(struct ivpu_device *vdev);
27+
void ivpu_fw_log_mark_read(struct ivpu_device *vdev);
2828
void ivpu_fw_log_reset(struct ivpu_device *vdev);
2929

3030

0 commit comments

Comments
 (0)