From 13dff256c887bce3f872aa33e12febfe1b06446d Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Sat, 25 May 2019 00:52:49 +0300 Subject: [PATCH] workers by number of cores --- src/device.c | 10 ++++++++-- src/main.c | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/device.c b/src/device.c index f7d12e6..7c03c8f 100644 --- a/src/device.c +++ b/src/device.c @@ -85,6 +85,12 @@ struct device_t *device_init() { struct controls_t *ctl; struct device_runtime_t *run; struct device_t *dev; + long cores_sysconf; + unsigned cores_available; + + cores_sysconf = sysconf(_SC_NPROCESSORS_ONLN); + cores_sysconf = (cores_sysconf < 0 ? 0 : cores_sysconf); + cores_available = max_u(min_u(cores_sysconf, 4), 1); A_CALLOC(ctl, 1); @@ -97,8 +103,8 @@ struct device_t *device_init() { dev->height = 480; dev->format = V4L2_PIX_FMT_YUYV; dev->standard = V4L2_STD_UNKNOWN; - dev->n_buffers = max_u(min_u(sysconf(_SC_NPROCESSORS_ONLN), 4), 1) + 1; - dev->n_workers = dev->n_buffers; + dev->n_buffers = cores_available + 1; + dev->n_workers = min_u(cores_available, dev->n_buffers); dev->timeout = 1; dev->error_delay = 1; dev->ctl = ctl; diff --git a/src/main.c b/src/main.c index de8b2b6..b7a11b5 100644 --- a/src/main.c +++ b/src/main.c @@ -133,9 +133,9 @@ static void _help(struct device_t *dev, struct encoder_t *encoder, struct http_s printf(" to automatic resolution change. Default: disabled.\n\n"); printf(" -b|--buffers ─────────────── The number of buffers to receive data from the device.\n"); printf(" Each buffer may processed using an intermediate thread.\n"); - printf(" Default: %u (the number of CPU cores (but not more 4) + 1).\n\n", dev->n_buffers); + printf(" Default: %u (the number of CPU cores (but not more than 4) + 1).\n\n", dev->n_buffers); printf(" -w|--workers ─────────────── The number of worker threads but not more than buffers.\n"); - printf(" Default: %u (== --buffers).\n\n", dev->n_workers); + printf(" Default: %u (the number of CPU cores (but not more than 4)).\n\n", dev->n_workers); printf(" -q|--quality ─────────────── Set quality of JPEG encoding from 1 to 100 (best). Default: %u.\n\n", encoder->quality); printf(" -c|--encoder ──────────── Use specified encoder. It may affects to workers number.\n"); printf(" Available: %s; default: CPU.\n\n", ENCODER_TYPES_STR);