From owner-svn-src-all@freebsd.org Wed May 16 10:08:51 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 96CFDED6D2C; Wed, 16 May 2018 10:08:51 +0000 (UTC) (envelope-from dumbbell@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47095818A7; Wed, 16 May 2018 10:08:51 +0000 (UTC) (envelope-from dumbbell@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 279D918C83; Wed, 16 May 2018 10:08:51 +0000 (UTC) (envelope-from dumbbell@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w4GA8pZ9091710; Wed, 16 May 2018 10:08:51 GMT (envelope-from dumbbell@FreeBSD.org) Received: (from dumbbell@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w4GA8oeD091706; Wed, 16 May 2018 10:08:50 GMT (envelope-from dumbbell@FreeBSD.org) Message-Id: <201805161008.w4GA8oeD091706@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dumbbell set sender to dumbbell@FreeBSD.org using -f From: =?UTF-8?Q?Jean-S=c3=a9bastien_P=c3=a9dron?= Date: Wed, 16 May 2018 10:08:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r333670 - head/sys/dev/vt X-SVN-Group: head X-SVN-Commit-Author: dumbbell X-SVN-Commit-Paths: head/sys/dev/vt X-SVN-Commit-Revision: 333670 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 May 2018 10:08:51 -0000 Author: dumbbell Date: Wed May 16 10:08:50 2018 New Revision: 333670 URL: https://svnweb.freebsd.org/changeset/base/333670 Log: vt(4): Resume vt_timer() in vtterm_post_input() only There is no need to try to resume it after each smaller operations (putchar, cursor_position, copy, fill). The resume function already checks if the timer is armed before doing anything, but it uses an atomic cmpset which is expensive. And resuming the timer at the end of input processing is enough. While here, we also skip timer resume if the input is for another windows than the currently displayed one. I.e. if `ttyv0` is currently displayed, any changes to `ttyv1` shouldn't resume the timer (which would refresh `ttyv0`). By doing the same benchmark as r333669, I get: * vt(4), before r333669: 1500 ms * vt(4), with this patch: 760 ms * syscons(4): 700 ms Modified: head/sys/dev/vt/vt.h head/sys/dev/vt/vt_core.c head/sys/dev/vt/vt_cpulogos.c Modified: head/sys/dev/vt/vt.h ============================================================================== --- head/sys/dev/vt/vt.h Wed May 16 09:01:02 2018 (r333669) +++ head/sys/dev/vt/vt.h Wed May 16 10:08:50 2018 (r333670) @@ -172,7 +172,7 @@ struct vt_device { #define VT_LOCK_ASSERT(vd, what) mtx_assert(&(vd)->vd_lock, what) void vt_resume(struct vt_device *vd); -void vt_resume_flush_timer(struct vt_device *vd, int ms); +void vt_resume_flush_timer(struct vt_window *vw, int ms); void vt_suspend(struct vt_device *vd); /* Modified: head/sys/dev/vt/vt_core.c ============================================================================== --- head/sys/dev/vt/vt_core.c Wed May 16 09:01:02 2018 (r333669) +++ head/sys/dev/vt/vt_core.c Wed May 16 10:08:50 2018 (r333670) @@ -289,9 +289,13 @@ vt_schedule_flush(struct vt_device *vd, int ms) } void -vt_resume_flush_timer(struct vt_device *vd, int ms) +vt_resume_flush_timer(struct vt_window *vw, int ms) { + struct vt_device *vd = vw->vw_device; + if (vd->vd_curwindow != vw) + return; + if (!(vd->vd_flags & VDF_ASYNC) || !atomic_cmpset_int(&vd->vd_timer_armed, 0, 1)) return; @@ -564,7 +568,7 @@ vt_window_switch(struct vt_window *vw) if (vd->vd_driver->vd_postswitch) vd->vd_driver->vd_postswitch(vd); - vt_resume_flush_timer(vd, 0); + vt_resume_flush_timer(vw, 0); /* Restore per-window keyboard mode. */ mtx_lock(&Giant); @@ -684,7 +688,7 @@ vt_scroll(struct vt_window *vw, int offset, int whence diff = vthistory_seek(&vw->vw_buf, offset, whence); if (diff) vw->vw_device->vd_flags |= VDF_INVALID; - vt_resume_flush_timer(vw->vw_device, 0); + vt_resume_flush_timer(vw, 0); } static int @@ -1040,7 +1044,6 @@ vtterm_cursor(struct terminal *tm, const term_pos_t *p struct vt_window *vw = tm->tm_softc; vtbuf_cursor_position(&vw->vw_buf, p); - vt_resume_flush_timer(vw->vw_device, 0); } static void @@ -1049,7 +1052,6 @@ vtterm_putchar(struct terminal *tm, const term_pos_t * struct vt_window *vw = tm->tm_softc; vtbuf_putchar(&vw->vw_buf, p, c); - vt_resume_flush_timer(vw->vw_device, 0); } static void @@ -1058,7 +1060,6 @@ vtterm_fill(struct terminal *tm, const term_rect_t *r, struct vt_window *vw = tm->tm_softc; vtbuf_fill(&vw->vw_buf, r, c); - vt_resume_flush_timer(vw->vw_device, 0); } static void @@ -1068,7 +1069,6 @@ vtterm_copy(struct terminal *tm, const term_rect_t *r, struct vt_window *vw = tm->tm_softc; vtbuf_copy(&vw->vw_buf, r, p); - vt_resume_flush_timer(vw->vw_device, 0); } static void @@ -1088,7 +1088,7 @@ vtterm_param(struct terminal *tm, int cmd, unsigned in /* FALLTHROUGH */ case TP_SHOWCURSOR: vtbuf_cursor_visibility(&vw->vw_buf, arg); - vt_resume_flush_timer(vw->vw_device, 0); + vt_resume_flush_timer(vw, 0); break; case TP_MOUSE: vw->vw_mouse_level = arg; @@ -1331,7 +1331,7 @@ vtterm_post_input(struct terminal *tm) struct vt_window *vw = tm->tm_softc; vtbuf_unlock(&vw->vw_buf); - vt_resume_flush_timer(vw->vw_device, 0); + vt_resume_flush_timer(vw, 0); } static void @@ -1684,7 +1684,7 @@ vt_change_font(struct vt_window *vw, struct vt_font *v /* Force a full redraw the next timer tick. */ if (vd->vd_curwindow == vw) { vd->vd_flags |= VDF_INVALID; - vt_resume_flush_timer(vw->vw_device, 0); + vt_resume_flush_timer(vw, 0); } vw->vw_flags &= ~VWF_BUSY; VT_UNLOCK(vd); @@ -1911,7 +1911,7 @@ vt_mouse_event(int type, int x, int y, int event, int vd->vd_mx / vf->vf_width, vd->vd_my / vf->vf_height); - vt_resume_flush_timer(vw->vw_device, 0); + vt_resume_flush_timer(vw, 0); return; /* Done */ case MOUSE_BUTTON_EVENT: /* Buttons */ @@ -1975,7 +1975,7 @@ vt_mouse_event(int type, int x, int y, int event, int * We have something marked to copy, so update pointer to * window with selection. */ - vt_resume_flush_timer(vw->vw_device, 0); + vt_resume_flush_timer(vw, 0); switch (mark) { case VTB_MARK_END: @@ -2030,7 +2030,7 @@ vt_mouse_state(int show) /* Mark mouse position as dirty. */ vt_mark_mouse_position_as_dirty(vd, false); - vt_resume_flush_timer(vw->vw_device, 0); + vt_resume_flush_timer(vw, 0); } #endif @@ -2808,7 +2808,7 @@ vt_replace_backend(const struct vt_driver *drv, void * /* Allow to put chars now. */ terminal_mute(vd->vd_curwindow->vw_terminal, 0); /* Rerun timer for screen updates. */ - vt_resume_flush_timer(vd, 0); + vt_resume_flush_timer(vd->vd_curwindow, 0); } /* Modified: head/sys/dev/vt/vt_cpulogos.c ============================================================================== --- head/sys/dev/vt/vt_cpulogos.c Wed May 16 09:01:02 2018 (r333669) +++ head/sys/dev/vt/vt_cpulogos.c Wed May 16 10:08:50 2018 (r333670) @@ -194,7 +194,7 @@ vt_fini_logos(void *dummy __unused) if (vd->vd_curwindow == vw) { vd->vd_flags |= VDF_INVALID; - vt_resume_flush_timer(vd, 0); + vt_resume_flush_timer(vw, 0); } VT_UNLOCK(vd); } @@ -253,7 +253,7 @@ vt_init_logos(void *dummy) if (vd->vd_curwindow == vw) { vd->vd_flags |= VDF_INVALID; - vt_resume_flush_timer(vd, 0); + vt_resume_flush_timer(vw, 0); } callout_init(&vt_splash_cpu_callout, 1);