Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
To: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>,
	dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org,
	amd-gfx@lists.freedesktop.org, matthew.auld@intel.com,
	christian.koenig@amd.com, alexander.deucher@amd.com
Subject: Re: [Intel-gfx] [PATCH] drm: Alloc high address for drm buddy topdown flag
Date: Mon, 9 Jan 2023 11:13:28 +0100	[thread overview]
Message-ID: <8354c408-623a-1fc0-d5e0-201a0bce0309@gmail.com> (raw)
In-Reply-To: <20230107151523.29864-1-Arunpravin.PaneerSelvam@amd.com>

Am 07.01.23 um 16:15 schrieb Arunpravin Paneer Selvam:
> As we are observing low numbers in viewperf graphics benchmark, we
> are strictly not allowing the top down flag enabled allocations
> to steal the memory space from cpu visible region.
>
> The approach is, we are sorting each order list entries in
> ascending order and compare the last entry of each order
> list in the freelist and return the max block.
>
> This patch improves the viewperf 3D benchmark scores.
>
> Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>

Acked-by: Christian König <christian.koenig@amd.com>, but somebody with more insight of the drm buddy allocator should take a closer look at this.


> ---
>   drivers/gpu/drm/drm_buddy.c | 81 ++++++++++++++++++++++++-------------
>   1 file changed, 54 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
> index 11bb59399471..50916b2f2fc5 100644
> --- a/drivers/gpu/drm/drm_buddy.c
> +++ b/drivers/gpu/drm/drm_buddy.c
> @@ -38,6 +38,25 @@ static void drm_block_free(struct drm_buddy *mm,
>   	kmem_cache_free(slab_blocks, block);
>   }
>   
> +static void list_insert_sorted(struct drm_buddy *mm,
> +			       struct drm_buddy_block *block)
> +{
> +	struct drm_buddy_block *node;
> +	struct list_head *head;
> +
> +	head = &mm->free_list[drm_buddy_block_order(block)];
> +	if (list_empty(head)) {
> +		list_add(&block->link, head);
> +		return;
> +	}
> +
> +	list_for_each_entry(node, head, link)
> +		if (drm_buddy_block_offset(block) < drm_buddy_block_offset(node))
> +			break;
> +
> +	__list_add(&block->link, node->link.prev, &node->link);
> +}
> +
>   static void mark_allocated(struct drm_buddy_block *block)
>   {
>   	block->header &= ~DRM_BUDDY_HEADER_STATE;
> @@ -52,8 +71,7 @@ static void mark_free(struct drm_buddy *mm,
>   	block->header &= ~DRM_BUDDY_HEADER_STATE;
>   	block->header |= DRM_BUDDY_FREE;
>   
> -	list_add(&block->link,
> -		 &mm->free_list[drm_buddy_block_order(block)]);
> +	list_insert_sorted(mm, block);
>   }
>   
>   static void mark_split(struct drm_buddy_block *block)
> @@ -387,20 +405,26 @@ alloc_range_bias(struct drm_buddy *mm,
>   }
>   
>   static struct drm_buddy_block *
> -get_maxblock(struct list_head *head)
> +get_maxblock(struct drm_buddy *mm, unsigned int order)
>   {
>   	struct drm_buddy_block *max_block = NULL, *node;
> +	unsigned int i;
>   
> -	max_block = list_first_entry_or_null(head,
> -					     struct drm_buddy_block,
> -					     link);
> -	if (!max_block)
> -		return NULL;
> +	for (i = order; i <= mm->max_order; ++i) {
> +		if (!list_empty(&mm->free_list[i])) {
> +			node = list_last_entry(&mm->free_list[i],
> +					       struct drm_buddy_block,
> +					       link);
> +			if (!max_block) {
> +				max_block = node;
> +				continue;
> +			}
>   
> -	list_for_each_entry(node, head, link) {
> -		if (drm_buddy_block_offset(node) >
> -		    drm_buddy_block_offset(max_block))
> -			max_block = node;
> +			if (drm_buddy_block_offset(node) >
> +				drm_buddy_block_offset(max_block)) {
> +				max_block = node;
> +			}
> +		}
>   	}
>   
>   	return max_block;
> @@ -412,20 +436,23 @@ alloc_from_freelist(struct drm_buddy *mm,
>   		    unsigned long flags)
>   {
>   	struct drm_buddy_block *block = NULL;
> -	unsigned int i;
> +	unsigned int tmp;
>   	int err;
>   
> -	for (i = order; i <= mm->max_order; ++i) {
> -		if (flags & DRM_BUDDY_TOPDOWN_ALLOCATION) {
> -			block = get_maxblock(&mm->free_list[i]);
> -			if (block)
> -				break;
> -		} else {
> -			block = list_first_entry_or_null(&mm->free_list[i],
> -							 struct drm_buddy_block,
> -							 link);
> -			if (block)
> -				break;
> +	if (flags & DRM_BUDDY_TOPDOWN_ALLOCATION) {
> +		block = get_maxblock(mm, order);
> +		if (block)
> +			/* Store the obtained block order */
> +			tmp = drm_buddy_block_order(block);
> +	} else {
> +		for (tmp = order; tmp <= mm->max_order; ++tmp) {
> +			if (!list_empty(&mm->free_list[tmp])) {
> +				block = list_last_entry(&mm->free_list[tmp],
> +							struct drm_buddy_block,
> +							link);
> +				if (block)
> +					break;
> +			}
>   		}
>   	}
>   
> @@ -434,18 +461,18 @@ alloc_from_freelist(struct drm_buddy *mm,
>   
>   	BUG_ON(!drm_buddy_block_is_free(block));
>   
> -	while (i != order) {
> +	while (tmp != order) {
>   		err = split_block(mm, block);
>   		if (unlikely(err))
>   			goto err_undo;
>   
>   		block = block->right;
> -		i--;
> +		tmp--;
>   	}
>   	return block;
>   
>   err_undo:
> -	if (i != order)
> +	if (tmp != order)
>   		__drm_buddy_free(mm, block);
>   	return ERR_PTR(err);
>   }


  parent reply	other threads:[~2023-01-09 10:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-07 15:15 [Intel-gfx] [PATCH] drm: Alloc high address for drm buddy topdown flag Arunpravin Paneer Selvam
2023-01-07 16:08 ` [Intel-gfx] ✓ Fi.CI.BAT: success for " Patchwork
2023-01-07 17:30 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " Patchwork
2023-01-09 10:13 ` Christian König [this message]
2023-01-09 15:03   ` [Intel-gfx] [PATCH] " Alex Deucher
2023-01-10 12:02 ` Matthew Auld
2023-01-10 15:26   ` Arunpravin Paneer Selvam
2023-01-10 15:50   ` Matthew Auld

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=8354c408-623a-1fc0-d5e0-201a0bce0309@gmail.com \
    --to=ckoenig.leichtzumerken@gmail.com \
    --cc=Arunpravin.PaneerSelvam@amd.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=matthew.auld@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