mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kuan-Wei Chiu <visitorckw@gmail.com>
To: Alex Hung <alex.hung@amd.com>
Cc: austin.zheng@amd.com, jun.lei@amd.com, harry.wentland@amd.com,
	sunpeng.li@amd.com, siqueira@igalia.com,
	alexander.deucher@amd.com, christian.koenig@amd.com,
	airlied@gmail.com, simona@ffwll.ch,
	Aurabindo Pillai <Aurabindo.Pillai@amd.com>,
	zaeem.mohamed@amd.com, wenjing.liu@amd.com,
	chiahsuan.chung@amd.com, Natanel.Roizenman@amd.com,
	Daniel.Sa@amd.com, jserv@ccns.ncku.edu.tw,
	amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] drm/amd/display: Optimize remove_duplicates() from O(N^2) to O(N)
Date: Tue, 9 Sep 2025 17:10:47 +0800	[thread overview]
Message-ID: <aL/vF2Q075yTzUqP@visitorckw-System-Product-Name> (raw)
In-Reply-To: <0ed3fa16-9e0d-4f8d-ac22-c9f6b541ae8b@amd.com>

On Mon, Sep 08, 2025 at 11:10:30AM -0600, Alex Hung wrote:
> 
> 
> On 8/24/25 12:23, Kuan-Wei Chiu wrote:
> > Replace the previous O(N^2) implementation of remove_duplicates() in
> > with a O(N) version using a fast/slow pointer approach. The new version
> > keeps only the first occurrence of each element and compacts the array
> > in place, improving efficiency without changing functionality.
> > 
> > Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
> > ---
> > Verified correctness using the following simple unit test:
> > 
> > double arr1[] = {1,1,2,2,3}; int size1=5;
> > remove_duplicates(arr1,&size1);
> > assert(size1==3 && arr1[0]==1 && arr1[1]==2 && arr1[2]==3);
> > 
> > double arr2[] = {1,2,3}; int size2=3;
> > remove_duplicates(arr2,&size2);
> > assert(size2==3 && arr2[0]==1 && arr2[1]==2 && arr2[2]==3);
> > 
> > double arr3[] = {5,5,5,5}; int size3=4;
> > remove_duplicates(arr3,&size3);
> > assert(size3==1 && arr3[0]==5);
> > 
> > double arr4[] = {}; int size4=0;
> > remove_duplicates(arr4,&size4);
> > assert(size4==0);
> > 
> >   .../dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c | 18 ++++++++----------
> >   1 file changed, 8 insertions(+), 10 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c b/drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c
> > index 2b13a5e88917..5100e0e7af42 100644
> > --- a/drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c
> > +++ b/drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c
> > @@ -50,18 +50,16 @@ static void set_reserved_time_on_all_planes_with_stream_index(struct display_con
> >   static void remove_duplicates(double *list_a, int *list_a_size)
> >   {
> > -	int cur_element = 0;
> > -	// For all elements b[i] in list_b[]
> > -	while (cur_element < *list_a_size - 1) {
> > -		if (list_a[cur_element] == list_a[cur_element + 1]) {
> > -			for (int j = cur_element + 1; j < *list_a_size - 1; j++) {
> > -				list_a[j] = list_a[j + 1];
> > -			}
> > -			*list_a_size = *list_a_size - 1;
> > -		} else {
> > -			cur_element++;
> > +	int j = 0;
> > +
> > +	for (int i = 1; i < *list_a_size; i++) {
> > +		if (list_a[j] != list_a[i]) {
> > +			j++;
> > +			list_a[j] = list_a[i];
> >   		}
> >   	}
> > +
> > +	*list_a_size = j + 1;
> 
> A corner case needs fixing:
> 
> When input *list_a_size is zero, it will be updated to 1, unlike the
> original code. Maybe a early return when *list_a_size is zero?
> 
I noticed this issue while running my simple unit test.
I forgot to squash the fixup patch before submitting.
Sorry about that.
I'll send a v2 shortly.

Regards,
Kuan-Wei

> Hi Aurabindo,
> 
> Do you have other comments or other concerns?
> 
> 
> >   }
> >   static bool increase_mpc_combine_factor(unsigned int *mpc_combine_factor, unsigned int limit)
> 

      parent reply	other threads:[~2025-09-09  9:10 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-24 18:23 [PATCH 0/2] drm/amd/display: optimize reserved time candidates handling Kuan-Wei Chiu
2025-08-24 18:23 ` [PATCH 1/2] drm/amd/display: Optimize reserved time candidates sorting using standard sort() Kuan-Wei Chiu
2025-09-08 17:05   ` Alex Hung
2025-09-08 17:35     ` Christian König
2025-09-09  9:09       ` Kuan-Wei Chiu
2025-08-24 18:23 ` [PATCH 2/2] drm/amd/display: Optimize remove_duplicates() from O(N^2) to O(N) Kuan-Wei Chiu
2025-09-08 17:10   ` Alex Hung
2025-09-08 17:58     ` Aurabindo Pillai
2025-09-09  9:10     ` Kuan-Wei Chiu [this message]

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=aL/vF2Q075yTzUqP@visitorckw-System-Product-Name \
    --to=visitorckw@gmail.com \
    --cc=Aurabindo.Pillai@amd.com \
    --cc=Daniel.Sa@amd.com \
    --cc=Natanel.Roizenman@amd.com \
    --cc=airlied@gmail.com \
    --cc=alex.hung@amd.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=austin.zheng@amd.com \
    --cc=chiahsuan.chung@amd.com \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=harry.wentland@amd.com \
    --cc=jserv@ccns.ncku.edu.tw \
    --cc=jun.lei@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=siqueira@igalia.com \
    --cc=sunpeng.li@amd.com \
    --cc=wenjing.liu@amd.com \
    --cc=zaeem.mohamed@amd.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

all inboxes | Powered by JetHome®