Skip to content

Commit

Permalink
ntsync: Allow waits to use the REALTIME clock.
Browse files Browse the repository at this point in the history
NtWaitForMultipleObjects() can receive a timeout in two forms, relative or
absolute. Relative timeouts are unaffected by changes to the system time and do
not count down while the system suspends; for absolute timeouts the opposite is
true.

In order to make the interface and implementation simpler, the ntsync driver
only deals in absolute timeouts. However, we need to be able to emulate both
behaviours apropos suspension and time adjustment, which is achieved by allowing
either the MONOTONIC or REALTIME clock to be used.

Signed-off-by: Elizabeth Figura <zfigura@codeweavers.com>
Signed-off-by: Alexandre Frade <kernel@xanmod.org>
  • Loading branch information
Elizabeth Figura authored and xanmod committed Mar 1, 2024
1 parent 0446fcf commit e98635b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion drivers/misc/ntsync.c
Original file line number Diff line number Diff line change
Expand Up @@ -778,11 +778,15 @@ static void put_obj(struct ntsync_obj *obj)
static int ntsync_schedule(const struct ntsync_q *q, const struct ntsync_wait_args *args)
{
ktime_t timeout = ns_to_ktime(args->timeout);
clockid_t clock = CLOCK_MONOTONIC;
ktime_t *timeout_ptr;
int ret = 0;

timeout_ptr = (args->timeout == U64_MAX ? NULL : &timeout);

if (args->flags & NTSYNC_WAIT_REALTIME)
clock = CLOCK_REALTIME;

do {
if (signal_pending(current)) {
ret = -ERESTARTSYS;
Expand All @@ -794,7 +798,7 @@ static int ntsync_schedule(const struct ntsync_q *q, const struct ntsync_wait_ar
ret = 0;
break;
}
ret = schedule_hrtimeout(timeout_ptr, HRTIMER_MODE_ABS);
ret = schedule_hrtimeout_range_clock(timeout_ptr, 0, HRTIMER_MODE_ABS, clock);
} while (ret < 0);
__set_current_state(TASK_RUNNING);

Expand All @@ -817,6 +821,9 @@ static int setup_wait(struct ntsync_device *dev,
if (!args->owner)
return -EINVAL;

if (args->pad || (args->flags & ~NTSYNC_WAIT_REALTIME))
return -EINVAL;

if (args->count > NTSYNC_MAX_WAIT_COUNT)
return -EINVAL;

Expand Down
4 changes: 4 additions & 0 deletions include/uapi/linux/ntsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ struct ntsync_event_args {
__u32 signaled;
};

#define NTSYNC_WAIT_REALTIME 0x1

struct ntsync_wait_args {
__u64 timeout;
__u64 objs;
__u32 count;
__u32 owner;
__u32 index;
__u32 alert;
__u32 flags;
__u32 pad;
};

#define NTSYNC_MAX_WAIT_COUNT 64
Expand Down

0 comments on commit e98635b

Please sign in to comment.