conf: add 'tweak.pty-prefetch-buffer-size-kb' setting

This controls the size of the buffers used by the PTY reader
thread. The default is 512KB, for now.
This commit is contained in:
Daniel Eklöf 2020-06-19 17:15:55 +02:00
parent 984d008250
commit 1b06486c98
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 19 additions and 11 deletions

View file

@ -657,6 +657,18 @@ parse_section_tweak(
conf->tweak.max_shm_pool_size); conf->tweak.max_shm_pool_size);
} }
else if (strcmp(key, "pty-prefetch-buffer-size-kb") == 0) {
unsigned long kb;
if (!str_to_ulong(value, 10, &kb)) {
LOG_ERR("%s:%d: expected an integer: %s", path, lineno, value);
return false;
}
conf->tweak.pty_prefetch_size = min(kb * 1024, UINT32_MAX);
LOG_WARN("tweak: pty-prefetch-buffer-size=%u bytes",
conf->tweak.pty_prefetch_size);
}
else { else {
LOG_ERR("%s:%u: invalid key: %s", path, lineno, key); LOG_ERR("%s:%u: invalid key: %s", path, lineno, key);
return false; return false;
@ -930,6 +942,7 @@ config_load(struct config *conf, const char *conf_path)
.delayed_render_lower_ns = 500000, /* 0.5ms */ .delayed_render_lower_ns = 500000, /* 0.5ms */
.delayed_render_upper_ns = 16666666 / 2, /* half a frame period (60Hz) */ .delayed_render_upper_ns = 16666666 / 2, /* half a frame period (60Hz) */
.max_shm_pool_size = 512 * 1024 * 1024, .max_shm_pool_size = 512 * 1024 * 1024,
.pty_prefetch_size = 512 * 1024,
}, },
}; };

View file

@ -81,6 +81,7 @@ struct config {
uint64_t delayed_render_lower_ns; uint64_t delayed_render_lower_ns;
uint64_t delayed_render_upper_ns; uint64_t delayed_render_upper_ns;
off_t max_shm_pool_size; off_t max_shm_pool_size;
unsigned pty_prefetch_size;
} tweak; } tweak;
}; };

View file

@ -317,12 +317,6 @@ ptmx_reader_thread(void *_term)
amount = term->ptmx_read_buffer.size - len; amount = term->ptmx_read_buffer.size - len;
} }
/* TODO */
if (amount == 0) {
LOG_ERR("PTY read buffer full");
abort();
}
ssize_t count = read(term->ptmx, &buf[len], amount); ssize_t count = read(term->ptmx, &buf[len], amount);
if (count < 0) { if (count < 0) {
LOG_ERRNO("failed to read from PTY"); LOG_ERRNO("failed to read from PTY");
@ -904,10 +898,10 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
.ptmx_read_buffer = { .ptmx_read_buffer = {
.event_fd = ptmx_event_fd, .event_fd = ptmx_event_fd,
.idx = 0, .idx = 0,
.size = 4 * 1024 * 1024, .size = conf->tweak.pty_prefetch_size,
.buf = { .buf = {
{.data = malloc(4 * 1024 * 1024), .len = 0}, {.data = malloc(conf->tweak.pty_prefetch_size), .len = 0},
{.data = malloc(4 * 1024 * 1024), .len = 0}, {.data = malloc(conf->tweak.pty_prefetch_size), .len = 0},
}, },
}, },
.ptmx_buffer = tll_init(), .ptmx_buffer = tll_init(),

View file

@ -215,12 +215,12 @@ struct terminal {
mtx_t lock; mtx_t lock;
cnd_t cond; cnd_t cond;
int event_fd; int event_fd;
int size; unsigned size;
uint8_t idx; uint8_t idx;
struct { struct {
uint8_t *data; uint8_t *data;
int len; unsigned len;
} buf[2]; } buf[2];
} ptmx_read_buffer; } ptmx_read_buffer;