From: Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: kamil.konieczny@linux.intel.com, adam.miszczak@linux.intel.com,
jakub1.kolakowski@intel.com, lukasz.laguna@intel.com,
michal.wajdeczko@intel.com, michal.winiarski@intel.com,
narasimha.c.v@intel.com, piotr.piorkowski@intel.com,
satyanarayana.k.v.p@intel.com, tomasz.lis@intel.com,
Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>
Subject: [PATCH v3 i-g-t 2/4] lib/xe/xe_sriov_provisioning: Refactor range handling and logging
Date: Thu, 21 Nov 2024 15:18:49 +0100 [thread overview]
Message-ID: <20241121141851.631877-3-marcin.bernatowicz@linux.intel.com> (raw)
In-Reply-To: <20241121141851.631877-1-marcin.bernatowicz@linux.intel.com>
Introduce an append_range helper to reduce code duplication in handling
provisioned PTE ranges. Limit debug logs to the first 70 entries for
clarity and improved reasoning. Enhance error handling by propagating
realloc failures.
Signed-off-by: Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>
Reviewed-by: Lukasz Laguna <lukasz.laguna@intel.com>
Cc: Adam Miszczak <adam.miszczak@linux.intel.com>
Cc: C V Narasimha <narasimha.c.v@intel.com>
Cc: Jakub Kolakowski <jakub1.kolakowski@intel.com>
Cc: K V P Satyanarayana <satyanarayana.k.v.p@intel.com>
Cc: Lukasz Laguna <lukasz.laguna@intel.com>
Cc: Michał Wajdeczko <michal.wajdeczko@intel.com>
Cc: Michał Winiarski <michal.winiarski@intel.com>
Cc: Piotr Piórkowski <piotr.piorkowski@intel.com>
Cc: Tomasz Lis <tomasz.lis@intel.com>
---
lib/xe/xe_sriov_provisioning.c | 71 ++++++++++++++++++++++------------
1 file changed, 47 insertions(+), 24 deletions(-)
diff --git a/lib/xe/xe_sriov_provisioning.c b/lib/xe/xe_sriov_provisioning.c
index 7cde2c240..d448a53d8 100644
--- a/lib/xe/xe_sriov_provisioning.c
+++ b/lib/xe/xe_sriov_provisioning.c
@@ -3,7 +3,7 @@
* Copyright(c) 2024 Intel Corporation. All rights reserved.
*/
-#include <stdlib.h>
+#include <errno.h>
#include "igt_core.h"
#include "intel_chipset.h"
@@ -48,6 +48,37 @@ static uint64_t get_vfid_mask(int fd)
GGTT_PTE_VFID_MASK : PRE_1250_IP_VER_GGTT_PTE_VFID_MASK;
}
+#define MAX_DEBUG_ENTRIES 70
+
+static int append_range(struct xe_sriov_provisioned_range **ranges,
+ unsigned int *nr_ranges, unsigned int vf_id,
+ uint32_t start, uint32_t end)
+{
+ struct xe_sriov_provisioned_range *new_ranges;
+
+ new_ranges = realloc(*ranges,
+ (*nr_ranges + 1) * sizeof(struct xe_sriov_provisioned_range));
+ if (!new_ranges) {
+ free(*ranges);
+ *ranges = NULL;
+ *nr_ranges = 0;
+ return -ENOMEM;
+ }
+
+ *ranges = new_ranges;
+ if (*nr_ranges < MAX_DEBUG_ENTRIES)
+ igt_debug("Found VF%u GGTT range [%#x-%#x] num_ptes=%ld\n",
+ vf_id, start, end,
+ (end - start + sizeof(xe_ggtt_pte_t)) /
+ sizeof(xe_ggtt_pte_t));
+ (*ranges)[*nr_ranges].vf_id = vf_id;
+ (*ranges)[*nr_ranges].start = start;
+ (*ranges)[*nr_ranges].end = end;
+ (*nr_ranges)++;
+
+ return 0;
+}
+
/**
* xe_sriov_find_ggtt_provisioned_pte_offsets - Find GGTT provisioned PTE offsets
* @pf_fd: File descriptor for the Physical Function
@@ -76,6 +107,7 @@ int xe_sriov_find_ggtt_provisioned_pte_offsets(int pf_fd, int gt, struct xe_mmio
uint32_t current_start = 0;
uint32_t current_end = 0;
xe_ggtt_pte_t pte;
+ int ret;
*ranges = NULL;
*nr_ranges = 0;
@@ -86,18 +118,11 @@ int xe_sriov_find_ggtt_provisioned_pte_offsets(int pf_fd, int gt, struct xe_mmio
if (vf_id != current_vf_id) {
if (current_vf_id != -1) {
- /* End the current range */
- *ranges = realloc(*ranges, (*nr_ranges + 1) *
- sizeof(struct xe_sriov_provisioned_range));
- igt_assert(*ranges);
- igt_debug("Found VF%u ggtt range [%#x-%#x] num_ptes=%ld\n",
- current_vf_id, current_start, current_end,
- (current_end - current_start + sizeof(xe_ggtt_pte_t)) /
- sizeof(xe_ggtt_pte_t));
- (*ranges)[*nr_ranges].vf_id = current_vf_id;
- (*ranges)[*nr_ranges].start = current_start;
- (*ranges)[*nr_ranges].end = current_end;
- (*nr_ranges)++;
+ /* End the current range and append it */
+ ret = append_range(ranges, nr_ranges, current_vf_id,
+ current_start, current_end);
+ if (ret < 0)
+ return ret;
}
/* Start a new range */
current_vf_id = vf_id;
@@ -107,18 +132,16 @@ int xe_sriov_find_ggtt_provisioned_pte_offsets(int pf_fd, int gt, struct xe_mmio
}
if (current_vf_id != -1) {
- *ranges = realloc(*ranges, (*nr_ranges + 1) *
- sizeof(struct xe_sriov_provisioned_range));
- igt_assert(*ranges);
- igt_debug("Found VF%u ggtt range [%#x-%#x] num_ptes=%ld\n",
- current_vf_id, current_start, current_end,
- (current_end - current_start + sizeof(xe_ggtt_pte_t)) /
- sizeof(xe_ggtt_pte_t));
- (*ranges)[*nr_ranges].vf_id = current_vf_id;
- (*ranges)[*nr_ranges].start = current_start;
- (*ranges)[*nr_ranges].end = current_end;
- (*nr_ranges)++;
+ /* Append the last range */
+ ret = append_range(ranges, nr_ranges, current_vf_id,
+ current_start, current_end);
+ if (ret < 0)
+ return ret;
}
+ if (*nr_ranges > MAX_DEBUG_ENTRIES)
+ igt_debug("Ranges output trimmed to first %u entries out of %u\n",
+ MAX_DEBUG_ENTRIES, *nr_ranges);
+
return 0;
}
--
2.31.1
next prev parent reply other threads:[~2024-11-21 14:19 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-21 14:18 [PATCH v3 i-g-t 0/4] Improvements for xe_sriov_flr test and xe_mmio lib Marcin Bernatowicz
2024-11-21 14:18 ` [PATCH v3 i-g-t 1/4] lib/xe/xe_mmio: Replace open-coded init/cleanup with existing functions Marcin Bernatowicz
2024-11-21 14:18 ` Marcin Bernatowicz [this message]
2024-11-21 14:18 ` [PATCH v3 i-g-t 3/4] tests/xe/xe_sriov_flr: Use SKIP for unmet subcheck prerequisites Marcin Bernatowicz
2024-11-22 10:39 ` Laguna, Lukasz
2024-11-21 14:18 ` [PATCH v3 i-g-t 4/4] lib/xe/xe_sriov_provisioning: Iterate only within valid PTE offsets Marcin Bernatowicz
2024-11-22 10:43 ` Laguna, Lukasz
2024-11-21 17:31 ` ✓ Xe.CI.BAT: success for Improvements for xe_sriov_flr test and xe_mmio lib (rev3) Patchwork
2024-11-21 17:44 ` ✗ i915.CI.BAT: failure " Patchwork
2024-11-22 2:31 ` ✗ Xe.CI.Full: " Patchwork
2024-11-22 13:29 ` Bernatowicz, Marcin
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=20241121141851.631877-3-marcin.bernatowicz@linux.intel.com \
--to=marcin.bernatowicz@linux.intel.com \
--cc=adam.miszczak@linux.intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=jakub1.kolakowski@intel.com \
--cc=kamil.konieczny@linux.intel.com \
--cc=lukasz.laguna@intel.com \
--cc=michal.wajdeczko@intel.com \
--cc=michal.winiarski@intel.com \
--cc=narasimha.c.v@intel.com \
--cc=piotr.piorkowski@intel.com \
--cc=satyanarayana.k.v.p@intel.com \
--cc=tomasz.lis@intel.com \
/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