2015-06-10 16:35:20 +00:00
|
|
|
/*
|
2010-05-17 22:18:00 +00:00
|
|
|
* Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
|
|
|
|
* Copyright (C) 2007 The Regents of the University of California.
|
|
|
|
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
|
|
|
|
* Written by Brian Behlendorf <behlendorf1@llnl.gov>.
|
2008-05-26 04:38:26 +00:00
|
|
|
* UCRL-CODE-235197
|
|
|
|
*
|
2010-05-17 22:18:00 +00:00
|
|
|
* This file is part of the SPL, Solaris Porting Layer.
|
2013-03-05 01:26:55 +00:00
|
|
|
* For details, see <http://zfsonlinux.org/>.
|
2010-05-17 22:18:00 +00:00
|
|
|
*
|
|
|
|
* The SPL is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
2008-05-26 04:38:26 +00:00
|
|
|
*
|
2010-05-17 22:18:00 +00:00
|
|
|
* The SPL is distributed in the hope that it will be useful, but WITHOUT
|
2008-05-26 04:38:26 +00:00
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2010-05-17 22:18:00 +00:00
|
|
|
* with the SPL. If not, see <http://www.gnu.org/licenses/>.
|
2015-06-10 16:35:20 +00:00
|
|
|
*
|
2010-05-17 22:18:00 +00:00
|
|
|
* Solaris Porting Layer (SPL) Credential Implementation.
|
2015-06-10 16:35:20 +00:00
|
|
|
*/
|
2008-05-26 04:38:26 +00:00
|
|
|
|
2008-05-15 17:10:30 +00:00
|
|
|
#include <sys/condvar.h>
|
2014-12-08 18:04:42 +00:00
|
|
|
#include <sys/time.h>
|
2016-05-11 23:51:29 +00:00
|
|
|
#include <linux/hrtimer.h>
|
2018-02-16 01:53:18 +00:00
|
|
|
#include <linux/compiler_compat.h>
|
2008-05-15 17:10:30 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
__cv_init(kcondvar_t *cvp, char *name, kcv_type_t type, void *arg)
|
|
|
|
{
|
|
|
|
ASSERT(cvp);
|
2012-04-06 18:29:23 +00:00
|
|
|
ASSERT(name == NULL);
|
2008-05-15 17:10:30 +00:00
|
|
|
ASSERT(type == CV_DEFAULT);
|
|
|
|
ASSERT(arg == NULL);
|
|
|
|
|
|
|
|
cvp->cv_magic = CV_MAGIC;
|
|
|
|
init_waitqueue_head(&cvp->cv_event);
|
2011-02-04 22:09:08 +00:00
|
|
|
init_waitqueue_head(&cvp->cv_destroy);
|
2008-05-15 17:10:30 +00:00
|
|
|
atomic_set(&cvp->cv_waiters, 0);
|
2012-11-05 17:04:50 +00:00
|
|
|
atomic_set(&cvp->cv_refs, 1);
|
2008-05-15 17:10:30 +00:00
|
|
|
cvp->cv_mutex = NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__cv_init);
|
|
|
|
|
2011-02-04 22:09:08 +00:00
|
|
|
static int
|
|
|
|
cv_destroy_wakeup(kcondvar_t *cvp)
|
|
|
|
{
|
2012-11-05 17:04:50 +00:00
|
|
|
if (!atomic_read(&cvp->cv_waiters) && !atomic_read(&cvp->cv_refs)) {
|
|
|
|
ASSERT(cvp->cv_mutex == NULL);
|
|
|
|
ASSERT(!waitqueue_active(&cvp->cv_event));
|
2015-06-10 16:35:20 +00:00
|
|
|
return (1);
|
2012-11-05 17:04:50 +00:00
|
|
|
}
|
2011-02-04 22:09:08 +00:00
|
|
|
|
2015-06-10 16:35:20 +00:00
|
|
|
return (0);
|
2011-02-04 22:09:08 +00:00
|
|
|
}
|
|
|
|
|
2008-05-15 17:10:30 +00:00
|
|
|
void
|
|
|
|
__cv_destroy(kcondvar_t *cvp)
|
|
|
|
{
|
|
|
|
ASSERT(cvp);
|
|
|
|
ASSERT(cvp->cv_magic == CV_MAGIC);
|
2011-02-04 22:09:08 +00:00
|
|
|
|
2012-11-05 17:04:50 +00:00
|
|
|
cvp->cv_magic = CV_DESTROY;
|
|
|
|
atomic_dec(&cvp->cv_refs);
|
|
|
|
|
|
|
|
/* Block until all waiters are woken and references dropped. */
|
2011-02-04 22:09:08 +00:00
|
|
|
while (cv_destroy_wakeup(cvp) == 0)
|
|
|
|
wait_event_timeout(cvp->cv_destroy, cv_destroy_wakeup(cvp), 1);
|
|
|
|
|
2012-09-07 18:05:46 +00:00
|
|
|
ASSERT3P(cvp->cv_mutex, ==, NULL);
|
2012-11-05 17:04:50 +00:00
|
|
|
ASSERT3S(atomic_read(&cvp->cv_refs), ==, 0);
|
2012-09-07 18:05:46 +00:00
|
|
|
ASSERT3S(atomic_read(&cvp->cv_waiters), ==, 0);
|
|
|
|
ASSERT3S(waitqueue_active(&cvp->cv_event), ==, 0);
|
2008-05-15 17:10:30 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__cv_destroy);
|
|
|
|
|
2010-05-14 16:24:51 +00:00
|
|
|
static void
|
2012-12-21 02:29:16 +00:00
|
|
|
cv_wait_common(kcondvar_t *cvp, kmutex_t *mp, int state, int io)
|
2008-05-15 17:10:30 +00:00
|
|
|
{
|
|
|
|
DEFINE_WAIT(wait);
|
2016-01-07 03:05:24 +00:00
|
|
|
kmutex_t *m;
|
2008-05-15 17:10:30 +00:00
|
|
|
|
|
|
|
ASSERT(cvp);
|
2015-06-10 16:35:20 +00:00
|
|
|
ASSERT(mp);
|
2008-05-15 17:10:30 +00:00
|
|
|
ASSERT(cvp->cv_magic == CV_MAGIC);
|
|
|
|
ASSERT(mutex_owned(mp));
|
2012-11-05 17:04:50 +00:00
|
|
|
atomic_inc(&cvp->cv_refs);
|
2008-05-15 17:10:30 +00:00
|
|
|
|
2018-02-16 01:53:18 +00:00
|
|
|
m = READ_ONCE(cvp->cv_mutex);
|
2016-01-07 03:05:24 +00:00
|
|
|
if (!m)
|
|
|
|
m = xchg(&cvp->cv_mutex, mp);
|
2008-05-15 17:10:30 +00:00
|
|
|
/* Ensure the same mutex is used by all callers */
|
2016-01-07 03:05:24 +00:00
|
|
|
ASSERT(m == NULL || m == mp);
|
2008-05-15 17:10:30 +00:00
|
|
|
|
2010-05-14 16:24:51 +00:00
|
|
|
prepare_to_wait_exclusive(&cvp->cv_event, &wait, state);
|
2008-05-15 17:10:30 +00:00
|
|
|
atomic_inc(&cvp->cv_waiters);
|
|
|
|
|
2015-06-10 16:35:20 +00:00
|
|
|
/*
|
|
|
|
* Mutex should be dropped after prepare_to_wait() this
|
2008-05-15 17:10:30 +00:00
|
|
|
* ensures we're linked in to the waiters list and avoids the
|
2015-06-10 16:35:20 +00:00
|
|
|
* race where 'cvp->cv_waiters > 0' but the list is empty.
|
|
|
|
*/
|
2008-05-15 17:10:30 +00:00
|
|
|
mutex_exit(mp);
|
2012-12-21 02:29:16 +00:00
|
|
|
if (io)
|
|
|
|
io_schedule();
|
|
|
|
else
|
|
|
|
schedule();
|
2008-05-15 17:10:30 +00:00
|
|
|
|
2010-11-23 18:56:55 +00:00
|
|
|
/* No more waiters a different mutex could be used */
|
2011-02-04 22:09:08 +00:00
|
|
|
if (atomic_dec_and_test(&cvp->cv_waiters)) {
|
2016-01-07 03:05:24 +00:00
|
|
|
/*
|
|
|
|
* This is set without any lock, so it's racy. But this is
|
|
|
|
* just for debug anyway, so make it best-effort
|
|
|
|
*/
|
2010-11-23 18:56:55 +00:00
|
|
|
cvp->cv_mutex = NULL;
|
2011-02-04 22:09:08 +00:00
|
|
|
wake_up(&cvp->cv_destroy);
|
|
|
|
}
|
2010-11-23 18:56:55 +00:00
|
|
|
|
2008-05-15 17:10:30 +00:00
|
|
|
finish_wait(&cvp->cv_event, &wait);
|
2012-11-05 17:04:50 +00:00
|
|
|
atomic_dec(&cvp->cv_refs);
|
2016-01-07 03:05:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Hold mutex after we release the cvp, otherwise we could dead lock
|
|
|
|
* with a thread holding the mutex and call cv_destroy.
|
|
|
|
*/
|
|
|
|
mutex_enter(mp);
|
2008-05-15 17:10:30 +00:00
|
|
|
}
|
2010-05-14 16:24:51 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
__cv_wait(kcondvar_t *cvp, kmutex_t *mp)
|
|
|
|
{
|
2012-12-21 02:29:16 +00:00
|
|
|
cv_wait_common(cvp, mp, TASK_UNINTERRUPTIBLE, 0);
|
2010-05-14 16:24:51 +00:00
|
|
|
}
|
2008-05-15 17:10:30 +00:00
|
|
|
EXPORT_SYMBOL(__cv_wait);
|
|
|
|
|
2018-01-24 19:33:47 +00:00
|
|
|
void
|
|
|
|
__cv_wait_io(kcondvar_t *cvp, kmutex_t *mp)
|
|
|
|
{
|
|
|
|
cv_wait_common(cvp, mp, TASK_UNINTERRUPTIBLE, 1);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__cv_wait_io);
|
|
|
|
|
2010-05-14 16:24:51 +00:00
|
|
|
void
|
2015-06-10 16:35:20 +00:00
|
|
|
__cv_wait_sig(kcondvar_t *cvp, kmutex_t *mp)
|
2010-05-14 16:24:51 +00:00
|
|
|
{
|
2012-12-21 02:29:16 +00:00
|
|
|
cv_wait_common(cvp, mp, TASK_INTERRUPTIBLE, 0);
|
2010-05-14 16:24:51 +00:00
|
|
|
}
|
2015-06-10 16:35:20 +00:00
|
|
|
EXPORT_SYMBOL(__cv_wait_sig);
|
2010-05-14 16:24:51 +00:00
|
|
|
|
2018-01-24 19:33:47 +00:00
|
|
|
#if defined(HAVE_IO_SCHEDULE_TIMEOUT)
|
|
|
|
#define spl_io_schedule_timeout(t) io_schedule_timeout(t)
|
|
|
|
#else
|
|
|
|
static void
|
|
|
|
__cv_wakeup(unsigned long data)
|
2012-12-21 02:29:16 +00:00
|
|
|
{
|
2018-01-24 19:33:47 +00:00
|
|
|
wake_up_process((struct task_struct *)data);
|
2012-12-21 02:29:16 +00:00
|
|
|
}
|
2018-01-24 19:33:47 +00:00
|
|
|
|
|
|
|
static long
|
|
|
|
spl_io_schedule_timeout(long time_left)
|
|
|
|
{
|
|
|
|
long expire_time = jiffies + time_left;
|
|
|
|
struct timer_list timer;
|
|
|
|
|
|
|
|
init_timer(&timer);
|
|
|
|
setup_timer(&timer, __cv_wakeup, (unsigned long)current);
|
|
|
|
timer.expires = expire_time;
|
|
|
|
add_timer(&timer);
|
|
|
|
|
|
|
|
io_schedule();
|
|
|
|
|
|
|
|
del_timer_sync(&timer);
|
|
|
|
time_left = expire_time - jiffies;
|
|
|
|
|
|
|
|
return (time_left < 0 ? 0 : time_left);
|
|
|
|
}
|
|
|
|
#endif
|
2012-12-21 02:29:16 +00:00
|
|
|
|
2015-06-10 16:35:20 +00:00
|
|
|
/*
|
|
|
|
* 'expire_time' argument is an absolute wall clock time in jiffies.
|
2008-05-15 17:10:30 +00:00
|
|
|
* Return value is time left (expire_time - now) or -1 if timeout occurred.
|
|
|
|
*/
|
2010-12-06 11:35:58 +00:00
|
|
|
static clock_t
|
2015-06-10 16:35:20 +00:00
|
|
|
__cv_timedwait_common(kcondvar_t *cvp, kmutex_t *mp, clock_t expire_time,
|
2018-01-24 19:33:47 +00:00
|
|
|
int state, int io)
|
2008-05-15 17:10:30 +00:00
|
|
|
{
|
|
|
|
DEFINE_WAIT(wait);
|
2016-01-07 03:05:24 +00:00
|
|
|
kmutex_t *m;
|
2008-05-15 17:10:30 +00:00
|
|
|
clock_t time_left;
|
|
|
|
|
|
|
|
ASSERT(cvp);
|
2015-06-10 16:35:20 +00:00
|
|
|
ASSERT(mp);
|
2008-05-15 17:10:30 +00:00
|
|
|
ASSERT(cvp->cv_magic == CV_MAGIC);
|
|
|
|
ASSERT(mutex_owned(mp));
|
|
|
|
|
2017-05-25 17:01:44 +00:00
|
|
|
/* XXX - Does not handle jiffie wrap properly */
|
|
|
|
time_left = expire_time - jiffies;
|
|
|
|
if (time_left <= 0)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
atomic_inc(&cvp->cv_refs);
|
2018-02-16 01:53:18 +00:00
|
|
|
m = READ_ONCE(cvp->cv_mutex);
|
2016-01-07 03:05:24 +00:00
|
|
|
if (!m)
|
|
|
|
m = xchg(&cvp->cv_mutex, mp);
|
2008-05-15 17:10:30 +00:00
|
|
|
/* Ensure the same mutex is used by all callers */
|
2016-01-07 03:05:24 +00:00
|
|
|
ASSERT(m == NULL || m == mp);
|
2008-05-15 17:10:30 +00:00
|
|
|
|
2010-12-06 11:35:58 +00:00
|
|
|
prepare_to_wait_exclusive(&cvp->cv_event, &wait, state);
|
2008-05-15 17:10:30 +00:00
|
|
|
atomic_inc(&cvp->cv_waiters);
|
|
|
|
|
2015-06-10 16:35:20 +00:00
|
|
|
/*
|
|
|
|
* Mutex should be dropped after prepare_to_wait() this
|
2008-05-15 17:10:30 +00:00
|
|
|
* ensures we're linked in to the waiters list and avoids the
|
2015-06-10 16:35:20 +00:00
|
|
|
* race where 'cvp->cv_waiters > 0' but the list is empty.
|
|
|
|
*/
|
2008-05-15 17:10:30 +00:00
|
|
|
mutex_exit(mp);
|
2018-01-24 19:33:47 +00:00
|
|
|
if (io)
|
|
|
|
time_left = spl_io_schedule_timeout(time_left);
|
|
|
|
else
|
|
|
|
time_left = schedule_timeout(time_left);
|
2008-05-15 17:10:30 +00:00
|
|
|
|
2010-11-23 18:56:55 +00:00
|
|
|
/* No more waiters a different mutex could be used */
|
2011-02-04 22:09:08 +00:00
|
|
|
if (atomic_dec_and_test(&cvp->cv_waiters)) {
|
2016-01-07 03:05:24 +00:00
|
|
|
/*
|
|
|
|
* This is set without any lock, so it's racy. But this is
|
|
|
|
* just for debug anyway, so make it best-effort
|
|
|
|
*/
|
2010-11-23 18:56:55 +00:00
|
|
|
cvp->cv_mutex = NULL;
|
2011-02-04 22:09:08 +00:00
|
|
|
wake_up(&cvp->cv_destroy);
|
|
|
|
}
|
2010-11-23 18:56:55 +00:00
|
|
|
|
2008-05-15 17:10:30 +00:00
|
|
|
finish_wait(&cvp->cv_event, &wait);
|
2012-11-05 17:04:50 +00:00
|
|
|
atomic_dec(&cvp->cv_refs);
|
2008-05-15 17:10:30 +00:00
|
|
|
|
2016-01-07 03:05:24 +00:00
|
|
|
/*
|
|
|
|
* Hold mutex after we release the cvp, otherwise we could dead lock
|
|
|
|
* with a thread holding the mutex and call cv_destroy.
|
|
|
|
*/
|
|
|
|
mutex_enter(mp);
|
2014-11-05 22:30:35 +00:00
|
|
|
return (time_left > 0 ? time_left : -1);
|
2008-05-15 17:10:30 +00:00
|
|
|
}
|
2010-12-06 11:35:58 +00:00
|
|
|
|
|
|
|
clock_t
|
|
|
|
__cv_timedwait(kcondvar_t *cvp, kmutex_t *mp, clock_t exp_time)
|
|
|
|
{
|
2018-01-24 19:33:47 +00:00
|
|
|
return (__cv_timedwait_common(cvp, mp, exp_time,
|
|
|
|
TASK_UNINTERRUPTIBLE, 0));
|
2010-12-06 11:35:58 +00:00
|
|
|
}
|
2008-05-15 17:10:30 +00:00
|
|
|
EXPORT_SYMBOL(__cv_timedwait);
|
|
|
|
|
2018-01-24 19:33:47 +00:00
|
|
|
clock_t
|
|
|
|
__cv_timedwait_io(kcondvar_t *cvp, kmutex_t *mp, clock_t exp_time)
|
|
|
|
{
|
|
|
|
return (__cv_timedwait_common(cvp, mp, exp_time,
|
|
|
|
TASK_UNINTERRUPTIBLE, 1));
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__cv_timedwait_io);
|
|
|
|
|
2010-12-06 11:35:58 +00:00
|
|
|
clock_t
|
2015-06-10 16:35:20 +00:00
|
|
|
__cv_timedwait_sig(kcondvar_t *cvp, kmutex_t *mp, clock_t exp_time)
|
2010-12-06 11:35:58 +00:00
|
|
|
{
|
2018-01-24 19:33:47 +00:00
|
|
|
return (__cv_timedwait_common(cvp, mp, exp_time,
|
|
|
|
TASK_INTERRUPTIBLE, 0));
|
2010-12-06 11:35:58 +00:00
|
|
|
}
|
2015-06-10 16:35:20 +00:00
|
|
|
EXPORT_SYMBOL(__cv_timedwait_sig);
|
2010-12-06 11:35:58 +00:00
|
|
|
|
2013-11-01 20:37:58 +00:00
|
|
|
/*
|
2015-06-10 16:35:20 +00:00
|
|
|
* 'expire_time' argument is an absolute clock time in nanoseconds.
|
2013-11-01 20:37:58 +00:00
|
|
|
* Return value is time left (expire_time - now) or -1 if timeout occurred.
|
|
|
|
*/
|
|
|
|
static clock_t
|
2015-06-10 16:35:20 +00:00
|
|
|
__cv_timedwait_hires(kcondvar_t *cvp, kmutex_t *mp, hrtime_t expire_time,
|
|
|
|
int state)
|
2013-11-01 20:37:58 +00:00
|
|
|
{
|
|
|
|
DEFINE_WAIT(wait);
|
2016-01-07 03:05:24 +00:00
|
|
|
kmutex_t *m;
|
2017-05-25 17:01:44 +00:00
|
|
|
hrtime_t time_left;
|
2016-05-11 23:51:29 +00:00
|
|
|
ktime_t ktime_left;
|
2013-11-01 20:37:58 +00:00
|
|
|
|
|
|
|
ASSERT(cvp);
|
|
|
|
ASSERT(mp);
|
|
|
|
ASSERT(cvp->cv_magic == CV_MAGIC);
|
|
|
|
ASSERT(mutex_owned(mp));
|
|
|
|
|
2017-05-25 17:01:44 +00:00
|
|
|
time_left = expire_time - gethrtime();
|
|
|
|
if (time_left <= 0)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
atomic_inc(&cvp->cv_refs);
|
2018-02-16 01:53:18 +00:00
|
|
|
m = READ_ONCE(cvp->cv_mutex);
|
2016-01-07 03:05:24 +00:00
|
|
|
if (!m)
|
|
|
|
m = xchg(&cvp->cv_mutex, mp);
|
2013-11-01 20:37:58 +00:00
|
|
|
/* Ensure the same mutex is used by all callers */
|
2016-01-07 03:05:24 +00:00
|
|
|
ASSERT(m == NULL || m == mp);
|
2013-11-01 20:37:58 +00:00
|
|
|
|
|
|
|
prepare_to_wait_exclusive(&cvp->cv_event, &wait, state);
|
|
|
|
atomic_inc(&cvp->cv_waiters);
|
|
|
|
|
2015-06-10 16:35:20 +00:00
|
|
|
/*
|
|
|
|
* Mutex should be dropped after prepare_to_wait() this
|
2013-11-01 20:37:58 +00:00
|
|
|
* ensures we're linked in to the waiters list and avoids the
|
2015-06-10 16:35:20 +00:00
|
|
|
* race where 'cvp->cv_waiters > 0' but the list is empty.
|
|
|
|
*/
|
2013-11-01 20:37:58 +00:00
|
|
|
mutex_exit(mp);
|
2015-06-10 16:35:20 +00:00
|
|
|
/*
|
|
|
|
* Allow a 100 us range to give kernel an opportunity to coalesce
|
|
|
|
* interrupts
|
|
|
|
*/
|
2016-05-11 23:51:29 +00:00
|
|
|
ktime_left = ktime_set(0, time_left);
|
|
|
|
schedule_hrtimeout_range(&ktime_left, 100 * NSEC_PER_USEC,
|
|
|
|
HRTIMER_MODE_REL);
|
2013-11-01 20:37:58 +00:00
|
|
|
|
|
|
|
/* No more waiters a different mutex could be used */
|
|
|
|
if (atomic_dec_and_test(&cvp->cv_waiters)) {
|
2016-01-07 03:05:24 +00:00
|
|
|
/*
|
|
|
|
* This is set without any lock, so it's racy. But this is
|
|
|
|
* just for debug anyway, so make it best-effort
|
|
|
|
*/
|
2013-11-01 20:37:58 +00:00
|
|
|
cvp->cv_mutex = NULL;
|
|
|
|
wake_up(&cvp->cv_destroy);
|
|
|
|
}
|
|
|
|
|
|
|
|
finish_wait(&cvp->cv_event, &wait);
|
|
|
|
atomic_dec(&cvp->cv_refs);
|
|
|
|
|
2016-01-07 03:05:24 +00:00
|
|
|
mutex_enter(mp);
|
2013-11-01 20:37:58 +00:00
|
|
|
time_left = expire_time - gethrtime();
|
2016-05-11 23:51:29 +00:00
|
|
|
return (time_left > 0 ? NSEC_TO_TICK(time_left) : -1);
|
2013-11-01 20:37:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compatibility wrapper for the cv_timedwait_hires() Illumos interface.
|
|
|
|
*/
|
2016-05-11 23:51:29 +00:00
|
|
|
static clock_t
|
2018-02-07 19:49:38 +00:00
|
|
|
cv_timedwait_hires_common(kcondvar_t *cvp, kmutex_t *mp, hrtime_t tim,
|
|
|
|
hrtime_t res, int flag, int state)
|
2013-11-01 20:37:58 +00:00
|
|
|
{
|
|
|
|
if (res > 1) {
|
|
|
|
/*
|
|
|
|
* Align expiration to the specified resolution.
|
|
|
|
*/
|
|
|
|
if (flag & CALLOUT_FLAG_ROUNDUP)
|
|
|
|
tim += res - 1;
|
|
|
|
tim = (tim / res) * res;
|
|
|
|
}
|
|
|
|
|
2016-05-20 23:35:52 +00:00
|
|
|
if (!(flag & CALLOUT_FLAG_ABSOLUTE))
|
|
|
|
tim += gethrtime();
|
2016-05-11 23:51:29 +00:00
|
|
|
|
|
|
|
return (__cv_timedwait_hires(cvp, mp, tim, state));
|
|
|
|
}
|
2013-11-01 20:37:58 +00:00
|
|
|
|
2016-05-11 23:51:29 +00:00
|
|
|
clock_t
|
|
|
|
cv_timedwait_hires(kcondvar_t *cvp, kmutex_t *mp, hrtime_t tim, hrtime_t res,
|
|
|
|
int flag)
|
|
|
|
{
|
|
|
|
return (cv_timedwait_hires_common(cvp, mp, tim, res, flag,
|
|
|
|
TASK_UNINTERRUPTIBLE));
|
2013-11-01 20:37:58 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(cv_timedwait_hires);
|
|
|
|
|
2016-05-11 23:51:29 +00:00
|
|
|
clock_t
|
2018-02-07 19:49:38 +00:00
|
|
|
cv_timedwait_sig_hires(kcondvar_t *cvp, kmutex_t *mp, hrtime_t tim,
|
|
|
|
hrtime_t res, int flag)
|
2016-05-11 23:51:29 +00:00
|
|
|
{
|
|
|
|
return (cv_timedwait_hires_common(cvp, mp, tim, res, flag,
|
|
|
|
TASK_INTERRUPTIBLE));
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(cv_timedwait_sig_hires);
|
|
|
|
|
2008-05-15 17:10:30 +00:00
|
|
|
void
|
|
|
|
__cv_signal(kcondvar_t *cvp)
|
|
|
|
{
|
|
|
|
ASSERT(cvp);
|
|
|
|
ASSERT(cvp->cv_magic == CV_MAGIC);
|
2012-11-05 17:04:50 +00:00
|
|
|
atomic_inc(&cvp->cv_refs);
|
2008-05-15 17:10:30 +00:00
|
|
|
|
2015-06-10 16:35:20 +00:00
|
|
|
/*
|
|
|
|
* All waiters are added with WQ_FLAG_EXCLUSIVE so only one
|
2008-05-15 17:10:30 +00:00
|
|
|
* waiter will be set runable with each call to wake_up().
|
|
|
|
* Additionally wake_up() holds a spin_lock assoicated with
|
2015-06-10 16:35:20 +00:00
|
|
|
* the wait queue to ensure we don't race waking up processes.
|
|
|
|
*/
|
2008-05-15 17:10:30 +00:00
|
|
|
if (atomic_read(&cvp->cv_waiters) > 0)
|
|
|
|
wake_up(&cvp->cv_event);
|
|
|
|
|
2012-11-05 17:04:50 +00:00
|
|
|
atomic_dec(&cvp->cv_refs);
|
2008-05-15 17:10:30 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__cv_signal);
|
|
|
|
|
|
|
|
void
|
|
|
|
__cv_broadcast(kcondvar_t *cvp)
|
|
|
|
{
|
|
|
|
ASSERT(cvp);
|
|
|
|
ASSERT(cvp->cv_magic == CV_MAGIC);
|
2012-11-05 17:04:50 +00:00
|
|
|
atomic_inc(&cvp->cv_refs);
|
2008-05-15 17:10:30 +00:00
|
|
|
|
2015-06-10 16:35:20 +00:00
|
|
|
/*
|
|
|
|
* Wake_up_all() will wake up all waiters even those which
|
|
|
|
* have the WQ_FLAG_EXCLUSIVE flag set.
|
|
|
|
*/
|
2008-05-15 17:10:30 +00:00
|
|
|
if (atomic_read(&cvp->cv_waiters) > 0)
|
|
|
|
wake_up_all(&cvp->cv_event);
|
|
|
|
|
2012-11-05 17:04:50 +00:00
|
|
|
atomic_dec(&cvp->cv_refs);
|
2008-05-15 17:10:30 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__cv_broadcast);
|