-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
* GPL HEADER START
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* GPL HEADER END
*/
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
+ *
+ * Copyright (c) 2011, 2013, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
*/
#define DEBUG_SUBSYSTEM S_LNET
-#ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
-#endif
#include <linux/module.h>
#include <linux/kernel.h>
+#include <linux/fs_struct.h>
#include <linux/sched.h>
#include <libcfs/libcfs.h>
}
EXPORT_SYMBOL(cfs_waitq_add);
+#ifndef HAVE___ADD_WAIT_QUEUE_EXCLUSIVE
+
+static inline void __add_wait_queue_exclusive(wait_queue_head_t *q,
+ wait_queue_t *wait)
+{
+ wait->flags |= WQ_FLAG_EXCLUSIVE;
+ __add_wait_queue(q, wait);
+}
+
+#endif /* HAVE___ADD_WAIT_QUEUE_EXCLUSIVE */
+
void
cfs_waitq_add_exclusive(cfs_waitq_t *waitq,
cfs_waitlink_t *link)
}
EXPORT_SYMBOL(cfs_waitq_add_exclusive);
+/**
+ * wait_queue_t of Linux (version < 2.6.34) is a FIFO list for exclusively
+ * waiting threads, which is not always desirable because all threads will
+ * be waken up again and again, even user only needs a few of them to be
+ * active most time. This is not good for performance because cache can
+ * be polluted by different threads.
+ *
+ * LIFO list can resolve this problem because we always wakeup the most
+ * recent active thread by default.
+ *
+ * NB: please don't call non-exclusive & exclusive wait on the same
+ * waitq if cfs_waitq_add_exclusive_head is used.
+ */
+void
+cfs_waitq_add_exclusive_head(cfs_waitq_t *waitq, cfs_waitlink_t *link)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&LINUX_WAITQ_HEAD(waitq)->lock, flags);
+ __add_wait_queue_exclusive(LINUX_WAITQ_HEAD(waitq), LINUX_WAITQ(link));
+ spin_unlock_irqrestore(&LINUX_WAITQ_HEAD(waitq)->lock, flags);
+}
+EXPORT_SYMBOL(cfs_waitq_add_exclusive_head);
+
void
cfs_waitq_del(cfs_waitq_t *waitq, cfs_waitlink_t *link)
{
{
#if defined(CONFIG_KGDB)
// BREAKPOINT();
-#elif defined(__arch_um__)
- asm("int $3");
#else
/* nothing */
#endif
}
-void cfs_daemonize(char *str) {
- unsigned long flags;
-
- lock_kernel();
- daemonize(str);
- SIGNAL_MASK_LOCK(current, flags);
- sigfillset(¤t->blocked);
- RECALC_SIGPENDING;
- SIGNAL_MASK_UNLOCK(current, flags);
- unlock_kernel();
-}
-
-int cfs_daemonize_ctxt(char *str) {
- struct task_struct *tsk = current;
- struct fs_struct *fs = NULL;
-
- cfs_daemonize(str);
- fs = copy_fs_struct(tsk->fs);
- if (fs == NULL)
- return -ENOMEM;
- exit_fs(tsk);
- tsk->fs = fs;
- return 0;
-}
-
-
sigset_t
-cfs_get_blockedsigs(void)
+cfs_block_allsigs(void)
{
- unsigned long flags;
- sigset_t old;
+ unsigned long flags;
+ sigset_t old;
- SIGNAL_MASK_LOCK(current, flags);
- old = current->blocked;
- SIGNAL_MASK_UNLOCK(current, flags);
- return old;
+ spin_lock_irqsave(¤t->sighand->siglock, flags);
+ old = current->blocked;
+ sigfillset(¤t->blocked);
+ recalc_sigpending();
+ spin_unlock_irqrestore(¤t->sighand->siglock, flags);
+ return old;
}
-sigset_t
-cfs_block_allsigs(void)
+sigset_t cfs_block_sigs(unsigned long sigs)
{
- unsigned long flags;
- sigset_t old;
-
- SIGNAL_MASK_LOCK(current, flags);
- old = current->blocked;
- sigfillset(¤t->blocked);
- RECALC_SIGPENDING;
- SIGNAL_MASK_UNLOCK(current, flags);
+ unsigned long flags;
+ sigset_t old;
- return old;
+ spin_lock_irqsave(¤t->sighand->siglock, flags);
+ old = current->blocked;
+ sigaddsetmask(¤t->blocked, sigs);
+ recalc_sigpending();
+ spin_unlock_irqrestore(¤t->sighand->siglock, flags);
+ return old;
}
-sigset_t
-cfs_block_sigs(sigset_t bits)
+/* Block all signals except for the @sigs */
+sigset_t cfs_block_sigsinv(unsigned long sigs)
{
- unsigned long flags;
- sigset_t old;
+ unsigned long flags;
+ sigset_t old;
- SIGNAL_MASK_LOCK(current, flags);
- old = current->blocked;
- current->blocked = bits;
- RECALC_SIGPENDING;
- SIGNAL_MASK_UNLOCK(current, flags);
- return old;
+ spin_lock_irqsave(¤t->sighand->siglock, flags);
+ old = current->blocked;
+ sigaddsetmask(¤t->blocked, ~sigs);
+ recalc_sigpending();
+ spin_unlock_irqrestore(¤t->sighand->siglock, flags);
+ return old;
}
void
cfs_restore_sigs (cfs_sigset_t old)
{
- unsigned long flags;
+ unsigned long flags;
- SIGNAL_MASK_LOCK(current, flags);
- current->blocked = old;
- RECALC_SIGPENDING;
- SIGNAL_MASK_UNLOCK(current, flags);
+ spin_lock_irqsave(¤t->sighand->siglock, flags);
+ current->blocked = old;
+ recalc_sigpending();
+ spin_unlock_irqrestore(¤t->sighand->siglock, flags);
}
int
cfs_signal_pending(void)
{
- return signal_pending(current);
+ return signal_pending(current);
}
void
cfs_clear_sigpending(void)
{
- unsigned long flags;
+ unsigned long flags;
- SIGNAL_MASK_LOCK(current, flags);
- CLEAR_SIGPENDING;
- SIGNAL_MASK_UNLOCK(current, flags);
+ spin_lock_irqsave(¤t->sighand->siglock, flags);
+ clear_tsk_thread_flag(current, TIF_SIGPENDING);
+ spin_unlock_irqrestore(¤t->sighand->siglock, flags);
}
int
EXPORT_SYMBOL(libcfs_arch_init);
EXPORT_SYMBOL(libcfs_arch_cleanup);
EXPORT_SYMBOL(cfs_enter_debugger);
-EXPORT_SYMBOL(cfs_daemonize);
-EXPORT_SYMBOL(cfs_daemonize_ctxt);
EXPORT_SYMBOL(cfs_block_allsigs);
EXPORT_SYMBOL(cfs_block_sigs);
-EXPORT_SYMBOL(cfs_get_blockedsigs);
+EXPORT_SYMBOL(cfs_block_sigsinv);
EXPORT_SYMBOL(cfs_restore_sigs);
EXPORT_SYMBOL(cfs_signal_pending);
EXPORT_SYMBOL(cfs_clear_sigpending);