From patchwork Fri Jun 23 17:48:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rostislav Pehlivanov X-Patchwork-Id: 4094 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.22.4 with SMTP id 4csp234847vsw; Fri, 23 Jun 2017 10:48:25 -0700 (PDT) X-Received: by 10.28.203.65 with SMTP id b62mr6161005wmg.9.1498240105170; Fri, 23 Jun 2017 10:48:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498240105; cv=none; d=google.com; s=arc-20160816; b=IqlcL486xEKs75XOjwpMDMVhjJCUJg7/mqLS22EO/D0fKE5gny9cRwaaLeO2BRQ5h3 zwybI5ulYXm/QU70OxWHvyCqn1u2e+j7e4y+iKgggRZUFvRhUH89DtQIZaE9vqMKsszn P7nqb8knJDtF+EKnIijIEDYbNrh77NCOsvbjWeQdfCwuBnbt34+y7D3gFkq6uQ2Q9Fei od+xPj46cMJudqwzbglgi1dZYk3338hZx6BWmu8qBnbN7xuJFl00CDCztdgo2Ka09TSr FzVjQ+i3Mbs89F6f627PjNyaNtlHZfTJu0llX8Jakahj2RUrzkDQEJeyi0JtTQXLtjv1 Ionw== 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=xqYKlrZbxt1IlGVaHk+D/qg059X/emzpbNvtCwwpldI=; b=VqWCe/+WwFwXkwdL3cevNNsjL+DtucIZ6lvo2NZHqMmid0rcm/tZDsocLdjpcdbqdz ebI7Yin895Spph14qNabR5lpwHyXpi1kOTQpXttV1fZb52d8bS9KZTIz0K1GjRXE6iOP 6Qvu7hCgjutsZPHrfSx2WmUAfxpMglhTcdO91GX1p6eOEKA0Sg4g5hOQqAmhLRAKSlYN T7rniYW+aky0yGyoyyvdn7VTffGLfr4Ka9SMSMweGK8McoIXPEl2rFlecrAej+RhX/Dd tUNzpoM3e5KAs6u4UVLDuKtgHyL2NPPXClyrB3p2ojzEwXXWyw2xmbl1sQ2UJafJYOFj bayw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.b=bCxyamsz; 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 u27si4836232wru.142.2017.06.23.10.48.23; Fri, 23 Jun 2017 10:48:25 -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=bCxyamsz; 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 3519D689E65; Fri, 23 Jun 2017 20:48:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f196.google.com (mail-wr0-f196.google.com [209.85.128.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 37492689DF0 for ; Fri, 23 Jun 2017 20:48:13 +0300 (EEST) Received: by mail-wr0-f196.google.com with SMTP id 77so14160972wrb.3 for ; Fri, 23 Jun 2017 10:48:13 -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=ePtmRtFb1r7TGFvxquFniNWkCNU7+apTl/THmT71LCg=; b=bCxyamszstyWP85PYZKlx/+uf5Ljmu0nnPtsL5WENFbbSFaxY3GOYWascLH915rZrP GA4wvTuzIIsZChn3RHfztzg1wbu3w7cBTMZf8oQ8bYQ74MBAoVidRYkBrAb5YOxuPUiK Y8XuIxiYqIa0ra2kNYpnLrs677663adk0WxEhhg4PWWM5hWi3NvLVrPuOdfdaBtG90+T 3OfPFKtoM6yGvnShAN7uNIfgGeeyi6ytNucMqPq445K0/MIb1cp7FOVZk6ISD41LRTkP SGF7LqHQ9HvCWETAg07yk4xIcNT02jDuFDkIHcMUGYm2jI5EDJflJV5htFFgBoTvqmJb PmVQ== 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=ePtmRtFb1r7TGFvxquFniNWkCNU7+apTl/THmT71LCg=; b=Kw34JydHEe4WA5ggMiDJxSAa+pIzaZntPDxJEntu57qbbQ9EnbGWy/FuumwjTH6wzN mFu4DnnzCHX9+0/ohD8ttFd3ap+2QIfmiAfRkLwTgDipJv4g51zuLZhS+w1jW3DJUCCe gSJeztiPS2RN1lb4gYFlnfDS2kqKMSNWwRDqgYAg3i3P4eRyzW7kpE4OxoSVzt4JaQ+K baIE7Z7IMjphKdQmjiMWlYgZsyMBdq1VV1iFyELIk5cPa4VyiG1WMM2J0/CSYWbofEju kiB4MVTQVlIMFTXnY/WjVk12iKmzvlZ5JrLtUqY/wYEILAryy2xt468Zh8KcLTmZngU1 c0rQ== X-Gm-Message-State: AKS2vOx70cOfjhCqXy0oe9Zk9zAdtl1pxPbYaHPnpzpmANYGE4dKaHlJ RE4bU0aIC6ZAcdWMSfY= X-Received: by 10.223.138.234 with SMTP id z39mr6449028wrz.50.1498240092816; Fri, 23 Jun 2017 10:48:12 -0700 (PDT) Received: from moonbase.lan ([2a00:23c4:7c80:f00:f121:7da9:4a59:e523]) by smtp.gmail.com with ESMTPSA id 94sm3442071wrp.63.2017.06.23.10.48.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Jun 2017 10:48:11 -0700 (PDT) From: Rostislav Pehlivanov To: ffmpeg-devel@ffmpeg.org Date: Fri, 23 Jun 2017 18:48:04 +0100 Message-Id: <20170623174804.89943-1-atomnuker@gmail.com> X-Mailer: git-send-email 2.13.1.704.gde00cce3c MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] 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 , with the addition it'll define _GNU_SOURCE in the configure system, making the functionality usable on modern glibc systems. Signed-off-by: Rostislav Pehlivanov --- 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..319f2ef52c 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 && add_cppflags -D_GNU_SOURCE fi enabled pthreads && diff --git a/libavcodec/frame_thread_encoder.c b/libavcodec/frame_thread_encoder.c index 6cf1a68fe7..7cee23760e 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; + ff_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..8e69e93f71 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; + ff_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..5d0d10d8d8 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; + ff_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..87da83ecaa 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; + ff_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..cd54c248ff 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; + ff_thread_setname("lavf-async-buf"); + while (1) { int fifo_space, to_copy; diff --git a/libavformat/udp.c b/libavformat/udp.c index 3835f989c4..c0a61002fd 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; + ff_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..24a4f1b083 100644 --- a/libavutil/thread.h +++ b/libavutil/thread.h @@ -127,10 +127,23 @@ static inline int strict_pthread_once(pthread_once_t *once_control, void (*init_ #define pthread_once strict_pthread_once #endif +static inline void ff_thread_setname(const char *name) +{ +#if HAVE_PTHREAD_SETNAME_NP +#if defined(__APPLE__) + pthread_setname_np(name); +#elif defined(__linux__) && defined(__GLIBC__) + pthread_setname_np(pthread_self(), name); +#endif +#endif +} + #elif HAVE_OS2THREADS #include "compat/os2threads.h" +#define ff_thread_setname(name) (0) #else #include "compat/w32pthreads.h" +#define ff_thread_setname(name) (0) #endif #define AVMutex pthread_mutex_t @@ -157,6 +170,8 @@ static inline int strict_pthread_once(pthread_once_t *once_control, void (*init_ #define AVOnce char #define AV_ONCE_INIT 0 +#define ff_thread_setname(name) (0) + static inline int ff_thread_once(char *control, void (*routine)(void)) { if (!*control) {