mirror of
				https://github.com/tmux/tmux.git
				synced 2025-10-26 12:27:15 +00:00 
			
		
		
		
	Sync OpenBSD patchset 1072:
Add a simple form of output rate limiting by counting the number of certain C0 sequences (linefeeds, backspaces, carriage returns) and if it exceeds a threshold (current default 50/millisecond), start to redraw the pane every 100 milliseconds instead of making each change as it comes. Two configuration options - c0-change-trigger and c0-change-interval. This makes tmux much more responsive under very fast output (for example yes(1) or accidentally cat'ing a large file) but may not be perfect on all terminals and connections - feedback very welcome, particularly where this change has a negative rather than positive effect (making it off by default is a possibility). After much experimentation based originally on a request Robin Lee Powell (which ended with a completely different solution), this idea from discussion with Ailin Nemui.
This commit is contained in:
		
							
								
								
									
										16
									
								
								input.c
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								input.c
									
									
									
									
									
								
							| @@ -908,6 +908,7 @@ input_c0_dispatch(struct input_ctx *ictx) | |||||||
| 	struct screen_write_ctx	*sctx = &ictx->ctx; | 	struct screen_write_ctx	*sctx = &ictx->ctx; | ||||||
| 	struct window_pane	*wp = ictx->wp; | 	struct window_pane	*wp = ictx->wp; | ||||||
| 	struct screen		*s = sctx->s; | 	struct screen		*s = sctx->s; | ||||||
|  | 	u_int			 trigger; | ||||||
|  |  | ||||||
| 	log_debug("%s: '%c", __func__, ictx->ch); | 	log_debug("%s: '%c", __func__, ictx->ch); | ||||||
|  |  | ||||||
| @@ -919,7 +920,7 @@ input_c0_dispatch(struct input_ctx *ictx) | |||||||
| 		break; | 		break; | ||||||
| 	case '\010':	/* BS */ | 	case '\010':	/* BS */ | ||||||
| 		screen_write_backspace(sctx); | 		screen_write_backspace(sctx); | ||||||
| 		break; | 		goto count_c0; | ||||||
| 	case '\011':	/* HT */ | 	case '\011':	/* HT */ | ||||||
| 		/* Don't tab beyond the end of the line. */ | 		/* Don't tab beyond the end of the line. */ | ||||||
| 		if (s->cx >= screen_size_x(s) - 1) | 		if (s->cx >= screen_size_x(s) - 1) | ||||||
| @@ -936,10 +937,10 @@ input_c0_dispatch(struct input_ctx *ictx) | |||||||
| 	case '\013':	/* VT */ | 	case '\013':	/* VT */ | ||||||
| 	case '\014':	/* FF */ | 	case '\014':	/* FF */ | ||||||
| 		screen_write_linefeed(sctx, 0); | 		screen_write_linefeed(sctx, 0); | ||||||
| 		break; | 		goto count_c0; | ||||||
| 	case '\015':	/* CR */ | 	case '\015':	/* CR */ | ||||||
| 		screen_write_carriagereturn(sctx); | 		screen_write_carriagereturn(sctx); | ||||||
| 		break; | 		goto count_c0; | ||||||
| 	case '\016':	/* SO */ | 	case '\016':	/* SO */ | ||||||
| 		ictx->cell.attr |= GRID_ATTR_CHARSET; | 		ictx->cell.attr |= GRID_ATTR_CHARSET; | ||||||
| 		break; | 		break; | ||||||
| @@ -951,6 +952,15 @@ input_c0_dispatch(struct input_ctx *ictx) | |||||||
| 		break; | 		break; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	return (0); | ||||||
|  |  | ||||||
|  | count_c0: | ||||||
|  | 	trigger = options_get_number(&wp->window->options, "c0-change-trigger"); | ||||||
|  | 	if (++wp->changes == trigger) { | ||||||
|  | 		wp->flags |= PANE_DROP; | ||||||
|  | 		window_pane_timer_start(wp); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	return (0); | 	return (0); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -464,6 +464,21 @@ const struct options_table_entry window_options_table[] = { | |||||||
| 	  .default_num = 1 | 	  .default_num = 1 | ||||||
| 	}, | 	}, | ||||||
|  |  | ||||||
|  |  | ||||||
|  | 	{ .name = "c0-change-trigger", | ||||||
|  | 	  .type = OPTIONS_TABLE_NUMBER, | ||||||
|  | 	  .default_num = 50, | ||||||
|  | 	  .minimum = 0, | ||||||
|  | 	  .maximum = USHRT_MAX | ||||||
|  | 	}, | ||||||
|  |  | ||||||
|  | 	{ .name = "c0-change-interval", | ||||||
|  | 	  .type = OPTIONS_TABLE_NUMBER, | ||||||
|  | 	  .default_num = 100, | ||||||
|  | 	  .minimum = 1, | ||||||
|  | 	  .maximum = USHRT_MAX | ||||||
|  | 	}, | ||||||
|  |  | ||||||
| 	{ .name = "clock-mode-colour", | 	{ .name = "clock-mode-colour", | ||||||
| 	  .type = OPTIONS_TABLE_COLOUR, | 	  .type = OPTIONS_TABLE_COLOUR, | ||||||
| 	  .default_num = 4 | 	  .default_num = 4 | ||||||
|   | |||||||
							
								
								
									
										18
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								tmux.1
									
									
									
									
									
								
							| @@ -2467,6 +2467,24 @@ It may be switched off globally with: | |||||||
| set-window-option -g automatic-rename off | set-window-option -g automatic-rename off | ||||||
| .Ed | .Ed | ||||||
| .Pp | .Pp | ||||||
|  | .It Ic c0-change-interval Ar interval | ||||||
|  | .It Ic c0-change-trigger Ar trigger | ||||||
|  | These two options configure a simple form of rate limiting for a pane. | ||||||
|  | If | ||||||
|  | .Nm | ||||||
|  | sees more than | ||||||
|  | .Ar trigger | ||||||
|  | C0 sequences that modify the screen (for example, carriage returns, linefeeds | ||||||
|  | or backspaces) in one millisecond, it will stop updating the pane immediately and | ||||||
|  | instead redraw it entirely every | ||||||
|  | .Ar interval | ||||||
|  | milliseconds. | ||||||
|  | This helps to prevent fast output (such as | ||||||
|  | .Xr yes 1 | ||||||
|  | overwhelming the terminal). | ||||||
|  | The default is a trigger of 50 and an interval of 100. | ||||||
|  | A trigger of zero disables the rate limiting. | ||||||
|  | .Pp | ||||||
| .It Ic clock-mode-colour Ar colour | .It Ic clock-mode-colour Ar colour | ||||||
| Set clock colour. | Set clock colour. | ||||||
| .Pp | .Pp | ||||||
|   | |||||||
							
								
								
									
										7
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								tmux.h
									
									
									
									
									
								
							| @@ -807,6 +807,7 @@ struct window_pane { | |||||||
|  |  | ||||||
| 	int		 flags; | 	int		 flags; | ||||||
| #define PANE_REDRAW 0x1 | #define PANE_REDRAW 0x1 | ||||||
|  | #define PANE_DROP 0x2 | ||||||
|  |  | ||||||
| 	char		*cmd; | 	char		*cmd; | ||||||
| 	char		*shell; | 	char		*shell; | ||||||
| @@ -815,6 +816,10 @@ struct window_pane { | |||||||
| 	pid_t		 pid; | 	pid_t		 pid; | ||||||
| 	char		 tty[TTY_NAME_MAX]; | 	char		 tty[TTY_NAME_MAX]; | ||||||
|  |  | ||||||
|  | 	u_int		 changes; | ||||||
|  | 	struct event	 changes_timer; | ||||||
|  | 	u_int		 changes_redraw; | ||||||
|  |  | ||||||
| 	int		 fd; | 	int		 fd; | ||||||
| 	struct bufferevent *event; | 	struct bufferevent *event; | ||||||
|  |  | ||||||
| @@ -1959,6 +1964,7 @@ void		 window_destroy_panes(struct window *); | |||||||
| struct window_pane *window_pane_find_by_id(u_int); | struct window_pane *window_pane_find_by_id(u_int); | ||||||
| struct window_pane *window_pane_create(struct window *, u_int, u_int, u_int); | struct window_pane *window_pane_create(struct window *, u_int, u_int, u_int); | ||||||
| void		 window_pane_destroy(struct window_pane *); | void		 window_pane_destroy(struct window_pane *); | ||||||
|  | void		 window_pane_timer_start(struct window_pane *); | ||||||
| int		 window_pane_spawn(struct window_pane *, const char *, | int		 window_pane_spawn(struct window_pane *, const char *, | ||||||
| 		     const char *, const char *, struct environ *, | 		     const char *, const char *, struct environ *, | ||||||
| 		     struct termios *, char **); | 		     struct termios *, char **); | ||||||
| @@ -1977,7 +1983,6 @@ int		 window_pane_visible(struct window_pane *); | |||||||
| char		*window_pane_search( | char		*window_pane_search( | ||||||
| 		     struct window_pane *, const char *, u_int *); | 		     struct window_pane *, const char *, u_int *); | ||||||
| char		*window_printable_flags(struct session *, struct winlink *); | char		*window_printable_flags(struct session *, struct winlink *); | ||||||
|  |  | ||||||
| struct window_pane *window_pane_find_up(struct window_pane *); | struct window_pane *window_pane_find_up(struct window_pane *); | ||||||
| struct window_pane *window_pane_find_down(struct window_pane *); | struct window_pane *window_pane_find_down(struct window_pane *); | ||||||
| struct window_pane *window_pane_find_left(struct window_pane *); | struct window_pane *window_pane_find_left(struct window_pane *); | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								tty.c
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								tty.c
									
									
									
									
									
								
							| @@ -661,7 +661,7 @@ tty_write( | |||||||
|  |  | ||||||
| 	if (wp->window->flags & WINDOW_REDRAW || wp->flags & PANE_REDRAW) | 	if (wp->window->flags & WINDOW_REDRAW || wp->flags & PANE_REDRAW) | ||||||
| 		return; | 		return; | ||||||
| 	if (!window_pane_visible(wp)) | 	if (!window_pane_visible(wp) || wp->flags & PANE_DROP) | ||||||
| 		return; | 		return; | ||||||
|  |  | ||||||
| 	for (i = 0; i < ARRAY_LENGTH(&clients); i++) { | 	for (i = 0; i < ARRAY_LENGTH(&clients); i++) { | ||||||
|   | |||||||
							
								
								
									
										40
									
								
								window.c
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								window.c
									
									
									
									
									
								
							| @@ -58,6 +58,7 @@ struct window_pane_tree all_window_panes; | |||||||
| u_int	next_window_pane_id; | u_int	next_window_pane_id; | ||||||
| u_int	next_window_id; | u_int	next_window_id; | ||||||
|  |  | ||||||
|  | void	window_pane_timer_callback(int, short, void *); | ||||||
| void	window_pane_read_callback(struct bufferevent *, void *); | void	window_pane_read_callback(struct bufferevent *, void *); | ||||||
| void	window_pane_error_callback(struct bufferevent *, short, void *); | void	window_pane_error_callback(struct bufferevent *, short, void *); | ||||||
|  |  | ||||||
| @@ -645,6 +646,8 @@ window_pane_destroy(struct window_pane *wp) | |||||||
| { | { | ||||||
| 	window_pane_reset_mode(wp); | 	window_pane_reset_mode(wp); | ||||||
|  |  | ||||||
|  | 	event_del(&wp->changes_timer); | ||||||
|  |  | ||||||
| 	if (wp->fd != -1) { | 	if (wp->fd != -1) { | ||||||
| 		bufferevent_free(wp->event); | 		bufferevent_free(wp->event); | ||||||
| 		close(wp->fd); | 		close(wp->fd); | ||||||
| @@ -765,6 +768,43 @@ window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell, | |||||||
| 	return (0); | 	return (0); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | void | ||||||
|  | window_pane_timer_start(struct window_pane *wp) | ||||||
|  | { | ||||||
|  | 	struct timeval	tv; | ||||||
|  |  | ||||||
|  | 	tv.tv_sec = 0; | ||||||
|  | 	tv.tv_usec = 1000; | ||||||
|  |  | ||||||
|  | 	evtimer_del(&wp->changes_timer); | ||||||
|  | 	evtimer_set(&wp->changes_timer, window_pane_timer_callback, wp); | ||||||
|  | 	evtimer_add(&wp->changes_timer, &tv); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void | ||||||
|  | window_pane_timer_callback(unused int fd, unused short events, void *data) | ||||||
|  | { | ||||||
|  | 	struct window_pane	*wp = data; | ||||||
|  | 	struct window		*w = wp->window; | ||||||
|  | 	u_int			 interval, trigger; | ||||||
|  |  | ||||||
|  | 	interval = options_get_number(&w->options, "c0-change-interval"); | ||||||
|  | 	trigger = options_get_number(&w->options, "c0-change-trigger"); | ||||||
|  |  | ||||||
|  | 	if (wp->changes_redraw++ == interval) { | ||||||
|  | 		wp->flags |= PANE_REDRAW; | ||||||
|  | 		wp->changes_redraw = 0; | ||||||
|  |  | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if (trigger == 0 || wp->changes < trigger) { | ||||||
|  | 		wp->flags |= PANE_REDRAW; | ||||||
|  | 		wp->flags &= ~PANE_DROP; | ||||||
|  | 	} else | ||||||
|  | 		window_pane_timer_start(wp); | ||||||
|  | 	wp->changes = 0; | ||||||
|  | } | ||||||
|  |  | ||||||
| /* ARGSUSED */ | /* ARGSUSED */ | ||||||
| void | void | ||||||
| window_pane_read_callback(unused struct bufferevent *bufev, void *data) | window_pane_read_callback(unused struct bufferevent *bufev, void *data) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Tiago Cunha
					Tiago Cunha