From: Alan Previn <alan.previn.teres.alexis@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t v2 04/11] tools/intel_guc_logger: Add helper function for flusher code
Date: Tue, 6 Dec 2022 00:58:42 -0800 [thread overview]
Message-ID: <20221206085849.271505-5-alan.previn.teres.alexis@intel.com> (raw)
In-Reply-To: <20221206085849.271505-1-alan.previn.teres.alexis@intel.com>
Add an abstraction for the flusher-thread's code that writes
the log buffer data to file. This prepares us for future
patches that requires calling the same helper for different
types of data flushing.
Signed-off-by: Alan Previn <alan.previn.teres.alexis@intel.com>
---
tools/intel_guc_logger.c | 53 +++++++++++++++++++++++++++-------------
1 file changed, 36 insertions(+), 17 deletions(-)
diff --git a/tools/intel_guc_logger.c b/tools/intel_guc_logger.c
index f694ff18..ce4d1bc5 100644
--- a/tools/intel_guc_logger.c
+++ b/tools/intel_guc_logger.c
@@ -317,6 +317,40 @@ static void pull_data(struct thread_t *tdata)
}
}
+static bool file_reached_maxsize(struct global_t *gbl, struct guc_t *guc)
+{
+ if (gbl->max_filesize && MB(gbl->max_filesize) - guc->total_bytes_written <= 0)
+ return true;
+
+ return false;
+}
+
+static int _write(struct global_t *gbl, struct guc_t *guc,
+ char *inptr, int copy_size)
+{
+ int ret = 0;
+
+ ret = write(guc->outfd, inptr, copy_size);
+ if (ret < 0) {
+ igt_warn("Copy to file failed with err %d, stopping!\n", ret);
+ guc->stop_logging = true;
+ } else if (!ret) {
+ igt_warn("Copy to file flushed zero bytes!\n");
+ } else {
+ if (ret != copy_size)
+ igt_warn("File write size err: ask = %d, copied = %d!\n",
+ copy_size, ret);
+ guc->total_bytes_written += ret;
+ igt_info("wrote %d KB out to dat file\n", (ret / 1024));
+ if (file_reached_maxsize(gbl, guc)) {
+ igt_info("Reached target filesize of %" PRIu64 " bytes\n",
+ MB(gbl->max_filesize));
+ guc->stop_logging = true;
+ }
+ }
+ return ret;
+}
+
static void *flusher(void *arg)
{
char *ptr;
@@ -351,23 +385,8 @@ static void *flusher(void *arg)
ptr = guc->readbuf + (guc->consumed % guc->subbuf_count) * subbuf_size;
- ret = write(guc->outfd, ptr, subbuf_size);
- if (ret < 0) {
- igt_warn("Dump to file failed with err %d, stopping!\n", ret);
- guc->stop_logging = true;
- } else if (!ret) {
- igt_warn("Dump to file flushed zero bytes!\n");
- } else {
- if (ret != subbuf_size)
- igt_warn("Dump size mismatch = %d!\n", ret);
- guc->total_bytes_written += ret;
- igt_info("wrote %d KB out to dat file\n", (ret / 1024));
- if (gbl->max_filesize && guc->total_bytes_written >
- MB(gbl->max_filesize)) {
- igt_debug("reached the target of %" PRIu64 " bytes\n",
- MB(gbl->max_filesize));
- guc->stop_logging = true;
- }
+ ret = _write(gbl, guc, ptr, subbuf_size);
+ if (ret > 0) {
pthread_mutex_lock(&guc->mutex);
guc->consumed++;
pthread_cond_signal(&guc->overflow_cond);
--
2.34.1
next prev parent reply other threads:[~2022-12-06 8:56 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-06 8:58 [igt-dev] [PATCH i-g-t v2 00/11] Resurrect GuC Relay Logging Alan Previn
2022-12-06 8:58 ` [igt-dev] [PATCH i-g-t v2 01/11] tools/intel_guc_logger: Re-enable basic functionality Alan Previn
2023-01-20 20:26 ` [igt-dev] [i-g-t, v2, " Dong, Zhanjun
2023-03-14 21:46 ` Teres Alexis, Alan Previn
2022-12-06 8:58 ` [igt-dev] [PATCH i-g-t v2 02/11] tools/intel_guc_logger: Refactor intel_guc_logger globals into structs Alan Previn
2023-02-01 0:04 ` [igt-dev] [i-g-t, v2, " Dong, Zhanjun
2023-03-14 21:47 ` Teres Alexis, Alan Previn
2022-12-06 8:58 ` [igt-dev] [PATCH i-g-t v2 03/11] tools/intel_guc_logger: Add GT-ID selection for intel_guc_logger Alan Previn
2023-03-14 21:54 ` Teres Alexis, Alan Previn
2022-12-06 8:58 ` Alan Previn [this message]
2022-12-06 8:58 ` [igt-dev] [PATCH i-g-t v2 05/11] tools/intel_guc_logger: Add GuC Log header structure definition Alan Previn
2022-12-06 8:58 ` [igt-dev] [PATCH i-g-t v2 06/11] tools/intel_guc_logger: Concatenate log samples into a contiguous file Alan Previn
2022-12-06 8:58 ` [igt-dev] [PATCH i-g-t v2 07/11] tools/intel_guc_logger: Add overflow awareness Alan Previn
2022-12-06 8:58 ` [igt-dev] [PATCH i-g-t v2 08/11] tools/intel_guc_logger: Limit relay logging output file to 4GB Alan Previn
2022-12-06 8:58 ` [igt-dev] [PATCH i-g-t v2 09/11] tools/intel_guc_logger: By default don't change GuC log verbosity Alan Previn
2022-12-06 8:58 ` [igt-dev] [PATCH i-g-t v2 10/11] tools/intel_guc_logger: On exit, save any leftover GuC log data Alan Previn
2022-12-06 8:58 ` [igt-dev] [PATCH i-g-t v2 11/11] tools/intel_guc_logger: Add useful debug messages Alan Previn
2022-12-06 9:41 ` [igt-dev] ✓ Fi.CI.BAT: success for Resurrect GuC Relay Logging (rev2) Patchwork
2022-12-06 11:27 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
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=20221206085849.271505-5-alan.previn.teres.alexis@intel.com \
--to=alan.previn.teres.alexis@intel.com \
--cc=igt-dev@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox