public inbox for intel-xe@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Gustavo Sousa <gustavo.sousa@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: Gustavo Sousa <gustavo.sousa@intel.com>,
	 Matt Roper <matthew.d.roper@intel.com>
Subject: [PATCH v2 5/7] drm/xe/rtp: Extract rule_match_item()
Date: Thu, 30 Apr 2026 17:20:06 -0300	[thread overview]
Message-ID: <20260430-rtp-rule-parser-v2-5-157e98b4ab51@intel.com> (raw)
In-Reply-To: <20260430-rtp-rule-parser-v2-0-157e98b4ab51@intel.com>

The current logic in rule_matches() mixes individual rule matching
with the logic necessary for handling OR operations.  Let's simplify
rule_matches() to focus on the latter by extracting individual rule
matching into a separate function called rule_match_item().

Reviewed-by: Matt Roper <matthew.d.roper@intel.com>
Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
---
 drivers/gpu/drm/xe/xe_rtp.c | 219 +++++++++++++++++++-------------------------
 1 file changed, 94 insertions(+), 125 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_rtp.c b/drivers/gpu/drm/xe/xe_rtp.c
index df72b456ab16..c49f80f398af 100644
--- a/drivers/gpu/drm/xe/xe_rtp.c
+++ b/drivers/gpu/drm/xe/xe_rtp.c
@@ -30,6 +30,96 @@ static bool has_samedia(const struct xe_device *xe)
 	return xe->info.media_verx100 >= 1300;
 }
 
+static bool rule_match_item(const struct xe_device *xe,
+			    struct xe_gt *gt,
+			    struct xe_hw_engine *hwe,
+			    const struct xe_rtp_rule *r)
+{
+	switch (r->match_type) {
+	case XE_RTP_MATCH_PLATFORM:
+		return xe->info.platform == r->platform;
+	case XE_RTP_MATCH_SUBPLATFORM:
+		return xe->info.platform == r->platform &&
+			xe->info.subplatform == r->subplatform;
+	case XE_RTP_MATCH_PLATFORM_STEP:
+		if (drm_WARN_ON(&xe->drm, xe->info.step.platform == STEP_NONE))
+			return false;
+
+		return xe->info.step.platform >= r->step_start &&
+			xe->info.step.platform < r->step_end;
+	case XE_RTP_MATCH_GRAPHICS_VERSION:
+		if (drm_WARN_ON(&xe->drm, !gt))
+			return false;
+
+		return xe->info.graphics_verx100 == r->ver_start &&
+			(!has_samedia(xe) || !xe_gt_is_media_type(gt));
+	case XE_RTP_MATCH_GRAPHICS_VERSION_RANGE:
+		if (drm_WARN_ON(&xe->drm, !gt))
+			return false;
+
+		return xe->info.graphics_verx100 >= r->ver_start &&
+			xe->info.graphics_verx100 <= r->ver_end &&
+			(!has_samedia(xe) || !xe_gt_is_media_type(gt));
+	case XE_RTP_MATCH_GRAPHICS_VERSION_ANY_GT:
+		if (drm_WARN_ON(&xe->drm, !gt))
+			return false;
+
+		return xe->info.graphics_verx100 == r->ver_start;
+	case XE_RTP_MATCH_GRAPHICS_STEP:
+		if (drm_WARN_ON(&xe->drm, !gt))
+			return false;
+
+		return xe->info.step.graphics >= r->step_start &&
+			xe->info.step.graphics < r->step_end &&
+			(!has_samedia(xe) || !xe_gt_is_media_type(gt));
+	case XE_RTP_MATCH_MEDIA_VERSION:
+		if (drm_WARN_ON(&xe->drm, !gt))
+			return false;
+
+		return xe->info.media_verx100 == r->ver_start &&
+			(!has_samedia(xe) || xe_gt_is_media_type(gt));
+	case XE_RTP_MATCH_MEDIA_VERSION_RANGE:
+		if (drm_WARN_ON(&xe->drm, !gt))
+			return false;
+
+		return xe->info.media_verx100 >= r->ver_start &&
+			xe->info.media_verx100 <= r->ver_end &&
+			(!has_samedia(xe) || xe_gt_is_media_type(gt));
+	case XE_RTP_MATCH_MEDIA_STEP:
+		if (drm_WARN_ON(&xe->drm, !gt))
+			return false;
+
+		return xe->info.step.media >= r->step_start &&
+			xe->info.step.media < r->step_end &&
+			(!has_samedia(xe) || xe_gt_is_media_type(gt));
+	case XE_RTP_MATCH_MEDIA_VERSION_ANY_GT:
+		if (drm_WARN_ON(&xe->drm, !gt))
+			return false;
+
+		return xe->info.media_verx100 == r->ver_start;
+	case XE_RTP_MATCH_INTEGRATED:
+		return !xe->info.is_dgfx;
+	case XE_RTP_MATCH_DISCRETE:
+		return xe->info.is_dgfx;
+	case XE_RTP_MATCH_ENGINE_CLASS:
+		if (drm_WARN_ON(&xe->drm, !hwe))
+			return false;
+
+		return hwe->class == r->engine_class;
+	case XE_RTP_MATCH_NOT_ENGINE_CLASS:
+		if (drm_WARN_ON(&xe->drm, !hwe))
+			return false;
+
+		return hwe->class != r->engine_class;
+	case XE_RTP_MATCH_FUNC:
+		return r->match_func(xe, gt, hwe);
+	default:
+		drm_warn(&xe->drm, "Invalid RTP match %u\n",
+			 r->match_type);
+		return false;
+	}
+}
+
 static bool rule_matches_with_err(const struct xe_device *xe,
 				  struct xe_gt *gt,
 				  struct xe_hw_engine *hwe,
@@ -39,14 +129,12 @@ static bool rule_matches_with_err(const struct xe_device *xe,
 {
 	const struct xe_rtp_rule *r;
 	unsigned int i, rcount = 0;
-	bool match;
 
 	if (err)
 		*err = 0;
 
 	for (r = rules, i = 0; i < n_rules; r = &rules[++i]) {
-		switch (r->match_type) {
-		case XE_RTP_MATCH_OR:
+		if (r->match_type == XE_RTP_MATCH_OR) {
 			if (drm_WARN_ON(&xe->drm, !rcount)) {
 				if (err)
 					*err = -EINVAL;
@@ -59,128 +147,11 @@ static bool rule_matches_with_err(const struct xe_device *xe,
 			 * rules and return true.
 			 */
 			return true;
-		case XE_RTP_MATCH_PLATFORM:
-			match = xe->info.platform == r->platform;
-			break;
-		case XE_RTP_MATCH_SUBPLATFORM:
-			match = xe->info.platform == r->platform &&
-				xe->info.subplatform == r->subplatform;
-			break;
-		case XE_RTP_MATCH_PLATFORM_STEP:
-			if (drm_WARN_ON(&xe->drm, xe->info.step.platform == STEP_NONE)) {
-				match = false;
-				break;
-			}
-
-			match = xe->info.step.platform >= r->step_start &&
-				xe->info.step.platform < r->step_end;
-			break;
-		case XE_RTP_MATCH_GRAPHICS_VERSION:
-			if (drm_WARN_ON(&xe->drm, !gt)) {
-				match = false;
-				break;
-			}
-
-			match = xe->info.graphics_verx100 == r->ver_start &&
-				(!has_samedia(xe) || !xe_gt_is_media_type(gt));
-			break;
-		case XE_RTP_MATCH_GRAPHICS_VERSION_RANGE:
-			if (drm_WARN_ON(&xe->drm, !gt)) {
-				match = false;
-				break;
-			}
-
-			match = xe->info.graphics_verx100 >= r->ver_start &&
-				xe->info.graphics_verx100 <= r->ver_end &&
-				(!has_samedia(xe) || !xe_gt_is_media_type(gt));
-			break;
-		case XE_RTP_MATCH_GRAPHICS_VERSION_ANY_GT:
-			if (drm_WARN_ON(&xe->drm, !gt)) {
-				match = false;
-				break;
-			}
-
-			match = xe->info.graphics_verx100 == r->ver_start;
-			break;
-		case XE_RTP_MATCH_GRAPHICS_STEP:
-			if (drm_WARN_ON(&xe->drm, !gt)) {
-				match = false;
-				break;
-			}
-
-			match = xe->info.step.graphics >= r->step_start &&
-				xe->info.step.graphics < r->step_end &&
-				(!has_samedia(xe) || !xe_gt_is_media_type(gt));
-			break;
-		case XE_RTP_MATCH_MEDIA_VERSION:
-			if (drm_WARN_ON(&xe->drm, !gt)) {
-				match = false;
-				break;
-			}
-
-			match = xe->info.media_verx100 == r->ver_start &&
-				(!has_samedia(xe) || xe_gt_is_media_type(gt));
-			break;
-		case XE_RTP_MATCH_MEDIA_VERSION_RANGE:
-			if (drm_WARN_ON(&xe->drm, !gt)) {
-				match = false;
-				break;
-			}
-
-			match = xe->info.media_verx100 >= r->ver_start &&
-				xe->info.media_verx100 <= r->ver_end &&
-				(!has_samedia(xe) || xe_gt_is_media_type(gt));
-			break;
-		case XE_RTP_MATCH_MEDIA_STEP:
-			if (drm_WARN_ON(&xe->drm, !gt)) {
-				match = false;
-				break;
-			}
-
-			match = xe->info.step.media >= r->step_start &&
-				xe->info.step.media < r->step_end &&
-				(!has_samedia(xe) || xe_gt_is_media_type(gt));
-			break;
-		case XE_RTP_MATCH_MEDIA_VERSION_ANY_GT:
-			if (drm_WARN_ON(&xe->drm, !gt)) {
-				match = false;
-				break;
-			}
-
-			match = xe->info.media_verx100 == r->ver_start;
-			break;
-		case XE_RTP_MATCH_INTEGRATED:
-			match = !xe->info.is_dgfx;
-			break;
-		case XE_RTP_MATCH_DISCRETE:
-			match = xe->info.is_dgfx;
-			break;
-		case XE_RTP_MATCH_ENGINE_CLASS:
-			if (drm_WARN_ON(&xe->drm, !hwe)) {
-				match = false;
-				break;
-			}
-
-			match = hwe->class == r->engine_class;
-			break;
-		case XE_RTP_MATCH_NOT_ENGINE_CLASS:
-			if (drm_WARN_ON(&xe->drm, !hwe)) {
-				match = false;
-				break;
-			}
-
-			match = hwe->class != r->engine_class;
-			break;
-		case XE_RTP_MATCH_FUNC:
-			match = r->match_func(xe, gt, hwe);
-			break;
-		default:
-			drm_warn(&xe->drm, "Invalid RTP match %u\n",
-				 r->match_type);
-			match = false;
 		}
 
-		if (!match) {
+		if (rule_match_item(xe, gt, hwe, r)) {
+			rcount++;
+		} else {
 			/*
 			 * Advance rules until we find XE_RTP_MATCH_OR to check
 			 * if there's another set of conditions to check
@@ -192,8 +163,6 @@ static bool rule_matches_with_err(const struct xe_device *xe,
 				return false;
 
 			rcount = 0;
-		} else {
-			rcount++;
 		}
 	}
 

-- 
2.53.0


  parent reply	other threads:[~2026-04-30 20:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-30 20:20 [PATCH v2 0/7] drm/xe/rtp: Miscellaneous improvements to rule matching Gustavo Sousa
2026-04-30 20:20 ` [PATCH v2 1/7] drm/xe/rtp: Write kunit test cases specific for " Gustavo Sousa
2026-04-30 20:20 ` [PATCH v2 2/7] drm/xe/rtp: Drop rule matching cases from rtp_to_sr_cases and rtp_cases Gustavo Sousa
2026-04-30 20:20 ` [PATCH v2 3/7] drm/xe/rtp: Don't short-circuit to false in or-yes case Gustavo Sousa
2026-04-30 20:20 ` [PATCH v2 4/7] drm/xe/rtp: Do not break parsing when missing context Gustavo Sousa
2026-04-30 20:20 ` Gustavo Sousa [this message]
2026-04-30 20:20 ` [PATCH v2 6/7] drm/xe/rtp: Fully parse the ruleset Gustavo Sousa
2026-04-30 20:20 ` [PATCH v2 7/7] drm/xe/rtp: Implement a structured parser for rule matching Gustavo Sousa
2026-04-30 21:02 ` ✗ CI.checkpatch: warning for drm/xe/rtp: Miscellaneous improvements to rule matching (rev2) Patchwork
2026-04-30 21:03 ` ✓ CI.KUnit: success " Patchwork
2026-04-30 21:59 ` ✓ Xe.CI.BAT: " Patchwork
2026-05-01  9:25 ` ✗ Xe.CI.FULL: failure " 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=20260430-rtp-rule-parser-v2-5-157e98b4ab51@intel.com \
    --to=gustavo.sousa@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.d.roper@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