Commit 4b5d04f4 authored by Andrey Kamaev's avatar Andrey Kamaev

Fixed tbb hang in Android apps

parent d05b788d
...@@ -92,16 +92,16 @@ list(APPEND lib_srcs "${tbb_src_dir}/src/rml/client/rml_tbb.cpp") ...@@ -92,16 +92,16 @@ list(APPEND lib_srcs "${tbb_src_dir}/src/rml/client/rml_tbb.cpp")
add_definitions(-D__TBB_DYNAMIC_LOAD_ENABLED=0 #required add_definitions(-D__TBB_DYNAMIC_LOAD_ENABLED=0 #required
-D__TBB_BUILD=1 #required -D__TBB_BUILD=1 #required
-D__TBB_USE_GENERIC_DWORD_LOAD_STORE=1 #needed by TBB 4.0 update 1,2 -D__TBB_SURVIVE_THREAD_SWITCH=0 #no cilk on Android
-D__TBB_TASK_CPP_DIRECTLY_INCLUDED=1 #needed by TBB 4.0 update 3 -D__TBB_USE_GENERIC_DWORD_LOAD_STORE=1 #needed by TBB 4.0 update 1,2; fixed in TBB 4.0 update 3 but it has 2 new problems
-DUSE_PTHREAD #required
-DTBB_USE_GCC_BUILTINS=1 #required -DTBB_USE_GCC_BUILTINS=1 #required
-DTBB_USE_DEBUG=0 #just ot be sure -DTBB_USE_DEBUG=0 #just ot be sure
-DTBB_NO_LEGACY=1 #don't need backward compatibility -DTBB_NO_LEGACY=1 #don't need backward compatibility
-DUSE_PTHREAD #required
-DDO_ITT_NOTIFY=0 #it seems that we don't need these notifications -DDO_ITT_NOTIFY=0 #it seems that we don't need these notifications
) )
add_library(tbb STATIC ${lib_srcs} ${lib_hdrs}) add_library(tbb STATIC ${lib_srcs} ${lib_hdrs} "${CMAKE_CURRENT_SOURCE_DIR}/android_additional.h" "${CMAKE_CURRENT_SOURCE_DIR}/version_string.tmp")
target_link_libraries(tbb c m dl) target_link_libraries(tbb c m dl)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w -include \"${CMAKE_CURRENT_SOURCE_DIR}/android_additional.h\"") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w -include \"${CMAKE_CURRENT_SOURCE_DIR}/android_additional.h\"")
......
#include <sys/syscall.h> #include <cstdio>
#include <pthread.h>
typedef unsigned long cpu_set_t; static inline int getPossibleCPUs()
#define __NCPUBITS (8 * sizeof (unsigned long)) {
FILE* cpuPossible = fopen("/sys/devices/system/cpu/possible", "r");
if(!cpuPossible)
#define CPU_SET(cpu, cpusetp) \ return 1;
((*(cpusetp)) |= (1UL << ((cpu) % __NCPUBITS)))
#define CPU_ISSET(cpu, cpusetp) \ char buf[2000]; //big enough for 1000 CPUs in worst possible configuration
((*(cpusetp)) & (1UL << ((cpu) % __NCPUBITS))) char* pbuf = fgets(buf, sizeof(buf), cpuPossible);
fclose(cpuPossible);
if(!pbuf)
return 1;
#define CPU_ZERO(cpusetp) \ //parse string of form "0-1,3,5-7,10,13-15"
memset((cpusetp), 0, sizeof(cpu_set_t)) int cpusAvailable = 0;
inline static int while(*pbuf)
sched_setaffinity(pid_t pid, size_t len, cpu_set_t const * cpusetp) {
{ const char* pos = pbuf;
return syscall(__NR_sched_setaffinity, pid, len, cpusetp); bool range = false;
while(*pbuf && *pbuf != ',')
{
if(*pbuf == '-') range = true;
++pbuf;
}
if(*pbuf) *pbuf++ = 0;
if(!range)
++cpusAvailable;
else
{
int rstart = 0, rend = 0;
sscanf(pos, "%d-%d", &rstart, &rend);
cpusAvailable += rend - rstart + 1;
}
}
return cpusAvailable ? cpusAvailable : 1;
} }
inline static int #define __TBB_HardwareConcurrency() getPossibleCPUs()
sched_getaffinity(pid_t pid, size_t len, cpu_set_t const * cpusetp)
{
return syscall(__NR_sched_getaffinity, pid, len, cpusetp);
}
...@@ -108,7 +108,7 @@ if(CMAKE_COMPILER_IS_GNUCXX) ...@@ -108,7 +108,7 @@ if(CMAKE_COMPILER_IS_GNUCXX)
# Profiling? # Profiling?
if(ENABLE_PROFILING) if(ENABLE_PROFILING)
set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -pg -g") set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -pg -g")
elseif(NOT APPLE) elseif(NOT APPLE AND NOT ANDROID)
# Remove unreferenced functions: function level linking # Remove unreferenced functions: function level linking
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -ffunction-sections") set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -ffunction-sections")
endif() endif()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment