kernel - All lwkt thread now start out mpsafe part 2/2
authorMatthew Dillon <dillon@apollo.backplane.com>
Sun, 29 Aug 2010 00:30:29 +0000 (17:30 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Sun, 29 Aug 2010 00:30:29 +0000 (17:30 -0700)
* Remove the TDF_MPSAFE flag entirely.  All thread creation of all
  types now start running the thread without the mplock.

  Drivers which aren't mpsafe immediately acquire the mplock.

28 files changed:
sys/dev/netif/iwl/if_iwl.c
sys/kern/dsched/fq/fq_diskops.c
sys/kern/init_main.c
sys/kern/kern_fork.c
sys/kern/kern_intr.c
sys/kern/kern_kthread.c
sys/kern/kern_nrandom.c
sys/kern/kern_timeout.c
sys/kern/lwkt_thread.c
sys/kern/subr_bus.c
sys/kern/subr_disk.c
sys/kern/subr_taskqueue.c
sys/kern/usched_bsd4.c
sys/kern/usched_dummy.c
sys/kern/vfs_journal.c
sys/net/if.c
sys/net/netisr.c
sys/net/route.c
sys/netinet/ip_demux.c
sys/netinet/tcp_subr.c
sys/platform/pc32/i386/machdep.c
sys/platform/pc64/x86_64/machdep.c
sys/platform/vkernel/platform/globaldata.c
sys/platform/vkernel64/platform/globaldata.c
sys/sys/thread.h
sys/vfs/devfs/devfs_core.c
sys/vfs/hammer/hammer_flusher.c
sys/vfs/nfs/nfs_vfsops.c

index e38bd3c..f1a19ff 100644 (file)
@@ -503,7 +503,7 @@ iwl_create_thread(struct iwlcom *iwl, int unit)
        iwl->iwl_thread_port.mp_putport = iwl_put_port;
 
        lwkt_create(iwl_service_loop, iwl, NULL, &iwl->iwl_thread,
-                   TDF_MPSAFE, unit % ncpus, "iwl%d", unit);
+                   0, unit % ncpus, "iwl%d", unit);
 }
 
 static void
index 3156853..487ea51 100644 (file)
@@ -73,10 +73,12 @@ fq_prepare(struct dsched_disk_ctx *ds_diskctx)
        struct  fq_disk_ctx     *diskctx = (struct fq_disk_ctx *)ds_diskctx;
        struct thread *td_core, *td_balance;
 
-       lwkt_create((void (*)(void *))fq_dispatcher, diskctx, &td_core, NULL,
-           TDF_MPSAFE, -1, "fq_dispatch_%s", ds_diskctx->dp->d_cdev->si_name);
+       lwkt_create((void (*)(void *))fq_dispatcher, diskctx, &td_core,
+                   NULL, 0, -1, "fq_dispatch_%s",
+                   ds_diskctx->dp->d_cdev->si_name);
        lwkt_create((void (*)(void *))fq_balance_thread, diskctx, &td_balance,
-           NULL, TDF_MPSAFE, -1, "fq_balance_%s", ds_diskctx->dp->d_cdev->si_name);
+                   NULL, 0, -1, "fq_balance_%s",
+                   ds_diskctx->dp->d_cdev->si_name);
        diskctx->td_balance = td_balance;
 
        return 0;
index d562436..b62ea10 100644 (file)
@@ -161,8 +161,7 @@ sysinit_add(struct sysinit **set, struct sysinit **set_end)
 void
 mi_proc0init(struct globaldata *gd, struct user *proc0paddr)
 {
-       lwkt_init_thread(&thread0, proc0paddr, LWKT_THREAD_STACK,
-                        TDF_MPSAFE, gd);
+       lwkt_init_thread(&thread0, proc0paddr, LWKT_THREAD_STACK, 0, gd);
        lwkt_set_comm(&thread0, "thread0");
 #ifdef SMP
        thread0.td_mpcount = 1; /* will hold mplock initially */
index 3cfa02f..87a4077 100644 (file)
@@ -617,7 +617,7 @@ lwp_fork(struct lwp *origlp, struct proc *destproc, int flags)
        destproc->p_lasttid = lp->lwp_tid;
        destproc->p_nthreads++;
 
-       td = lwkt_alloc_thread(NULL, LWKT_THREAD_STACK, -1, TDF_MPSAFE);
+       td = lwkt_alloc_thread(NULL, LWKT_THREAD_STACK, -1, 0);
        lp->lwp_thread = td;
        td->td_proc = destproc;
        td->td_lwp = lp;
index f4efa9d..39160d2 100644 (file)
@@ -220,10 +220,8 @@ register_int(int intr, inthand2_t *handler, void *arg, const char *name,
      * it up.
      */
     if (emergency_intr_thread.td_kstack == NULL) {
-       lwkt_create(ithread_emergency, NULL, NULL,
-                   &emergency_intr_thread,
-                   TDF_STOPREQ|TDF_INTTHREAD|TDF_MPSAFE,
-                   -1, "ithread emerg");
+       lwkt_create(ithread_emergency, NULL, NULL, &emergency_intr_thread,
+                   TDF_STOPREQ | TDF_INTTHREAD, -1, "ithread emerg");
        systimer_init_periodic_nq(&emergency_intr_timer,
                    emergency_intr_timer_callback, &emergency_intr_thread, 
                    (emergency_intr_enable ? emergency_intr_freq : 1));
@@ -237,9 +235,9 @@ register_int(int intr, inthand2_t *handler, void *arg, const char *name,
      */
     if (info->i_state == ISTATE_NOTHREAD) {
        info->i_state = ISTATE_NORMAL;
-       lwkt_create((void *)ithread_handler, (void *)(intptr_t)intr, NULL,
-           &info->i_thread, TDF_STOPREQ|TDF_INTTHREAD|TDF_MPSAFE, -1, 
-           "ithread %d", intr);
+       lwkt_create(ithread_handler, (void *)(intptr_t)intr, NULL,
+                   &info->i_thread, TDF_STOPREQ | TDF_INTTHREAD, -1,
+                   "ithread %d", intr);
        if (intr >= FIRST_SOFTINT)
            lwkt_setpri(&info->i_thread, TDPRI_SOFT_NORM);
        else
@@ -741,7 +739,7 @@ ithread_handler(void *arg)
 
     /*
      * The loop must be entered with one critical section held.  The thread
-     * is created with TDF_MPSAFE so the MP lock is not held on start.
+     * does not hold the mplock on startup.
      */
     gd = mycpu;
     lseconds = gd->gd_time_seconds;
index f9f3998..4778078 100644 (file)
@@ -57,8 +57,7 @@ kthread_create(void (*func)(void *), void *arg,
     thread_t td;
     __va_list ap;
 
-    td = lwkt_alloc_thread(NULL, LWKT_THREAD_STACK, -1,
-                          TDF_VERBOSE | TDF_MPSAFE);
+    td = lwkt_alloc_thread(NULL, LWKT_THREAD_STACK, -1, TDF_VERBOSE);
     if (tdp)
        *tdp = td;
     cpu_set_thread_handler(td, kthread_exit, func, arg);
@@ -86,8 +85,7 @@ kthread_create_cpu(void (*func)(void *), void *arg,
     thread_t td;
     __va_list ap;
 
-    td = lwkt_alloc_thread(NULL, LWKT_THREAD_STACK, cpu,
-                          TDF_VERBOSE | TDF_MPSAFE);
+    td = lwkt_alloc_thread(NULL, LWKT_THREAD_STACK, cpu, TDF_VERBOSE);
     if (tdp)
        *tdp = td;
     cpu_set_thread_handler(td, kthread_exit, func, arg);
@@ -118,7 +116,7 @@ kthread_create_stk(void (*func)(void *), void *arg,
     thread_t td;
     __va_list ap;
 
-    td = lwkt_alloc_thread(NULL, stksize, -1, TDF_VERBOSE | TDF_MPSAFE);
+    td = lwkt_alloc_thread(NULL, stksize, -1, TDF_VERBOSE);
     if (tdp)
        *tdp = td;
     cpu_set_thread_handler(td, kthread_exit, func, arg);
index 2a140bb..5103885 100644 (file)
@@ -599,8 +599,7 @@ static
 void
 rand_thread_init(void)
 {
-       lwkt_create(rand_thread_loop, NULL, &rand_td, NULL,
-                   TDF_MPSAFE, 0, "random");
+       lwkt_create(rand_thread_loop, NULL, &rand_td, NULL, 0, 0, "random");
 }
 
 SYSINIT(rand, SI_SUB_HELPER_THREADS, SI_ORDER_ANY, rand_thread_init, 0);
index f27f209..09b8470 100644 (file)
@@ -177,7 +177,7 @@ swi_softclock_setup(void *arg)
                 * the cpu they were scheduled on.
                 */
                lwkt_create(softclock_handler, sc, NULL,
-                           &sc->thread, TDF_STOPREQ|TDF_INTTHREAD|TDF_MPSAFE,
+                           &sc->thread, TDF_STOPREQ | TDF_INTTHREAD,
                            cpu, "softclock %d", cpu);
        }
 }
index 1311f37..964ddc2 100644 (file)
@@ -368,15 +368,17 @@ lwkt_init_thread_remote(void *arg)
 
 #endif
 
+/*
+ * lwkt core thread structural initialization.
+ *
+ * NOTE: All threads are initialized as mpsafe threads.
+ */
 void
 lwkt_init_thread(thread_t td, void *stack, int stksize, int flags,
                struct globaldata *gd)
 {
     globaldata_t mygd = mycpu;
 
-    /* all threads start mpsafe now */
-    KKASSERT(flags & TDF_MPSAFE);
-
     bzero(td, sizeof(struct thread));
     td->td_kstack = stack;
     td->td_kstack_size = stksize;
@@ -385,10 +387,6 @@ lwkt_init_thread(thread_t td, void *stack, int stksize, int flags,
     td->td_pri = TDPRI_KERN_DAEMON;
     td->td_critcount = 1;
     td->td_toks_stop = &td->td_toks_base;
-#ifdef SMP
-    if ((flags & TDF_MPSAFE) == 0)
-       td->td_mpcount = 1;
-#endif
     if (lwkt_use_spin_port)
        lwkt_initport_spin(&td->td_msgport);
     else
index 312c29c..26cdd6f 100644 (file)
@@ -1674,8 +1674,7 @@ device_attach_async(device_t dev)
 
        atomic_add_int(&numasyncthreads, 1);
        lwkt_create(device_attach_thread, dev, &td, NULL,
-                   TDF_MPSAFE, 0,
-                   (dev->desc ? dev->desc : "devattach"));
+                   0, 0, (dev->desc ? dev->desc : "devattach"));
 }
 
 static void
index b9e84e1..7e889a7 100644 (file)
@@ -1281,7 +1281,7 @@ disk_init(void)
 
        lwkt_gettoken(&disklist_token);
        lwkt_create(disk_msg_core, /*args*/NULL, &td_core, NULL,
-                   TDF_MPSAFE, 0, "disk_msg_core");
+                   0, 0, "disk_msg_core");
        tsleep(td_core, 0, "diskcore", 0);
        lwkt_reltoken(&disklist_token);
 }
index de294aa..94dc634 100644 (file)
@@ -339,12 +339,14 @@ taskqueue_start_threads(struct taskqueue **tqp, int count, int pri, int ncpu,
 
                if (count == 1) {
                        error = lwkt_create(taskqueue_thread_loop, tqp,
-                           &tq->tq_threads[i], NULL, TDF_STOPREQ | TDF_MPSAFE,
-                           cpu, "%s", ktname);
+                                           &tq->tq_threads[i], NULL,
+                                           TDF_STOPREQ, cpu,
+                                           "%s", ktname);
                } else {
                        error = lwkt_create(taskqueue_thread_loop, tqp,
-                           &tq->tq_threads[i], NULL, TDF_STOPREQ | TDF_MPSAFE,
-                           cpu, "%s_%d", ktname, i);
+                                           &tq->tq_threads[i], NULL,
+                                           TDF_STOPREQ, cpu,
+                                           "%s_%d", ktname, i);
                }
                if (error) {
                        kprintf("%s: kthread_add(%s): error %d", __func__,
index 8c208c2..18096f4 100644 (file)
@@ -1195,7 +1195,7 @@ sched_thread_cpu_init(void)
            kprintf(" %d", i);
 
        lwkt_create(sched_thread, NULL, NULL, &dd->helper_thread, 
-                   TDF_STOPREQ | TDF_MPSAFE, i, "usched %d", i);
+                   TDF_STOPREQ, i, "usched %d", i);
 
        /*
         * Allow user scheduling on the target cpu.  cpu #0 has already
index fb22eb8..e66ae7c 100644 (file)
@@ -537,7 +537,7 @@ dummy_sched_thread_cpu_init(void)
            kprintf(" %d", i);
 
        lwkt_create(dummy_sched_thread, NULL, NULL, &dd->helper_thread, 
-                   TDF_STOPREQ | TDF_MPSAFE, i, "dsched %d", i);
+                   TDF_STOPREQ, i, "dsched %d", i);
 
        /*
         * Allow user scheduling on the target cpu.  cpu #0 has already
index f13c184..03193d8 100644 (file)
@@ -120,16 +120,16 @@ journal_create_threads(struct journal *jo)
        jo->flags &= ~(MC_JOURNAL_STOP_REQ | MC_JOURNAL_STOP_IMM);
        jo->flags |= MC_JOURNAL_WACTIVE;
        lwkt_create(journal_wthread, jo, NULL, &jo->wthread,
-                   TDF_STOPREQ | TDF_MPSAFE,
-                   -1, "journal w:%.*s", JIDMAX, jo->id);
+                   TDF_STOPREQ, -1,
+                   "journal w:%.*s", JIDMAX, jo->id);
        lwkt_setpri(&jo->wthread, TDPRI_KERN_DAEMON);
        lwkt_schedule(&jo->wthread);
 
        if (jo->flags & MC_JOURNAL_WANT_FULLDUPLEX) {
            jo->flags |= MC_JOURNAL_RACTIVE;
            lwkt_create(journal_rthread, jo, NULL, &jo->rthread,
-                       TDF_STOPREQ | TDF_MPSAFE,
-                       -1, "journal r:%.*s", JIDMAX, jo->id);
+                       TDF_STOPREQ, -1,
+                       "journal r:%.*s", JIDMAX, jo->id);
            lwkt_setpri(&jo->rthread, TDPRI_KERN_DAEMON);
            lwkt_schedule(&jo->rthread);
        }
index 34ba9d2..8fd4813 100644 (file)
@@ -2495,7 +2495,8 @@ ifnetinit(void *dummy __unused)
                struct thread *thr = &ifnet_threads[i];
 
                lwkt_create(netmsg_service_loop, &ifnet_mpsafe_thread, NULL,
-                           thr, TDF_NETWORK | TDF_MPSAFE, i, "ifnet %d", i);
+                           thr, TDF_NETWORK, i,
+                           "ifnet %d", i);
                netmsg_service_port_init(&thr->td_msgport);
        }
 }
index 209aede..f28626e 100644 (file)
@@ -177,7 +177,7 @@ netisr_init(void)
      */
     for (i = 0; i < ncpus; ++i) {
        lwkt_create(netmsg_service_loop, &netisr_mpsafe_thread, NULL,
-                   &netisr_cpu[i], TDF_NETWORK | TDF_MPSAFE, i,
+                   &netisr_cpu[i], TDF_NETWORK, i,
                    "netisr_cpu %d", i);
        netmsg_service_port_init(&netisr_cpu[i].td_msgport);
     }
@@ -346,7 +346,7 @@ netmsg_service_loop(void *arg)
     int mplocked, *mpsafe_mode = arg;
 
     /*
-     * Thread was started with TDF_MPSAFE
+     * Threads always start mpsafe.
      */
     mplocked = 0;
 
index c7d8b5e..f3ebb80 100644 (file)
@@ -154,7 +154,7 @@ route_init(void)
 
        for (cpu = 0; cpu < ncpus; cpu++) {
                lwkt_create(rtable_service_loop, NULL, &rtd, NULL,
-                           TDF_MPSAFE, cpu, "rtable_cpu %d", cpu);
+                           0, cpu, "rtable_cpu %d", cpu);
                rt_ports[cpu] = &rtd->td_msgport;
        }
 }
index 046ebba..5a0d164 100644 (file)
@@ -568,7 +568,7 @@ tcp_thread_init(void)
 
        for (cpu = 0; cpu < ncpus2; cpu++) {
                lwkt_create(tcpmsg_service_loop, NULL, NULL,
-                           &tcp_thread[cpu], TDF_NETWORK | TDF_MPSAFE, cpu,
+                           &tcp_thread[cpu], TDF_NETWORK, cpu,
                            "tcp_thread %d", cpu);
                netmsg_service_port_init(&tcp_thread[cpu].td_msgport);
        }
@@ -581,7 +581,7 @@ udp_thread_init(void)
 
        for (cpu = 0; cpu < ncpus2; cpu++) {
                lwkt_create(netmsg_service_loop, &udp_mpsafe_thread, NULL,
-                           &udp_thread[cpu], TDF_NETWORK | TDF_MPSAFE, cpu,
+                           &udp_thread[cpu], TDF_NETWORK, cpu,
                            "udp_thread %d", cpu);
                netmsg_service_port_init(&udp_thread[cpu].td_msgport);
        }
index c24f496..ab3327e 100644 (file)
@@ -400,7 +400,7 @@ tcpmsg_service_loop(void *dummy)
        int mplocked;
 
        /*
-        * Thread was started with TDF_MPSAFE
+        * Threads always start mpsafe.
         */
        mplocked = 0;
 
index 1ccf9b0..668edd8 100644 (file)
@@ -2105,7 +2105,7 @@ cpu_gdinit(struct mdglobaldata *gd, int cpu)
        lwkt_init_thread(&gd->mi.gd_idlethread, 
                        gd->mi.gd_prvspace->idlestack, 
                        sizeof(gd->mi.gd_prvspace->idlestack), 
-                       TDF_MPSAFE, &gd->mi);
+                       0, &gd->mi);
        lwkt_set_comm(&gd->mi.gd_idlethread, "idle_%d", cpu);
        gd->mi.gd_idlethread.td_switch = cpu_lwkt_switch;
        gd->mi.gd_idlethread.td_sp -= sizeof(void *);
index 426462d..7836d18 100644 (file)
@@ -1872,7 +1872,7 @@ cpu_gdinit(struct mdglobaldata *gd, int cpu)
        lwkt_init_thread(&gd->mi.gd_idlethread, 
                        gd->mi.gd_prvspace->idlestack, 
                        sizeof(gd->mi.gd_prvspace->idlestack), 
-                       TDF_MPSAFE, &gd->mi);
+                       0, &gd->mi);
        lwkt_set_comm(&gd->mi.gd_idlethread, "idle_%d", cpu);
        gd->mi.gd_idlethread.td_switch = cpu_lwkt_switch;
        gd->mi.gd_idlethread.td_sp -= sizeof(void *);
index e0a762b..9b956bf 100644 (file)
@@ -71,7 +71,7 @@ cpu_gdinit(struct mdglobaldata *gd, int cpu)
        lwkt_init_thread(&gd->mi.gd_idlethread,
                        gd->mi.gd_prvspace->idlestack,
                        sizeof(gd->mi.gd_prvspace->idlestack),
-                       TDF_MPSAFE, &gd->mi);
+                       0, &gd->mi);
        lwkt_set_comm(&gd->mi.gd_idlethread, "idle_%d", cpu);
        gd->mi.gd_idlethread.td_switch = cpu_lwkt_switch;
        gd->mi.gd_idlethread.td_sp -= sizeof(void *);
index cd7da82..163b2b0 100644 (file)
@@ -71,7 +71,7 @@ cpu_gdinit(struct mdglobaldata *gd, int cpu)
        lwkt_init_thread(&gd->mi.gd_idlethread,
                        gd->mi.gd_prvspace->idlestack,
                        sizeof(gd->mi.gd_prvspace->idlestack),
-                       TDF_MPSAFE, &gd->mi);
+                       0, &gd->mi);
        lwkt_set_comm(&gd->mi.gd_idlethread, "idle_%d", cpu);
        gd->mi.gd_idlethread.td_switch = cpu_lwkt_switch;
        gd->mi.gd_idlethread.td_sp -= sizeof(void *);
index 0559377..d6730ae 100644 (file)
@@ -309,7 +309,7 @@ struct thread {
 #define TDF_BLOCKED            0x00040000      /* Thread is blocked */
 #define TDF_PANICWARN          0x00080000      /* panic warning in switch */
 #define TDF_BLOCKQ             0x00100000      /* on block queue */
-#define TDF_MPSAFE             0x00200000      /* (thread creation) */
+#define TDF_UNUSED200000       0x00200000
 #define TDF_EXITING            0x00400000      /* thread exiting */
 #define TDF_USINGFP            0x00800000      /* thread using fp coproc */
 #define TDF_KERNELFP           0x01000000      /* kernel using fp coproc */
index 1db3c47..f0a8a0e 100644 (file)
@@ -2374,7 +2374,7 @@ devfs_init(void)
 
        lockmgr(&devfs_lock, LK_EXCLUSIVE);
        lwkt_create(devfs_msg_core, /*args*/NULL, &td_core, NULL,
-                   TDF_MPSAFE, 0, "devfs_msg_core");
+                   0, 0, "devfs_msg_core");
        while (devfs_run == 0)
                lksleep(td_core, &devfs_lock, 0, "devfsc", 0);
        lockmgr(&devfs_lock, LK_RELEASE);
index 45bdfa3..f86f783 100644 (file)
@@ -171,13 +171,13 @@ hammer_flusher_create(hammer_mount_t hmp)
        TAILQ_INIT(&hmp->flusher.ready_list);
 
        lwkt_create(hammer_flusher_master_thread, hmp,
-                   &hmp->flusher.td, NULL, TDF_MPSAFE, -1, "hammer-M");
+                   &hmp->flusher.td, NULL, 0, -1, "hammer-M");
        for (i = 0; i < HAMMER_MAX_FLUSHERS; ++i) {
                info = kmalloc(sizeof(*info), hmp->m_misc, M_WAITOK|M_ZERO);
                info->hmp = hmp;
                TAILQ_INSERT_TAIL(&hmp->flusher.ready_list, info, entry);
                lwkt_create(hammer_flusher_slave_thread, info,
-                           &info->td, NULL, TDF_MPSAFE, -1, "hammer-S%d", i);
+                           &info->td, NULL, 0, -1, "hammer-S%d", i);
        }
 }
 
index c291c7a..88431aa 100644 (file)
@@ -1121,9 +1121,9 @@ mountnfs(struct nfs_args *argp, struct mount *mp, struct sockaddr *nam,
         * Start the reader and writer threads.
         */
        lwkt_create(nfssvc_iod_reader, nmp, &nmp->nm_rxthread,
-                   NULL, TDF_MPSAFE, rxcpu, "nfsiod_rx");
+                   NULL, 0, rxcpu, "nfsiod_rx");
        lwkt_create(nfssvc_iod_writer, nmp, &nmp->nm_txthread,
-                   NULL, TDF_MPSAFE, txcpu, "nfsiod_tx");
+                   NULL, 0, txcpu, "nfsiod_tx");
 
        return (0);
 bad: