public inbox for amd-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: "Zhang, Jerry (Junwei)" <Jerry.Zhang-5C7GfCeVMHo@public.gmane.org>
To: "Christian König"
	<ckoenig.leichtzumerken-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: Re: [PATCH 04/11] drm/amdgpu: add some VM PD/PT iterators
Date: Tue, 11 Sep 2018 10:38:01 +0800	[thread overview]
Message-ID: <5B972A89.60500@amd.com> (raw)
In-Reply-To: <20180909180339.1910-5-christian.koenig-5C7GfCeVMHo@public.gmane.org>

On 09/10/2018 02:03 AM, Christian König wrote:
> Both a leaf as well as dfs iterator to walk over all the PDs/PTs.
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 221 +++++++++++++++++++++++++++++++++
>   1 file changed, 221 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 416eccd9ea29..4007202585d4 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -355,6 +355,227 @@ static struct amdgpu_vm_pt *amdgpu_vm_pt_parent(struct amdgpu_vm_pt *pt)
>   	return list_first_entry(&parent->va, struct amdgpu_vm_pt, base.bo_list);
>   }
>
> +/**
> + * amdgpu_vm_pt_cursor - state for for_each_amdgpu_vm_pt
> + */
> +struct amdgpu_vm_pt_cursor {
> +	uint64_t pfn;
> +	struct amdgpu_vm_pt *parent;
> +	struct amdgpu_vm_pt *entry;
> +	unsigned level;
> +};
> +
> +/**
> + * amdgpu_vm_pt_start - start PD/PT walk
> + *
> + * @adev: amdgpu_device pointer
> + * @vm: amdgpu_vm structure
> + * @start: start address of the walk
> + * @cursor: state to initialize
> + *
> + * Initialize a amdgpu_vm_pt_cursor to start a walk.
> + */
> +static void amdgpu_vm_pt_start(struct amdgpu_device *adev,
> +			       struct amdgpu_vm *vm, uint64_t start,
> +			       struct amdgpu_vm_pt_cursor *cursor)
> +{
> +	cursor->pfn = start;
> +	cursor->parent = NULL;
> +	cursor->entry = &vm->root;
> +	cursor->level = adev->vm_manager.root_level;
> +}
> +
> +/**
> + * amdgpu_vm_pt_descendant - got to child node

seems typo for "go to"

Jerry

> + *
> + * @adev: amdgpu_device pointer
> + * @cursor: current state
> + *
> + * Walk to the child node of the current node.
> + * Returns:
> + * True if the walk was possible, false otherwise.
> + */
> +static bool amdgpu_vm_pt_descendant(struct amdgpu_device *adev,
> +				    struct amdgpu_vm_pt_cursor *cursor)
> +{
> +	unsigned num_entries, shift, idx;
> +
> +	if (!cursor->entry->entries)
> +		return false;
> +
> +	BUG_ON(!cursor->entry->base.bo);
> +	num_entries = amdgpu_vm_num_entries(adev, cursor->level);
> +	shift = amdgpu_vm_level_shift(adev, cursor->level);
> +
> +	++cursor->level;
> +	idx = (cursor->pfn >> shift) % num_entries;
> +	cursor->parent = cursor->entry;
> +	cursor->entry = &cursor->entry->entries[idx];
> +	return true;
> +}
> +
> +/**
> + * amdgpu_vm_pt_sibling - go to sibling node
> + *
> + * @adev: amdgpu_device pointer
> + * @cursor: current state
> + *
> + * Walk to the sibling node of the current node.
> + * Returns:
> + * True if the walk was possible, false otherwise.
> + */
> +static bool amdgpu_vm_pt_sibling(struct amdgpu_device *adev,
> +				 struct amdgpu_vm_pt_cursor *cursor)
> +{
> +	unsigned shift, num_entries;
> +
> +	/* Root doesn't have a sibling */
> +	if (!cursor->parent)
> +		return false;
> +
> +	/* Go to our parents and see if we got a sibling */
> +	shift = amdgpu_vm_level_shift(adev, cursor->level - 1);
> +	num_entries = amdgpu_vm_num_entries(adev, cursor->level - 1);
> +
> +	if (cursor->entry == &cursor->parent->entries[num_entries - 1])
> +		return false;
> +
> +	cursor->pfn += 1ULL << shift;
> +	cursor->pfn &= ~((1ULL << shift) - 1);
> +	++cursor->entry;
> +	return true;
> +}
> +
> +/**
> + * amdgpu_vm_pt_ancestor - go to parent node
> + *
> + * @adev: amdgpu_device pointer
> + * @cursor: current state
> + *
> + * Walk to the parent node of the current node.
> + * Returns:
> + * True if the walk was possible, false otherwise.
> + */
> +static bool amdgpu_vm_pt_ancestor(struct amdgpu_vm_pt_cursor *cursor)
> +{
> +	if (!cursor->parent)
> +		return false;
> +
> +	--cursor->level;
> +	cursor->entry = cursor->parent;
> +	cursor->parent = amdgpu_vm_pt_parent(cursor->parent);
> +	return true;
> +}
> +
> +/**
> + * amdgpu_vm_pt_next - get next PD/PT in hieratchy
> + *
> + * @adev: amdgpu_device pointer
> + * @cursor: current state
> + *
> + * Walk the PD/PT tree to the next node.
> + */
> +static void amdgpu_vm_pt_next(struct amdgpu_device *adev,
> +			      struct amdgpu_vm_pt_cursor *cursor)
> +{
> +	/* First try a newborn child */
> +	if (amdgpu_vm_pt_descendant(adev, cursor))
> +		return;
> +
> +	/* If that didn't worked try to find a sibling */
> +	while (!amdgpu_vm_pt_sibling(adev, cursor)) {
> +		/* No sibling, go to our parents and grandparents */
> +		if (!amdgpu_vm_pt_ancestor(cursor)) {
> +			cursor->pfn = ~0ll;
> +			return;
> +		}
> +	}
> +}
> +
> +/**
> + * amdgpu_vm_pt_first_leaf - get first leaf PD/PT
> + *
> + * @adev: amdgpu_device pointer
> + * @vm: amdgpu_vm structure
> + * @start: start addr of the walk
> + * @cursor: state to initialize
> + *
> + * Start a walk and go directly to the leaf node.
> + */
> +static void amdgpu_vm_pt_first_leaf(struct amdgpu_device *adev,
> +				    struct amdgpu_vm *vm, uint64_t start,
> +				    struct amdgpu_vm_pt_cursor *cursor)
> +{
> +	amdgpu_vm_pt_start(adev, vm, start, cursor);
> +	while (amdgpu_vm_pt_descendant(adev, cursor));
> +}
> +
> +/**
> + * amdgpu_vm_pt_next_leaf - get next leaf PD/PT
> + *
> + * @adev: amdgpu_device pointer
> + * @cursor: current state
> + *
> + * Walk the PD/PT tree to the next leaf node.
> + */
> +static void amdgpu_vm_pt_next_leaf(struct amdgpu_device *adev,
> +				   struct amdgpu_vm_pt_cursor *cursor)
> +{
> +	amdgpu_vm_pt_next(adev, cursor);
> +	while (amdgpu_vm_pt_descendant(adev, cursor));
> +}
> +
> +/**
> + * for_each_amdgpu_vm_pt_leaf - walk over all leaf PDs/PTs in the hierarchy
> + */
> +#define for_each_amdgpu_vm_pt_leaf(adev, vm, start, end, cursor)		\
> +	for (amdgpu_vm_pt_first_leaf((adev), (vm), (start), &(cursor));		\
> +	     (cursor).pfn <= end; amdgpu_vm_pt_next_leaf((adev), &(cursor)))
> +
> +/**
> + * amdgpu_vm_pt_first_dfs - start a deep first search
> + *
> + * @adev: amdgpu_device structure
> + * @vm: amdgpu_vm structure
> + * @cursor: state to initialize
> + *
> + * Starts a deep first traversal of the PD/PT tree.
> + */
> +static void amdgpu_vm_pt_first_dfs(struct amdgpu_device *adev,
> +				   struct amdgpu_vm *vm,
> +				   struct amdgpu_vm_pt_cursor *cursor)
> +{
> +	amdgpu_vm_pt_start(adev, vm, 0, cursor);
> +	while (amdgpu_vm_pt_descendant(adev, cursor));
> +}
> +
> +/**
> + * amdgpu_vm_pt_next_dfs - get the next node for a deep first search
> + *
> + * @adev: amdgpu_device structure
> + * @cursor: current state
> + *
> + * Move the cursor to the next node in a deep first search.
> + */
> +static void amdgpu_vm_pt_next_dfs(struct amdgpu_device *adev,
> +				  struct amdgpu_vm_pt_cursor *cursor)
> +{
> +	if (!cursor->parent)
> +		cursor->entry = NULL;
> +	else if (amdgpu_vm_pt_sibling(adev, cursor))
> +		while (amdgpu_vm_pt_descendant(adev, cursor));
> +	else
> +		amdgpu_vm_pt_ancestor(cursor);
> +}
> +
> +/**
> + * for_each_amdgpu_vm_pt_dfs_safe - safe deep first search of all PDs/PTs
> + */
> +#define for_each_amdgpu_vm_pt_dfs_safe(adev, vm, cursor, entry)			\
> +	for (amdgpu_vm_pt_first_dfs((adev), (vm), &(cursor)),			\
> +	     (entry) = (cursor).entry; (entry); (entry) = (cursor).entry,	\
> +	     amdgpu_vm_pt_next_dfs((adev), &(cursor)))
> +
>   /**
>    * amdgpu_vm_get_pd_bo - add the VM PD to a validation list
>    *
>
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2018-09-11  2:38 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-09 18:03 Optimize VM handling a bit more Christian König
     [not found] ` <20180909180339.1910-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-09-09 18:03   ` [PATCH 01/11] drm/amdgpu: try allocating VRAM as power of two Christian König
     [not found]     ` <20180909180339.1910-2-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-09-11  0:08       ` Felix Kuehling
     [not found]         ` <60b9c96a-d31d-cd61-df22-c8414f0166dc-5C7GfCeVMHo@public.gmane.org>
2018-09-11  6:49           ` Christian König
     [not found]             ` <9b61bb4c-4721-c8af-0810-4ecc18ed1ea4-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-09-11  7:37               ` Michel Dänzer
     [not found]                 ` <46b7da24-4b04-7daf-e6c3-07e10ecb6fd6-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-09-11  7:46                   ` Christian König
     [not found]                     ` <d0af0309-e4f9-9825-fd30-9cf79ed5f823-5C7GfCeVMHo@public.gmane.org>
2018-09-11  7:55                       ` Michel Dänzer
     [not found]                         ` <5fd331d0-24ab-7540-2d0a-b227230743c0-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-09-11  8:20                           ` Christian König
     [not found]                             ` <a3c91610-e5e2-c666-cfda-344f1f40485c-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-09-11  8:25                               ` Michel Dänzer
2018-09-11 14:27               ` Kuehling, Felix
     [not found]                 ` <DM5PR12MB17073F8B673AEFC092FBA5B392040-2J9CzHegvk9TCtO+SvGBKwdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2018-09-11 14:48                   ` Christian König
     [not found]                     ` <2361b55f-ed56-bd42-b628-fc001d9ea300-5C7GfCeVMHo@public.gmane.org>
2018-09-11 22:25                       ` Felix Kuehling
2018-09-11  9:50       ` Huang Rui
2018-09-11 11:16         ` Christian König
2018-09-09 18:03   ` [PATCH 02/11] drm/amdgpu: add amdgpu_vm_pt_parent helper Christian König
2018-09-09 18:03   ` [PATCH 03/11] drm/amdgpu: add amdgpu_vm_update_func Christian König
2018-09-09 18:03   ` [PATCH 04/11] drm/amdgpu: add some VM PD/PT iterators Christian König
     [not found]     ` <20180909180339.1910-5-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-09-11  1:51       ` Felix Kuehling
2018-09-11  2:38       ` Zhang, Jerry (Junwei) [this message]
2018-09-09 18:03   ` [PATCH 05/11] drm/amdgpu: use leaf iterator for allocating PD/PT Christian König
2018-09-09 18:03   ` [PATCH 06/11] drm/amdgpu: use dfs iterator to free PDs/PTs Christian König
2018-09-09 18:03   ` [PATCH 07/11] drm/amdgpu: use the DFS iterator in amdgpu_vm_invalidate_level Christian König
     [not found]     ` <20180909180339.1910-8-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-09-11  0:19       ` Felix Kuehling
2018-09-09 18:03   ` [PATCH 08/11] drm/amdgpu: use leaf iterator for filling PTs Christian König
2018-09-09 18:03   ` [PATCH 09/11] drm/amdgpu: meld together VM fragment and huge page handling Christian König
2018-09-09 18:03   ` [PATCH 10/11] drm/amdgpu: use the maximum possible fragment size on Vega/Raven Christian König
     [not found]     ` <20180909180339.1910-11-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-09-11  0:45       ` Felix Kuehling
2018-09-09 18:03   ` [PATCH 11/11] drm/amdgpu: allow fragment processing for invalid PTEs Christian König
2018-09-11  2:17   ` Optimize VM handling a bit more Felix Kuehling
2018-09-11  2:39   ` Zhang, Jerry (Junwei)

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=5B972A89.60500@amd.com \
    --to=jerry.zhang-5c7gfcevmho@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=ckoenig.leichtzumerken-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    /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