Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_cons.c
Show First 20 Lines • Show All 597 Lines • ▼ Show 20 Lines | |||||
* Redirect console output to a tty. | * Redirect console output to a tty. | ||||
*/ | */ | ||||
int | int | ||||
constty_set(struct tty *tp) | constty_set(struct tty *tp) | ||||
{ | { | ||||
int size = consmsgbuf_size; | int size = consmsgbuf_size; | ||||
void *buf = NULL; | void *buf = NULL; | ||||
tty_assert_locked(tp); | ttydisc_assert_locked(tp); | ||||
if (constty == tp) | if (constty == tp) | ||||
return (0); | return (0); | ||||
if (constty != NULL) | if (constty != NULL) | ||||
return (EBUSY); | return (EBUSY); | ||||
if (consbuf == NULL) { | if (consbuf == NULL) { | ||||
tty_unlock(tp); | ttydisc_unlock(tp); | ||||
buf = malloc(size, M_TTYCONS, M_WAITOK); | buf = malloc(size, M_TTYCONS, M_WAITOK); | ||||
tty_lock(tp); | ttydisc_lock(tp); | ||||
imp: I thought that ttydisc is a sx lock, so this shouldn't be needed.... Or is that a 'future thing… | |||||
kevansAuthorUnsubmitted Done Inline ActionsThe ttydisc lock is separated out, so it's effectively the discipline + driver lock while the historical tty lock is just for the tty itself. kevans: The ttydisc lock is separated out, so it's effectively the discipline + driver lock while the… | |||||
impUnsubmitted Not Done Inline ActionsI thought wrong, it's still mtx. imp: I thought wrong, it's still mtx. | |||||
} | } | ||||
mtx_lock(&constty_mtx); | mtx_lock(&constty_mtx); | ||||
if (constty != NULL) { | if (constty != NULL) { | ||||
mtx_unlock(&constty_mtx); | mtx_unlock(&constty_mtx); | ||||
free(buf, M_TTYCONS); | free(buf, M_TTYCONS); | ||||
return (EBUSY); | return (EBUSY); | ||||
} | } | ||||
if (consbuf == NULL) { | if (consbuf == NULL) { | ||||
consbuf = buf; | consbuf = buf; | ||||
msgbuf_init(&consmsgbuf, buf, size); | msgbuf_init(&consmsgbuf, buf, size); | ||||
} else | } else | ||||
free(buf, M_TTYCONS); | free(buf, M_TTYCONS); | ||||
constty = tp; | constty = tp; | ||||
mtx_unlock(&constty_mtx); | mtx_unlock(&constty_mtx); | ||||
callout_init_mtx(&conscallout, tty_getlock(tp), 0); | callout_init_mtx(&conscallout, ttydisc_getlock(tp), 0); | ||||
constty_timeout(tp); | constty_timeout(tp); | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Disable console redirection to a tty. | * Disable console redirection to a tty. | ||||
*/ | */ | ||||
int | int | ||||
constty_clear(struct tty *tp) | constty_clear(struct tty *tp) | ||||
{ | { | ||||
int c; | int c; | ||||
tty_assert_locked(tp); | ttydisc_assert_locked(tp); | ||||
if (constty != tp) | if (constty != tp) | ||||
return (ENXIO); | return (ENXIO); | ||||
callout_stop(&conscallout); | callout_stop(&conscallout); | ||||
mtx_lock(&constty_mtx); | mtx_lock(&constty_mtx); | ||||
constty = NULL; | constty = NULL; | ||||
mtx_unlock(&constty_mtx); | mtx_unlock(&constty_mtx); | ||||
while ((c = msgbuf_getchar(&consmsgbuf)) != -1) | while ((c = msgbuf_getchar(&consmsgbuf)) != -1) | ||||
cnputc(c); | cnputc(c); | ||||
/* We never free consbuf because it can still be in use. */ | /* We never free consbuf because it can still be in use. */ | ||||
return (0); | return (0); | ||||
} | } | ||||
/* Times per second to check for pending console tty messages. */ | /* Times per second to check for pending console tty messages. */ | ||||
static int constty_wakeups_per_second = 15; | static int constty_wakeups_per_second = 15; | ||||
SYSCTL_INT(_kern, OID_AUTO, constty_wakeups_per_second, CTLFLAG_RW, | SYSCTL_INT(_kern, OID_AUTO, constty_wakeups_per_second, CTLFLAG_RW, | ||||
&constty_wakeups_per_second, 0, | &constty_wakeups_per_second, 0, | ||||
"Times per second to check for pending console tty messages"); | "Times per second to check for pending console tty messages"); | ||||
static void | static void | ||||
constty_timeout(void *arg) | constty_timeout(void *arg) | ||||
{ | { | ||||
struct tty *tp = arg; | struct tty *tp = arg; | ||||
int c; | int c; | ||||
tty_assert_locked(tp); | ttydisc_assert_locked(tp); | ||||
while ((c = msgbuf_getchar(&consmsgbuf)) != -1) { | while ((c = msgbuf_getchar(&consmsgbuf)) != -1) { | ||||
if (tty_putchar(tp, c) < 0) { | if (tty_putchar(tp, c) < 0) { | ||||
constty_clear(tp); | constty_clear(tp); | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
callout_reset_sbt(&conscallout, SBT_1S / constty_wakeups_per_second, | callout_reset_sbt(&conscallout, SBT_1S / constty_wakeups_per_second, | ||||
0, constty_timeout, tp, C_PREL(1)); | 0, constty_timeout, tp, C_PREL(1)); | ||||
▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines |
I thought that ttydisc is a sx lock, so this shouldn't be needed.... Or is that a 'future thing after these patches'?