iris: Move iris_bo_madvise() to i915/iris_bufmgr.c

Start to split functions that are not in hot paths to specific i915
files.

Also making it static as iris_bo_madvise() is only called from
iris_bufmgr.c and adding a enum iris_madvice to be used among all
backends.

Signed-off-by: José Roberto de Souza <jose.souza@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21688>
This commit is contained in:
José Roberto de Souza
2022-10-21 07:19:59 -07:00
committed by Marge Bot
parent 736d6643bb
commit 5dc0f18333
6 changed files with 106 additions and 28 deletions
@@ -0,0 +1,44 @@
/*
* Copyright © 2023 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include "i915/iris_bufmgr.h"
#include "common/intel_gem.h"
#include "iris/iris_bufmgr.h"
#include "drm-uapi/i915_drm.h"
bool
iris_i915_bo_madvise(struct iris_bo *bo, enum iris_madvice state)
{
uint32_t i915_state = state == IRIS_MADVICE_WILL_NEED ?
I915_MADV_WILLNEED : I915_MADV_DONTNEED;
struct drm_i915_gem_madvise madv = {
.handle = bo->gem_handle,
.madv = i915_state,
.retained = 1,
};
intel_ioctl(iris_bufmgr_get_fd(bo->bufmgr), DRM_IOCTL_I915_GEM_MADVISE, &madv);
return madv.retained;
}
@@ -0,0 +1,30 @@
/*
* Copyright © 2023 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#pragma once
#include <stdbool.h>
struct iris_bo;
enum iris_madvice;
bool iris_i915_bo_madvise(struct iris_bo *bo, enum iris_madvice state);
@@ -26,7 +26,7 @@
#include "drm-uapi/i915_drm.h"
#include "iris_bufmgr.h"
#include "iris/iris_bufmgr.h"
static uint32_t
i915_gem_create(struct iris_bufmgr *bufmgr,
+24 -13
View File
@@ -66,6 +66,7 @@
#include "iris_context.h"
#include "string.h"
#include "iris_kmd_backend.h"
#include "i915/iris_bufmgr.h"
#include "drm-uapi/i915_drm.h"
@@ -527,21 +528,31 @@ iris_bo_busy(struct iris_bo *bo)
return busy;
}
int
iris_bo_madvise(struct iris_bo *bo, int state)
/**
* Specify the volatility of the buffer.
* \param bo Buffer to create a name for
* \param state The purgeable status
*
* Use IRIS_MADVICE_DONT_NEED to mark the buffer as purgeable, and it will be
* reclaimed under memory pressure. If you subsequently require the buffer,
* then you must pass IRIS_MADVICE_WILL_NEED to mark the buffer as required.
*
* Returns true if the buffer was retained, or false if it was discarded
* whilst marked as IRIS_MADVICE_DONT_NEED.
*/
static bool
iris_bo_madvise(struct iris_bo *bo, enum iris_madvice state)
{
/* We can't madvise suballocated BOs. */
assert(iris_bo_is_real(bo));
struct drm_i915_gem_madvise madv = {
.handle = bo->gem_handle,
.madv = state,
.retained = 1,
};
intel_ioctl(bo->bufmgr->fd, DRM_IOCTL_I915_GEM_MADVISE, &madv);
return madv.retained;
switch (iris_bufmgr_get_device_info(bo->bufmgr)->kmd_type) {
case INTEL_KMD_TYPE_I915:
return iris_i915_bo_madvise(bo, state);
default:
unreachable("missing");
return false;
}
}
static struct iris_bo *
@@ -905,7 +916,7 @@ alloc_bo_from_cache(struct iris_bufmgr *bufmgr,
list_del(&cur->head);
/* Tell the kernel we need this BO. If it still exists, we're done! */
if (iris_bo_madvise(cur, I915_MADV_WILLNEED)) {
if (iris_bo_madvise(cur, IRIS_MADVICE_WILL_NEED)) {
bo = cur;
break;
}
@@ -1439,7 +1450,7 @@ bo_unreference_final(struct iris_bo *bo, time_t time)
if (bo->real.reusable)
bucket = bucket_for_size(bufmgr, bo->size, bo->real.heap);
/* Put the buffer into our internal cache for reuse if we can. */
if (bucket && iris_bo_madvise(bo, I915_MADV_DONTNEED)) {
if (bucket && iris_bo_madvise(bo, IRIS_MADVICE_DONT_NEED)) {
bo->real.free_time = time;
bo->name = NULL;
+5 -14
View File
@@ -472,20 +472,6 @@ void iris_bo_mark_exported(struct iris_bo *bo);
*/
bool iris_bo_busy(struct iris_bo *bo);
/**
* Specify the volatility of the buffer.
* \param bo Buffer to create a name for
* \param madv The purgeable status
*
* Use I915_MADV_DONTNEED to mark the buffer as purgeable, and it will be
* reclaimed under memory pressure. If you subsequently require the buffer,
* then you must pass I915_MADV_WILLNEED to mark the buffer as required.
*
* Returns 1 if the buffer was retained, or 0 if it was discarded whilst
* marked as I915_MADV_DONTNEED.
*/
int iris_bo_madvise(struct iris_bo *bo, int madv);
struct iris_bufmgr *iris_bufmgr_get_for_fd(int fd, bool bo_reuse);
int iris_bufmgr_get_fd(struct iris_bufmgr *bufmgr);
@@ -597,4 +583,9 @@ uint64_t iris_bufmgr_vram_size(struct iris_bufmgr *bufmgr);
uint64_t iris_bufmgr_sram_size(struct iris_bufmgr *bufmgr);
const struct intel_device_info *iris_bufmgr_get_device_info(struct iris_bufmgr *bufmgr);
enum iris_madvice {
IRIS_MADVICE_WILL_NEED = 0,
IRIS_MADVICE_DONT_NEED = 1,
};
#endif /* IRIS_BUFMGR_H */
+2
View File
@@ -19,6 +19,8 @@
# SOFTWARE.
files_libiris = files(
'i915/iris_bufmgr.c',
'i915/iris_bufmgr.h',
'i915/iris_kmd_backend.c',
'driinfo_iris.h',
'iris_batch.c',