--- //depot/projects/smpng/sys/conf/options 2010-11-04 18:31:34.000000000 0000 +++ //depot/user/jhb/socket/conf/options 2010-12-17 17:59:42.000000000 0000 @@ -178,6 +178,7 @@ SYSVSHM opt_sysvipc.h SW_WATCHDOG opt_watchdog.h TURNSTILE_PROFILING +ULE_INTERACTIVE_TIMESHARE opt_sched.h VFS_AIO VERBOSE_SYSINIT opt_global.h WLCACHE opt_wavelan.h --- //depot/projects/smpng/sys/dev/usb/usb_process.h 2009-08-25 21:12:15.000000000 0000 +++ //depot/user/jhb/socket/dev/usb/usb_process.h 2010-12-21 20:30:04.000000000 0000 @@ -27,11 +27,13 @@ #ifndef _USB_PROCESS_H_ #define _USB_PROCESS_H_ +#include #include +#include /* defines */ -#define USB_PRI_HIGH PI_NET -#define USB_PRI_MED PI_DISK +#define USB_PRI_HIGH PI_SWI(SWI_NET) +#define USB_PRI_MED PI_SWI(SWI_CAMBIO) #define USB_PROC_WAIT_TIMEOUT 2 #define USB_PROC_WAIT_DRAIN 1 --- //depot/projects/smpng/sys/kern/init_main.c 2010-11-04 18:31:34.000000000 0000 +++ //depot/user/jhb/socket/kern/init_main.c 2010-12-28 19:53:22.000000000 0000 @@ -461,7 +461,7 @@ td->td_user_pri = PUSER; td->td_base_user_pri = PUSER; td->td_priority = PVM; - td->td_base_pri = PUSER; + td->td_base_pri = PVM; td->td_oncpu = 0; td->td_flags = TDF_INMEM|TDP_KTHREAD; td->td_cpuset = cpuset_thread0(); --- //depot/projects/smpng/sys/kern/kern_intr.c 2010-11-02 16:45:24.000000000 0000 +++ //depot/user/jhb/socket/kern/kern_intr.c 2010-12-21 20:30:04.000000000 0000 @@ -130,22 +130,18 @@ INTR_TYPE_CAM | INTR_TYPE_MISC | INTR_TYPE_CLK | INTR_TYPE_AV); switch (flags) { case INTR_TYPE_TTY: - pri = PI_TTYLOW; + pri = PI_TTY; break; case INTR_TYPE_BIO: - /* - * XXX We need to refine this. BSD/OS distinguishes - * between tape and disk priorities. - */ pri = PI_DISK; break; case INTR_TYPE_NET: pri = PI_NET; break; case INTR_TYPE_CAM: - pri = PI_DISK; /* XXX or PI_CAM? */ + pri = PI_DISK; break; - case INTR_TYPE_AV: /* Audio/video */ + case INTR_TYPE_AV: pri = PI_AV; break; case INTR_TYPE_CLK: @@ -1082,7 +1078,7 @@ *eventp = ie; } error = intr_event_add_handler(ie, name, NULL, handler, arg, - (pri * RQ_PPQ) + PI_SOFT, flags, cookiep); + PI_SWI(pri), flags, cookiep); if (error) return (error); if (pri == SWI_CLOCK) { @@ -1656,18 +1652,13 @@ case PI_AV: db_printf("AV "); break; - case PI_TTYHIGH: - case PI_TTYLOW: + case PI_TTY: db_printf("TTY "); break; - case PI_TAPE: - db_printf("TAPE"); - break; case PI_NET: db_printf("NET "); break; case PI_DISK: - case PI_DISKLOW: db_printf("DISK"); break; case PI_DULL: @@ -1675,7 +1666,7 @@ break; default: if (ih->ih_pri >= PI_SOFT) - db_printf("SWI "); + db_printf("SWI %d", (ih->ih_pri - PI_SOFT) / RQ_PPQ); else db_printf("%4u", ih->ih_pri); break; --- //depot/projects/smpng/sys/kern/kern_kthread.c 2010-11-04 18:31:34.000000000 0000 +++ //depot/user/jhb/socket/kern/kern_kthread.c 2010-12-28 19:53:22.000000000 0000 @@ -117,14 +117,15 @@ /* call the processes' main()... */ cpu_set_fork_handler(td, func, arg); + thread_lock(td); TD_SET_CAN_RUN(td); + sched_prio(td, PVM); + sched_user_prio(td, PUSER); /* Delay putting it on the run queue until now. */ - if (!(flags & RFSTOPPED)) { - thread_lock(td); + if (!(flags & RFSTOPPED)) sched_add(td, SRQ_BORING); - thread_unlock(td); - } + thread_unlock(td); return 0; } --- //depot/projects/smpng/sys/kern/kern_synch.c 2009-07-30 13:43:20.000000000 0000 +++ //depot/user/jhb/socket/kern/kern_synch.c 2010-12-17 17:59:42.000000000 0000 @@ -546,7 +546,8 @@ { thread_lock(td); - sched_prio(td, PRI_MAX_TIMESHARE); + if (PRI_BASE(td->td_pri_class) == PRI_TIMESHARE) + sched_prio(td, PRI_MAX_TIMESHARE); mi_switch(SW_VOL | SWT_RELINQUISH, NULL); thread_unlock(td); td->td_retval[0] = 0; --- //depot/projects/smpng/sys/kern/sched_4bsd.c 2010-09-21 20:19:24.000000000 0000 +++ //depot/user/jhb/socket/kern/sched_4bsd.c 2010-12-17 17:59:42.000000000 0000 @@ -922,7 +922,7 @@ THREAD_LOCK_ASSERT(td, MA_OWNED); td->td_slptick = ticks; td->td_sched->ts_slptime = 0; - if (pri) + if (pri != 0 && PRI_BASE(td->td_pri_class) == PRI_TIMESHARE) sched_prio(td, pri); if (TD_IS_SUSPENDED(td) || pri >= PSOCK) td->td_flags |= TDF_CANSWAP; --- //depot/projects/smpng/sys/kern/sched_ule.c 2010-11-04 18:31:34.000000000 0000 +++ //depot/user/jhb/socket/kern/sched_ule.c 2010-12-22 13:10:25.000000000 0000 @@ -117,6 +117,28 @@ CPU_ISSET((cpu), &(td)->td_cpuset->cs_mask) /* + * When using timeshare priorities for both interactive and + * non-interactive threads, the interactive priority area is split up + * into four ranges. The first range handles interactive threads. + * The last three ranges (NHALF, x, and NHALF) handle non-interactive + * threads with the outer ranges supporting nice values. + */ +#ifdef ULE_INTERACTIVE_TIMESHARE +#define PRI_TIMESHARE_RANGE (PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE) +#define PRI_INTERACT_RANGE ((PRI_TIMESHARE_RANGE - SCHED_PRI_NRESV) / 2) + +#define PRI_MIN_INTERACT PRI_MIN_TIMESHARE +#define PRI_MAX_INTERACT (PRI_MIN_TIMESHARE + PRI_INTERACT_RANGE - 1) +#define PRI_MIN_SLOW (PRI_MIN_TIMESHARE + PRI_INTERACT_RANGE) +#define PRI_MAX_SLOW PRI_MAX_TIMESHARE +#else +#define PRI_MIN_INTERACT PRI_MIN_REALTIME +#define PRI_MAX_INTERACT PRI_MAX_REALTIME +#define PRI_MIN_SLOW PRI_MIN_TIMESHARE +#define PRI_MAX_SLOW PRI_MAX_TIMESHARE +#endif + +/* * Cpu percentage computation macros and defines. * * SCHED_TICK_SECS: Number of seconds to average the cpu usage across. @@ -134,6 +156,13 @@ #define SCHED_TICK_TOTAL(ts) (max((ts)->ts_ltick - (ts)->ts_ftick, hz)) /* + * These macros determine priorities for interactive threads. + */ +#define SCHED_IPRI_MIN PRI_MIN_INTERACT +#define SCHED_IPRI_MAX PRI_MAX_INTERACT +#define SCHED_IPRI_RANGE (SCHED_IPRI_MAX - SCHED_IPRI_MIN) + +/* * These macros determine priorities for non-interactive threads. They are * assigned a priority based on their recent cpu utilization as expressed * by the ratio of ticks to the tick total. NHALF priorities at the start @@ -147,8 +176,8 @@ */ #define SCHED_PRI_NRESV (PRIO_MAX - PRIO_MIN) #define SCHED_PRI_NHALF (SCHED_PRI_NRESV / 2) -#define SCHED_PRI_MIN (PRI_MIN_TIMESHARE + SCHED_PRI_NHALF) -#define SCHED_PRI_MAX (PRI_MAX_TIMESHARE - SCHED_PRI_NHALF) +#define SCHED_PRI_MIN (PRI_MIN_SLOW + SCHED_PRI_NHALF) +#define SCHED_PRI_MAX (PRI_MAX_SLOW - SCHED_PRI_NHALF) #define SCHED_PRI_RANGE (SCHED_PRI_MAX - SCHED_PRI_MIN) #define SCHED_PRI_TICKS(ts) \ (SCHED_TICK_HZ((ts)) / \ @@ -194,7 +223,7 @@ #else static int preempt_thresh = 0; #endif -static int static_boost = PRI_MIN_TIMESHARE; +static int static_boost = PRI_MIN_SLOW; static int sched_idlespins = 10000; static int sched_idlespinthresh = 16; @@ -393,10 +422,10 @@ if (pri <= preempt_thresh) return (1); /* - * If we're realtime or better and there is timeshare or worse running - * preempt only remote processors. + * If we're interactive or better and there is non-interactive + * or worse running preempt only remote processors. */ - if (remote && pri <= PRI_MAX_REALTIME && cpri > PRI_MAX_REALTIME) + if (remote && pri <= SCHED_IPRI_MAX && cpri > SCHED_IPRI_MAX) return (1); return (0); } @@ -423,7 +452,7 @@ tdq->tdq_transferable++; ts->ts_flags |= TSF_XFERABLE; } - if (pri <= PRI_MAX_REALTIME) { + if (pri < PRI_MIN_TIMESHARE) { ts->ts_runq = &tdq->tdq_realtime; } else if (pri <= PRI_MAX_TIMESHARE) { ts->ts_runq = &tdq->tdq_timeshare; @@ -1388,7 +1417,7 @@ int score; int pri; - if (td->td_pri_class != PRI_TIMESHARE) + if (PRI_BASE(td->td_pri_class) != PRI_TIMESHARE) return; /* * If the score is interactive we place the thread in the realtime @@ -1405,10 +1434,10 @@ */ score = imax(0, sched_interact_score(td) + td->td_proc->p_nice); if (score < sched_interact) { - pri = PRI_MIN_REALTIME; - pri += ((PRI_MAX_REALTIME - PRI_MIN_REALTIME) / sched_interact) + pri = SCHED_IPRI_MIN; + pri += (SCHED_IPRI_RANGE / sched_interact) * score; - KASSERT(pri >= PRI_MIN_REALTIME && pri <= PRI_MAX_REALTIME, + KASSERT(pri >= PRI_MIN_INTERACT && pri <= PRI_MAX_INTERACT, ("sched_priority: invalid interactive priority %d score %d", pri, score)); } else { @@ -1416,7 +1445,7 @@ if (td->td_sched->ts_ticks) pri += SCHED_PRI_TICKS(td->td_sched); pri += SCHED_PRI_NICE(td->td_proc->p_nice); - KASSERT(pri >= PRI_MIN_TIMESHARE && pri <= PRI_MAX_TIMESHARE, + KASSERT(pri >= PRI_MIN_SLOW && pri <= PRI_MAX_SLOW, ("sched_priority: invalid priority %d: nice %d, " "ticks %d ftick %d ltick %d tick pri %d", pri, td->td_proc->p_nice, td->td_sched->ts_ticks, @@ -1897,9 +1926,13 @@ THREAD_LOCK_ASSERT(td, MA_OWNED); td->td_slptick = ticks; + if (PRI_BASE(td->td_pri_class) != PRI_TIMESHARE) + return; if (TD_IS_SUSPENDED(td) || prio >= PSOCK) td->td_flags |= TDF_CANSWAP; - if (static_boost == 1 && prio) + if (prio == 0) + return; + if (static_boost == 1 || td->td_pflags & TDP_KTHREAD) sched_prio(td, prio); else if (static_boost && td->td_priority > static_boost) sched_prio(td, static_boost); @@ -2137,7 +2170,7 @@ ts = td->td_sched; if (td->td_pri_class & PRI_FIFO_BIT) return; - if (td->td_pri_class == PRI_TIMESHARE) { + if (PRI_BASE(td->td_pri_class) == PRI_TIMESHARE) { /* * We used a tick; charge it to the thread so * that we can compute our interactivity. --- //depot/projects/smpng/sys/kern/subr_autoconf.c 2010-08-18 14:03:49.000000000 0000 +++ //depot/user/jhb/socket/kern/subr_autoconf.c 2010-12-17 17:59:42.000000000 0000 @@ -135,7 +135,7 @@ warned = 0; while (!TAILQ_EMPTY(&intr_config_hook_list)) { if (msleep(&intr_config_hook_list, &intr_config_hook_lock, - PCONFIG, "conifhk", WARNING_INTERVAL_SECS * hz) == + 0, "conifhk", WARNING_INTERVAL_SECS * hz) == EWOULDBLOCK) { mtx_unlock(&intr_config_hook_lock); warned++; --- //depot/projects/smpng/sys/kern/subr_sleepqueue.c 2010-09-21 20:19:24.000000000 0000 +++ //depot/user/jhb/socket/kern/subr_sleepqueue.c 2010-12-17 17:59:42.000000000 0000 @@ -745,7 +745,8 @@ /* Adjust priority if requested. */ MPASS(pri == 0 || (pri >= PRI_MIN && pri <= PRI_MAX)); - if (pri != 0 && td->td_priority > pri) + if (pri != 0 && td->td_priority > pri && + PRI_BASE(td->td_pri_class) == PRI_TIMESHARE) sched_prio(td, pri); /* --- //depot/projects/smpng/sys/kern/vfs_subr.c 2010-09-21 20:19:24.000000000 0000 +++ //depot/user/jhb/socket/kern/vfs_subr.c 2010-12-21 20:50:26.000000000 0000 @@ -65,6 +65,7 @@ #include #include #include +#include #include #include #include @@ -1874,6 +1875,12 @@ * matter as we are just trying to generally pace the * filesystem activity. */ + if (syncer_state != SYNCER_RUNNING || + time_uptime == starttime) { + thread_lock(td); + sched_prio(td, PPAUSE); + thread_unlock(td); + } if (syncer_state != SYNCER_RUNNING) cv_timedwait(&sync_wakeup, &sync_mtx, hz / SYNCER_SHUTDOWN_SPEEDUP); --- //depot/projects/smpng/sys/net/flowtable.c 2010-06-25 20:21:33.000000000 0000 +++ //depot/user/jhb/socket/net/flowtable.c 2010-12-22 03:39:42.000000000 0000 @@ -1548,9 +1548,11 @@ flowtable_cleaner(void) { VNET_ITERATOR_DECL(vnet_iter); + struct thread *td; if (bootverbose) log(LOG_INFO, "flowtable cleaner started\n"); + td = curthread; while (1) { VNET_LIST_RLOCK(); VNET_FOREACH(vnet_iter) { @@ -1566,6 +1568,9 @@ * is arbitrary */ mtx_lock(&flowclean_lock); + thread_lock(td); + sched_prio(td, PPAUSE); + thread_unlock(td); cv_broadcast(&flowclean_cv); cv_timedwait(&flowclean_cv, &flowclean_lock, flowclean_freq); mtx_unlock(&flowclean_lock); --- //depot/projects/smpng/sys/sys/priority.h 2007-01-11 21:47:23.000000000 0000 +++ //depot/user/jhb/socket/sys/priority.h 2010-12-21 20:30:04.000000000 0000 @@ -67,10 +67,10 @@ * Priorities range from 0 to 255, but differences of less then 4 (RQ_PPQ) * are insignificant. Ranges are as follows: * - * Interrupt threads: 0 - 63 - * Top half kernel threads: 64 - 127 - * Realtime user threads: 128 - 159 - * Time sharing user threads: 160 - 223 + * Interrupt threads: 0 - 47 + * Realtime user threads: 48 - 79 + * Top half kernel threads: 80 - 119 + * Time sharing user threads: 120 - 223 * Idle user threads: 224 - 255 * * XXX If/When the specific interrupt thread and top half thread ranges @@ -81,21 +81,22 @@ #define PRI_MAX (255) /* Lowest priority. */ #define PRI_MIN_ITHD (PRI_MIN) -#define PRI_MAX_ITHD (PRI_MIN_KERN - 1) +#define PRI_MAX_ITHD (PRI_MIN_REALTIME - 1) #define PI_REALTIME (PRI_MIN_ITHD + 0) #define PI_AV (PRI_MIN_ITHD + 4) -#define PI_TTYHIGH (PRI_MIN_ITHD + 8) -#define PI_TAPE (PRI_MIN_ITHD + 12) -#define PI_NET (PRI_MIN_ITHD + 16) -#define PI_DISK (PRI_MIN_ITHD + 20) -#define PI_TTYLOW (PRI_MIN_ITHD + 24) -#define PI_DISKLOW (PRI_MIN_ITHD + 28) -#define PI_DULL (PRI_MIN_ITHD + 32) -#define PI_SOFT (PRI_MIN_ITHD + 36) +#define PI_NET (PRI_MIN_ITHD + 8) +#define PI_DISK (PRI_MIN_ITHD + 12) +#define PI_TTY (PRI_MIN_ITHD + 16) +#define PI_DULL (PRI_MIN_ITHD + 20) +#define PI_SOFT (PRI_MIN_ITHD + 24) +#define PI_SWI(x) (PI_SOFT + (x) * RQ_PPQ) + +#define PRI_MIN_REALTIME (48) +#define PRI_MAX_REALTIME (PRI_MIN_KERN - 1) -#define PRI_MIN_KERN (64) -#define PRI_MAX_KERN (PRI_MIN_REALTIME - 1) +#define PRI_MIN_KERN (80) +#define PRI_MAX_KERN (PRI_MIN_TIMESHARE - 1) #define PSWP (PRI_MIN_KERN + 0) #define PVM (PRI_MIN_KERN + 4) @@ -105,14 +106,10 @@ #define PZERO (PRI_MIN_KERN + 20) #define PSOCK (PRI_MIN_KERN + 24) #define PWAIT (PRI_MIN_KERN + 28) -#define PCONFIG (PRI_MIN_KERN + 32) -#define PLOCK (PRI_MIN_KERN + 36) -#define PPAUSE (PRI_MIN_KERN + 40) +#define PLOCK (PRI_MIN_KERN + 32) +#define PPAUSE (PRI_MIN_KERN + 36) -#define PRI_MIN_REALTIME (128) -#define PRI_MAX_REALTIME (PRI_MIN_TIMESHARE - 1) - -#define PRI_MIN_TIMESHARE (160) +#define PRI_MIN_TIMESHARE (120) #define PRI_MAX_TIMESHARE (PRI_MIN_IDLE - 1) #define PUSER (PRI_MIN_TIMESHARE)