Skip to content

Commit 9d333d6

Browse files
Iouri Tarassovchessturo
authored andcommitted
drivers: hv: dxgkrnl: Ioctls to manage scheduling priority
Implement iocts to manage compute device scheduling priority: - LX_DXGETCONTEXTINPROCESSSCHEDULINGPRIORITY - LX_DXGETCONTEXTSCHEDULINGPRIORITY - LX_DXSETCONTEXTINPROCESSSCHEDULINGPRIORITY - LX_DXSETCONTEXTSCHEDULINGPRIORITY Each compute device execution context has an assigned scheduling priority. It is used by the compute device scheduler on the host to pick contexts for execution. There is a global priority and a priority within a process. Signed-off-by: Iouri Tarassov <iourit@linux.microsoft.com> [kms: forward port to 6.6 from 6.1. No code changes made.] Signed-off-by: Kelsey Steele <kelseysteele@microsoft.com>
1 parent 1418968 commit 9d333d6

5 files changed

Lines changed: 294 additions & 6 deletions

File tree

drivers/hv/dxgkrnl/dxgkrnl.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,15 @@ int dxgvmb_send_set_allocation_priority(struct dxgprocess *process,
865865
int dxgvmb_send_get_allocation_priority(struct dxgprocess *process,
866866
struct dxgadapter *adapter,
867867
struct d3dkmt_getallocationpriority *a);
868+
int dxgvmb_send_set_context_sch_priority(struct dxgprocess *process,
869+
struct dxgadapter *adapter,
870+
struct d3dkmthandle context,
871+
int priority, bool in_process);
872+
int dxgvmb_send_get_context_sch_priority(struct dxgprocess *process,
873+
struct dxgadapter *adapter,
874+
struct d3dkmthandle context,
875+
int *priority,
876+
bool in_process);
868877
int dxgvmb_send_offer_allocations(struct dxgprocess *process,
869878
struct dxgadapter *adapter,
870879
struct d3dkmt_offerallocations *args);

drivers/hv/dxgkrnl/dxgvmbus.c

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,6 +2949,69 @@ int dxgvmb_send_get_allocation_priority(struct dxgprocess *process,
29492949
return ret;
29502950
}
29512951

2952+
int dxgvmb_send_set_context_sch_priority(struct dxgprocess *process,
2953+
struct dxgadapter *adapter,
2954+
struct d3dkmthandle context,
2955+
int priority,
2956+
bool in_process)
2957+
{
2958+
struct dxgkvmb_command_setcontextschedulingpriority2 *command;
2959+
int ret;
2960+
struct dxgvmbusmsg msg = {.hdr = NULL};
2961+
2962+
ret = init_message(&msg, adapter, process, sizeof(*command));
2963+
if (ret)
2964+
goto cleanup;
2965+
command = (void *)msg.msg;
2966+
2967+
command_vgpu_to_host_init2(&command->hdr,
2968+
DXGK_VMBCOMMAND_SETCONTEXTSCHEDULINGPRIORITY,
2969+
process->host_handle);
2970+
command->context = context;
2971+
command->priority = priority;
2972+
command->in_process = in_process;
2973+
ret = dxgvmb_send_sync_msg_ntstatus(msg.channel, msg.hdr, msg.size);
2974+
cleanup:
2975+
free_message(&msg, process);
2976+
if (ret)
2977+
DXG_TRACE("err: %d", ret);
2978+
return ret;
2979+
}
2980+
2981+
int dxgvmb_send_get_context_sch_priority(struct dxgprocess *process,
2982+
struct dxgadapter *adapter,
2983+
struct d3dkmthandle context,
2984+
int *priority,
2985+
bool in_process)
2986+
{
2987+
struct dxgkvmb_command_getcontextschedulingpriority *command;
2988+
struct dxgkvmb_command_getcontextschedulingpriority_return result = { };
2989+
int ret;
2990+
struct dxgvmbusmsg msg = {.hdr = NULL};
2991+
2992+
ret = init_message(&msg, adapter, process, sizeof(*command));
2993+
if (ret)
2994+
goto cleanup;
2995+
command = (void *)msg.msg;
2996+
2997+
command_vgpu_to_host_init2(&command->hdr,
2998+
DXGK_VMBCOMMAND_GETCONTEXTSCHEDULINGPRIORITY,
2999+
process->host_handle);
3000+
command->context = context;
3001+
command->in_process = in_process;
3002+
ret = dxgvmb_send_sync_msg(msg.channel, msg.hdr, msg.size,
3003+
&result, sizeof(result));
3004+
if (ret >= 0) {
3005+
ret = ntstatus2int(result.status);
3006+
*priority = result.priority;
3007+
}
3008+
cleanup:
3009+
free_message(&msg, process);
3010+
if (ret)
3011+
DXG_TRACE("err: %d", ret);
3012+
return ret;
3013+
}
3014+
29523015
int dxgvmb_send_offer_allocations(struct dxgprocess *process,
29533016
struct dxgadapter *adapter,
29543017
struct d3dkmt_offerallocations *args)
@@ -2991,7 +3054,7 @@ int dxgvmb_send_offer_allocations(struct dxgprocess *process,
29913054
cleanup:
29923055
free_message(&msg, process);
29933056
if (ret)
2994-
pr_debug("err: %s %d", __func__, ret);
3057+
DXG_TRACE("err: %d", ret);
29953058
return ret;
29963059
}
29973060

@@ -3067,7 +3130,7 @@ int dxgvmb_send_reclaim_allocations(struct dxgprocess *process,
30673130
cleanup:
30683131
free_message((struct dxgvmbusmsg *)&msg, process);
30693132
if (ret)
3070-
pr_debug("err: %s %d", __func__, ret);
3133+
DXG_TRACE("err: %d", ret);
30713134
return ret;
30723135
}
30733136

drivers/hv/dxgkrnl/dxgvmbus.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,25 @@ struct dxgkvmb_command_getallocationpriority_return {
331331
/* u32 priorities[allocation_count or 1]; */
332332
};
333333

334+
/* Returns ntstatus */
335+
struct dxgkvmb_command_setcontextschedulingpriority2 {
336+
struct dxgkvmb_command_vgpu_to_host hdr;
337+
struct d3dkmthandle context;
338+
int priority;
339+
bool in_process;
340+
};
341+
342+
struct dxgkvmb_command_getcontextschedulingpriority {
343+
struct dxgkvmb_command_vgpu_to_host hdr;
344+
struct d3dkmthandle context;
345+
bool in_process;
346+
};
347+
348+
struct dxgkvmb_command_getcontextschedulingpriority_return {
349+
struct ntstatus status;
350+
int priority;
351+
};
352+
334353
struct dxgkvmb_command_createdevice {
335354
struct dxgkvmb_command_vgpu_to_host hdr;
336355
struct d3dkmt_createdeviceflags flags;

drivers/hv/dxgkrnl/ioctl.c

Lines changed: 173 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3660,6 +3660,171 @@ dxgkio_get_allocation_priority(struct dxgprocess *process, void *__user inargs)
36603660
return ret;
36613661
}
36623662

3663+
static int
3664+
set_context_scheduling_priority(struct dxgprocess *process,
3665+
struct d3dkmthandle hcontext,
3666+
int priority, bool in_process)
3667+
{
3668+
int ret = 0;
3669+
struct dxgdevice *device = NULL;
3670+
struct dxgadapter *adapter = NULL;
3671+
3672+
device = dxgprocess_device_by_object_handle(process,
3673+
HMGRENTRY_TYPE_DXGCONTEXT,
3674+
hcontext);
3675+
if (device == NULL) {
3676+
ret = -EINVAL;
3677+
goto cleanup;
3678+
}
3679+
adapter = device->adapter;
3680+
ret = dxgadapter_acquire_lock_shared(adapter);
3681+
if (ret < 0) {
3682+
adapter = NULL;
3683+
goto cleanup;
3684+
}
3685+
ret = dxgvmb_send_set_context_sch_priority(process, adapter,
3686+
hcontext, priority,
3687+
in_process);
3688+
if (ret < 0)
3689+
DXG_ERR("send_set_context_scheduling_priority failed");
3690+
cleanup:
3691+
if (adapter)
3692+
dxgadapter_release_lock_shared(adapter);
3693+
if (device)
3694+
kref_put(&device->device_kref, dxgdevice_release);
3695+
3696+
return ret;
3697+
}
3698+
3699+
static int
3700+
dxgkio_set_context_scheduling_priority(struct dxgprocess *process,
3701+
void *__user inargs)
3702+
{
3703+
struct d3dkmt_setcontextschedulingpriority args;
3704+
int ret;
3705+
3706+
ret = copy_from_user(&args, inargs, sizeof(args));
3707+
if (ret) {
3708+
DXG_ERR("failed to copy input args");
3709+
ret = -EINVAL;
3710+
goto cleanup;
3711+
}
3712+
3713+
ret = set_context_scheduling_priority(process, args.context,
3714+
args.priority, false);
3715+
cleanup:
3716+
DXG_TRACE("ioctl:%s %d", errorstr(ret), ret);
3717+
return ret;
3718+
}
3719+
3720+
static int
3721+
get_context_scheduling_priority(struct dxgprocess *process,
3722+
struct d3dkmthandle hcontext,
3723+
int __user *priority,
3724+
bool in_process)
3725+
{
3726+
int ret;
3727+
struct dxgdevice *device = NULL;
3728+
struct dxgadapter *adapter = NULL;
3729+
int pri = 0;
3730+
3731+
device = dxgprocess_device_by_object_handle(process,
3732+
HMGRENTRY_TYPE_DXGCONTEXT,
3733+
hcontext);
3734+
if (device == NULL) {
3735+
ret = -EINVAL;
3736+
goto cleanup;
3737+
}
3738+
adapter = device->adapter;
3739+
ret = dxgadapter_acquire_lock_shared(adapter);
3740+
if (ret < 0) {
3741+
adapter = NULL;
3742+
goto cleanup;
3743+
}
3744+
ret = dxgvmb_send_get_context_sch_priority(process, adapter,
3745+
hcontext, &pri, in_process);
3746+
if (ret < 0)
3747+
goto cleanup;
3748+
ret = copy_to_user(priority, &pri, sizeof(pri));
3749+
if (ret) {
3750+
DXG_ERR("failed to copy priority to user");
3751+
ret = -EINVAL;
3752+
}
3753+
3754+
cleanup:
3755+
if (adapter)
3756+
dxgadapter_release_lock_shared(adapter);
3757+
if (device)
3758+
kref_put(&device->device_kref, dxgdevice_release);
3759+
3760+
return ret;
3761+
}
3762+
3763+
static int
3764+
dxgkio_get_context_scheduling_priority(struct dxgprocess *process,
3765+
void *__user inargs)
3766+
{
3767+
struct d3dkmt_getcontextschedulingpriority args;
3768+
struct d3dkmt_getcontextschedulingpriority __user *input = inargs;
3769+
int ret;
3770+
3771+
ret = copy_from_user(&args, inargs, sizeof(args));
3772+
if (ret) {
3773+
DXG_ERR("failed to copy input args");
3774+
ret = -EINVAL;
3775+
goto cleanup;
3776+
}
3777+
3778+
ret = get_context_scheduling_priority(process, args.context,
3779+
&input->priority, false);
3780+
cleanup:
3781+
DXG_TRACE("ioctl:%s %d", errorstr(ret), ret);
3782+
return ret;
3783+
}
3784+
3785+
static int
3786+
dxgkio_set_context_process_scheduling_priority(struct dxgprocess *process,
3787+
void *__user inargs)
3788+
{
3789+
struct d3dkmt_setcontextinprocessschedulingpriority args;
3790+
int ret;
3791+
3792+
ret = copy_from_user(&args, inargs, sizeof(args));
3793+
if (ret) {
3794+
DXG_ERR("failed to copy input args");
3795+
ret = -EINVAL;
3796+
goto cleanup;
3797+
}
3798+
3799+
ret = set_context_scheduling_priority(process, args.context,
3800+
args.priority, true);
3801+
cleanup:
3802+
DXG_TRACE("ioctl:%s %d", errorstr(ret), ret);
3803+
return ret;
3804+
}
3805+
3806+
static int
3807+
dxgkio_get_context_process_scheduling_priority(struct dxgprocess *process,
3808+
void __user *inargs)
3809+
{
3810+
struct d3dkmt_getcontextinprocessschedulingpriority args;
3811+
int ret;
3812+
3813+
ret = copy_from_user(&args, inargs, sizeof(args));
3814+
if (ret) {
3815+
DXG_ERR("failed to copy input args");
3816+
ret = -EINVAL;
3817+
goto cleanup;
3818+
}
3819+
3820+
ret = get_context_scheduling_priority(process, args.context,
3821+
&((struct d3dkmt_getcontextinprocessschedulingpriority *)
3822+
inargs)->priority, true);
3823+
cleanup:
3824+
DXG_TRACE("ioctl:%s %d", errorstr(ret), ret);
3825+
return ret;
3826+
}
3827+
36633828
static int
36643829
dxgkio_change_vidmem_reservation(struct dxgprocess *process, void *__user inargs)
36653830
{
@@ -4655,8 +4820,10 @@ static struct ioctl_desc ioctls[] = {
46554820
/* 0x1e */ {},
46564821
/* 0x1f */ {dxgkio_flush_heap_transitions, LX_DXFLUSHHEAPTRANSITIONS},
46574822
/* 0x20 */ {},
4658-
/* 0x21 */ {},
4659-
/* 0x22 */ {},
4823+
/* 0x21 */ {dxgkio_get_context_process_scheduling_priority,
4824+
LX_DXGETCONTEXTINPROCESSSCHEDULINGPRIORITY},
4825+
/* 0x22 */ {dxgkio_get_context_scheduling_priority,
4826+
LX_DXGETCONTEXTSCHEDULINGPRIORITY},
46604827
/* 0x23 */ {},
46614828
/* 0x24 */ {},
46624829
/* 0x25 */ {dxgkio_lock2, LX_DXLOCK2},
@@ -4669,8 +4836,10 @@ static struct ioctl_desc ioctls[] = {
46694836
/* 0x2c */ {dxgkio_reclaim_allocations, LX_DXRECLAIMALLOCATIONS2},
46704837
/* 0x2d */ {},
46714838
/* 0x2e */ {dxgkio_set_allocation_priority, LX_DXSETALLOCATIONPRIORITY},
4672-
/* 0x2f */ {},
4673-
/* 0x30 */ {},
4839+
/* 0x2f */ {dxgkio_set_context_process_scheduling_priority,
4840+
LX_DXSETCONTEXTINPROCESSSCHEDULINGPRIORITY},
4841+
/* 0x30 */ {dxgkio_set_context_scheduling_priority,
4842+
LX_DXSETCONTEXTSCHEDULINGPRIORITY},
46744843
/* 0x31 */ {dxgkio_signal_sync_object_cpu,
46754844
LX_DXSIGNALSYNCHRONIZATIONOBJECTFROMCPU},
46764845
/* 0x32 */ {dxgkio_signal_sync_object_gpu,

include/uapi/misc/d3dkmthk.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,26 @@ struct d3dkmt_submitcommandtohwqueue {
708708
#endif
709709
};
710710

711+
struct d3dkmt_setcontextschedulingpriority {
712+
struct d3dkmthandle context;
713+
int priority;
714+
};
715+
716+
struct d3dkmt_setcontextinprocessschedulingpriority {
717+
struct d3dkmthandle context;
718+
int priority;
719+
};
720+
721+
struct d3dkmt_getcontextschedulingpriority {
722+
struct d3dkmthandle context;
723+
int priority;
724+
};
725+
726+
struct d3dkmt_getcontextinprocessschedulingpriority {
727+
struct d3dkmthandle context;
728+
int priority;
729+
};
730+
711731
struct d3dkmt_setallocationpriority {
712732
struct d3dkmthandle device;
713733
struct d3dkmthandle resource;
@@ -1419,6 +1439,10 @@ struct d3dkmt_shareobjectwithhost {
14191439
_IOWR(0x47, 0x1d, struct d3dkmt_destroysynchronizationobject)
14201440
#define LX_DXFLUSHHEAPTRANSITIONS \
14211441
_IOWR(0x47, 0x1f, struct d3dkmt_flushheaptransitions)
1442+
#define LX_DXGETCONTEXTINPROCESSSCHEDULINGPRIORITY \
1443+
_IOWR(0x47, 0x21, struct d3dkmt_getcontextinprocessschedulingpriority)
1444+
#define LX_DXGETCONTEXTSCHEDULINGPRIORITY \
1445+
_IOWR(0x47, 0x22, struct d3dkmt_getcontextschedulingpriority)
14221446
#define LX_DXLOCK2 \
14231447
_IOWR(0x47, 0x25, struct d3dkmt_lock2)
14241448
#define LX_DXMARKDEVICEASERROR \
@@ -1431,6 +1455,10 @@ struct d3dkmt_shareobjectwithhost {
14311455
_IOWR(0x47, 0x2c, struct d3dkmt_reclaimallocations2)
14321456
#define LX_DXSETALLOCATIONPRIORITY \
14331457
_IOWR(0x47, 0x2e, struct d3dkmt_setallocationpriority)
1458+
#define LX_DXSETCONTEXTINPROCESSSCHEDULINGPRIORITY \
1459+
_IOWR(0x47, 0x2f, struct d3dkmt_setcontextinprocessschedulingpriority)
1460+
#define LX_DXSETCONTEXTSCHEDULINGPRIORITY \
1461+
_IOWR(0x47, 0x30, struct d3dkmt_setcontextschedulingpriority)
14341462
#define LX_DXSIGNALSYNCHRONIZATIONOBJECTFROMCPU \
14351463
_IOWR(0x47, 0x31, struct d3dkmt_signalsynchronizationobjectfromcpu)
14361464
#define LX_DXSIGNALSYNCHRONIZATIONOBJECTFROMGPU \

0 commit comments

Comments
 (0)