diff --git a/docs/windows.txt b/docs/windows.txt index 1cabfe24724..6ea0351f698 100644 --- a/docs/windows.txt +++ b/docs/windows.txt @@ -43,7 +43,13 @@ Windows performance options window and all DirectDraw/Direct3D code to execute on a second thread, which can improve performance on hyperthreaded and multicore systems. The default is OFF (-nomultithreading). - + +-numprocessors + Specify the number of processors to use for work queues. Specifying + "auto" will use the value reported by the system or environment + variable OSDPROCESSORS. To avoid abuse, this value is internally limited + to 4 times the number of processors reported by the system. + The default is "auto". Windows video options diff --git a/src/osd/windows/winmain.c b/src/osd/windows/winmain.c index 735b4ba984a..0b9b25ad47a 100644 --- a/src/osd/windows/winmain.c +++ b/src/osd/windows/winmain.c @@ -165,6 +165,7 @@ const options_entry mame_win_options[] = { NULL, NULL, OPTION_HEADER, "WINDOWS PERFORMANCE OPTIONS" }, { "priority(-15-1)", "0", 0, "thread priority for the main game thread; range from -15 to 1" }, { "multithreading;mt", "0", OPTION_BOOLEAN, "enable multithreading; this enables rendering and blitting on a separate thread" }, + { "numprocessors;np", "auto", 0, "number of processors; this overrides the number the system reports" }, // video options { NULL, NULL, OPTION_HEADER, "WINDOWS VIDEO OPTIONS" }, @@ -309,6 +310,7 @@ static void output_oslog(running_machine *machine, const char *buffer) void osd_init(running_machine *machine) { int watchdog = options_get_int(mame_options(), WINOPTION_WATCHDOG); + const char *stemp; // thread priority if (!options_get_bool(mame_options(), OPTION_DEBUG)) @@ -317,6 +319,21 @@ void osd_init(running_machine *machine) // ensure we get called on the way out add_exit_callback(machine, osd_exit); + // get number of processors + stemp = options_get_string(mame_options(), WINOPTION_NUMPROCESSORS); + + osd_num_processors = 0; + + if (strcmp(stemp, "auto") != 0) + { + osd_num_processors = atoi(stemp); + if (osd_num_processors < 1) + { + mame_printf_warning("Warning: numprocessors < 1 doesn't make much sense. Assuming auto ...\n"); + osd_num_processors = 0; + } + } + // initialize the subsystems winvideo_init(machine); winsound_init(machine); diff --git a/src/osd/windows/winmain.h b/src/osd/windows/winmain.h index 2cf5180369a..9f788ac93b8 100644 --- a/src/osd/windows/winmain.h +++ b/src/osd/windows/winmain.h @@ -53,6 +53,7 @@ // performance options #define WINOPTION_PRIORITY "priority" #define WINOPTION_MULTITHREADING "multithreading" +#define WINOPTION_NUMPROCESSORS "numprocessors" // video options #define WINOPTION_VIDEO "video" @@ -131,6 +132,8 @@ extern const options_entry mame_win_options[]; +// defined in winwork.c +extern int osd_num_processors; //============================================================ diff --git a/src/osd/windows/winwork.c b/src/osd/windows/winwork.c index b9416db39fc..7c827d3a31f 100644 --- a/src/osd/windows/winwork.c +++ b/src/osd/windows/winwork.c @@ -174,7 +174,11 @@ struct _osd_work_item volatile INT32 done; // is the item done? }; +//============================================================ +// GLOBAL VARIABLES +//============================================================ +int osd_num_processors = 0; //============================================================ // FUNCTION PROTOTYPES @@ -677,20 +681,28 @@ void osd_work_item_release(osd_work_item *item) static int effective_num_processors(void) { - TCHAR *procsoverride; SYSTEM_INFO info; - int numprocs = 0; - - // if the OSDPROCESSORS environment variable is set, use that value if valid - procsoverride = _tgetenv(_T("OSDPROCESSORS")); - if (procsoverride != NULL && _stscanf(procsoverride, _T("%d"), &numprocs) == 1 && numprocs > 0) - return numprocs; - - // otherwise, fetch the info from the system + // 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); + if (osd_num_processors > 0) + { + return MIN(info.dwNumberOfProcessors * 4, osd_num_processors); + } + else + { + TCHAR *procsoverride; + int numprocs = 0; + + // if the OSDPROCESSORS environment variable is set, use that value if valid + procsoverride = _tgetenv(_T("OSDPROCESSORS")); + if (procsoverride != NULL && _stscanf(procsoverride, _T("%d"), &numprocs) == 1 && numprocs > 0) + // Be well behaved ... + return MIN(info.dwNumberOfProcessors * 4, numprocs); + + // max out at 4 for now since scaling above that seems to do poorly + return MIN(info.dwNumberOfProcessors, 4); + } }