[x264-devel] thread affinity

Max Lapshin max.lapshin at gmail.com
Sun Aug 21 18:46:31 CEST 2011


Hi.

I'm running libx264 in threaded mode:  threads 6 or threads auto  on
Intel Core i5 2400 (3.2 GHz) under Debian Linux Sid with kernel 3.0.0
Task is to run live transcode of captured USB camera to H264 stream
(with sending frames via rtmp to erlyvideo server)

htop utility shows me that all threads are on one core and thus frames
are delayed.
I have attached them to cores by myself:

  int i;
  for(i = 0; i <= 4; i++) {
    memset( &p_aff, 0, sizeof(p_aff) );
    CPU_SET(i, &p_aff);
    sched_setaffinity(gettid() - 2 - i, sizeof(p_aff), &p_aff );
  }


(here I empirically try to calculate what threads are started by x264
and hope that I'm right).
After this dirty trick theads are spread across cores and everything goes great.

So, I have questions:

1) whom should I blame for this misbehaviour with locking busy threads
on one core:  linux 3.0.0, Linus himself, myself or some potentially
broken code in libx264 that glues threads together?
2) what should I do to fix this problem? My hack is working, but I'm
sure that it is bad solution.


More information about the x264-devel mailing list