[x265-commits] [x265] cmake: ignore older versions of libnuma

Steve Borho steve at borho.org
Wed Mar 4 21:41:42 CET 2015


details:   http://hg.videolan.org/x265/rev/6a9cff19ca93
branches:  
changeset: 9599:6a9cff19ca93
user:      Steve Borho <steve at borho.org>
date:      Mon Mar 02 10:04:37 2015 -0600
description:
cmake: ignore older versions of libnuma
Subject: [x265] cmake: add -fstack-protector to checked builds, if available

details:   http://hg.videolan.org/x265/rev/788f5768b107
branches:  
changeset: 9600:788f5768b107
user:      Steve Borho <steve at borho.org>
date:      Mon Mar 02 16:55:25 2015 -0600
description:
cmake: add -fstack-protector to checked builds, if available
Subject: [x265] cmake: more general support for clang/gcc -fsanitize options

details:   http://hg.videolan.org/x265/rev/c19c94af303f
branches:  
changeset: 9601:c19c94af303f
user:      Steve Borho <steve at borho.org>
date:      Wed Mar 04 08:32:04 2015 -0600
description:
cmake: more general support for clang/gcc -fsanitize options

Each compiler/platform supports different options, and since most must also be
passed to the linker, they are not easily auto-detected. 'undefined-trap' is
one exception
Subject: [x265] encoder: protect against logging inf stats if no RDO was performed

details:   http://hg.videolan.org/x265/rev/8cbb3771ae92
branches:  
changeset: 9602:8cbb3771ae92
user:      Steve Borho <steve at borho.org>
date:      Fri Feb 27 15:14:20 2015 -0600
description:
encoder: protect against logging inf stats if no RDO was performed

which mostly can only happen if you CTRL+C before the lookahead outputs any
frames.
Subject: [x265] threading: nit

details:   http://hg.videolan.org/x265/rev/6d7b522079b5
branches:  
changeset: 9603:6d7b522079b5
user:      Steve Borho <steve at borho.org>
date:      Wed Mar 04 08:28:48 2015 -0600
description:
threading: nit
Subject: [x265] frameencoder: nit

details:   http://hg.videolan.org/x265/rev/affaf2561104
branches:  
changeset: 9604:affaf2561104
user:      Steve Borho <steve at borho.org>
date:      Wed Mar 04 07:11:02 2015 -0600
description:
frameencoder: nit
Subject: [x265] primitives: ensure x265_cpu_cpuid() clears eax even when built without asm

details:   http://hg.videolan.org/x265/rev/6c70bf1d3c90
branches:  
changeset: 9605:6c70bf1d3c90
user:      Steve Borho <steve at borho.org>
date:      Wed Mar 04 07:20:07 2015 -0600
description:
primitives: ensure x265_cpu_cpuid() clears eax even when built without asm

valgrind found this error condition; when built without assembly cpu detection
was using an uninitialized variable.
Subject: [x265] weightb: avoid signed left-shifts (which cause -ftrapv exceptions)

details:   http://hg.videolan.org/x265/rev/058cbd563b8f
branches:  
changeset: 9606:058cbd563b8f
user:      Steve Borho <steve at borho.org>
date:      Wed Mar 04 10:35:55 2015 -0600
description:
weightb: avoid signed left-shifts (which cause -ftrapv exceptions)
Subject: [x265] me: split initialization to avoid harmless race hazard

details:   http://hg.videolan.org/x265/rev/9eceacadf27b
branches:  
changeset: 9607:9eceacadf27b
user:      Steve Borho <steve at borho.org>
date:      Mon Mar 02 18:52:34 2015 -0600
description:
me: split initialization to avoid harmless race hazard
Subject: [x265] slicetype: clear m_helpWanted with input lock held to prevent race

details:   http://hg.videolan.org/x265/rev/e1b402399735
branches:  
changeset: 9608:e1b402399735
user:      Steve Borho <steve at borho.org>
date:      Mon Mar 02 19:24:06 2015 -0600
description:
slicetype: clear m_helpWanted with input lock held to prevent race
Subject: [x265] encoder: divide init/start and stop/delete to prevent race hazards

details:   http://hg.videolan.org/x265/rev/1ce139389b3b
branches:  
changeset: 9609:1ce139389b3b
user:      Steve Borho <steve at borho.org>
date:      Mon Mar 02 19:54:42 2015 -0600
description:
encoder: divide init/start and stop/delete to prevent race hazards

Problems identified by helgrind, mostly theoretical hazards that are
very unlikely to occur or to cause problems if they did.
Subject: [x265] frameencoder: use a timed wait to avoid a help-wanted flag race hazard

details:   http://hg.videolan.org/x265/rev/e212eee15e98
branches:  
changeset: 9610:e212eee15e98
user:      Steve Borho <steve at borho.org>
date:      Wed Mar 04 08:30:49 2015 -0600
description:
frameencoder: use a timed wait to avoid a help-wanted flag race hazard

I've seen one deadlock when running within a debugger that pointed to a frame
encoder becoming stuck waiting for completion but no worker threads were aware
that the frame needed work.
Subject: [x265] threading: make Windows Event::timedWait() match behavior of POSIX version

details:   http://hg.videolan.org/x265/rev/7605e562bef6
branches:  
changeset: 9611:7605e562bef6
user:      Steve Borho <steve at borho.org>
date:      Wed Mar 04 14:40:44 2015 -0600
description:
threading: make Windows Event::timedWait() match behavior of POSIX version

diffstat:

 source/CMakeLists.txt           |  30 ++++++++++--
 source/common/predict.cpp       |   2 +-
 source/common/primitives.cpp    |   2 +-
 source/common/threading.h       |  10 +--
 source/encoder/api.cpp          |   1 +
 source/encoder/encoder.cpp      |  96 ++++++++++++++++++++++++++--------------
 source/encoder/encoder.h        |   1 +
 source/encoder/frameencoder.cpp |  12 +---
 source/encoder/motion.cpp       |  67 +++++++++++++--------------
 source/encoder/motion.h         |   1 +
 source/encoder/slicetype.cpp    |   6 +-
 11 files changed, 134 insertions(+), 94 deletions(-)

diffs (truncated from 465 to 300 lines):

diff -r 018e8bbaa854 -r 7605e562bef6 source/CMakeLists.txt
--- a/source/CMakeLists.txt	Fri Feb 27 11:46:09 2015 +0530
+++ b/source/CMakeLists.txt	Wed Mar 04 14:40:44 2015 -0600
@@ -58,11 +58,15 @@ if(UNIX)
     endif()
     find_package(Numa)
     if(NUMA_FOUND)
-        add_definitions(-DHAVE_LIBNUMA)
-        message(STATUS "libnuma found, building with support for NUMA nodes")
-        set(PLATFORM_LIBS ${PLATFORM_LIBS} ${NUMA_LIBRARY})
-        link_directories(${NUMA_LIBRARY_DIR})
-        include_directories(${NUMA_INCLUDE_DIR})
+        list(APPEND CMAKE_REQUIRED_LIBRARIES ${NUMA_LIBRARY})
+        check_symbol_exists(numa_node_of_cpu numa.h NUMA_V2)
+        if(NUMA_V2)
+            add_definitions(-DHAVE_LIBNUMA)
+            message(STATUS "libnuma found, building with support for NUMA nodes")
+            set(PLATFORM_LIBS ${PLATFORM_LIBS} ${NUMA_LIBRARY})
+            link_directories(${NUMA_LIBRARY_DIR})
+            include_directories(${NUMA_INCLUDE_DIR})
+        endif()
     endif()
     mark_as_advanced(LIBRT NUMA_FOUND)
 endif(UNIX)
@@ -158,6 +162,10 @@ if(GCC)
     if(CC_HAS_FNO_EXCEPTIONS_FLAG)
         add_definitions(-fno-exceptions)
     endif()
+    set(FSANITIZE "" CACHE STRING "-fsanitize options for GCC/clang")
+    if(FSANITIZE)
+        add_definitions(-fsanitize=${FSANITIZE})
+    endif()
     execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE CC_VERSION)
 endif(GCC)
 
@@ -176,9 +184,9 @@ option(CHECKED_BUILD "Enable run-time sa
 if(CHECKED_BUILD)
     add_definitions(-DCHECKED_BUILD=1)
     if(GCC)
-        check_cxx_compiler_flag(-fsanitize=address CC_HAS_FSANITIZE)              # clang and gcc
         check_cxx_compiler_flag(-fsanitize=undefined-trap CC_HAS_CATCH_UNDEFINED) # clang
         check_cxx_compiler_flag(-ftrapv CC_HAS_FTRAPV)                            # gcc
+        check_cxx_compiler_flag(-fstack-protector CC_HAS_STACK_PROTECT)           # gcc
         if(CC_HAS_FSANITIZE)
             add_definitions(-fsanitize=address)
         endif()
@@ -188,6 +196,9 @@ if(CHECKED_BUILD)
         if(CC_HAS_CATCH_UNDEFINED)
             add_definitions(-fsanitize=undefined-trap -fsanitize-undefined-trap-on-error)
         endif()
+        if(CC_HAS_STACK_PROTECT)
+            add_definitions(-fstack-protector)
+        endif()
     endif(GCC)
 endif()
 
@@ -416,6 +427,13 @@ if(ENABLE_CLI)
         endif()
     endif()
     set_target_properties(cli PROPERTIES OUTPUT_NAME x265)
+    if(FSANITIZE)
+        # clang and gcc need the sanitize options to be passed at link
+        # time so the appropriate ASAN/TSAN runtime libraries can be
+        # linked. Linking the cli to the static libx265 is usually
+        # required (by setting ENABLE_SHARED to OFF)
+        set_target_properties(cli PROPERTIES LINK_FLAGS "-fsanitize=${FSANITIZE}")
+    endif()
 
     install(TARGETS cli DESTINATION ${BIN_INSTALL_DIR})
 endif(ENABLE_CLI)
diff -r 018e8bbaa854 -r 7605e562bef6 source/common/predict.cpp
--- a/source/common/predict.cpp	Fri Feb 27 11:46:09 2015 +0530
+++ b/source/common/predict.cpp	Wed Mar 04 14:40:44 2015 -0600
@@ -50,7 +50,7 @@ namespace
 {
 inline pixel weightBidir(int w0, int16_t P0, int w1, int16_t P1, int round, int shift, int offset)
 {
-    return x265_clip((w0 * (P0 + IF_INTERNAL_OFFS) + w1 * (P1 + IF_INTERNAL_OFFS) + round + (offset << (shift - 1))) >> shift);
+    return x265_clip((w0 * (P0 + IF_INTERNAL_OFFS) + w1 * (P1 + IF_INTERNAL_OFFS) + round + (offset * (1 << (shift - 1)))) >> shift);
 }
 }
 
diff -r 018e8bbaa854 -r 7605e562bef6 source/common/primitives.cpp
--- a/source/common/primitives.cpp	Fri Feb 27 11:46:09 2015 +0530
+++ b/source/common/primitives.cpp	Wed Mar 04 14:40:44 2015 -0600
@@ -258,7 +258,7 @@ void x265_setup_primitives(x265_param *p
 extern "C" {
 int x265_cpu_cpuid_test(void) { return 0; }
 void x265_cpu_emms(void) {}
-void x265_cpu_cpuid(uint32_t, uint32_t *, uint32_t *, uint32_t *, uint32_t *) {}
+void x265_cpu_cpuid(uint32_t, uint32_t *eax, uint32_t *, uint32_t *, uint32_t *) { *eax = 0; }
 void x265_cpu_xgetbv(uint32_t, uint32_t *, uint32_t *) {}
 }
 #endif
diff -r 018e8bbaa854 -r 7605e562bef6 source/common/threading.h
--- a/source/common/threading.h	Fri Feb 27 11:46:09 2015 +0530
+++ b/source/common/threading.h	Wed Mar 04 14:40:44 2015 -0600
@@ -128,8 +128,8 @@ public:
 
     bool timedWait(uint32_t milliseconds)
     {
-        /* returns true if event was signaled */
-        return WaitForSingleObject(this->handle, milliseconds) == WAIT_OBJECT_0;
+        /* returns true if the wait timed out */
+        return WaitForSingleObject(this->handle, milliseconds) == WAIT_TIMEOUT;
     }
 
     void trigger()
@@ -263,10 +263,8 @@ public:
 
         /* blocking wait on conditional variable, mutex is atomically released
          * while blocked. When condition is signaled, mutex is re-acquired */
-        while (m_counter == 0)
-        {
+        while (!m_counter)
             pthread_cond_wait(&m_cond, &m_mutex);
-        }
 
         m_counter--;
         pthread_mutex_unlock(&m_mutex);
@@ -277,7 +275,7 @@ public:
         bool bTimedOut = false;
 
         pthread_mutex_lock(&m_mutex);
-        if (m_counter == 0)
+        if (!m_counter)
         {
             struct timeval tv;
             struct timespec ts;
diff -r 018e8bbaa854 -r 7605e562bef6 source/encoder/api.cpp
--- a/source/encoder/api.cpp	Fri Feb 27 11:46:09 2015 +0530
+++ b/source/encoder/api.cpp	Wed Mar 04 14:40:44 2015 -0600
@@ -173,6 +173,7 @@ void x265_encoder_close(x265_encoder *en
     {
         Encoder *encoder = static_cast<Encoder*>(enc);
 
+        encoder->stop();
         encoder->printSummary();
         encoder->destroy();
         delete encoder;
diff -r 018e8bbaa854 -r 7605e562bef6 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Fri Feb 27 11:46:09 2015 +0530
+++ b/source/encoder/encoder.cpp	Wed Mar 04 14:40:44 2015 -0600
@@ -81,6 +81,8 @@ Encoder::Encoder()
     m_analysisFile = NULL;
     for (int i = 0; i < X265_MAX_FRAME_THREADS; i++)
         m_frameEncoder[i] = NULL;
+
+    MotionEstimate::initScales();
 }
 
 void Encoder::create()
@@ -244,8 +246,10 @@ void Encoder::create()
             x265_log(m_param, X265_LOG_ERROR, "Unable to initialize frame encoder, aborting\n");
             m_aborted = true;
         }
+    }
+    for (int i = 0; i < m_param->frameNumThreads; i++)
         m_frameEncoder[i]->start();
-    }
+
     if (m_param->bEmitHRDSEI)
         m_rateControl->initHRD(m_sps);
     if (!m_rateControl->init(m_sps))
@@ -274,6 +278,26 @@ void Encoder::create()
     m_encodeStartTime = x265_mdate();
 }
 
+void Encoder::stop()
+{
+    if (m_rateControl)
+        m_rateControl->terminate(); // unblock all blocked RC calls
+
+    if (m_lookahead)
+        m_lookahead->stop();
+    
+    for (int i = 0; i < m_param->frameNumThreads; i++)
+    {
+        if (m_frameEncoder[i])
+        {
+            m_frameEncoder[i]->getEncodedPicture(m_nalList);
+            m_frameEncoder[i]->m_threadActive = false;
+            m_frameEncoder[i]->m_enable.trigger();
+            m_frameEncoder[i]->stop();
+        }
+    }
+}
+
 void Encoder::destroy()
 {
     if (m_exportedPic)
@@ -282,21 +306,14 @@ void Encoder::destroy()
         m_exportedPic = NULL;
     }
 
-    if (m_rateControl)
-        m_rateControl->terminate(); // unblock all blocked RC calls
-
-    if (m_lookahead)
-        m_lookahead->stop();
-    
     for (int i = 0; i < m_param->frameNumThreads; i++)
-        if (m_frameEncoder[i]) m_frameEncoder[i]->getEncodedPicture(m_nalList);
-		
-    for (int i = 0; i < m_param->frameNumThreads; i++)
+    {
         if (m_frameEncoder[i])
         {
             m_frameEncoder[i]->destroy();
             delete m_frameEncoder[i];
         }
+    }
 
     // thread pools can be cleaned up now that all the JobProviders are
     // known to be shutdown
@@ -322,13 +339,18 @@ void Encoder::destroy()
 
     if (m_analysisFile)
         fclose(m_analysisFile);
-    free(m_param->analysisFileName);
-    free(m_param->csvfn);
     if (m_csvfpt)
         fclose(m_csvfpt);
-    free(m_param->rc.statFileName); // alloc'd by strdup
 
-    X265_FREE(m_param);
+    if (m_param)
+    {
+        free(m_param->rc.statFileName); // allocs by strdup
+        free(m_param->analysisFileName);
+        free(m_param->csvfn);
+        free(m_param->numaPools);
+
+        X265_FREE(m_param);
+    }
 }
 
 void Encoder::updateVbvPlan(RateControl* rc)
@@ -894,27 +916,33 @@ void Encoder::printSummary()
     x265_log(m_param, X265_LOG_INFO, "CU: %%%05.2lf time spent in other tasks\n",
              100.0 * unaccounted / totalWorkerTime);
 
-    x265_log(m_param, X265_LOG_INFO, "CU: Intra RDO time  per depth %%%05.2lf %%%05.2lf %%%05.2lf %%%05.2lf\n",
-             100.0 * cuStats.intraRDOElapsedTime[0] / intraRDOTotalTime,  // 64
-             100.0 * cuStats.intraRDOElapsedTime[1] / intraRDOTotalTime,  // 32
-             100.0 * cuStats.intraRDOElapsedTime[2] / intraRDOTotalTime,  // 16
-             100.0 * cuStats.intraRDOElapsedTime[3] / intraRDOTotalTime); // 8
-    x265_log(m_param, X265_LOG_INFO, "CU: Intra RDO calls per depth %%%05.2lf %%%05.2lf %%%05.2lf %%%05.2lf\n",
-             100.0 * cuStats.countIntraRDO[0] / intraRDOTotalCount,  // 64
-             100.0 * cuStats.countIntraRDO[1] / intraRDOTotalCount,  // 32
-             100.0 * cuStats.countIntraRDO[2] / intraRDOTotalCount,  // 16
-             100.0 * cuStats.countIntraRDO[3] / intraRDOTotalCount); // 8
+    if (intraRDOTotalTime && intraRDOTotalCount)
+    {
+        x265_log(m_param, X265_LOG_INFO, "CU: Intra RDO time  per depth %%%05.2lf %%%05.2lf %%%05.2lf %%%05.2lf\n",
+                 100.0 * cuStats.intraRDOElapsedTime[0] / intraRDOTotalTime,  // 64
+                 100.0 * cuStats.intraRDOElapsedTime[1] / intraRDOTotalTime,  // 32
+                 100.0 * cuStats.intraRDOElapsedTime[2] / intraRDOTotalTime,  // 16
+                 100.0 * cuStats.intraRDOElapsedTime[3] / intraRDOTotalTime); // 8
+        x265_log(m_param, X265_LOG_INFO, "CU: Intra RDO calls per depth %%%05.2lf %%%05.2lf %%%05.2lf %%%05.2lf\n",
+                 100.0 * cuStats.countIntraRDO[0] / intraRDOTotalCount,  // 64
+                 100.0 * cuStats.countIntraRDO[1] / intraRDOTotalCount,  // 32
+                 100.0 * cuStats.countIntraRDO[2] / intraRDOTotalCount,  // 16
+                 100.0 * cuStats.countIntraRDO[3] / intraRDOTotalCount); // 8
+    }
 
-    x265_log(m_param, X265_LOG_INFO, "CU: Inter RDO time  per depth %%%05.2lf %%%05.2lf %%%05.2lf %%%05.2lf\n",
-             100.0 * cuStats.interRDOElapsedTime[0] / interRDOTotalTime,  // 64
-             100.0 * cuStats.interRDOElapsedTime[1] / interRDOTotalTime,  // 32
-             100.0 * cuStats.interRDOElapsedTime[2] / interRDOTotalTime,  // 16
-             100.0 * cuStats.interRDOElapsedTime[3] / interRDOTotalTime); // 8
-    x265_log(m_param, X265_LOG_INFO, "CU: Inter RDO calls per depth %%%05.2lf %%%05.2lf %%%05.2lf %%%05.2lf\n",
-             100.0 * cuStats.countInterRDO[0] / interRDOTotalCount,  // 64
-             100.0 * cuStats.countInterRDO[1] / interRDOTotalCount,  // 32
-             100.0 * cuStats.countInterRDO[2] / interRDOTotalCount,  // 16
-             100.0 * cuStats.countInterRDO[3] / interRDOTotalCount); // 8
+    if (interRDOTotalTime && interRDOTotalCount)
+    {
+        x265_log(m_param, X265_LOG_INFO, "CU: Inter RDO time  per depth %%%05.2lf %%%05.2lf %%%05.2lf %%%05.2lf\n",
+                 100.0 * cuStats.interRDOElapsedTime[0] / interRDOTotalTime,  // 64
+                 100.0 * cuStats.interRDOElapsedTime[1] / interRDOTotalTime,  // 32
+                 100.0 * cuStats.interRDOElapsedTime[2] / interRDOTotalTime,  // 16
+                 100.0 * cuStats.interRDOElapsedTime[3] / interRDOTotalTime); // 8
+        x265_log(m_param, X265_LOG_INFO, "CU: Inter RDO calls per depth %%%05.2lf %%%05.2lf %%%05.2lf %%%05.2lf\n",
+                 100.0 * cuStats.countInterRDO[0] / interRDOTotalCount,  // 64
+                 100.0 * cuStats.countInterRDO[1] / interRDOTotalCount,  // 32
+                 100.0 * cuStats.countInterRDO[2] / interRDOTotalCount,  // 16
+                 100.0 * cuStats.countInterRDO[3] / interRDOTotalCount); // 8
+    }
 
     x265_log(m_param, X265_LOG_INFO, "CU: " X265_LL " %dX%d CTUs compressed in %.3lf seconds, %.3lf CTUs per worker-second\n",
              cuStats.totalCTUs, g_maxCUSize, g_maxCUSize,
diff -r 018e8bbaa854 -r 7605e562bef6 source/encoder/encoder.h
--- a/source/encoder/encoder.h	Fri Feb 27 11:46:09 2015 +0530
+++ b/source/encoder/encoder.h	Wed Mar 04 14:40:44 2015 -0600
@@ -136,6 +136,7 @@ public:
     ~Encoder() {}
 
     void create();
+    void stop();


More information about the x265-commits mailing list