All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: "Goel, Akash" <akash.goel@intel.com>, intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH 06/19] drm/i915: Handle log buffer flush interrupt event from GuC
Date: Wed, 17 Aug 2016 14:19:28 +0100	[thread overview]
Message-ID: <57B46460.1020307@linux.intel.com> (raw)
In-Reply-To: <57B44BF4.30301@linux.intel.com>


On 17/08/16 12:35, Tvrtko Ursulin wrote:
> On 17/08/16 12:24, Goel, Akash wrote:

[snip]

>> Won't the 2nd memcpy (from the copy on stack to the relay buffer) be
>> really fast ?
>> The copy on stack (16 bytes) will most likely be in the CPU cache and
>> the same area is used for all 3 buffer types.
> 
> Yes I realized later you use it more in later patches.
> 
> I don't think it is slow but was just wondering if it could be made 
> tidier by getting rid of one copy.
> 
> Would have to apply the series to see how the final loop looks like, but 
> would something like the below be possible:
> 
>      if (!log_buffer_snapshot_state) {
>          .. read_ptr update from wc ..
>          continue;
>      }
> 
>      memcpy from wc to final buffer
> 
>      .. the rest of processing you do reading from the copy ..
> 
> ?

Not even compile tested and possibly incorrectly refactored,
but what do you think of:

static bool
guc_log_check_overflow(struct intel_guc *guc,
		       enum guc_log_buffer_type type,
		       struct guc_log_buffer *snapshot)
{
	unsigned int full_cnt, prev_full_cnt;
	bool overflow = false;

	guc->log.flush_count[type]++;

	full_cnt = snapshot.buffer_full_cnt;
	prev_full_cnt = guc->log.prev_overflow_count[type];

	if (full_cnt != prev_full_cnt) {
		overflow = true;

		guc->log.prev_overflow_count[type] = full_cnt;
		guc->log.total_overflow_count[type] += full_cnt - prev_full_cnt;

		if (full_cnt < prev_full_cnt) {
			/* buffer_full_cnt is a 4 bit counter */
			guc->log.total_overflow_count[type] += 16;
		}
	}

	return overflow;
}

static void guc_read_update_log_buffer(struct intel_guc *guc)
{
	struct guc_log_buffer *log_buffer, *snapshot;
	void *src_data, *dst_data;
	enum guc_log_buffer_type type;

	if (WARN_ON(!guc->log.buf_addr))
		return;

	/* Get the pointer to shared GuC log buffer */
	log_buffer = src_data = guc->log.buf_addr;

	/* Get the pointer to local buffer to store the logs */
	dst_data = snapshot = guc_get_write_buffer(guc);

	/* Actual logs are present from the 2nd page */
	src_data += PAGE_SIZE;
	dst_data += PAGE_SIZE;

	for (type = GUC_ISR_LOG_BUFFER; type < GUC_MAX_LOG_BUFFER;
	     type++, log_buffer++) {
		unsigned int buffer_size, bytes_to_copy;
		unsigned int read_offset, write_offset;
		bool new_overflow;

		/* Clear the 'flush to file' flag */
		log_buffer->flush_to_file = 0;

		if (unlikely(!snapshot)) {
			/* Update the read pointer in the shared log buffer */
			log_buffer->read_ptr = log_buffer.sampled_write_ptr;
			continue;
		}

		memcpy(snapshot, &log_buffer, sizeof(*snapshot));

		buffer_size = guc_get_log_buffer_size(type);
		read_offset = snapshot.read_ptr;
		write_offset = snapshot.sampled_write_ptr;

		/* The write pointer could have been updated by the GuC
		 * firmware, after sending the flush interrupt to Host,
		 * for consistency set the write pointer value to same
		 * value of sampled_write_ptr in the snapshot buffer.
		 */
		snapshot->write_ptr = write_offset;

		new_overflow = guc_log_check_overflow(guc, type, snapshot);
		if (unlikely(new_overflow)) {
			DRM_ERROR_RATELIMITED("GuC log buffer overflow\n");
			/* copy the whole buffer in case of overflow */
			read_offset = 0;
			write_offset = buffer_size;
		} else if (unlikely((read_offset > buffer_size) ||
		           (write_offset > buffer_size))) {
			DRM_ERROR("invalid log buffer state\n");
			/* copy whole buffer as offsets are unreliable */
			read_offset = 0;
			write_offset = buffer_size;
		}

		/* Just copy the newly written data */
		if (read_offset > write_offset) {
			bytes_to_copy = buffer_size - read_offset;

			i915_memcpy_from_wc(dst_data, src_data, write_offset);
		} else {
			bytes_to_copy = write_offset - read_offset;
		}
		i915_memcpy_from_wc(dst_data + read_offset,
				    src_data + read_offset, bytes_to_copy);

		src_data += buffer_size;
		dst_data += buffer_size;

		/* Update the read pointer in the shared log buffer */
		log_buffer->read_ptr = snapshot.sampled_write_ptr;

		snapshot++;
	}

	if (snapshot) {
		guc_move_to_next_buf(guc);
	} else {
		/* Used rate limited to avoid deluge of messages, logs might be
		 * getting consumed by User at a slow rate.
		 */
		DRM_ERROR_RATELIMITED("no sub-buffer to capture log buffer\n");
		guc->log.capture_miss_count++;
	}
}

Removes the double memcpy and shortens some variable names in order
to make the whole thing more readable.

Regards,

Tvrtko

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2016-08-17 13:19 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-17 10:14 [PATCH v7 00/19] Support for sustained capturing of GuC firmware logs akash.goel
2016-08-17 10:14 ` [PATCH 01/19] drm/i915: Decouple GuC log setup from verbosity parameter akash.goel
2016-08-17 10:14 ` [PATCH 02/19] drm/i915: Add GuC ukernel logging related fields to fw interface file akash.goel
2016-08-17 10:14 ` [PATCH 03/19] drm/i915: New structure to contain GuC logging related fields akash.goel
2016-08-17 10:14 ` [PATCH 04/19] drm/i915: Add low level set of routines for programming PM IER/IIR/IMR register set akash.goel
2016-08-17 10:14 ` [PATCH 05/19] drm/i915: Support for GuC interrupts akash.goel
2016-08-17 10:51   ` Tvrtko Ursulin
2016-08-17 10:14 ` [PATCH 06/19] drm/i915: Handle log buffer flush interrupt event from GuC akash.goel
2016-08-17 11:07   ` Tvrtko Ursulin
2016-08-17 11:24     ` Goel, Akash
2016-08-17 11:35       ` Tvrtko Ursulin
2016-08-17 13:19         ` Tvrtko Ursulin [this message]
2016-08-17 10:14 ` [PATCH 07/19] relay: Use per CPU constructs for the relay channel buffer pointers akash.goel
2016-08-17 10:14 ` [PATCH 08/19] drm/i915: Add a relay backed debugfs interface for capturing GuC logs akash.goel
2016-08-17 11:11   ` Tvrtko Ursulin
2016-08-17 10:14 ` [PATCH 09/19] drm/i915: New lock to serialize the Host2GuC actions akash.goel
2016-08-17 10:14 ` [PATCH 10/19] drm/i915: Add stats for GuC log buffer flush interrupts akash.goel
2016-08-17 10:14 ` [PATCH 11/19] drm/i915: Optimization to reduce the sampling time of GuC log buffer akash.goel
2016-08-17 10:14 ` [PATCH 12/19] drm/i915: Increase GuC log buffer size to reduce flush interrupts akash.goel
2016-08-17 10:14 ` [PATCH 13/19] drm/i915: Augment i915 error state to include the dump of GuC log buffer akash.goel
2016-08-17 10:14 ` [PATCH 14/19] drm/i915: Forcefully flush GuC log buffer on reset akash.goel
2016-08-17 11:16   ` Tvrtko Ursulin
2016-08-17 10:14 ` [PATCH 15/19] drm/i915: Debugfs support for GuC logging control akash.goel
2016-08-17 10:14 ` [PATCH 16/19] drm/i915: Use uncached(WC) mapping for acessing the GuC log buffer akash.goel
2016-08-17 10:14 ` [PATCH 17/19] drm/i915: Use SSE4.1 movntdqa based memcpy for sampling " akash.goel
2016-08-17 10:14 ` [PATCH 18/19] drm/i915: Early creation of relay channel for capturing boot time logs akash.goel
2016-08-17 10:14 ` [PATCH 19/19] drm/i915: Sync against the GuC log buffer flush work item on system suspend akash.goel
2016-08-17 11:27   ` Tvrtko Ursulin
2016-08-17 11:41     ` Chris Wilson
2016-08-17 12:45       ` Goel, Akash
2016-08-17 13:11         ` Imre Deak
2016-08-17 15:37           ` Goel, Akash
2016-08-18  3:45             ` Goel, Akash
2016-08-18 10:55               ` Imre Deak
2016-08-18 11:24                 ` Goel, Akash
2016-08-18 12:59                   ` Imre Deak
2016-08-18 13:47                     ` Goel, Akash
2016-08-18 14:18                       ` Imre Deak
2016-08-18 14:35                         ` Goel, Akash
2016-08-18 14:55                           ` Imre Deak
2016-08-18 15:01                             ` Goel, Akash
2016-08-17 10:29 ` ✗ Ro.CI.BAT: failure for Support for sustained capturing of GuC firmware logs (rev8) Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2016-08-19  8:42 [PATCH v8 00/19] Support for sustained capturing of GuC firmware logs akash.goel
2016-08-19  8:43 ` [PATCH 06/19] drm/i915: Handle log buffer flush interrupt event from GuC akash.goel
2016-08-19 10:08   ` Tvrtko Ursulin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57B46460.1020307@linux.intel.com \
    --to=tvrtko.ursulin@linux.intel.com \
    --cc=akash.goel@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.