From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 25135CAC597 for ; Mon, 15 Sep 2025 15:17:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B4ED810E4E4; Mon, 15 Sep 2025 15:17:03 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="BlIvbxcu"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8C63E10E4E4 for ; Mon, 15 Sep 2025 15:17:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1757949423; x=1789485423; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=jBmrZ/h/ltnpAMcBQI0q0C1gL5SB0sJeqaSkQZDE/Qo=; b=BlIvbxcu44Lz5jeXapEfU2d2Rn/R0+j5XIhMlCcfjycJMSG6ZRizBpbw TqKUTrX1TX01fQ0Iuv0qGGRpHE5fOFy/SS1i+BNYsR+BhV2KptpLEUpam udWheZ5DLWR4UHAAs8VdLZ0Lcuut4M0jDHkoczqQxa+65JiOREvA4igKI YCeewjcV1HXwAMt4nUGvKSyOopfG5AvXc1QiL6WE3cZhSPTeISin8yLAg W2t2IMppq5CZlI6iksfSRGFnheBkKbnPtM/rxorcsdl2V0xcqKvvB0fpm F5BM/2bdoFQszOGAxCGnnPLGYBRYrB5Nlsjfyj2KPi7hq8ybHfbA57iaf w==; X-CSE-ConnectionGUID: dPkZSoG0TCaXQd0W9ldctA== X-CSE-MsgGUID: x5V8cap8QXquJoB5YbCDVQ== X-IronPort-AV: E=McAfee;i="6800,10657,11531"; a="60157164" X-IronPort-AV: E=Sophos;i="6.17,312,1747724400"; d="scan'208";a="60157164" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Sep 2025 08:17:02 -0700 X-CSE-ConnectionGUID: IrpG3Ie3TNqBM5aieX3ldA== X-CSE-MsgGUID: zh6dL2IOQyuC4p2S2S1/YA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,266,1751266800"; d="scan'208";a="178656082" Received: from bergbenj-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.245.90]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Sep 2025 08:17:00 -0700 Date: Mon, 15 Sep 2025 18:16:57 +0300 From: Ville =?iso-8859-1?Q?Syrj=E4l=E4?= To: "Cavitt, Jonathan" Cc: "Nikula, Jani" , "intel-gfx@lists.freedesktop.org" , "Gupta, saurabhg" , "Zuo, Alex" , "Manna, Animesh" Subject: Re: [PATCH] drm/i915/display: Simplify modular operations with vtotal Message-ID: References: <20250911153921.9038-2-jonathan.cavitt@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Patchwork-Hint: comment Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" On Mon, Sep 15, 2025 at 02:49:22PM +0000, Cavitt, Jonathan wrote: > -----Original Message----- > From: Ville Syrjälä > Sent: Friday, September 12, 2025 8:30 AM > To: Cavitt, Jonathan > Cc: Nikula, Jani ; intel-gfx@lists.freedesktop.org; Gupta, saurabhg ; Zuo, Alex ; Manna, Animesh > Subject: Re: [PATCH] drm/i915/display: Simplify modular operations with vtotal > > > > On Fri, Sep 12, 2025 at 02:29:17PM +0000, Cavitt, Jonathan wrote: > > > -----Original Message----- > > > From: Nikula, Jani > > > Sent: Friday, September 12, 2025 1:56 AM > > > To: Cavitt, Jonathan ; intel-gfx@lists.freedesktop.org > > > Cc: Gupta, saurabhg ; Zuo, Alex ; Cavitt, Jonathan ; ville.syrjala@linux.intel.com; Manna, Animesh > > > Subject: Re: [PATCH] drm/i915/display: Simplify modular operations with vtotal > > > > > > > > On Thu, 11 Sep 2025, Jonathan Cavitt wrote: > > > > > There are a couple of modulus operations in the i915 display code with > > > > > vtotal as the divisor that add vtotal to the dividend. In modular > > > > > arithmetic, adding the divisor to the dividend is equivalent to adding > > > > > zero to the dividend, so this addition can be dropped. > > > > > > > > The result might become negative with this? > > > > > > > > BR, > > > > Jani. > > > > > > > > > > > > > > Signed-off-by: Jonathan Cavitt > > > > > Cc: Ville Syrjälä > > > > > Cc: Animesh Manna > > > > > Cc: Jani Nikula > > > > > --- > > > > > drivers/gpu/drm/i915/display/intel_dsb.c | 4 ++-- > > > > > drivers/gpu/drm/i915/display/intel_vblank.c | 2 +- > > > > > 2 files changed, 3 insertions(+), 3 deletions(-) > > > > > > > > > > diff --git a/drivers/gpu/drm/i915/display/intel_dsb.c b/drivers/gpu/drm/i915/display/intel_dsb.c > > > > > index dee44d45b668..67315116839b 100644 > > > > > --- a/drivers/gpu/drm/i915/display/intel_dsb.c > > > > > +++ b/drivers/gpu/drm/i915/display/intel_dsb.c > > > > > @@ -173,7 +173,7 @@ static int dsb_scanline_to_hw(struct intel_atomic_state *state, > > > > > intel_pre_commit_crtc_state(state, crtc); > > > > > int vtotal = dsb_vtotal(state, crtc); > > > > > > > > > > - return (scanline + vtotal - intel_crtc_scanline_offset(crtc_state)) % vtotal; > > > > > + return (scanline - intel_crtc_scanline_offset(crtc_state)) % vtotal; > > > > > > intel_crtc_scanline_offset returns -1, 1, or 2. So the result here could only be negative if > > > the value of scanline is less than 2. > > > > > > > > } > > > > > > > > > > /* > > > > > @@ -482,7 +482,7 @@ static void assert_dsl_ok(struct intel_atomic_state *state, > > > > > * Waiting for the entire frame doesn't make sense, > > > > > * (IN==don't wait, OUT=wait forever). > > > > > */ > > > > > - drm_WARN(crtc->base.dev, (end - start + vtotal) % vtotal == vtotal - 1, > > > > > + drm_WARN(crtc->base.dev, (end - start) % vtotal == vtotal - 1, > > > > > > This can only be negative if start is less than end, which doesn't seem possible. > > > > > > > > "[CRTC:%d:%s] DSB %d bad scanline window wait: %d-%d (vt=%d)\n", > > > > > crtc->base.base.id, crtc->base.name, dsb->id, > > > > > start, end, vtotal); > > > > > diff --git a/drivers/gpu/drm/i915/display/intel_vblank.c b/drivers/gpu/drm/i915/display/intel_vblank.c > > > > > index c15234c1d96e..bcfca2fcef3c 100644 > > > > > --- a/drivers/gpu/drm/i915/display/intel_vblank.c > > > > > +++ b/drivers/gpu/drm/i915/display/intel_vblank.c > > > > > @@ -288,7 +288,7 @@ static int __intel_get_crtc_scanline(struct intel_crtc *crtc) > > > > > * See update_scanline_offset() for the details on the > > > > > * scanline_offset adjustment. > > > > > */ > > > > > - return (position + vtotal + crtc->scanline_offset) % vtotal; > > > > > + return (position + crtc->scanline_offset) % vtotal; > > > > > > crtc->scanline_offset = intel_crtc_scanline_offset(crtc_state). > > > And position = intel_de_read_fw(display, PIPEDSL(display, pipe)) & PIPEDSL_LINE_MASK. > > > Finally, #define PIPEDSL_LINE_MASK REG_GENMASK(19, 0) > > > So, unless position = 0 on display versions 1 or 2 (where intel_crtc_scanline_offset returns -1), this cannot be negative. > > > > Scanlines can be anything from 0 to vtotal-1. > > So nak on this patch. > > > > > > > > ... > > > Wait, if crtc->scanline_offset = intel_crtc_scanline_offset(crtc_state), then why are we recalculating > > > it in dsb_scanline_to_hw? That should also probably be fixed, but not in this patch. > > > > Not sure what you think needs fixing. dsb_scanline_to_hw() is the > > inverse of most other uses of scanline_offset. > > Well, yes, we subtract it instead of adding it. > > But like, in dsb_scanline_to_hw: > > """ > return (scanline + vtotal - intel_crtc_scanline_offset(crtc_state)) % vtotal; > """ > > Can this not be simplified to: > > """ > return (scanline + vtotal - crtc->scanline_offset) % vtotal; > """ > > ? No. crtc->scanline_offset may not be correct at that point in time. -- Ville Syrjälä Intel