]> Pileus Git - ~andy/linux/blob - drivers/staging/lustre/lustre/libcfs/linux/linux-prim.c
Merge branch 'timers/core' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
[~andy/linux] / drivers / staging / lustre / lustre / libcfs / linux / linux-prim.c
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 <linux/libcfs/libcfs.h>
44
45 #if defined(CONFIG_KGDB)
46 #include <asm/kgdb.h>
47 #endif
48
49 #define LINUX_WAITQ(w) ((wait_queue_t *) w)
50 #define LINUX_WAITQ_HEAD(w) ((wait_queue_head_t *) w)
51
52 void
53 init_waitqueue_entry_current(wait_queue_t *link)
54 {
55         init_waitqueue_entry(LINUX_WAITQ(link), current);
56 }
57 EXPORT_SYMBOL(init_waitqueue_entry_current);
58
59 /**
60  * wait_queue_t of Linux (version < 2.6.34) is a FIFO list for exclusively
61  * waiting threads, which is not always desirable because all threads will
62  * be waken up again and again, even user only needs a few of them to be
63  * active most time. This is not good for performance because cache can
64  * be polluted by different threads.
65  *
66  * LIFO list can resolve this problem because we always wakeup the most
67  * recent active thread by default.
68  *
69  * NB: please don't call non-exclusive & exclusive wait on the same
70  * waitq if add_wait_queue_exclusive_head is used.
71  */
72 void
73 add_wait_queue_exclusive_head(wait_queue_head_t *waitq, wait_queue_t *link)
74 {
75         unsigned long flags;
76
77         spin_lock_irqsave(&LINUX_WAITQ_HEAD(waitq)->lock, flags);
78         __add_wait_queue_exclusive(LINUX_WAITQ_HEAD(waitq), LINUX_WAITQ(link));
79         spin_unlock_irqrestore(&LINUX_WAITQ_HEAD(waitq)->lock, flags);
80 }
81 EXPORT_SYMBOL(add_wait_queue_exclusive_head);
82
83 void
84 waitq_wait(wait_queue_t *link, long state)
85 {
86         schedule();
87 }
88 EXPORT_SYMBOL(waitq_wait);
89
90 int64_t
91 waitq_timedwait(wait_queue_t *link, long state, int64_t timeout)
92 {
93         return schedule_timeout(timeout);
94 }
95 EXPORT_SYMBOL(waitq_timedwait);
96
97 void
98 schedule_timeout_and_set_state(long state, int64_t timeout)
99 {
100         set_current_state(state);
101         schedule_timeout(timeout);
102 }
103 EXPORT_SYMBOL(schedule_timeout_and_set_state);
104
105 /* deschedule for a bit... */
106 void
107 cfs_pause(cfs_duration_t ticks)
108 {
109         set_current_state(TASK_UNINTERRUPTIBLE);
110         schedule_timeout(ticks);
111 }
112 EXPORT_SYMBOL(cfs_pause);
113
114 void cfs_init_timer(struct timer_list *t)
115 {
116         init_timer(t);
117 }
118 EXPORT_SYMBOL(cfs_init_timer);
119
120 void cfs_timer_init(struct timer_list *t, cfs_timer_func_t *func, void *arg)
121 {
122         init_timer(t);
123         t->function = func;
124         t->data = (unsigned long)arg;
125 }
126 EXPORT_SYMBOL(cfs_timer_init);
127
128 void cfs_timer_done(struct timer_list *t)
129 {
130         return;
131 }
132 EXPORT_SYMBOL(cfs_timer_done);
133
134 void cfs_timer_arm(struct timer_list *t, cfs_time_t deadline)
135 {
136         mod_timer(t, deadline);
137 }
138 EXPORT_SYMBOL(cfs_timer_arm);
139
140 void cfs_timer_disarm(struct timer_list *t)
141 {
142         del_timer(t);
143 }
144 EXPORT_SYMBOL(cfs_timer_disarm);
145
146 int  cfs_timer_is_armed(struct timer_list *t)
147 {
148         return timer_pending(t);
149 }
150 EXPORT_SYMBOL(cfs_timer_is_armed);
151
152 cfs_time_t cfs_timer_deadline(struct timer_list *t)
153 {
154         return t->expires;
155 }
156 EXPORT_SYMBOL(cfs_timer_deadline);
157
158 void cfs_enter_debugger(void)
159 {
160 #if defined(CONFIG_KGDB)
161 //      BREAKPOINT();
162 #else
163         /* nothing */
164 #endif
165 }
166
167
168 sigset_t
169 cfs_block_allsigs(void)
170 {
171         unsigned long     flags;
172         sigset_t        old;
173
174         SIGNAL_MASK_LOCK(current, flags);
175         old = current->blocked;
176         sigfillset(&current->blocked);
177         recalc_sigpending();
178         SIGNAL_MASK_UNLOCK(current, flags);
179
180         return old;
181 }
182
183 sigset_t cfs_block_sigs(unsigned long sigs)
184 {
185         unsigned long  flags;
186         sigset_t        old;
187
188         SIGNAL_MASK_LOCK(current, flags);
189         old = current->blocked;
190         sigaddsetmask(&current->blocked, sigs);
191         recalc_sigpending();
192         SIGNAL_MASK_UNLOCK(current, flags);
193         return old;
194 }
195
196 /* Block all signals except for the @sigs */
197 sigset_t cfs_block_sigsinv(unsigned long sigs)
198 {
199         unsigned long flags;
200         sigset_t old;
201
202         SIGNAL_MASK_LOCK(current, flags);
203         old = current->blocked;
204         sigaddsetmask(&current->blocked, ~sigs);
205         recalc_sigpending();
206         SIGNAL_MASK_UNLOCK(current, flags);
207
208         return old;
209 }
210
211 void
212 cfs_restore_sigs (sigset_t old)
213 {
214         unsigned long  flags;
215
216         SIGNAL_MASK_LOCK(current, flags);
217         current->blocked = old;
218         recalc_sigpending();
219         SIGNAL_MASK_UNLOCK(current, flags);
220 }
221
222 int
223 cfs_signal_pending(void)
224 {
225         return signal_pending(current);
226 }
227
228 void
229 cfs_clear_sigpending(void)
230 {
231         unsigned long flags;
232
233         SIGNAL_MASK_LOCK(current, flags);
234         clear_tsk_thread_flag(current, TIF_SIGPENDING);
235         SIGNAL_MASK_UNLOCK(current, flags);
236 }
237
238 int
239 libcfs_arch_init(void)
240 {
241         return 0;
242 }
243
244 void
245 libcfs_arch_cleanup(void)
246 {
247         return;
248 }
249
250 EXPORT_SYMBOL(libcfs_arch_init);
251 EXPORT_SYMBOL(libcfs_arch_cleanup);
252 EXPORT_SYMBOL(cfs_enter_debugger);
253 EXPORT_SYMBOL(cfs_block_allsigs);
254 EXPORT_SYMBOL(cfs_block_sigs);
255 EXPORT_SYMBOL(cfs_block_sigsinv);
256 EXPORT_SYMBOL(cfs_restore_sigs);
257 EXPORT_SYMBOL(cfs_signal_pending);
258 EXPORT_SYMBOL(cfs_clear_sigpending);