[U-Boot] [PATCH v4 6/6] iotrace: fix behaviour when buffer is full

Ramon Fried ramon.fried at gmail.com
Wed May 30 20:10:02 UTC 2018


Don't continue updating the offset when buffer is full.
When the buffer size exhausts and there's no space left to write
warn the user and update only the needed size and not both the
offset and needed size.

Add needed buffer size information in the iotrace command.

Signed-off-by: Ramon Fried <ramon.fried at gmail.com>

---

Changes in v4: None
Changes in v3:
- fixed wrong usage of WARN_ONCE

Changes in v2:
- introduced needed_size to notify the user about the needed buffer size.

Changes in v1: None

 cmd/iotrace.c     | 11 ++++++-----
 common/iotrace.c  | 13 +++++++++++--
 include/iotrace.h |  5 +++--
 3 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/cmd/iotrace.c b/cmd/iotrace.c
index f50a3c3a1a..fc77f63de6 100644
--- a/cmd/iotrace.c
+++ b/cmd/iotrace.c
@@ -9,12 +9,13 @@
 
 static void do_print_stats(void)
 {
-	ulong start, size, offset, count;
+	ulong start, size, needed_size, offset, count;
 
 	printf("iotrace is %sabled\n", iotrace_get_enabled() ? "en" : "dis");
-	iotrace_get_buffer(&start, &size, &offset, &count);
+	iotrace_get_buffer(&start, &size, &needed_size, &offset, &count);
 	printf("Start:  %08lx\n", start);
-	printf("Size:   %08lx\n", size);
+	printf("Actual Size:   %08lx\n", size);
+	printf("Needed Size:   %08lx\n", needed_size);
 	iotrace_get_region(&start, &size);
 	printf("Region: %08lx\n", start);
 	printf("Size:   %08lx\n", size);
@@ -26,11 +27,11 @@ static void do_print_stats(void)
 
 static void do_print_trace(void)
 {
-	ulong start, size, offset, count;
+	ulong start, size, needed_size, offset, count;
 
 	struct iotrace_record *cur_record;
 
-	iotrace_get_buffer(&start, &size, &offset, &count);
+	iotrace_get_buffer(&start, &size, &needed_size, &offset, &count);
 
 	if (!start || !size || !count)
 		return;
diff --git a/common/iotrace.c b/common/iotrace.c
index 83691b1dba..49bee3c92a 100644
--- a/common/iotrace.c
+++ b/common/iotrace.c
@@ -15,7 +15,8 @@ DECLARE_GLOBAL_DATA_PTR;
  * struct iotrace - current trace status and checksum
  *
  * @start:	Start address of iotrace buffer
- * @size:	Size of iotrace buffer in bytes
+ * @size:	Actual size of iotrace buffer in bytes
+ * @needed_size: Needed of iotrace buffer in bytes
  * @offset:	Current write offset into iotrace buffer
  * @region_start: Address of IO region to trace
  * @region_size: Size of region to trace. if 0 will trace all address space
@@ -25,6 +26,7 @@ DECLARE_GLOBAL_DATA_PTR;
 static struct iotrace {
 	ulong start;
 	ulong size;
+	ulong needed_size;
 	ulong offset;
 	ulong region_start;
 	ulong region_size;
@@ -55,7 +57,12 @@ static void add_record(int flags, const void *ptr, ulong value)
 		rec = (struct iotrace_record *)map_sysmem(
 					iotrace.start + iotrace.offset,
 					sizeof(value));
+	} else {
+		WARN_ONCE(1, "WARNING: iotrace buffer exhausted, please check needed length using \"iotrace stats\"\n");
+		iotrace.needed_size += sizeof(struct iotrace_record);
+		return;
 	}
+
 	rec->timestamp = timer_get_us();
 	rec->flags = flags;
 	rec->addr = map_to_sysmem(ptr);
@@ -65,6 +72,7 @@ static void add_record(int flags, const void *ptr, ulong value)
 	iotrace.crc32 = crc32(iotrace.crc32, (unsigned char *)rec,
 			      sizeof(*rec));
 
+	iotrace.needed_size += sizeof(struct iotrace_record);
 	iotrace.offset += sizeof(struct iotrace_record);
 }
 
@@ -162,10 +170,11 @@ void iotrace_set_buffer(ulong start, ulong size)
 	iotrace.crc32 = 0;
 }
 
-void iotrace_get_buffer(ulong *start, ulong *size, ulong *offset, ulong *count)
+void iotrace_get_buffer(ulong *start, ulong *size, ulong *needed_size, ulong *offset, ulong *count)
 {
 	*start = iotrace.start;
 	*size = iotrace.size;
+	*needed_size = iotrace.needed_size;
 	*offset = iotrace.offset;
 	*count = iotrace.offset / sizeof(struct iotrace_record);
 }
diff --git a/include/iotrace.h b/include/iotrace.h
index b6e006ced0..ad7092e97d 100644
--- a/include/iotrace.h
+++ b/include/iotrace.h
@@ -146,11 +146,12 @@ void iotrace_set_buffer(ulong start, ulong size);
  * iotrace_get_buffer() - Get buffer information
  *
  * @start: Returns start address of buffer
- * @size: Returns size of buffer in bytes
+ * @size: Returns actual size of buffer in bytes
+ * @needed_size: Returns needed size of buffer in bytes
  * @offset: Returns the byte offset where the next output trace record will
  * @count: Returns the number of trace records recorded
  * be written (or would be if the buffer was large enough)
  */
-void iotrace_get_buffer(ulong *start, ulong *size, ulong *offset, ulong *count);
+void iotrace_get_buffer(ulong *start, ulong *size, ulong *needed_size, ulong *offset, ulong *count);
 
 #endif /* __IOTRACE_H */
-- 
2.17.0



More information about the U-Boot mailing list