dsched_fq - move to lockmgr
authorAlex Hornung <ahornung@gmail.com>
Mon, 19 Apr 2010 14:07:25 +0000 (14:07 +0000)
committerAlex Hornung <ahornung@gmail.com>
Mon, 19 Apr 2010 19:01:12 +0000 (19:01 +0000)
sys/dsched/fq/dsched_fq.h
sys/dsched/fq/dsched_fq_core.c
sys/dsched/fq/dsched_fq_diskops.c

index c825687..fb30faa 100644 (file)
 #define        FQ_FQP_UNLOCK(x)        lockmgr(&(x)->lock, LK_RELEASE); \
                                fq_dereference_priv((x));
 
+#define        FQ_DPRIV_LOCKINIT(x)    lockinit(&(x)->lock, "fqpdiskq", 0, LK_CANRECURSE)
+#define        FQ_DPRIV_LOCK(x)        fq_reference_dpriv((x)); \
+                               lockmgr(&(x)->lock, LK_EXCLUSIVE)
+#define        FQ_DPRIV_UNLOCK(x)      lockmgr(&(x)->lock, LK_RELEASE); \
+                               fq_dereference_dpriv((x))
+
+#define        FQ_GLOBAL_FQMP_LOCKINIT(x)      lockinit(&fq_fqmp_lock, "fqmpglob", 0, LK_CANRECURSE)
+#define        FQ_GLOBAL_FQMP_LOCK(x)  lockmgr(&fq_fqmp_lock, LK_EXCLUSIVE)
+#define        FQ_GLOBAL_FQMP_UNLOCK(x)        lockmgr(&fq_fqmp_lock, LK_RELEASE)
+
+
+
 #define        FQ_FQMP_LOCKINIT(x)     spin_init(&(x)->lock)
 #if 0
 #define        FQ_FQP_LOCKINIT(x)      spin_init(&(x)->lock)
 #endif
+#if 0
 #define        FQ_DPRIV_LOCKINIT(x)    spin_init(&(x)->lock)
+#endif
+#if 0
 #define        FQ_GLOBAL_FQMP_LOCKINIT(x)      spin_init(&fq_fqmp_lock)
-
+#endif
 
 #define        FQ_FQMP_LOCK(x)         fq_reference_mpriv((x)); \
                                spin_lock_wr(&(x)->lock)
 #define        FQ_FQP_LOCK(x)          fq_reference_priv((x)); \
                                spin_lock_wr(&(x)->lock)
 #endif
-
+#if 0
 #define        FQ_DPRIV_LOCK(x)        fq_reference_dpriv((x)); \
                                spin_lock_wr(&(x)->lock)
-
+#endif
+#if 0
 #define        FQ_GLOBAL_FQMP_LOCK(x)  spin_lock_wr(&fq_fqmp_lock)
-
+#endif
 
 #define        FQ_FQMP_UNLOCK(x)       spin_unlock_wr(&(x)->lock); \
                                fq_dereference_mpriv((x))
 #define        FQ_FQP_UNLOCK(x)        spin_unlock_wr(&(x)->lock); \
                                fq_dereference_priv((x))
 #endif
-
+#if 0
 #define        FQ_DPRIV_UNLOCK(x)      spin_unlock_wr(&(x)->lock); \
                                fq_dereference_dpriv((x))
-
+#endif
+#if 0
 #define        FQ_GLOBAL_FQMP_UNLOCK(x) spin_unlock_wr(&fq_fqmp_lock)
+#endif
 
 #define        FQ_REBALANCE_TIMEOUT    1       /* in seconds */
 #define FQ_TOTAL_DISK_TIME     1000000*FQ_REBALANCE_TIMEOUT    /* in useconds */
@@ -136,7 +154,7 @@ struct dsched_fq_dpriv {
        struct thread   *td;
        struct thread   *td_balance;
        struct disk     *dp;
-       struct spinlock lock;
+       struct lock     lock;
        int     refcount;
 
        int     avg_rq_time;    /* XXX: unused */
index 23fe24f..19b675c 100644 (file)
@@ -80,7 +80,7 @@ static struct objcache        *fq_priv_cache;
 TAILQ_HEAD(, dsched_fq_mpriv)  dsched_fqmp_list =
                TAILQ_HEAD_INITIALIZER(dsched_fqmp_list);
 
-struct spinlock        fq_fqmp_lock;
+struct lock    fq_fqmp_lock;
 struct callout fq_callout;
 
 extern struct dsched_ops dsched_fq_ops;
@@ -132,13 +132,13 @@ fq_dereference_dpriv(struct dsched_fq_dpriv *dpriv)
                kprintf("dpriv (%p) destruction started, trace:\n", dpriv);
                print_backtrace(4);
 #endif
-               spin_lock_wr(&dpriv->lock);
+               lockmgr(&dpriv->lock, LK_EXCLUSIVE);
                TAILQ_FOREACH_MUTABLE(fqp, &dpriv->fq_priv_list, dlink, fqp2) {
                        TAILQ_REMOVE(&dpriv->fq_priv_list, fqp, dlink);
                        fqp->flags &= ~FQP_LINKED_DPRIV;
                        fq_dereference_priv(fqp);
                }
-               spin_unlock_wr(&dpriv->lock);
+               lockmgr(&dpriv->lock, LK_RELEASE);
 
                objcache_put(fq_dpriv_cache, dpriv);
                atomic_subtract_int(&fq_stats.dpriv_allocations, 1);
@@ -167,12 +167,12 @@ fq_dereference_priv(struct dsched_fq_priv *fqp)
                KKASSERT(fqp->qlength == 0);
 
                if (fqp->flags & FQP_LINKED_DPRIV) {
-                       spin_lock_wr(&dpriv->lock);
+                       lockmgr(&dpriv->lock, LK_EXCLUSIVE);
 
                        TAILQ_REMOVE(&dpriv->fq_priv_list, fqp, dlink);
                        fqp->flags &= ~FQP_LINKED_DPRIV;
 
-                       spin_unlock_wr(&dpriv->lock);
+                       lockmgr(&dpriv->lock, LK_RELEASE);
                }
 
                if (fqp->flags & FQP_LINKED_FQMP) {
@@ -343,7 +343,7 @@ fq_dispatcher(struct dsched_fq_dpriv *dpriv)
        for(;;) {
                idle = 0;
                /* sleep ~60 ms */
-               if ((ssleep(dpriv, &dpriv->lock, 0, "fq_dispatcher", hz/15) == 0)) {
+               if ((lksleep(dpriv, &dpriv->lock, 0, "fq_dispatcher", hz/15) == 0)) {
                        /*
                         * We've been woken up; this either means that we are
                         * supposed to die away nicely or that the disk is idle.
@@ -430,7 +430,7 @@ fq_balance_thread(struct dsched_fq_dpriv *dpriv)
        FQ_DPRIV_LOCK(dpriv);
        for (;;) {
                /* sleep ~1s */
-               if ((ssleep(curthread, &dpriv->lock, 0, "fq_balancer", hz/2) == 0)) {
+               if ((lksleep(curthread, &dpriv->lock, 0, "fq_balancer", hz/2) == 0)) {
                        if (__predict_false(dpriv->die)) {
                                FQ_DPRIV_UNLOCK(dpriv);
                                lwkt_exit();
index ede872b..c9af26c 100644 (file)
@@ -77,7 +77,7 @@ dsched_exit_proc_t    fq_exit_proc;
 dsched_exit_thread_t   fq_exit_thread;
 
 extern struct dsched_fq_stats  fq_stats;
-extern struct spinlock fq_fqmp_lock;
+extern struct lock     fq_fqmp_lock;
 extern TAILQ_HEAD(, dsched_fq_mpriv)   dsched_fqmp_list;
 extern struct callout  fq_callout;
 
@@ -123,9 +123,9 @@ fq_prepare(struct disk *dp)
        FQ_GLOBAL_FQMP_UNLOCK();
 
        lwkt_create((void (*)(void *))fq_dispatcher, dpriv, &td_core, NULL,
-           0, 0, "fq_dispatch_%s", dp->d_cdev->si_name);
+           TDF_MPSAFE, -1, "fq_dispatch_%s", dp->d_cdev->si_name);
        lwkt_create((void (*)(void *))fq_balance_thread, dpriv, &td_balance,
-           NULL, 0, 0, "fq_balance_%s", dp->d_cdev->si_name);
+           NULL, TDF_MPSAFE, -1, "fq_balance_%s", dp->d_cdev->si_name);
        dpriv->td_balance = td_balance;
 
        return 0;