mirror of
https://github.com/holub/mame
synced 2025-06-29 23:48:56 +03:00
more sdlwork.c and winwork.c consolidation / SDL now supports envrionment variable OSDWORKQUEUEMAXTHREADS (nw)
This commit is contained in:
parent
f4d61505ee
commit
1a610ff531
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -9552,6 +9552,8 @@ src/osd/windows/winmain.c svneol=native#text/plain
|
||||
src/osd/windows/winmain.h svneol=native#text/plain
|
||||
src/osd/windows/winmenu.c svneol=native#text/plain
|
||||
src/osd/windows/winmisc.c svneol=native#text/plain
|
||||
src/osd/windows/winos.c svneol=native#text/plain
|
||||
src/osd/windows/winos.h svneol=native#text/plain
|
||||
src/osd/windows/winprefix.h svneol=native#text/plain
|
||||
src/osd/windows/winptty.c svneol=native#text/plain
|
||||
src/osd/windows/winsocket.c svneol=native#text/plain
|
||||
|
@ -20,6 +20,8 @@
|
||||
#include "osdcore.h"
|
||||
#include "strconv.h"
|
||||
|
||||
#include "../windows/winos.c"
|
||||
|
||||
//============================================================
|
||||
// PROTOTYPES
|
||||
//============================================================
|
||||
@ -157,21 +159,6 @@ void osd_sleep(osd_ticks_t duration)
|
||||
}
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// osd_num_processors
|
||||
//============================================================
|
||||
|
||||
int osd_get_num_processors(void)
|
||||
{
|
||||
SYSTEM_INFO info;
|
||||
|
||||
// otherwise, fetch the info from the system
|
||||
GetSystemInfo(&info);
|
||||
|
||||
// max out at 4 for now since scaling above that seems to do poorly
|
||||
return MIN(info.dwNumberOfProcessors, 4);
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// osd_malloc
|
||||
//============================================================
|
||||
@ -253,15 +240,6 @@ void osd_free(void *ptr)
|
||||
#endif
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// osd_getenv
|
||||
//============================================================
|
||||
|
||||
char *osd_getenv(const char *name)
|
||||
{
|
||||
return getenv(name);
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// osd_setenv
|
||||
//============================================================
|
||||
|
@ -44,8 +44,9 @@ int osd_num_processors = 0;
|
||||
// PARAMETERS
|
||||
//============================================================
|
||||
|
||||
#define SDLENV_PROCESSORS "OSDPROCESSORS"
|
||||
#define SDLENV_CPUMASKS "OSDCPUMASKS"
|
||||
#define ENV_PROCESSORS "OSDPROCESSORS"
|
||||
#define ENV_CPUMASKS "OSDCPUMASKS"
|
||||
#define ENV_WORKQUEUEMAXTHREADS "OSDWORKQUEUEMAXTHREADS"
|
||||
|
||||
#define INFINITE (osd_ticks_per_second() * (osd_ticks_t) 10000)
|
||||
#define SPIN_LOOP_TIME (osd_ticks_per_second() / 10000)
|
||||
@ -151,6 +152,7 @@ osd_work_queue *osd_work_queue_alloc(int flags)
|
||||
int numprocs = effective_num_processors();
|
||||
osd_work_queue *queue;
|
||||
int threadnum;
|
||||
char *osdworkqueuemaxthreads = osd_getenv("OSDWORKQUEUEMAXTHREADS");
|
||||
|
||||
// allocate a new queue
|
||||
queue = (osd_work_queue *)osd_malloc(sizeof(*queue));
|
||||
@ -181,6 +183,10 @@ osd_work_queue *osd_work_queue_alloc(int flags)
|
||||
else
|
||||
queue->threads = (flags & WORK_QUEUE_FLAG_MULTI) ? (numprocs - 1) : 1;
|
||||
|
||||
if (osdworkqueuemaxthreads != NULL && sscanf(osdworkqueuemaxthreads, "%d", &threadnum) == 1 && queue->threads > threadnum)
|
||||
queue->threads = threadnum;
|
||||
|
||||
|
||||
// clamp to the maximum
|
||||
queue->threads = MIN(queue->threads, WORK_MAX_THREADS);
|
||||
|
||||
@ -564,17 +570,21 @@ void osd_work_item_release(osd_work_item *item)
|
||||
|
||||
static int effective_num_processors(void)
|
||||
{
|
||||
char *procsoverride;
|
||||
int numprocs = 0;
|
||||
int physprocs = osd_get_num_processors();
|
||||
|
||||
// osd_num_processors == 0 for 'auto'
|
||||
if (osd_num_processors > 0)
|
||||
{
|
||||
return MIN(4 * physprocs, osd_num_processors);
|
||||
}
|
||||
else
|
||||
{
|
||||
char *procsoverride;
|
||||
int numprocs = 0;
|
||||
|
||||
// if the OSDPROCESSORS environment variable is set, use that value if valid
|
||||
procsoverride = osd_getenv(SDLENV_PROCESSORS);
|
||||
// note that we permit more than the real number of processors for testing
|
||||
procsoverride = osd_getenv(ENV_PROCESSORS);
|
||||
if (procsoverride != NULL && sscanf(procsoverride, "%d", &numprocs) == 1 && numprocs > 0)
|
||||
return MIN(4 * physprocs, numprocs);
|
||||
|
||||
@ -593,7 +603,7 @@ static UINT32 effective_cpu_mask(int index)
|
||||
char buf[5];
|
||||
UINT32 mask = 0xFFFF;
|
||||
|
||||
s = osd_getenv(SDLENV_CPUMASKS);
|
||||
s = osd_getenv(ENV_CPUMASKS);
|
||||
if (s != NULL && strcmp(s,"none"))
|
||||
{
|
||||
if (!strcmp(s,"auto"))
|
||||
|
@ -340,6 +340,7 @@ OSDCOREOBJS = \
|
||||
$(WINOBJ)/winsocket.o \
|
||||
$(WINOBJ)/winwork.o \
|
||||
$(WINOBJ)/winptty.o \
|
||||
$(WINOBJ)/winos.o \
|
||||
|
||||
|
||||
#-------------------------------------------------
|
||||
|
35
src/osd/windows/winos.c
Normal file
35
src/osd/windows/winos.c
Normal file
@ -0,0 +1,35 @@
|
||||
//============================================================
|
||||
//
|
||||
// winos.c - Win32 OS specific low level code
|
||||
//
|
||||
//============================================================
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
// MAME headers
|
||||
#include "osdcore.h"
|
||||
|
||||
//============================================================
|
||||
// osd_num_processors
|
||||
//============================================================
|
||||
|
||||
int osd_get_num_processors(void)
|
||||
{
|
||||
SYSTEM_INFO info;
|
||||
|
||||
// otherwise, fetch the info from the system
|
||||
GetSystemInfo(&info);
|
||||
|
||||
// max out at 4 for now since scaling above that seems to do poorly
|
||||
return MIN(info.dwNumberOfProcessors, 4);
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// osd_getenv
|
||||
//============================================================
|
||||
|
||||
char *osd_getenv(const char *name)
|
||||
{
|
||||
return getenv(name);
|
||||
}
|
32
src/osd/windows/winos.h
Normal file
32
src/osd/windows/winos.h
Normal file
@ -0,0 +1,32 @@
|
||||
//============================================================
|
||||
//
|
||||
// winos.h - Win32 OS specific low level code
|
||||
//
|
||||
//============================================================
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
osd_num_processors: return the number of processors
|
||||
|
||||
Parameters:
|
||||
|
||||
None.
|
||||
|
||||
Return value:
|
||||
|
||||
Number of processors
|
||||
-----------------------------------------------------------------------------*/
|
||||
int osd_get_num_processors(void);
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
osd_getenv: return pointer to environment variable
|
||||
|
||||
Parameters:
|
||||
|
||||
name - name of environment variable
|
||||
|
||||
Return value:
|
||||
|
||||
pointer to value
|
||||
-----------------------------------------------------------------------------*/
|
||||
char *osd_getenv(const char *name);
|
@ -21,6 +21,7 @@
|
||||
#include "osdcore.h"
|
||||
|
||||
#include "winsync.h"
|
||||
#include "winos.h"
|
||||
|
||||
#include "eminline.h"
|
||||
|
||||
@ -35,6 +36,9 @@
|
||||
// PARAMETERS
|
||||
//============================================================
|
||||
|
||||
#define ENV_PROCESSORS "OSDPROCESSORS"
|
||||
#define ENV_WORKQUEUEMAXTHREADS "OSDWORKQUEUEMAXTHREADS"
|
||||
|
||||
#define SPIN_LOOP_TIME (osd_ticks_per_second() / 1000)
|
||||
|
||||
|
||||
@ -156,7 +160,7 @@ osd_work_queue *osd_work_queue_alloc(int flags)
|
||||
int numprocs = effective_num_processors();
|
||||
osd_work_queue *queue;
|
||||
int threadnum;
|
||||
TCHAR *osdworkqueuemaxthreads = _tgetenv(_T("OSDWORKQUEUEMAXTHREADS"));
|
||||
char *osdworkqueuemaxthreads = osd_getenv("OSDWORKQUEUEMAXTHREADS");
|
||||
|
||||
// allocate a new queue
|
||||
queue = (osd_work_queue *)osd_malloc(sizeof(*queue));
|
||||
@ -187,7 +191,7 @@ osd_work_queue *osd_work_queue_alloc(int flags)
|
||||
else
|
||||
queue->threads = (flags & WORK_QUEUE_FLAG_MULTI) ? numprocs : 1;
|
||||
|
||||
if (osdworkqueuemaxthreads != NULL && _stscanf(osdworkqueuemaxthreads, _T("%d"), &threadnum) == 1 && queue->threads > threadnum)
|
||||
if (osdworkqueuemaxthreads != NULL && sscanf(osdworkqueuemaxthreads, "%d", &threadnum) == 1 && queue->threads > threadnum)
|
||||
queue->threads = threadnum;
|
||||
|
||||
// multi-queues with high frequency items should top out at 4 for now
|
||||
@ -349,12 +353,13 @@ void osd_work_queue_free(osd_work_queue *queue)
|
||||
{
|
||||
work_thread_info *thread = &queue->thread[threadnum];
|
||||
osd_ticks_t total = thread->runtime + thread->waittime + thread->spintime;
|
||||
printf("Thread %d: items=%9d run=%5.2f%% (%5.2f%%) spin=%5.2f%% wait/other=%5.2f%%\n",
|
||||
printf("Thread %d: items=%9d run=%5.2f%% (%5.2f%%) spin=%5.2f%% wait/other=%5.2f%% total=%9d\n",
|
||||
threadnum, thread->itemsdone,
|
||||
(double)thread->runtime * 100.0 / (double)total,
|
||||
(double)thread->actruntime * 100.0 / (double)total,
|
||||
(double)thread->spintime * 100.0 / (double)total,
|
||||
(double)thread->waittime * 100.0 / (double)total);
|
||||
(double)thread->waittime * 100.0 / (double)total,
|
||||
(UINT32) total);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -559,26 +564,26 @@ void osd_work_item_release(osd_work_item *item)
|
||||
|
||||
static int effective_num_processors(void)
|
||||
{
|
||||
SYSTEM_INFO info;
|
||||
// fetch the info from the system
|
||||
GetSystemInfo(&info);
|
||||
int physprocs = osd_get_num_processors();
|
||||
|
||||
// osd_num_processors == 0 for 'auto'
|
||||
if (osd_num_processors > 0)
|
||||
{
|
||||
return MIN(info.dwNumberOfProcessors * 4, osd_num_processors);
|
||||
return MIN(4 * physprocs, osd_num_processors);
|
||||
}
|
||||
else
|
||||
{
|
||||
TCHAR *procsoverride;
|
||||
char *procsoverride;
|
||||
int numprocs = 0;
|
||||
|
||||
// if the OSDPROCESSORS environment variable is set, use that value if valid
|
||||
// note that we permit more than the real number of processors for testing
|
||||
procsoverride = _tgetenv(_T("OSDPROCESSORS"));
|
||||
if (procsoverride != NULL && _stscanf(procsoverride, _T("%d"), &numprocs) == 1 && numprocs > 0)
|
||||
return MIN(info.dwNumberOfProcessors * 4, numprocs);
|
||||
procsoverride = osd_getenv(ENV_PROCESSORS);
|
||||
if (procsoverride != NULL && sscanf(procsoverride, "%d", &numprocs) == 1 && numprocs > 0)
|
||||
return MIN(4 * physprocs, numprocs);
|
||||
|
||||
return info.dwNumberOfProcessors;
|
||||
// otherwise, return the info from the system
|
||||
return physprocs;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user