tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

mutexes, IPL, tty locking

There is something that confuses me about the TTY locking scheme, and I
wonder if it is a bug in the kernel code or in my expectations?

Consider the following code.  The kernel defies my expectations at line
10, because the IPL is always IPL_HIGH, and at line 11, because the
system panics.

     1  kmutex_t tty_lock, alldevs_mtx;
     2  mutex_init(&tty_lock, MUTEX_DEFAULT, IPL_VM);
     3  mutex_init(&alldevs_mtx, MUTEX_DEFAULT, IPL_HIGH);
     4  /* IPL == x */
     5  mutex_enter(&tty_lock);
     6  /* I expect for IPL to be max(x, IPL_VM) */
     7  mutex_enter(&alldevs_mtx);
     8  /* I expect for IPL to be max(x, IPL_HIGH) */
     9  mutex_exit(&alldevs_mtx);
    10  /* I expect for IPL to be max(x, IPL_VM) */
    11  ttysleep(...);  /* panic: cpu_switchto: switching above IPL_SCHED (8) */
    12  mutex_exit(&tty_lock);
    13  /* I expect for IPL to be x */

The sequence of events above will occur if sys/kern/tty.c:ttywait()
calls a driver output routine, (*tp->t_oproc)(tp), that acquires and
releases a mutex such as alldevs_mtx.

Is it more reasonable for the kernel to expect the driver output routine
to restore the IPL, or to expect the tty routines such as ttywait() to
save and restore the IPL across calls to the output routine?


David Young             OJC Technologies      Urbana, IL * (217) 278-3933

Home | Main Index | Thread Index | Old Index