Commit 49c9dd0d authored by Prakash Sangappa's avatar Prakash Sangappa Committed by akpm

ipc: update semtimedop() to use hrtimer

semtimedop() should be converted to use hrtimer like it has been done for
most of the system calls with timeouts.  This system call already takes a
struct timespec as an argument and can therefore provide finer granularity
timed wait.

Link: https://lkml.kernel.org/r/1651187881-2858-1-git-send-email-prakash.sangappa@oracle.comSigned-off-by: default avatarPrakash Sangappa <prakash.sangappa@oracle.com>
Reviewed-by: default avatarThomas Gleixner <tglx@linutronix.de>
Reviewed-by: default avatarDavidlohr Bueso <dave@stgolabs.net>
Reviewed-by: default avatarManfred Spraul <manfred@colorfullife.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 0e900029
...@@ -1993,7 +1993,9 @@ long __do_semtimedop(int semid, struct sembuf *sops, ...@@ -1993,7 +1993,9 @@ long __do_semtimedop(int semid, struct sembuf *sops,
int max, locknum; int max, locknum;
bool undos = false, alter = false, dupsop = false; bool undos = false, alter = false, dupsop = false;
struct sem_queue queue; struct sem_queue queue;
unsigned long dup = 0, jiffies_left = 0; unsigned long dup = 0;
ktime_t expires, *exp = NULL;
bool timed_out = false;
if (nsops < 1 || semid < 0) if (nsops < 1 || semid < 0)
return -EINVAL; return -EINVAL;
...@@ -2001,12 +2003,11 @@ long __do_semtimedop(int semid, struct sembuf *sops, ...@@ -2001,12 +2003,11 @@ long __do_semtimedop(int semid, struct sembuf *sops,
return -E2BIG; return -E2BIG;
if (timeout) { if (timeout) {
if (timeout->tv_sec < 0 || timeout->tv_nsec < 0 || if (!timespec64_valid(timeout))
timeout->tv_nsec >= 1000000000L) { return -EINVAL;
error = -EINVAL; expires = ktime_add_safe(ktime_get(),
goto out; timespec64_to_ktime(*timeout));
} exp = &expires;
jiffies_left = timespec64_to_jiffies(timeout);
} }
...@@ -2164,10 +2165,8 @@ long __do_semtimedop(int semid, struct sembuf *sops, ...@@ -2164,10 +2165,8 @@ long __do_semtimedop(int semid, struct sembuf *sops,
sem_unlock(sma, locknum); sem_unlock(sma, locknum);
rcu_read_unlock(); rcu_read_unlock();
if (timeout) timed_out = !schedule_hrtimeout_range(exp,
jiffies_left = schedule_timeout(jiffies_left); current->timer_slack_ns, HRTIMER_MODE_ABS);
else
schedule();
/* /*
* fastpath: the semop has completed, either successfully or * fastpath: the semop has completed, either successfully or
...@@ -2208,7 +2207,7 @@ long __do_semtimedop(int semid, struct sembuf *sops, ...@@ -2208,7 +2207,7 @@ long __do_semtimedop(int semid, struct sembuf *sops,
/* /*
* If an interrupt occurred we have to clean up the queue. * If an interrupt occurred we have to clean up the queue.
*/ */
if (timeout && jiffies_left == 0) if (timed_out)
error = -EAGAIN; error = -EAGAIN;
} while (error == -EINTR && !signal_pending(current)); /* spurious */ } while (error == -EINTR && !signal_pending(current)); /* spurious */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment