Whamcloud - gitweb
LU-1402 libcfs: CFS_ALLOC_HIGH is __GFP_HIGHMEM
[fs/lustre-release.git] / libcfs / libcfs / linux / linux-prim.c
index 79dce3e..e5c56b5 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- 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.
@@ -28,6 +26,8 @@
 /*
  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, Whamcloud, Inc.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -73,6 +73,17 @@ cfs_waitq_add(cfs_waitq_t *waitq, cfs_waitlink_t *link)
 }
 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)
@@ -81,6 +92,30 @@ cfs_waitq_add_exclusive(cfs_waitq_t *waitq,
 }
 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)
 {
@@ -275,18 +310,32 @@ cfs_block_allsigs(void)
         return old;
 }
 
-sigset_t
-cfs_block_sigs(sigset_t bits)
+sigset_t cfs_block_sigs(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;
+       SIGNAL_MASK_LOCK(current, flags);
+       old = current->blocked;
+       sigaddsetmask(&current->blocked, sigs);
+       RECALC_SIGPENDING;
+       SIGNAL_MASK_UNLOCK(current, flags);
+       return old;
+}
+
+/* Block all signals except for the @sigs */
+sigset_t cfs_block_sigsinv(unsigned long sigs)
+{
+       unsigned long flags;
+       sigset_t old;
+
+       SIGNAL_MASK_LOCK(current, flags);
+       old = current->blocked;
+       sigaddsetmask(&current->blocked, ~sigs);
+       RECALC_SIGPENDING;
+       SIGNAL_MASK_UNLOCK(current, flags);
+
+       return old;
 }
 
 void
@@ -335,6 +384,7 @@ EXPORT_SYMBOL(cfs_daemonize);
 EXPORT_SYMBOL(cfs_daemonize_ctxt);
 EXPORT_SYMBOL(cfs_block_allsigs);
 EXPORT_SYMBOL(cfs_block_sigs);
+EXPORT_SYMBOL(cfs_block_sigsinv);
 EXPORT_SYMBOL(cfs_restore_sigs);
 EXPORT_SYMBOL(cfs_signal_pending);
 EXPORT_SYMBOL(cfs_clear_sigpending);