Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f3e99f1a authored by Eric Holmberg's avatar Eric Holmberg
Browse files

trace: ipc_logging: fix non-destructive read logic



When dumping logs through debugfs, a non-destructive read is performed
and after all data has been printed, the call waits on a completion for
new log data.  When that event is completed, the entire contents of the
logs are incorrectly printed.

Fix the read logic to correctly update the non-destructive read pointer
such that only the new data is printed to the logs.

CRs-Fixed: 681317
Change-Id: Ia12787b576b18b9f5174cefe91eb283979c286f7
Signed-off-by: default avatarEric Holmberg <eholmber@codeaurora.org>
parent 9a9c1f23
Loading
Loading
Loading
Loading
+33 −13
Original line number Diff line number Diff line
@@ -89,6 +89,30 @@ static int is_read_empty(struct ipc_log_context *ilctxt)
		 ilctxt->write_page->hdr.write_offset));
}

/**
 * is_nd_read_equal_read - Return true if the non-destructive read is equal to
 * the destructive read
 *
 * @ilctxt: logging context
 * @returns: true if nd read is equal to read; false otherwise
 */
static bool is_nd_read_equal_read(struct ipc_log_context *ilctxt)
{
	uint16_t read_offset;
	uint16_t nd_read_offset;

	if (ilctxt->nd_read_page == ilctxt->read_page) {
		read_offset = ilctxt->read_page->hdr.read_offset;
		nd_read_offset = ilctxt->nd_read_page->hdr.nd_read_offset;

		if (read_offset == nd_read_offset)
			return true;
	}

	return false;
}


static struct ipc_log_page *get_next_page(struct ipc_log_context *ilctxt,
					  struct ipc_log_page *cur_pg)
{
@@ -158,6 +182,7 @@ static void ipc_log_drop(struct ipc_log_context *ilctxt, void *data,
		int data_size)
{
	int bytes_to_read;
	bool push_nd_read;

	bytes_to_read = MIN(LOG_PAGE_DATA_SIZE
				- ilctxt->read_page->hdr.read_offset,
@@ -168,10 +193,10 @@ static void ipc_log_drop(struct ipc_log_context *ilctxt, void *data,

	if (bytes_to_read != data_size) {
		/* not enough space, wrap read to next page */
		ilctxt->read_page->hdr.read_offset = 0;
		push_nd_read = is_nd_read_equal_read(ilctxt);

		if (ilctxt->nd_read_page == ilctxt->read_page) {
			/* app reading from the same page */
		ilctxt->read_page->hdr.read_offset = 0;
		if (push_nd_read) {
			ilctxt->read_page->hdr.nd_read_offset = 0;
			ilctxt->read_page = get_next_page(ilctxt,
				ilctxt->read_page);
@@ -189,19 +214,14 @@ static void ipc_log_drop(struct ipc_log_context *ilctxt, void *data,

		bytes_to_read = (data_size - bytes_to_read);
	}
	ilctxt->read_page->hdr.read_offset += bytes_to_read;
	ilctxt->write_avail += data_size;

	/* update non-destructive read pointer if necessary */
	if (ilctxt->nd_read_page == ilctxt->read_page) {
		uint16_t read_offset, nd_read_offset;

		read_offset = ilctxt->read_page->hdr.read_offset;
		nd_read_offset = ilctxt->nd_read_page->hdr.nd_read_offset;
	push_nd_read = is_nd_read_equal_read(ilctxt);
	ilctxt->read_page->hdr.read_offset += bytes_to_read;
	ilctxt->write_avail += data_size;

		if (read_offset > nd_read_offset)
			ilctxt->nd_read_page->hdr.nd_read_offset = read_offset;
	}
	if (push_nd_read)
		ilctxt->nd_read_page->hdr.nd_read_offset += bytes_to_read;
}

/**