mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alex Hung <alex.hung@amd.com>
To: Kuan-Wei Chiu <visitorckw@gmail.com>,
	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
Cc: 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 1/2] drm/amd/display: Optimize reserved time candidates sorting using standard sort()
Date: Mon, 8 Sep 2025 11:05:05 -0600	[thread overview]
Message-ID: <c28df8a2-9ec1-41d0-afe4-4ee047290d27@amd.com> (raw)
In-Reply-To: <20250824182359.142050-2-visitorckw@gmail.com>



On 8/24/25 12:23, Kuan-Wei Chiu wrote:
> Replace the custom bubble sort used for sorting reserved time
> candidates in with the kernel's standard sort() helper. The previous
> code had O(N^2) time complexity, while the generic kernel sort runs in
> O(N log N). This improves efficiency and removes the need for a local
> sorting implementation, while keeping functionality unchanged.
> 
> Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
> ---
> Compile test only.
> 
>   .../dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c   | 23 +++++++++++--------
>   1 file changed, 13 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 e763c8e45da8..2b13a5e88917 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
> @@ -2,19 +2,21 @@
>   //
>   // Copyright 2024 Advanced Micro Devices, Inc.
>   
> +#include <linux/sort.h>
> +

Thanks for working on this, but this file is shared with another OS and 
it is not possible to replace sort function with Linux-only sort.

>   #include "dml2_pmo_factory.h"
>   #include "dml2_pmo_dcn3.h"
>   
> -static void sort(double *list_a, int list_a_size)
> +static int cmp_double(const void *a, const void *b)
>   {
> -	// For all elements b[i] in list_b[]
> -	for (int i = 0; i < list_a_size - 1; i++) {
> -		// Find the first element of list_a that's larger than b[i]
> -		for (int j = i; j < list_a_size - 1; j++) {
> -			if (list_a[j] > list_a[j + 1])
> -				swap(list_a[j], list_a[j + 1]);
> -		}
> -	}
> +	double da = *(const double *)a;
> +	double db = *(const double *)b;
> +
> +	if (da < db)
> +		return -1;
> +	if (da > db)
> +		return 1;
> +	return 0;
>   }
>   
>   static double get_max_reserved_time_on_all_planes_with_stream_index(struct display_configuation_with_meta *config, unsigned int stream_index)
> @@ -634,7 +636,8 @@ bool pmo_dcn3_init_for_pstate_support(struct dml2_pmo_init_for_pstate_support_in
>   
>   		// Finally sort the array of candidates
>   		sort(pmo->scratch.pmo_dcn3.reserved_time_candidates[stream_index],
> -			pmo->scratch.pmo_dcn3.reserved_time_candidates_count[stream_index]);
> +		     pmo->scratch.pmo_dcn3.reserved_time_candidates_count[stream_index],
> +		     sizeof(double), cmp_double, NULL);
>   
>   		remove_duplicates(pmo->scratch.pmo_dcn3.reserved_time_candidates[stream_index],
>   			&pmo->scratch.pmo_dcn3.reserved_time_candidates_count[stream_index]);


  reply	other threads:[~2025-09-08 17:05 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 [this message]
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

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=c28df8a2-9ec1-41d0-afe4-4ee047290d27@amd.com \
    --to=alex.hung@amd.com \
    --cc=Daniel.Sa@amd.com \
    --cc=Natanel.Roizenman@amd.com \
    --cc=airlied@gmail.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=visitorckw@gmail.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®