Skip to content

Commit df8c378

Browse files
mbrost05lucasdemarchi
authored andcommitted
drm/gpusvm: Add timeslicing support to GPU SVM
Add timeslicing support to GPU SVM which will guarantee the GPU a minimum execution time on piece of physical memory before migration back to CPU. Intended to implement strict migration policies which require memory to be in a certain placement for correct execution. Required for shared CPU and GPU atomics on certain devices. Fixes: 99624bd ("drm/gpusvm: Add support for GPU Shared Virtual Memory") Cc: stable@vger.kernel.org Signed-off-by: Matthew Brost <matthew.brost@intel.com> Reviewed-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com> Link: https://lore.kernel.org/r/20250512135500.1405019-4-matthew.brost@intel.com (cherry picked from commit 8dc1812) Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
1 parent 794f549 commit df8c378

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

drivers/gpu/drm/drm_gpusvm.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,6 +1783,8 @@ int drm_gpusvm_migrate_to_devmem(struct drm_gpusvm *gpusvm,
17831783
goto err_finalize;
17841784

17851785
/* Upon success bind devmem allocation to range and zdd */
1786+
devmem_allocation->timeslice_expiration = get_jiffies_64() +
1787+
msecs_to_jiffies(ctx->timeslice_ms);
17861788
zdd->devmem_allocation = devmem_allocation; /* Owns ref */
17871789

17881790
err_finalize:
@@ -2003,6 +2005,13 @@ static int __drm_gpusvm_migrate_to_ram(struct vm_area_struct *vas,
20032005
void *buf;
20042006
int i, err = 0;
20052007

2008+
if (page) {
2009+
zdd = page->zone_device_data;
2010+
if (time_before64(get_jiffies_64(),
2011+
zdd->devmem_allocation->timeslice_expiration))
2012+
return 0;
2013+
}
2014+
20062015
start = ALIGN_DOWN(fault_addr, size);
20072016
end = ALIGN(fault_addr + 1, size);
20082017

include/drm/drm_gpusvm.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ struct drm_gpusvm_devmem_ops {
8989
* @ops: Pointer to the operations structure for GPU SVM device memory
9090
* @dpagemap: The struct drm_pagemap of the pages this allocation belongs to.
9191
* @size: Size of device memory allocation
92+
* @timeslice_expiration: Timeslice expiration in jiffies
9293
*/
9394
struct drm_gpusvm_devmem {
9495
struct device *dev;
@@ -97,6 +98,7 @@ struct drm_gpusvm_devmem {
9798
const struct drm_gpusvm_devmem_ops *ops;
9899
struct drm_pagemap *dpagemap;
99100
size_t size;
101+
u64 timeslice_expiration;
100102
};
101103

102104
/**
@@ -295,6 +297,8 @@ struct drm_gpusvm {
295297
* @check_pages_threshold: Check CPU pages for present if chunk is less than or
296298
* equal to threshold. If not present, reduce chunk
297299
* size.
300+
* @timeslice_ms: The timeslice MS which in minimum time a piece of memory
301+
* remains with either exclusive GPU or CPU access.
298302
* @in_notifier: entering from a MMU notifier
299303
* @read_only: operating on read-only memory
300304
* @devmem_possible: possible to use device memory
@@ -304,6 +308,7 @@ struct drm_gpusvm {
304308
*/
305309
struct drm_gpusvm_ctx {
306310
unsigned long check_pages_threshold;
311+
unsigned long timeslice_ms;
307312
unsigned int in_notifier :1;
308313
unsigned int read_only :1;
309314
unsigned int devmem_possible :1;

0 commit comments

Comments
 (0)