From 9fc317bd20d37da07fc8316d50cab576cd52ec19 Mon Sep 17 00:00:00 2001 From: kervala Date: Mon, 4 Jan 2016 15:33:55 +0100 Subject: [PATCH 1/5] Changed: Compile tools first because client needs some of them --HG-- branch : develop --- code/ryzom/CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/code/ryzom/CMakeLists.txt b/code/ryzom/CMakeLists.txt index 20590cc81..51b5134f7 100644 --- a/code/ryzom/CMakeLists.txt +++ b/code/ryzom/CMakeLists.txt @@ -6,6 +6,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/common ) SET(RZ_SERVER_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/server/src) ADD_SUBDIRECTORY(common) +ADD_SUBDIRECTORY(tools) IF(WITH_RYZOM_CLIENT) IF(NOT WITH_GUI) @@ -16,9 +17,7 @@ IF(WITH_RYZOM_CLIENT) ELSEIF(WITH_RYZOM_TOOLS) # Need clientsheets lib for sheets packer tool ADD_SUBDIRECTORY(client) -ENDIF(WITH_RYZOM_CLIENT) - -ADD_SUBDIRECTORY(tools) +ENDIF() IF(WITH_RYZOM_SERVER OR WITH_RYZOM_TOOLS) # Need servershare for build packed collision tool From b11fabe867c714f3c2ebe2e0dd7940b3c2906de6 Mon Sep 17 00:00:00 2001 From: kervala Date: Mon, 4 Jan 2016 15:35:02 +0100 Subject: [PATCH 2/5] Changed: Use __rdtsc() intrinsics everywhere for Intel CPUs --HG-- branch : develop --- code/nel/include/nel/misc/common.h | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/code/nel/include/nel/misc/common.h b/code/nel/include/nel/misc/common.h index 028fc0b0d..191db5188 100644 --- a/code/nel/include/nel/misc/common.h +++ b/code/nel/include/nel/misc/common.h @@ -38,6 +38,10 @@ # include #endif +#if defined(NL_CPU_INTEL) && defined(NL_COMP_GCC) +#include "x86intrin.h" +#endif + #include "string_common.h" #ifdef NL_OS_WINDOWS @@ -65,20 +69,8 @@ namespace NLMISC inline uint64 rdtsc() { - uint64 ticks; -# ifdef NL_OS_WINDOWS -# ifdef NL_NO_ASM - ticks = uint64(__rdtsc()); -# else - // We should use the intrinsic code now. ticks = uint64(__rdtsc()); - __asm rdtsc - __asm mov DWORD PTR [ticks], eax - __asm mov DWORD PTR [ticks + 4], edx -# endif // NL_NO_ASM -# else - __asm__ volatile(".byte 0x0f, 0x31" : "=a" (ticks.low), "=d" (ticks.high)); -# endif // NL_OS_WINDOWS - return ticks; + // __rdtsc() is defined under all platforms + return uint64(__rdtsc()); } #endif // NL_CPU_INTEL From 68aa20257fc8556330b2c08cfa76d7f2ab9fe68d Mon Sep 17 00:00:00 2001 From: kervala Date: Mon, 4 Jan 2016 15:39:31 +0100 Subject: [PATCH 3/5] Changed: Use new code to determine free disk space --HG-- branch : develop --- code/nel/include/nel/misc/system_info.h | 4 +- code/nel/src/misc/system_info.cpp | 56 ++++++++----------------- 2 files changed, 20 insertions(+), 40 deletions(-) diff --git a/code/nel/include/nel/misc/system_info.h b/code/nel/include/nel/misc/system_info.h index 4395277a1..747ff10d6 100644 --- a/code/nel/include/nel/misc/system_info.h +++ b/code/nel/include/nel/misc/system_info.h @@ -72,9 +72,9 @@ public: */ static bool isNT(); - /** Returns the space left on the hard drive that contains the filename + /** Returns the space left on the hard drive that contains the filename in bytes */ - static std::string availableHDSpace (const std::string &filename); + static uint64 availableHDSpace (const std::string &filename); /** Returns all the physical memory available on the computer (in bytes) */ diff --git a/code/nel/src/misc/system_info.cpp b/code/nel/src/misc/system_info.cpp index 0aa559e89..c891f97e2 100644 --- a/code/nel/src/misc/system_info.cpp +++ b/code/nel/src/misc/system_info.cpp @@ -34,6 +34,11 @@ # include # define nlcpuid(regs, idx) __cpuid(idx, regs[0], regs[1], regs[2], regs[3]) # endif // NL_CPU_INTEL +# ifdef NL_OS_MAC +# include +# else +# include +# endif #endif // NL_OS_WINDOWS #include "nel/misc/system_info.h" @@ -1118,49 +1123,24 @@ bool CSystemInfo::isNT() #endif } -string CSystemInfo::availableHDSpace (const string &filename) +uint64 CSystemInfo::availableHDSpace (const string &filename) { -#ifdef NL_OS_UNIX - string cmd = "df "; - if(filename.empty()) - cmd += "."; - else - cmd += filename; - cmd += " >/tmp/nelhdfs"; - sint error = system (cmd.c_str()); - if (error) - nlwarning("'%s' failed with error code %d", cmd.c_str(), error); - - int fd = open("/tmp/nelhdfs", O_RDONLY); - if (fd == -1) - { - return 0; - } - else - { - char buffer[4096+1]; - int len = read(fd, buffer, sizeof(buffer)-1); - close(fd); - buffer[len] = '\0'; - - vector splitted; - explode(string(buffer), string("\n"), splitted, true); + std::string path = CFile::getPath(filename); - if(splitted.size() < 2) - return "NoInfo"; - - vector sline; - explode(splitted[1], string(" "), sline, true); +#ifdef NL_OS_UNIX + struct stat stst; + struct statfs stfs; - if(sline.size() < 5) - return splitted[1]; + if (::stat(path.c_str(), &stst) == -1) return 0; + if (::statfs(c_str(), &stfs) == -1) return 0; - string space = sline[3] + "000"; - return bytesToHumanReadable(space); - } + return (uint64)(stfs.f_bavail * stst.st_blksize); #else - nlunreferenced(filename); - return "NoInfo"; + ULARGE_INTEGER freeSpace = {0}; + BOOL bRes = ::GetDiskFreeSpaceExA(path.c_str(), &freeSpace, NULL, NULL); + if (!bRes) return 0; + + return (uint64)freeSpace.QuadPart; #endif } From 9b8cdc282128b4145e7a4a6933c5662f882badff Mon Sep 17 00:00:00 2001 From: kervala Date: Mon, 4 Jan 2016 15:40:45 +0100 Subject: [PATCH 4/5] Changed: Use same _mm_getcsr and __cpuid intrinsics everywhere --HG-- branch : develop --- code/nel/src/misc/system_info.cpp | 85 ++----------------------------- 1 file changed, 5 insertions(+), 80 deletions(-) diff --git a/code/nel/src/misc/system_info.cpp b/code/nel/src/misc/system_info.cpp index c891f97e2..f621c4e68 100644 --- a/code/nel/src/misc/system_info.cpp +++ b/code/nel/src/misc/system_info.cpp @@ -955,19 +955,8 @@ static bool DetectSSE() // check OS support for SSE try { - #ifdef NL_OS_WINDOWS - #ifdef NL_NO_ASM unsigned int tmp = _mm_getcsr(); nlunreferenced(tmp); - #else - __asm - { - xorps xmm0, xmm0 // Streaming SIMD Extension - } - #endif // NL_NO_ASM - #elif NL_OS_UNIX - __asm__ __volatile__ ("xorps %xmm0, %xmm0;"); - #endif // NL_OS_UNIX } catch(...) { @@ -989,74 +978,10 @@ bool CSystemInfo::_HaveSSE = DetectSSE (); bool CSystemInfo::hasCPUID () { #ifdef NL_CPU_INTEL - uint32 result = 0; - #ifdef NL_OS_WINDOWS - #ifdef NL_NO_ASM - sint32 CPUInfo[4] = {-1}; - nlcpuid(CPUInfo, 0); - if (CPUInfo[3] != -1) result = 1; - #else - __asm - { - pushad - pushfd - // If ID bit of EFLAGS can change, then cpuid is available - pushfd - pop eax // Get EFLAG - mov ecx,eax - xor eax,0x200000 // Flip ID bit - push eax - popfd // Write EFLAGS - pushfd - pop eax // read back EFLAG - xor eax,ecx - je noCpuid // no flip -> no CPUID instr. - - popfd // restore state - popad - mov result, 1 - jmp CPUIDPresent - - noCpuid: - popfd // restore state - popad - mov result, 0 - CPUIDPresent: - } - #endif // NL_NO_ASM - #elif NL_OS_UNIX // NL_OS_WINDOWS - __asm__ __volatile__ ( - /* Save Register */ - "pushl %%ebp;" - "pushl %%ebx;" - "pushl %%edx;" - - /* Check if this CPU supports cpuid */ - "pushf;" - "pushf;" - "popl %%eax;" - "movl %%eax, %%ebx;" - "xorl $(1 << 21), %%eax;" // CPUID bit - "pushl %%eax;" - "popf;" - "pushf;" - "popl %%eax;" - "popf;" // Restore flags - "xorl %%ebx, %%eax;" - "jz NoCPUID;" - "movl $1, %0;" - "jmp CPUID;" - - "NoCPUID:;" - "movl $0, %0;" - "CPUID:;" - "popl %%edx;" - "popl %%ebx;" - "popl %%ebp;" - - :"=a"(result) - ); - #endif // NL_OS_UNIX + uint32 result = 0; + sint32 CPUInfo[4] = {-1}; + nlcpuid(CPUInfo, 0); + if (CPUInfo[3] != -1) result = 1; return result == 1; #else return false; @@ -1067,7 +992,7 @@ bool CSystemInfo::hasCPUID () uint32 CSystemInfo::getCPUID() { #ifdef NL_CPU_INTEL - if(hasCPUID()) + if (hasCPUID()) { uint32 result = 0; sint32 CPUInfo[4]; From 4d5be82f19e5b8292ac9ee4c21fbab1f205d284e Mon Sep 17 00:00:00 2001 From: kervala Date: Mon, 4 Jan 2016 15:40:56 +0100 Subject: [PATCH 5/5] Changed: Minor changes --HG-- branch : develop --- code/ryzom/CMakeLists.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/code/ryzom/CMakeLists.txt b/code/ryzom/CMakeLists.txt index 51b5134f7..3b955306f 100644 --- a/code/ryzom/CMakeLists.txt +++ b/code/ryzom/CMakeLists.txt @@ -1,8 +1,9 @@ #----------------------------------------------------------------------------- #Platform specifics -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/common/src ) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/common ) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/common/src) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/common) + SET(RZ_SERVER_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/server/src) ADD_SUBDIRECTORY(common) @@ -11,7 +12,7 @@ ADD_SUBDIRECTORY(tools) IF(WITH_RYZOM_CLIENT) IF(NOT WITH_GUI) MESSAGE( FATAL_ERROR "The client cannot be built without the NeL GUI Library (WITH_GUI)") - ENDIF(NOT WITH_GUI) + ENDIF() ADD_SUBDIRECTORY(client) ELSEIF(WITH_RYZOM_TOOLS) @@ -24,4 +25,4 @@ IF(WITH_RYZOM_SERVER OR WITH_RYZOM_TOOLS) # Need aishare for build wmap tool FIND_PACKAGE(MySQL REQUIRED) ADD_SUBDIRECTORY(server) -ENDIF(WITH_RYZOM_SERVER OR WITH_RYZOM_TOOLS) +ENDIF()