[PATCH v6 1/6] drm: move the buddy allocator from i915 into common drm

Matthew Auld matthew.auld at intel.com
Fri Jan 7 15:49:01 UTC 2022


On 26/12/2021 22:24, Arunpravin wrote:
> Move the base i915 buddy allocator code into drm
> - Move i915_buddy.h to include/drm
> - Move i915_buddy.c to drm root folder
> - Rename "i915" string with "drm" string wherever applicable
> - Rename "I915" string with "DRM" string wherever applicable
> - Fix header file dependencies
> - Fix alignment issues
> - add Makefile support for drm buddy
> - export functions and write kerneldoc description
> - Remove i915 selftest config check condition as buddy selftest
>    will be moved to drm selftest folder
> 
> cleanup i915 buddy references in i915 driver module
> and replace with drm buddy
> 
> v2:
>    - include header file in alphabetical order(Thomas)
>    - merged changes listed in the body section into a single patch
>      to keep the build intact(Christian, Jani)
> 
> v3:
>    - make drm buddy a separate module(Thomas, Christian)
> 
> v4:
>    - Fix build error reported by kernel test robot <lkp at intel.com>
>    - removed i915 buddy selftest from i915_mock_selftests.h to
>      avoid build error
>    - removed selftests/i915_buddy.c file as we create a new set of
>      buddy test cases in drm/selftests folder
> 
> v5:
>    - Fix merge conflict issue
> 
> Signed-off-by: Arunpravin <Arunpravin.PaneerSelvam at amd.com>

<snip>

> +int drm_buddy_init(struct drm_buddy_mm *mm, u64 size, u64 chunk_size)
> +{
> +	unsigned int i;
> +	u64 offset;
> +
> +	if (size < chunk_size)
> +		return -EINVAL;
> +
> +	if (chunk_size < PAGE_SIZE)
> +		return -EINVAL;
> +
> +	if (!is_power_of_2(chunk_size))
> +		return -EINVAL;
> +
> +	size = round_down(size, chunk_size);
> +
> +	mm->size = size;
> +	mm->avail = size;
> +	mm->chunk_size = chunk_size;
> +	mm->max_order = ilog2(size) - ilog2(chunk_size);
> +
> +	BUG_ON(mm->max_order > DRM_BUDDY_MAX_ORDER);
> +
> +	mm->slab_blocks = KMEM_CACHE(drm_buddy_block, 0);
> +	if (!mm->slab_blocks)
> +		return -ENOMEM;

It looks like every KMEM_CACHE() also creates a debugfs entry? See the 
error here[1]. I guess because we end with multiple instances in i915. 
If so, is it possible to have a single KMEM_CACHE() as part of the buddy 
module, similar to what i915 was doing previously?

[1] 
https://intel-gfx-ci.01.org/tree/drm-tip/Trybot_8217/shard-skl4/igt@i915_selftest@mock@memory_region.html


More information about the amd-gfx mailing list