Skip to content

Commit

Permalink
ipc: update semtimedop() to use hrtimer
Browse files Browse the repository at this point in the history
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/[email protected]
Signed-off-by: Prakash Sangappa <[email protected]>
Reviewed-by: Thomas Gleixner <[email protected]>
Reviewed-by: Davidlohr Bueso <[email protected]>
Reviewed-by: Manfred Spraul <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
Prakash Sangappa authored and akpm00 committed May 10, 2022
1 parent 0e90002 commit 49c9dd0
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions ipc/sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1993,20 +1993,21 @@ long __do_semtimedop(int semid, struct sembuf *sops,
int max, locknum;
bool undos = false, alter = false, dupsop = false;
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)
return -EINVAL;
if (nsops > ns->sc_semopm)
return -E2BIG;

if (timeout) {
if (timeout->tv_sec < 0 || timeout->tv_nsec < 0 ||
timeout->tv_nsec >= 1000000000L) {
error = -EINVAL;
goto out;
}
jiffies_left = timespec64_to_jiffies(timeout);
if (!timespec64_valid(timeout))
return -EINVAL;
expires = ktime_add_safe(ktime_get(),
timespec64_to_ktime(*timeout));
exp = &expires;
}


Expand Down Expand Up @@ -2164,10 +2165,8 @@ long __do_semtimedop(int semid, struct sembuf *sops,
sem_unlock(sma, locknum);
rcu_read_unlock();

if (timeout)
jiffies_left = schedule_timeout(jiffies_left);
else
schedule();
timed_out = !schedule_hrtimeout_range(exp,
current->timer_slack_ns, HRTIMER_MODE_ABS);

/*
* fastpath: the semop has completed, either successfully or
Expand Down Expand Up @@ -2208,7 +2207,7 @@ long __do_semtimedop(int semid, struct sembuf *sops,
/*
* If an interrupt occurred we have to clean up the queue.
*/
if (timeout && jiffies_left == 0)
if (timed_out)
error = -EAGAIN;
} while (error == -EINTR && !signal_pending(current)); /* spurious */

Expand Down

0 comments on commit 49c9dd0

Please sign in to comment.