Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Aug 2014 20:53:28 +0000 (UTC)
From:      Jean-Sebastien Pedron <dumbbell@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r270182 - stable/10/sys/dev/vt
Message-ID:  <201408192053.s7JKrSK8054325@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dumbbell
Date: Tue Aug 19 20:53:28 2014
New Revision: 270182
URL: http://svnweb.freebsd.org/changeset/base/270182

Log:
  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.

Modified:
  stable/10/sys/dev/vt/vt_buf.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/vt/vt_buf.c
==============================================================================
--- stable/10/sys/dev/vt/vt_buf.c	Tue Aug 19 20:35:09 2014	(r270181)
+++ stable/10/sys/dev/vt/vt_buf.c	Tue Aug 19 20:53:28 2014	(r270182)
@@ -229,10 +229,9 @@ vtbuf_dirty_axis(unsigned int begin, uns
 }
 
 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 ter
 	    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, con
 
 	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 t
 	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,
 {
 
 	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 *v
 	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
 	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);
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201408192053.s7JKrSK8054325>