Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/4] lavu/thread: add an internal function for setting thread name
@ 2022-10-18 16:53 Anton Khirnov
  2022-10-18 16:53 ` [FFmpeg-devel] [PATCH 2/4] lavc/pthread_frame: set worker thread names Anton Khirnov
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Anton Khirnov @ 2022-10-18 16:53 UTC (permalink / raw)
  To: ffmpeg-devel

Linux-only for now.
---
 configure          |  2 ++
 libavutil/thread.h | 16 +++++++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index f3fd91f592..494a03486c 100755
--- a/configure
+++ b/configure
@@ -2310,6 +2310,7 @@ SYSTEM_FUNCS="
     nanosleep
     PeekNamedPipe
     posix_memalign
+    prctl
     pthread_cancel
     sched_getaffinity
     SecItemImport
@@ -6294,6 +6295,7 @@ check_func  mmap
 check_func  mprotect
 # Solaris has nanosleep in -lrt, OpenSolaris no longer needs that
 check_func_headers time.h nanosleep || check_lib nanosleep time.h nanosleep -lrt
+check_func_headers sys/prctl.h prctl
 check_func  sched_getaffinity
 check_func  setrlimit
 check_struct "sys/stat.h" "struct stat" st_mtim.tv_nsec -D_BSD_SOURCE
diff --git a/libavutil/thread.h b/libavutil/thread.h
index 7106fd0d47..2f5e7e1cb5 100644
--- a/libavutil/thread.h
+++ b/libavutil/thread.h
@@ -24,6 +24,12 @@
 
 #include "config.h"
 
+#if HAVE_PRCTL
+#include <sys/prctl.h>
+#endif
+
+#include "error.h"
+
 #if HAVE_PTHREADS || HAVE_W32THREADS || HAVE_OS2THREADS
 
 #if HAVE_PTHREADS
@@ -33,7 +39,6 @@
 
 #include <stdlib.h>
 
-#include "error.h"
 #include "log.h"
 #include "macros.h"
 
@@ -187,4 +192,13 @@ static inline int ff_thread_once(char *control, void (*routine)(void))
 
 #endif
 
+static inline int ff_thread_setname(const char *name)
+{
+#if HAVE_PRCTL
+    return AVERROR(prctl(PR_SET_NAME, name));
+#endif
+
+    return AVERROR(ENOSYS);
+}
+
 #endif /* AVUTIL_THREAD_H */
-- 
2.35.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [FFmpeg-devel] [PATCH 2/4] lavc/pthread_frame: set worker thread names
  2022-10-18 16:53 [FFmpeg-devel] [PATCH 1/4] lavu/thread: add an internal function for setting thread name Anton Khirnov
@ 2022-10-18 16:53 ` Anton Khirnov
  2022-10-18 20:59   ` Henrik Gramner
  2022-10-18 16:53 ` [FFmpeg-devel] [PATCH 3/4] lavf: set internal " Anton Khirnov
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Anton Khirnov @ 2022-10-18 16:53 UTC (permalink / raw)
  To: ffmpeg-devel

---
 libavcodec/pthread_frame.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index f8fddc5e4d..7cd352160e 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -179,6 +179,17 @@ static void async_unlock(FrameThreadContext *fctx)
     pthread_mutex_unlock(&fctx->async_mutex);
 }
 
+static void thread_set_name(PerThreadContext *p)
+{
+    AVCodecContext *avctx = p->avctx;
+    int idx = p - p->parent->threads;
+    char name[16];
+
+    snprintf(name, sizeof(name), "d:%.7s:ft%d", avctx->codec->name, idx);
+
+    ff_thread_setname(name);
+}
+
 /**
  * Codec worker thread.
  *
@@ -192,6 +203,8 @@ static attribute_align_arg void *frame_worker_thread(void *arg)
     AVCodecContext *avctx = p->avctx;
     const FFCodec *codec = ffcodec(avctx->codec);
 
+    thread_set_name(p);
+
     pthread_mutex_lock(&p->mutex);
     while (1) {
         while (atomic_load(&p->state) == STATE_INPUT_READY && !p->die)
-- 
2.35.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [FFmpeg-devel] [PATCH 3/4] lavf: set internal thread names
  2022-10-18 16:53 [FFmpeg-devel] [PATCH 1/4] lavu/thread: add an internal function for setting thread name Anton Khirnov
  2022-10-18 16:53 ` [FFmpeg-devel] [PATCH 2/4] lavc/pthread_frame: set worker thread names Anton Khirnov
@ 2022-10-18 16:53 ` Anton Khirnov
  2022-10-18 16:53 ` [FFmpeg-devel] [PATCH 4/4] fftools/ffmpeg: set " Anton Khirnov
  2022-10-21  8:15 ` [FFmpeg-devel] [PATCH 1/4] lavu/thread: add an internal function for setting thread name Anton Khirnov
  3 siblings, 0 replies; 8+ messages in thread
From: Anton Khirnov @ 2022-10-18 16:53 UTC (permalink / raw)
  To: ffmpeg-devel

---
 libavformat/async.c | 2 ++
 libavformat/fifo.c  | 2 ++
 libavformat/udp.c   | 4 ++++
 3 files changed, 8 insertions(+)

diff --git a/libavformat/async.c b/libavformat/async.c
index 3c6f89cab9..e096b0bc6f 100644
--- a/libavformat/async.c
+++ b/libavformat/async.c
@@ -189,6 +189,8 @@ static void *async_buffer_task(void *arg)
     int           ret  = 0;
     int64_t       seek_ret;
 
+    ff_thread_setname("async");
+
     while (1) {
         int fifo_space, to_copy;
 
diff --git a/libavformat/fifo.c b/libavformat/fifo.c
index 692c854be2..7b35c9bf02 100644
--- a/libavformat/fifo.c
+++ b/libavformat/fifo.c
@@ -432,6 +432,8 @@ static void *fifo_consumer_thread(void *data)
     fifo_thread_ctx.avf = avf;
     fifo_thread_ctx.last_received_dts = AV_NOPTS_VALUE;
 
+    ff_thread_setname("fifo-consumer");
+
     while (1) {
         uint8_t just_flushed = 0;
 
diff --git a/libavformat/udp.c b/libavformat/udp.c
index 3b36a4a094..e8980b29d8 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -487,6 +487,8 @@ static void *circular_buffer_task_rx( void *_URLContext)
     UDPContext *s = h->priv_data;
     int old_cancelstate;
 
+    ff_thread_setname("udp-rx");
+
     pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_cancelstate);
     pthread_mutex_lock(&s->mutex);
     if (ff_socket_nonblock(s->udp_fd, 0) < 0) {
@@ -552,6 +554,8 @@ static void *circular_buffer_task_tx( void *_URLContext)
     int64_t burst_interval = s->bitrate ? (s->burst_bits * 1000000 / s->bitrate) : 0;
     int64_t max_delay = s->bitrate ?  ((int64_t)h->max_packet_size * 8 * 1000000 / s->bitrate + 1) : 0;
 
+    ff_thread_setname("udp-tx");
+
     pthread_mutex_lock(&s->mutex);
 
     if (ff_socket_nonblock(s->udp_fd, 0) < 0) {
-- 
2.35.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [FFmpeg-devel] [PATCH 4/4] fftools/ffmpeg: set thread names
  2022-10-18 16:53 [FFmpeg-devel] [PATCH 1/4] lavu/thread: add an internal function for setting thread name Anton Khirnov
  2022-10-18 16:53 ` [FFmpeg-devel] [PATCH 2/4] lavc/pthread_frame: set worker thread names Anton Khirnov
  2022-10-18 16:53 ` [FFmpeg-devel] [PATCH 3/4] lavf: set internal " Anton Khirnov
@ 2022-10-18 16:53 ` Anton Khirnov
  2022-10-21  8:15 ` [FFmpeg-devel] [PATCH 1/4] lavu/thread: add an internal function for setting thread name Anton Khirnov
  3 siblings, 0 replies; 8+ messages in thread
From: Anton Khirnov @ 2022-10-18 16:53 UTC (permalink / raw)
  To: ffmpeg-devel

---
 fftools/ffmpeg_demux.c | 9 +++++++++
 fftools/ffmpeg_mux.c   | 9 +++++++++
 2 files changed, 18 insertions(+)

diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 6e89f5999a..487053c592 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -177,6 +177,13 @@ static void ts_fixup(InputFile *ifile, AVPacket *pkt, int *repeat_pict)
         *repeat_pict = av_stream_get_parser(ist->st)->repeat_pict;
 }
 
+static void thread_set_name(InputFile *f)
+{
+    char name[16];
+    snprintf(name, sizeof(name), "dmx%d:%s", f->index, f->ctx->iformat->name);
+    ff_thread_setname(name);
+}
+
 static void *input_thread(void *arg)
 {
     InputFile *f = arg;
@@ -190,6 +197,8 @@ static void *input_thread(void *arg)
         goto finish;
     }
 
+    thread_set_name(f);
+
     while (1) {
         DemuxMsg msg = { NULL };
 
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 2b70143978..778626e20f 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -184,6 +184,13 @@ static int sync_queue_process(Muxer *mux, OutputStream *ost, AVPacket *pkt)
     return 0;
 }
 
+static void thread_set_name(OutputFile *of)
+{
+    char name[16];
+    snprintf(name, sizeof(name), "mux%d:%s", of->index, of->format->name);
+    ff_thread_setname(name);
+}
+
 static void *muxer_thread(void *arg)
 {
     Muxer     *mux = arg;
@@ -197,6 +204,8 @@ static void *muxer_thread(void *arg)
         goto finish;
     }
 
+    thread_set_name(of);
+
     while (1) {
         OutputStream *ost;
         int stream_idx;
-- 
2.35.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [FFmpeg-devel] [PATCH 2/4] lavc/pthread_frame: set worker thread names
  2022-10-18 16:53 ` [FFmpeg-devel] [PATCH 2/4] lavc/pthread_frame: set worker thread names Anton Khirnov
@ 2022-10-18 20:59   ` Henrik Gramner
  2022-10-19  4:51     ` Rémi Denis-Courmont
  0 siblings, 1 reply; 8+ messages in thread
From: Henrik Gramner @ 2022-10-18 20:59 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

On Tue, Oct 18, 2022 at 6:54 PM Anton Khirnov <anton@khirnov.net> wrote:
> +static void thread_set_name(PerThreadContext *p)
> +{
> +    AVCodecContext *avctx = p->avctx;
> +    int idx = p - p->parent->threads;
> +    char name[16];
> +
> +    snprintf(name, sizeof(name), "d:%.7s:ft%d", avctx->codec->name, idx);
> +
> +    ff_thread_setname(name);
> +}

How about having some kind of prefix to indicate that those are
libavcodec threads?

Could be helpful in a scenario where a process has threads spawned by
35 different libraries.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [FFmpeg-devel] [PATCH 2/4] lavc/pthread_frame: set worker thread names
  2022-10-18 20:59   ` Henrik Gramner
@ 2022-10-19  4:51     ` Rémi Denis-Courmont
  2022-10-19  9:06       ` [FFmpeg-devel] [PATCH] " Anton Khirnov
  0 siblings, 1 reply; 8+ messages in thread
From: Rémi Denis-Courmont @ 2022-10-19  4:51 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Le 18 octobre 2022 23:59:21 GMT+03:00, Henrik Gramner <henrik@gramner.com> a écrit :
>On Tue, Oct 18, 2022 at 6:54 PM Anton Khirnov <anton@khirnov.net> wrote:
>> +static void thread_set_name(PerThreadContext *p)
>> +{
>> +    AVCodecContext *avctx = p->avctx;
>> +    int idx = p - p->parent->threads;
>> +    char name[16];
>> +
>> +    snprintf(name, sizeof(name), "d:%.7s:ft%d", avctx->codec->name, idx);
>> +
>> +    ff_thread_setname(name);
>> +}
>
>How about having some kind of prefix to indicate that those are
>libavcodec threads?
>
>Could be helpful in a scenario where a process has threads spawned by
>35 different libraries.
>_______________________________________________
>ffmpeg-devel mailing list
>ffmpeg-devel@ffmpeg.org
>https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>To unsubscribe, visit link above, or email
>ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>

There's only 15 characters maximum, so not much for a prefix . I guess that's why it's just d:...
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [FFmpeg-devel] [PATCH] lavc/pthread_frame: set worker thread names
  2022-10-19  4:51     ` Rémi Denis-Courmont
@ 2022-10-19  9:06       ` Anton Khirnov
  0 siblings, 0 replies; 8+ messages in thread
From: Anton Khirnov @ 2022-10-19  9:06 UTC (permalink / raw)
  To: ffmpeg-devel

---
Yes, the space is limited and we could bikeshed until christmas about
the best way to use it.

Here's an attempt with an 'av' prefix, 'ft' (frame thread) changed to
df (decoder - frame thread), and only two characters guranteed for
thread index.
---
 libavcodec/pthread_frame.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index f8fddc5e4d..df82a4125f 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -179,6 +179,17 @@ static void async_unlock(FrameThreadContext *fctx)
     pthread_mutex_unlock(&fctx->async_mutex);
 }
 
+static void thread_set_name(PerThreadContext *p)
+{
+    AVCodecContext *avctx = p->avctx;
+    int idx = p - p->parent->threads;
+    char name[16];
+
+    snprintf(name, sizeof(name), "av:%.7s:df%d", avctx->codec->name, idx);
+
+    ff_thread_setname(name);
+}
+
 /**
  * Codec worker thread.
  *
@@ -192,6 +203,8 @@ static attribute_align_arg void *frame_worker_thread(void *arg)
     AVCodecContext *avctx = p->avctx;
     const FFCodec *codec = ffcodec(avctx->codec);
 
+    thread_set_name(p);
+
     pthread_mutex_lock(&p->mutex);
     while (1) {
         while (atomic_load(&p->state) == STATE_INPUT_READY && !p->die)
-- 
2.35.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/4] lavu/thread: add an internal function for setting thread name
  2022-10-18 16:53 [FFmpeg-devel] [PATCH 1/4] lavu/thread: add an internal function for setting thread name Anton Khirnov
                   ` (2 preceding siblings ...)
  2022-10-18 16:53 ` [FFmpeg-devel] [PATCH 4/4] fftools/ffmpeg: set " Anton Khirnov
@ 2022-10-21  8:15 ` Anton Khirnov
  3 siblings, 0 replies; 8+ messages in thread
From: Anton Khirnov @ 2022-10-21  8:15 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Will push the set soonish if nobody has more comments.

-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-10-21  8:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-18 16:53 [FFmpeg-devel] [PATCH 1/4] lavu/thread: add an internal function for setting thread name Anton Khirnov
2022-10-18 16:53 ` [FFmpeg-devel] [PATCH 2/4] lavc/pthread_frame: set worker thread names Anton Khirnov
2022-10-18 20:59   ` Henrik Gramner
2022-10-19  4:51     ` Rémi Denis-Courmont
2022-10-19  9:06       ` [FFmpeg-devel] [PATCH] " Anton Khirnov
2022-10-18 16:53 ` [FFmpeg-devel] [PATCH 3/4] lavf: set internal " Anton Khirnov
2022-10-18 16:53 ` [FFmpeg-devel] [PATCH 4/4] fftools/ffmpeg: set " Anton Khirnov
2022-10-21  8:15 ` [FFmpeg-devel] [PATCH 1/4] lavu/thread: add an internal function for setting thread name Anton Khirnov

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git