[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <c28df8a2-9ec1-41d0-afe4-4ee047290d27@amd.com>
Date: Mon, 8 Sep 2025 11:05:05 -0600
From: Alex Hung <alex.hung@....com>
To: Kuan-Wei Chiu <visitorckw@...il.com>, austin.zheng@....com,
jun.lei@....com, harry.wentland@....com, sunpeng.li@....com,
siqueira@...lia.com, alexander.deucher@....com, christian.koenig@....com,
airlied@...il.com, simona@...ll.ch
Cc: zaeem.mohamed@....com, wenjing.liu@....com, chiahsuan.chung@....com,
Natanel.Roizenman@....com, Daniel.Sa@....com, jserv@...s.ncku.edu.tw,
amd-gfx@...ts.freedesktop.org, dri-devel@...ts.freedesktop.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/2] drm/amd/display: Optimize reserved time candidates
sorting using standard sort()
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@...il.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]);
Powered by blists - more mailing lists