From patchwork Fri Jun 23 20:00:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rostislav Pehlivanov X-Patchwork-Id: 4095 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.22.4 with SMTP id 4csp281625vsw; Fri, 23 Jun 2017 13:00:17 -0700 (PDT) X-Received: by 10.28.216.11 with SMTP id p11mr6445249wmg.4.1498248017689; Fri, 23 Jun 2017 13:00:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498248017; cv=none; d=google.com; s=arc-20160816; b=E49g5pk0RLgCRrky0PUTGyeyET11vIhZJUgqaANqqjBbWg9qH4hYX5ml5jEOX6kzNw p7najVRD8kvb1jAaoH+QEXumNp+LHQZvTbv0eGXhijFc1nzl2TM+kZj3rrOLc7nQpylT 5jMFiVNYKXxbb7GxxNBEAJ/9JcH0TbXl4eC/xQROyAPFNlp7vFQjTMkrMyzS1YpP+J0x iARFoGiFFWbGx/+fY5nDlY0Yx9fXM4N+MFxuw0Sv6nojQ/IqDN9OrR1GfQAANy55koG4 /IK0nKQAFEG8eyrPW97YrYney2heDS2JO8EgAlBgmg6IxyJmrot7oWMe3xwbYVJKSJ7u wwLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to:arc-authentication-results; bh=6/+PyPuRXOkncOkCtJZQo25BfxOCRavUvpWqkbzCu3g=; b=LAUTkly7/IcSw7o2CA9bvbxdaTHAtz09Xe/ONYYPRdilxCY0Vlx310yOoCyUcj1L4x y4q0ZOP6nTBF6i432S+STM3Jrid0tIa/RUBgy3L4zxiINL2C8w0i9mknjuczOAu4sKiA HRAldMuN/jFmbgcwlyyUy6pVR252+xxbqWPUhhQMrvFhYBpcpGuawFKyF+WOLrQBJa+o mkytw1y6vcj/zFfc6oaGdZLfzY3N5DduJCo7erwTyFWIo+PAN1oIdLB02nXvfaJ9shrx YAjU/Rn4Zoq5Alyx5pZbx5n1zSwncJJWytPb5F3wgwZfqeMftsZM4wouEZscU51I5gRY fFkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.b=Z9B3Gmhs; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 73si5216518wrl.337.2017.06.23.13.00.15; Fri, 23 Jun 2017 13:00:17 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.b=Z9B3Gmhs; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B2DC4689CFA; Fri, 23 Jun 2017 23:00:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 14A5C689DDA for ; Fri, 23 Jun 2017 23:00:06 +0300 (EEST) Received: by mail-wr0-f193.google.com with SMTP id z45so15007857wrb.2 for ; Fri, 23 Jun 2017 13:00:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=s60nN8pKnncTKIW1/2TjGIUotWnqE3h9OQ9fTSi8EEk=; b=Z9B3GmhsxXSFqVvm9126CkGE+3ky9LSHKaQjRjFSsYNA1dQwtbpcmUqwK2gIhOEvTZ NXHX+pvwMMHJ3ujNVLw4eB7kbx7qW7u2e8qvjRIHJRp6sEZPffdOkwUs9Uy9zZL5ss0+ Q6/BpmEM+PjO0TPf02zAMzNO+4DuZMU7fDnVdJ7S+Dmz+jZZ8g11LC1GL8tptEP/4SIM JJe3E+FscAO5i9D5cBGzl4nEPxneGjGKDrHBcpuQC5SHwD6iWZbLOZVIFaeixHd9IMJG zhTFXkGrfOrOUs+9DXQSl4VDS8/8mybolE31jG5ZULiDyakqfCl3X1QlhlF7iHPx6yZs /kVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=s60nN8pKnncTKIW1/2TjGIUotWnqE3h9OQ9fTSi8EEk=; b=uSfLrtvswZbcXdeSaLRZywppayGQ/y7PiHDF5NiJ/pHlic0nct1AVNTsP4mfXUwZG0 MPSfxuLylUnlvVcM/8oc5IoalW2K6Lw2gfe8MCzAakcklmOvqja1enScW26lXaNLisSi mvSk1eGXQ6oM0/stspeR/oUjw1aem66PPS6iO6907gQWo6naVOndQdb2QL48P1BOVqVr hqizOsiu4Si5gFK7OsMeYbuyZrqNY78NqoM4hJxyg7Y798GntSdWEgIr5mEwH8r15/ND h2sRoEWdO7tBAe4IqoQ8zjbenDqgOBR6g6RnmYpnRwhuj9UX/lPj8mj9o89bRvgBqrIu zamg== X-Gm-Message-State: AKS2vOwLdYBchSLnWDmRzvCwMQAQAVv3d9COBJPBszqZEGSxxLXrtzL3 ucGk39ZzK9Sz5p3MQLo= X-Received: by 10.28.111.215 with SMTP id c84mr306386wmi.72.1498248005777; Fri, 23 Jun 2017 13:00:05 -0700 (PDT) Received: from moonbase.lan ([2a00:23c4:7c80:f00:f121:7da9:4a59:e523]) by smtp.gmail.com with ESMTPSA id y192sm3761980wmy.6.2017.06.23.13.00.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Jun 2017 13:00:05 -0700 (PDT) From: Rostislav Pehlivanov To: ffmpeg-devel@ffmpeg.org Date: Fri, 23 Jun 2017 21:00:03 +0100 Message-Id: <20170623200003.28914-1-atomnuker@gmail.com> X-Mailer: git-send-email 2.13.1.704.gde00cce3c MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] lavu: add ff_pthread_setname() and use it in various places X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Rostislav Pehlivanov Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This is a re-posting of an old patch by Clément Bœsch . Signed-off-by: Rostislav Pehlivanov --- Changes from V1: renamve function to avpriv_thread_setname use prctl on linux (universal across all libc) configure | 2 ++ libavcodec/frame_thread_encoder.c | 2 ++ libavcodec/pthread_frame.c | 2 ++ libavcodec/pthread_slice.c | 2 ++ libavfilter/pthread.c | 2 ++ libavformat/async.c | 2 ++ libavformat/udp.c | 3 +++ libavutil/thread.h | 15 +++++++++++++++ 8 files changed, 30 insertions(+) diff --git a/configure b/configure index dd9608540e..1bc0338f15 100755 --- a/configure +++ b/configure @@ -1976,6 +1976,7 @@ SYSTEM_FUNCS=" PeekNamedPipe posix_memalign pthread_cancel + pthread_setname_np sched_getaffinity SetConsoleTextAttribute SetConsoleCtrlHandler @@ -5765,6 +5766,7 @@ fi if enabled pthreads; then check_func pthread_cancel + check_func pthread_setname_np fi enabled pthreads && diff --git a/libavcodec/frame_thread_encoder.c b/libavcodec/frame_thread_encoder.c index 6cf1a68fe7..3ec82dfe2a 100644 --- a/libavcodec/frame_thread_encoder.c +++ b/libavcodec/frame_thread_encoder.c @@ -62,6 +62,8 @@ static void * attribute_align_arg worker(void *v){ ThreadContext *c = avctx->internal->frame_thread_encoder; AVPacket *pkt = NULL; + avpriv_thread_setname("lavc-frame-enc"); + while(!c->exit){ int got_packet, ret; AVFrame *frame; diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index 363b139f71..749ced42d6 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -169,6 +169,8 @@ static attribute_align_arg void *frame_worker_thread(void *arg) AVCodecContext *avctx = p->avctx; const AVCodec *codec = avctx->codec; + avpriv_thread_setname("lavc-frame"); + pthread_mutex_lock(&p->mutex); while (1) { while (atomic_load(&p->state) == STATE_INPUT_READY && !p->die) diff --git a/libavcodec/pthread_slice.c b/libavcodec/pthread_slice.c index 60f5b78891..a1b1402f7f 100644 --- a/libavcodec/pthread_slice.c +++ b/libavcodec/pthread_slice.c @@ -70,6 +70,8 @@ static void* attribute_align_arg worker(void *v) int thread_count = avctx->thread_count; int self_id; + avpriv_thread_setname("lavc-slice"); + pthread_mutex_lock(&c->current_job_lock); self_id = c->current_job++; for (;;){ diff --git a/libavfilter/pthread.c b/libavfilter/pthread.c index c7a00210d6..f4ecd39057 100644 --- a/libavfilter/pthread.c +++ b/libavfilter/pthread.c @@ -61,6 +61,8 @@ static void* attribute_align_arg worker(void *v) unsigned int last_execute = 0; int ret, self_id; + avpriv_thread_setname("lavfi-worker"); + pthread_mutex_lock(&c->current_job_lock); self_id = c->current_job++; diff --git a/libavformat/async.c b/libavformat/async.c index 54dbd2312a..8e7dd34401 100644 --- a/libavformat/async.c +++ b/libavformat/async.c @@ -181,6 +181,8 @@ static void *async_buffer_task(void *arg) int ret = 0; int64_t seek_ret; + avpriv_thread_setname("lavf-async-buf"); + while (1) { int fifo_space, to_copy; diff --git a/libavformat/udp.c b/libavformat/udp.c index 3835f989c4..1aaf577b57 100644 --- a/libavformat/udp.c +++ b/libavformat/udp.c @@ -36,6 +36,7 @@ #include "libavutil/avstring.h" #include "libavutil/opt.h" #include "libavutil/log.h" +#include "libavutil/thread.h" #include "libavutil/time.h" #include "internal.h" #include "network.h" @@ -502,6 +503,8 @@ static void *circular_buffer_task_rx( void *_URLContext) UDPContext *s = h->priv_data; int old_cancelstate; + avpriv_thread_setname("udp-circ-buf"); + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_cancelstate); pthread_mutex_lock(&s->mutex); if (ff_socket_nonblock(s->udp_fd, 0) < 0) { diff --git a/libavutil/thread.h b/libavutil/thread.h index f108e20052..b82d7e34c4 100644 --- a/libavutil/thread.h +++ b/libavutil/thread.h @@ -29,6 +29,10 @@ #if HAVE_PTHREADS #include +#if HAVE_PTHREAD_SETNAME_NP && defined(__linux__) +#include +#endif + #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1 #include "log.h" @@ -127,6 +131,17 @@ static inline int strict_pthread_once(pthread_once_t *once_control, void (*init_ #define pthread_once strict_pthread_once #endif +static inline void avpriv_thread_setname(const char *name) +{ +#if HAVE_PTHREAD_SETNAME_NP +#if defined(__APPLE__) + pthread_setname_np(name); +#elif defined(__linux__) + prctl(PR_SET_NAME, name); +#endif +#endif +} + #elif HAVE_OS2THREADS #include "compat/os2threads.h" #else