Skip to content

Commit d608fbf

Browse files
committed
drm/xe/pf: Increase PF GuC Buffer Cache size and use it for VF migration
Contiguous PF GGTT VMAs can be scarce after creating VFs. Increase the GuC buffer cache size to 8M for PF so that we can fit GuC migration data (which currently maxes out at just over 4M) and use the cache instead of allocating fresh BOs. Reviewed-by: Michal Wajdeczko <michal.wajdeczko@intel.com> Link: https://patch.msgid.link/20251112132220.516975-13-michal.winiarski@intel.com Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
1 parent dca2701 commit d608fbf

3 files changed

Lines changed: 30 additions & 33 deletions

File tree

drivers/gpu/drm/xe/xe_gt_sriov_pf_migration.c

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "xe_gt_sriov_pf_helpers.h"
1212
#include "xe_gt_sriov_pf_migration.h"
1313
#include "xe_gt_sriov_printk.h"
14-
#include "xe_guc.h"
14+
#include "xe_guc_buf.h"
1515
#include "xe_guc_ct.h"
1616
#include "xe_sriov.h"
1717
#include "xe_sriov_packet.h"
@@ -58,73 +58,56 @@ static int pf_send_guc_query_vf_state_size(struct xe_gt *gt, unsigned int vfid)
5858

5959
/* Return: number of state dwords saved or a negative error code on failure */
6060
static int pf_send_guc_save_vf_state(struct xe_gt *gt, unsigned int vfid,
61-
void *buff, size_t size)
61+
void *dst, size_t size)
6262
{
6363
const int ndwords = size / sizeof(u32);
64-
struct xe_tile *tile = gt_to_tile(gt);
65-
struct xe_device *xe = tile_to_xe(tile);
6664
struct xe_guc *guc = &gt->uc.guc;
67-
struct xe_bo *bo;
65+
CLASS(xe_guc_buf, buf)(&guc->buf, ndwords);
6866
int ret;
6967

7068
xe_gt_assert(gt, size % sizeof(u32) == 0);
7169
xe_gt_assert(gt, size == ndwords * sizeof(u32));
7270

73-
bo = xe_bo_create_pin_map_novm(xe, tile,
74-
ALIGN(size, PAGE_SIZE),
75-
ttm_bo_type_kernel,
76-
XE_BO_FLAG_SYSTEM |
77-
XE_BO_FLAG_GGTT |
78-
XE_BO_FLAG_GGTT_INVALIDATE, false);
79-
if (IS_ERR(bo))
80-
return PTR_ERR(bo);
71+
if (!xe_guc_buf_is_valid(buf))
72+
return -ENOBUFS;
73+
74+
/* FW expects this buffer to be zero-initialized */
75+
memset(xe_guc_buf_cpu_ptr(buf), 0, size);
8176

8277
ret = guc_action_vf_save_restore(guc, vfid, GUC_PF_OPCODE_VF_SAVE,
83-
xe_bo_ggtt_addr(bo), ndwords);
78+
xe_guc_buf_flush(buf), ndwords);
8479
if (!ret)
8580
ret = -ENODATA;
8681
else if (ret > ndwords)
8782
ret = -EPROTO;
8883
else if (ret > 0)
89-
xe_map_memcpy_from(xe, buff, &bo->vmap, 0, ret * sizeof(u32));
84+
memcpy(dst, xe_guc_buf_sync_read(buf), ret * sizeof(u32));
9085

91-
xe_bo_unpin_map_no_vm(bo);
9286
return ret;
9387
}
9488

9589
/* Return: number of state dwords restored or a negative error code on failure */
9690
static int pf_send_guc_restore_vf_state(struct xe_gt *gt, unsigned int vfid,
97-
const void *buff, size_t size)
91+
const void *src, size_t size)
9892
{
9993
const int ndwords = size / sizeof(u32);
100-
struct xe_tile *tile = gt_to_tile(gt);
101-
struct xe_device *xe = tile_to_xe(tile);
10294
struct xe_guc *guc = &gt->uc.guc;
103-
struct xe_bo *bo;
95+
CLASS(xe_guc_buf_from_data, buf)(&guc->buf, src, size);
10496
int ret;
10597

10698
xe_gt_assert(gt, size % sizeof(u32) == 0);
10799
xe_gt_assert(gt, size == ndwords * sizeof(u32));
108100

109-
bo = xe_bo_create_pin_map_novm(xe, tile,
110-
ALIGN(size, PAGE_SIZE),
111-
ttm_bo_type_kernel,
112-
XE_BO_FLAG_SYSTEM |
113-
XE_BO_FLAG_GGTT |
114-
XE_BO_FLAG_GGTT_INVALIDATE, false);
115-
if (IS_ERR(bo))
116-
return PTR_ERR(bo);
117-
118-
xe_map_memcpy_to(xe, &bo->vmap, 0, buff, size);
101+
if (!xe_guc_buf_is_valid(buf))
102+
return -ENOBUFS;
119103

120104
ret = guc_action_vf_save_restore(guc, vfid, GUC_PF_OPCODE_VF_RESTORE,
121-
xe_bo_ggtt_addr(bo), ndwords);
105+
xe_guc_buf_flush(buf), ndwords);
122106
if (!ret)
123107
ret = -ENODATA;
124108
else if (ret > ndwords)
125109
ret = -EPROTO;
126110

127-
xe_bo_unpin_map_no_vm(bo);
128111
return ret;
129112
}
130113

drivers/gpu/drm/xe/xe_gt_sriov_pf_migration.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
struct xe_gt;
1212
struct xe_sriov_packet;
1313

14+
/* TODO: get this information by querying GuC in the future */
15+
#define XE_GT_SRIOV_PF_MIGRATION_GUC_DATA_MAX_SIZE SZ_8M
16+
1417
int xe_gt_sriov_pf_migration_init(struct xe_gt *gt);
1518
int xe_gt_sriov_pf_migration_save_guc_state(struct xe_gt *gt, unsigned int vfid);
1619
int xe_gt_sriov_pf_migration_restore_guc_state(struct xe_gt *gt, unsigned int vfid);

drivers/gpu/drm/xe/xe_guc.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "xe_gt_printk.h"
2525
#include "xe_gt_sriov_vf.h"
2626
#include "xe_gt_throttle.h"
27+
#include "xe_gt_sriov_pf_migration.h"
2728
#include "xe_guc_ads.h"
2829
#include "xe_guc_buf.h"
2930
#include "xe_guc_capture.h"
@@ -40,6 +41,7 @@
4041
#include "xe_mmio.h"
4142
#include "xe_platform_types.h"
4243
#include "xe_sriov.h"
44+
#include "xe_sriov_pf_migration.h"
4345
#include "xe_uc.h"
4446
#include "xe_uc_fw.h"
4547
#include "xe_wa.h"
@@ -821,6 +823,14 @@ static int vf_guc_init_post_hwconfig(struct xe_guc *guc)
821823
return 0;
822824
}
823825

826+
static u32 guc_additional_cache_size(struct xe_device *xe)
827+
{
828+
if (IS_SRIOV_PF(xe) && xe_sriov_pf_migration_supported(xe))
829+
return XE_GT_SRIOV_PF_MIGRATION_GUC_DATA_MAX_SIZE;
830+
else
831+
return 0; /* Fallback to default size */
832+
}
833+
824834
/**
825835
* xe_guc_init_post_hwconfig - initialize GuC post hwconfig load
826836
* @guc: The GuC object
@@ -860,7 +870,8 @@ int xe_guc_init_post_hwconfig(struct xe_guc *guc)
860870
if (ret)
861871
return ret;
862872

863-
ret = xe_guc_buf_cache_init(&guc->buf);
873+
ret = xe_guc_buf_cache_init_with_size(&guc->buf,
874+
guc_additional_cache_size(guc_to_xe(guc)));
864875
if (ret)
865876
return ret;
866877

0 commit comments

Comments
 (0)