From 7daa04d3523ba48ea4928880d129119e21b0cd50 Mon Sep 17 00:00:00 2001 From: dumbbell Date: Tue, 19 Aug 2014 20:53:28 +0000 Subject: vt(4): Add vtbuf_dirty*_locked() to lock vtbuf once, not twice In several functions, vtbuf_putchar() in particular, the lock on vtbuf is acquired twice: 1. once by the said functions; 2. once in vtbuf_dirty(). Now, vtbuf_dirty_locked() and vtbuf_dirty_cell_locked() allow to acquire that lock only once. This improves the input speed of vt(4). To measure the gain, a 50,000-lines file was displayed on the console using cat(1). The time taken by cat(1) is reported below: o On amd64, with vt_vga: - before: 1.0" - after: 0.5" o On sparc64, with creator_vt: - before: 13.6" - after: 10.5" This is an MFC of r269780. --- sys/dev/vt/vt_buf.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/sys/dev/vt/vt_buf.c b/sys/dev/vt/vt_buf.c index 14e02f1..4003ce8 100644 --- a/sys/dev/vt/vt_buf.c +++ b/sys/dev/vt/vt_buf.c @@ -229,10 +229,9 @@ vtbuf_dirty_axis(unsigned int begin, unsigned int end) } static inline void -vtbuf_dirty(struct vt_buf *vb, const term_rect_t *area) +vtbuf_dirty_locked(struct vt_buf *vb, const term_rect_t *area) { - VTBUF_LOCK(vb); if (vb->vb_dirtyrect.tr_begin.tp_row > area->tr_begin.tp_row) vb->vb_dirtyrect.tr_begin.tp_row = area->tr_begin.tp_row; if (vb->vb_dirtyrect.tr_begin.tp_col > area->tr_begin.tp_col) @@ -245,18 +244,26 @@ vtbuf_dirty(struct vt_buf *vb, const term_rect_t *area) vtbuf_dirty_axis(area->tr_begin.tp_row, area->tr_end.tp_row); vb->vb_dirtymask.vbm_col |= vtbuf_dirty_axis(area->tr_begin.tp_col, area->tr_end.tp_col); +} + +static inline void +vtbuf_dirty(struct vt_buf *vb, const term_rect_t *area) +{ + + VTBUF_LOCK(vb); + vtbuf_dirty_locked(vb, area); VTBUF_UNLOCK(vb); } static inline void -vtbuf_dirty_cell(struct vt_buf *vb, const term_pos_t *p) +vtbuf_dirty_cell_locked(struct vt_buf *vb, const term_pos_t *p) { term_rect_t area; area.tr_begin = *p; area.tr_end.tp_row = p->tp_row + 1; area.tr_end.tp_col = p->tp_col + 1; - vtbuf_dirty(vb, &area); + vtbuf_dirty_locked(vb, &area); } static void @@ -373,9 +380,8 @@ vtbuf_fill_locked(struct vt_buf *vb, const term_rect_t *r, term_char_t c) VTBUF_LOCK(vb); vtbuf_fill(vb, r, c); + vtbuf_dirty_locked(vb, r); VTBUF_UNLOCK(vb); - - vtbuf_dirty(vb, r); } static void @@ -531,8 +537,8 @@ vtbuf_putchar(struct vt_buf *vb, const term_pos_t *p, term_char_t c) if (row[p->tp_col] != c) { VTBUF_LOCK(vb); row[p->tp_col] = c; + vtbuf_dirty_cell_locked(vb, p); VTBUF_UNLOCK(vb); - vtbuf_dirty_cell(vb, p); } } @@ -541,9 +547,11 @@ vtbuf_cursor_position(struct vt_buf *vb, const term_pos_t *p) { if (vb->vb_flags & VBF_CURSOR) { - vtbuf_dirty_cell(vb, &vb->vb_cursor); + VTBUF_LOCK(vb); + vtbuf_dirty_cell_locked(vb, &vb->vb_cursor); vb->vb_cursor = *p; - vtbuf_dirty_cell(vb, &vb->vb_cursor); + vtbuf_dirty_cell_locked(vb, &vb->vb_cursor); + VTBUF_UNLOCK(vb); } else { vb->vb_cursor = *p; } @@ -724,10 +732,10 @@ vtbuf_cursor_visibility(struct vt_buf *vb, int yes) else vb->vb_flags &= ~VBF_CURSOR; nflags = vb->vb_flags; - VTBUF_UNLOCK(vb); if (oflags != nflags) - vtbuf_dirty_cell(vb, &vb->vb_cursor); + vtbuf_dirty_cell_locked(vb, &vb->vb_cursor); + VTBUF_UNLOCK(vb); } void @@ -742,9 +750,9 @@ vtbuf_scroll_mode(struct vt_buf *vb, int yes) else vb->vb_flags &= ~VBF_SCROLL; nflags = vb->vb_flags; - VTBUF_UNLOCK(vb); if (oflags != nflags) - vtbuf_dirty_cell(vb, &vb->vb_cursor); + vtbuf_dirty_cell_locked(vb, &vb->vb_cursor); + VTBUF_UNLOCK(vb); } -- cgit v1.1