Deleted Added
full compact
linux_compat.c (280211) linux_compat.c (280764)
1/*-
2 * Copyright (c) 2010 Isilon Systems, Inc.
3 * Copyright (c) 2010 iX Systems, Inc.
4 * Copyright (c) 2010 Panasas, Inc.
5 * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 18 unchanged lines hidden (view full) ---

27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/malloc.h>
33#include <sys/kernel.h>
34#include <sys/sysctl.h>
1/*-
2 * Copyright (c) 2010 Isilon Systems, Inc.
3 * Copyright (c) 2010 iX Systems, Inc.
4 * Copyright (c) 2010 Panasas, Inc.
5 * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 18 unchanged lines hidden (view full) ---

27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/malloc.h>
33#include <sys/kernel.h>
34#include <sys/sysctl.h>
35#include <sys/proc.h>
36#include <sys/sleepqueue.h>
35#include <sys/lock.h>
36#include <sys/mutex.h>
37#include <sys/bus.h>
38#include <sys/fcntl.h>
39#include <sys/file.h>
40#include <sys/filio.h>
41#include <sys/rwlock.h>
42

--- 733 unchanged lines hidden (view full) ---

776 */
777 linux_timer_hz_mask = 1;
778 while (linux_timer_hz_mask < (unsigned long)hz)
779 linux_timer_hz_mask *= 2;
780 linux_timer_hz_mask--;
781}
782SYSINIT(linux_timer, SI_SUB_DRIVERS, SI_ORDER_FIRST, linux_timer_init, NULL);
783
37#include <sys/lock.h>
38#include <sys/mutex.h>
39#include <sys/bus.h>
40#include <sys/fcntl.h>
41#include <sys/file.h>
42#include <sys/filio.h>
43#include <sys/rwlock.h>
44

--- 733 unchanged lines hidden (view full) ---

778 */
779 linux_timer_hz_mask = 1;
780 while (linux_timer_hz_mask < (unsigned long)hz)
781 linux_timer_hz_mask *= 2;
782 linux_timer_hz_mask--;
783}
784SYSINIT(linux_timer, SI_SUB_DRIVERS, SI_ORDER_FIRST, linux_timer_init, NULL);
785
786void
787linux_complete_common(struct completion *c, int all)
788{
789 int wakeup_swapper;
790
791 sleepq_lock(c);
792 c->done++;
793 if (all)
794 wakeup_swapper = sleepq_broadcast(c, SLEEPQ_SLEEP, 0, 0);
795 else
796 wakeup_swapper = sleepq_signal(c, SLEEPQ_SLEEP, 0, 0);
797 sleepq_release(c);
798 if (wakeup_swapper)
799 kick_proc0();
800}
801
802/*
803 * Indefinite wait for done != 0 with or without signals.
804 */
805long
806linux_wait_for_common(struct completion *c, int flags)
807{
808
809 if (flags != 0)
810 flags = SLEEPQ_INTERRUPTIBLE | SLEEPQ_SLEEP;
811 else
812 flags = SLEEPQ_SLEEP;
813 for (;;) {
814 sleepq_lock(c);
815 if (c->done)
816 break;
817 sleepq_add(c, NULL, "completion", flags, 0);
818 if (flags & SLEEPQ_INTERRUPTIBLE) {
819 if (sleepq_wait_sig(c, 0) != 0)
820 return (-ERESTARTSYS);
821 } else
822 sleepq_wait(c, 0);
823 }
824 c->done--;
825 sleepq_release(c);
826
827 return (0);
828}
829
830/*
831 * Time limited wait for done != 0 with or without signals.
832 */
833long
834linux_wait_for_timeout_common(struct completion *c, long timeout, int flags)
835{
836 long end = jiffies + timeout;
837
838 if (flags != 0)
839 flags = SLEEPQ_INTERRUPTIBLE | SLEEPQ_SLEEP;
840 else
841 flags = SLEEPQ_SLEEP;
842 for (;;) {
843 int ret;
844
845 sleepq_lock(c);
846 if (c->done)
847 break;
848 sleepq_add(c, NULL, "completion", flags, 0);
849 sleepq_set_timeout(c, linux_timer_jiffies_until(end));
850 if (flags & SLEEPQ_INTERRUPTIBLE)
851 ret = sleepq_timedwait_sig(c, 0);
852 else
853 ret = sleepq_timedwait(c, 0);
854 if (ret != 0) {
855 /* check for timeout or signal */
856 if (ret == EWOULDBLOCK)
857 return (0);
858 else
859 return (-ERESTARTSYS);
860 }
861 }
862 c->done--;
863 sleepq_release(c);
864
865 /* return how many jiffies are left */
866 return (linux_timer_jiffies_until(end));
867}
868
869int
870linux_try_wait_for_completion(struct completion *c)
871{
872 int isdone;
873
874 isdone = 1;
875 sleepq_lock(c);
876 if (c->done)
877 c->done--;
878 else
879 isdone = 0;
880 sleepq_release(c);
881 return (isdone);
882}
883
884int
885linux_completion_done(struct completion *c)
886{
887 int isdone;
888
889 isdone = 1;
890 sleepq_lock(c);
891 if (c->done == 0)
892 isdone = 0;
893 sleepq_release(c);
894 return (isdone);
895}
896
784static void
785linux_compat_init(void *arg)
786{
787 struct sysctl_oid *rootoid;
788 int i;
789
790 rootoid = SYSCTL_ADD_ROOT_NODE(NULL,
791 OID_AUTO, "sys", CTLFLAG_RD|CTLFLAG_MPSAFE, NULL, "sys");

--- 29 unchanged lines hidden ---
897static void
898linux_compat_init(void *arg)
899{
900 struct sysctl_oid *rootoid;
901 int i;
902
903 rootoid = SYSCTL_ADD_ROOT_NODE(NULL,
904 OID_AUTO, "sys", CTLFLAG_RD|CTLFLAG_MPSAFE, NULL, "sys");

--- 29 unchanged lines hidden ---