Removing PAL.

This commit is contained in:
Ben Vanik
2014-08-16 21:19:21 -07:00
parent 6cb9ca432f
commit fdab788017
15 changed files with 16 additions and 374 deletions

View File

@@ -1,37 +0,0 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef XENIA_CORE_PAL_H_
#define XENIA_CORE_PAL_H_
#include <xenia/common.h>
#include <xenia/core/ref.h>
typedef struct {
int reserved;
} xe_pal_options_t;
int xe_pal_init(xe_pal_options_t options);
typedef struct {
struct {
uint32_t physical_count;
uint32_t logical_count;
} processors;
} xe_system_info;
int xe_pal_get_system_info(xe_system_info* out_info);
double xe_pal_now();
#endif // XENIA_CORE_PAL_H_

View File

@@ -1,84 +0,0 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include <xenia/core/pal.h>
#include <CoreFoundation/CoreFoundation.h>
#include <asl.h>
#include <mach/mach_time.h>
#include <mach/kern_return.h>
#include <sys/types.h>
#include <sys/sysctl.h>
namespace {
typedef struct xe_pal_mac {
double time_to_sec;
} xe_pal_mac_t;
xe_pal_mac_t* pal;
}
void xe_pal_dealloc();
int xe_pal_init(xe_pal_options_t options) {
pal = (xe_pal_mac_t*)xe_calloc(sizeof(pal));
mach_timebase_info_data_t info;
mach_timebase_info(&info);
pal->time_to_sec = (double)((info.numer / info.denom) / 1000000000.0);
atexit(xe_pal_dealloc);
return 0;
}
void xe_pal_dealloc() {
//
xe_free(pal);
}
int xe_pal_get_system_info(xe_system_info* out_info) {
xe_zero_struct(out_info, sizeof(xe_system_info));
out_info->processors.physical_count = 1;
out_info->processors.logical_count = 1;
// http://geekinfo.googlecode.com/svn-history/r74/trunk/src/macosxsystem.cpp
int count;
size_t size = sizeof(int);
if (!sysctlbyname("hw.physicalcpu", &count, &size, NULL, 0)) {
out_info->processors.physical_count = count;
} else if (!sysctlbyname("hw.packages", &count, &size, NULL, 0)) {
out_info->processors.physical_count = count;
} else {
out_info->processors.physical_count = 1;
}
if (!sysctlbyname("hw.logicalcpu", &count, &size, NULL, 0)) {
out_info->processors.logical_count = count;
} else if (!sysctlbyname("hw.ncpu", &count, &size, NULL, 0)) {
out_info->processors.logical_count = count;
} else {
out_info->processors.logical_count = 1;
}
return 0;
}
double xe_pal_now() {
// According to a bunch of random posts, CACurrentMediaTime is a better call:
// https://devforums.apple.com/message/118806#118806
// CACurrentMediaTime is based on mach_absolute_time(), which doesn't have a
// dependency on QuartzCore:
// http://developer.apple.com/library/mac/#qa/qa2004/qa1398.html
// return (double)CFAbsoluteTimeGetCurrent();
// return (double)CACurrentMediaTime();
return (double)(mach_absolute_time() * pal->time_to_sec);
}

View File

@@ -1,62 +0,0 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include <xenia/core/pal.h>
namespace {
typedef struct xe_pal_posix {
} xe_pal_posix_t;
xe_pal_posix_t* pal;
}
void xe_pal_dealloc();
int xe_pal_init(xe_pal_options_t options) {
pal = (xe_pal_posix_t)xe_calloc(sizeof(pal));
//
atexit(xe_pal_dealloc);
return 0;
}
void xe_pal_dealloc() {
//
xe_free(pal);
}
int xe_pal_get_system_info(xe_system_info* out_info) {
xe_zero_struct(out_info, sizeof(xe_system_info));
out_info->processors.physical_count = 1;
out_info->processors.logical_count = 1;
#if defined(_SC_NPROCESSORS_ONLN)
int nproc = sysconf(_SC_NPROCESSORS_ONLN);
if (nproc >= 1) {
// Only able to get logical count.
sysInfo->processors.logicalCount = nproc;
}
#else
#warning no calls to get processor counts
#endif // _SC_NPROCESSORS_ONLN
return 0;
}
double xe_pal_now() {
// http://www.kernel.org/doc/man-pages/online/pages/man2/clock_gettime.2.html
// http://juliusdavies.ca/posix_clocks/clock_realtime_linux_faq.html
struct timespec ts;
CPIGNORE(clock_gettime(CLOCK_MONOTONIC, &ts));
return (double)(ts.tv_sec + (ts.tv_nsec * 1000000000.0));
}

View File

@@ -1,146 +0,0 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include <xenia/core/pal.h>
#include <algorithm>
namespace {
typedef struct xe_pal_win {
bool use_high_perf_timer;
double inv_ticks_per_sec;
} xe_pal_win_t;
xe_pal_win_t* pal;
}
void xe_pal_dealloc();
int xe_pal_init(xe_pal_options_t options) {
pal = (xe_pal_win_t*)xe_calloc(sizeof(xe_pal_win_t));
// Get QPC timing frequency... hopefully stable over the life of the app,
// but likely not.
// TODO(benvanik): requery periodically/etc.
LARGE_INTEGER ticks_per_sec;
if (QueryPerformanceFrequency(&ticks_per_sec)) {
pal->use_high_perf_timer = true;
pal->inv_ticks_per_sec = 1.0 / (double)ticks_per_sec.QuadPart;
} else {
pal->use_high_perf_timer = false;
XELOGW("Falling back from high performance timer");
}
// Setup COM on the main thread.
// NOTE: this may fail if COM has already been initialized - that's OK.
CoInitializeEx(NULL, COINIT_MULTITHREADED);
atexit(xe_pal_dealloc);
return 0;
}
void xe_pal_dealloc() {
//
xe_free(pal);
}
// http://msdn.microsoft.com/en-us/library/ms683194.aspx
namespace {
DWORD CountSetBits(ULONG_PTR bitMask) {
DWORD LSHIFT = sizeof(ULONG_PTR)*8 - 1;
DWORD bitSetCount = 0;
ULONG_PTR bitTest = (ULONG_PTR)1 << LSHIFT;
for (DWORD i = 0; i <= LSHIFT; ++i, bitTest /= 2) {
bitSetCount += ((bitMask & bitTest)?1:0);
}
return bitSetCount;
}
}
int xe_pal_get_system_info(xe_system_info* out_info) {
int result_code = 1;
xe_zero_struct(out_info, sizeof(xe_system_info));
out_info->processors.physical_count = 1;
out_info->processors.logical_count = 1;
typedef BOOL (WINAPI *LPFN_GLPI)(
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION, PDWORD);
HMODULE kernel32 = NULL;
LPFN_GLPI glpi = NULL;
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer = NULL;
kernel32 = GetModuleHandle(L"kernel32");
XEEXPECTNOTNULL(kernel32);
glpi = (LPFN_GLPI)GetProcAddress(kernel32, "GetLogicalProcessorInformation");
XEEXPECTNOTNULL(glpi);
// Call GLPI once to get the buffer size, allocate it, then call again.
DWORD buffer_length = 0;
XEEXPECTFALSE(glpi(NULL, &buffer_length));
XEEXPECT(GetLastError() == ERROR_INSUFFICIENT_BUFFER);
buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)xe_malloc(buffer_length);
XEEXPECTNOTNULL(buffer);
XEEXPECTTRUE(glpi(buffer, &buffer_length));
XEEXPECTNOTZERO(buffer_length);
out_info->processors.physical_count = 0;
out_info->processors.logical_count = 0;
size_t info_count = buffer_length /
sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
for (size_t n = 0; n < info_count; n++) {
switch (buffer[n].Relationship) {
case RelationProcessorPackage:
out_info->processors.physical_count++;
break;
case RelationProcessorCore:
if (buffer[n].ProcessorCore.Flags == 1) {
// Hyper-threaded.
// The number of processors is set as bits in ProcessorMask.
out_info->processors.logical_count +=
CountSetBits(buffer[n].ProcessorMask);
} else {
// A real core - just count as one.
out_info->processors.logical_count++;
}
break;
}
}
out_info->processors.physical_count =
std::max(1u, out_info->processors.physical_count);
out_info->processors.logical_count =
std::max(1u, out_info->processors.logical_count);
result_code = 0;
XECLEANUP:
xe_free(buffer);
if (kernel32) {
FreeLibrary(kernel32);
}
return result_code;
}
double xe_pal_now() {
if (pal->use_high_perf_timer) {
LARGE_INTEGER counter;
QueryPerformanceCounter(&counter);
return counter.QuadPart * pal->inv_ticks_per_sec;
} else {
// Using GetSystemTimeAsFileTime instead of GetSystemTime() as it has a
// 100ns resolution.
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
ULARGE_INTEGER uli;
uli.LowPart = ft.dwLowDateTime;
uli.HighPart = ft.dwHighDateTime;
return uli.QuadPart / 10000000.0;
}
}

View File

@@ -4,7 +4,6 @@
'hash.cc',
'hash.h',
'mmap.h',
'pal.h',
'ref.cc',
'ref.h',
'run_loop.h',
@@ -20,18 +19,15 @@
}],
['OS == "linux"', {
'sources': [
'pal_posix.cc',
],
}],
['OS == "mac"', {
'sources': [
'pal_mac.cc',
],
}],
['OS == "win"', {
'sources': [
'mmap_win.cc',
'pal_win.cc',
'run_loop_win.cc',
'socket_win.cc',
],