1 /*
2 * GPL HEADER START
3 *
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 *
24 * GPL HEADER END
25 */
26 /*
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
29 *
30 * Copyright (c) 2011, 2012, Intel Corporation.
31 */
32 /*
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
35 */
36
37 #define DEBUG_SUBSYSTEM S_LNET
38 #include <linux/module.h>
39 #include <linux/kernel.h>
40 #include <linux/fs_struct.h>
41 #include <linux/sched.h>
42
43 #include "../../../include/linux/libcfs/libcfs.h"
44
45 #if defined(CONFIG_KGDB)
46 #include <linux/kgdb.h>
47 #endif
48
49 /**
50 * wait_queue_t of Linux (version < 2.6.34) is a FIFO list for exclusively
51 * waiting threads, which is not always desirable because all threads will
52 * be waken up again and again, even user only needs a few of them to be
53 * active most time. This is not good for performance because cache can
54 * be polluted by different threads.
55 *
56 * LIFO list can resolve this problem because we always wakeup the most
57 * recent active thread by default.
58 *
59 * NB: please don't call non-exclusive & exclusive wait on the same
60 * waitq if add_wait_queue_exclusive_head is used.
61 */
62 void
add_wait_queue_exclusive_head(wait_queue_head_t * waitq,wait_queue_t * link)63 add_wait_queue_exclusive_head(wait_queue_head_t *waitq, wait_queue_t *link)
64 {
65 unsigned long flags;
66
67 spin_lock_irqsave(&waitq->lock, flags);
68 __add_wait_queue_exclusive(waitq, link);
69 spin_unlock_irqrestore(&waitq->lock, flags);
70 }
71 EXPORT_SYMBOL(add_wait_queue_exclusive_head);
72
73 sigset_t
cfs_block_allsigs(void)74 cfs_block_allsigs(void)
75 {
76 unsigned long flags;
77 sigset_t old;
78
79 spin_lock_irqsave(¤t->sighand->siglock, flags);
80 old = current->blocked;
81 sigfillset(¤t->blocked);
82 recalc_sigpending();
83 spin_unlock_irqrestore(¤t->sighand->siglock, flags);
84
85 return old;
86 }
87 EXPORT_SYMBOL(cfs_block_allsigs);
88
cfs_block_sigs(unsigned long sigs)89 sigset_t cfs_block_sigs(unsigned long sigs)
90 {
91 unsigned long flags;
92 sigset_t old;
93
94 spin_lock_irqsave(¤t->sighand->siglock, flags);
95 old = current->blocked;
96 sigaddsetmask(¤t->blocked, sigs);
97 recalc_sigpending();
98 spin_unlock_irqrestore(¤t->sighand->siglock, flags);
99 return old;
100 }
101 EXPORT_SYMBOL(cfs_block_sigs);
102
103 /* Block all signals except for the @sigs */
cfs_block_sigsinv(unsigned long sigs)104 sigset_t cfs_block_sigsinv(unsigned long sigs)
105 {
106 unsigned long flags;
107 sigset_t old;
108
109 spin_lock_irqsave(¤t->sighand->siglock, flags);
110 old = current->blocked;
111 sigaddsetmask(¤t->blocked, ~sigs);
112 recalc_sigpending();
113 spin_unlock_irqrestore(¤t->sighand->siglock, flags);
114
115 return old;
116 }
117 EXPORT_SYMBOL(cfs_block_sigsinv);
118
119 void
cfs_restore_sigs(sigset_t old)120 cfs_restore_sigs(sigset_t old)
121 {
122 unsigned long flags;
123
124 spin_lock_irqsave(¤t->sighand->siglock, flags);
125 current->blocked = old;
126 recalc_sigpending();
127 spin_unlock_irqrestore(¤t->sighand->siglock, flags);
128 }
129 EXPORT_SYMBOL(cfs_restore_sigs);
130
131 int
cfs_signal_pending(void)132 cfs_signal_pending(void)
133 {
134 return signal_pending(current);
135 }
136 EXPORT_SYMBOL(cfs_signal_pending);
137
138 void
cfs_clear_sigpending(void)139 cfs_clear_sigpending(void)
140 {
141 unsigned long flags;
142
143 spin_lock_irqsave(¤t->sighand->siglock, flags);
144 clear_tsk_thread_flag(current, TIF_SIGPENDING);
145 spin_unlock_irqrestore(¤t->sighand->siglock, flags);
146 }
147 EXPORT_SYMBOL(cfs_clear_sigpending);
148