trunk/src/osd/windows/winwork.c
| r32109 | r32110 | |
| 21 | 21 | #include "osdcore.h" |
| 22 | 22 | |
| 23 | 23 | #include "winsync.h" |
| 24 | #include "winos.h" |
| 24 | 25 | |
| 25 | 26 | #include "eminline.h" |
| 26 | 27 | |
| r32109 | r32110 | |
| 35 | 36 | // PARAMETERS |
| 36 | 37 | //============================================================ |
| 37 | 38 | |
| 39 | #define ENV_PROCESSORS "OSDPROCESSORS" |
| 40 | #define ENV_WORKQUEUEMAXTHREADS "OSDWORKQUEUEMAXTHREADS" |
| 41 | |
| 38 | 42 | #define SPIN_LOOP_TIME (osd_ticks_per_second() / 1000) |
| 39 | 43 | |
| 40 | 44 | |
| r32109 | r32110 | |
| 156 | 160 | int numprocs = effective_num_processors(); |
| 157 | 161 | osd_work_queue *queue; |
| 158 | 162 | int threadnum; |
| 159 | | TCHAR *osdworkqueuemaxthreads = _tgetenv(_T("OSDWORKQUEUEMAXTHREADS")); |
| 163 | char *osdworkqueuemaxthreads = osd_getenv("OSDWORKQUEUEMAXTHREADS"); |
| 160 | 164 | |
| 161 | 165 | // allocate a new queue |
| 162 | 166 | queue = (osd_work_queue *)osd_malloc(sizeof(*queue)); |
| r32109 | r32110 | |
| 187 | 191 | else |
| 188 | 192 | queue->threads = (flags & WORK_QUEUE_FLAG_MULTI) ? numprocs : 1; |
| 189 | 193 | |
| 190 | | if (osdworkqueuemaxthreads != NULL && _stscanf(osdworkqueuemaxthreads, _T("%d"), &threadnum) == 1 && queue->threads > threadnum) |
| 194 | if (osdworkqueuemaxthreads != NULL && sscanf(osdworkqueuemaxthreads, "%d", &threadnum) == 1 && queue->threads > threadnum) |
| 191 | 195 | queue->threads = threadnum; |
| 192 | 196 | |
| 193 | 197 | // multi-queues with high frequency items should top out at 4 for now |
| r32109 | r32110 | |
| 349 | 353 | { |
| 350 | 354 | work_thread_info *thread = &queue->thread[threadnum]; |
| 351 | 355 | osd_ticks_t total = thread->runtime + thread->waittime + thread->spintime; |
| 352 | | printf("Thread %d: items=%9d run=%5.2f%% (%5.2f%%) spin=%5.2f%% wait/other=%5.2f%%\n", |
| 356 | printf("Thread %d: items=%9d run=%5.2f%% (%5.2f%%) spin=%5.2f%% wait/other=%5.2f%% total=%9d\n", |
| 353 | 357 | threadnum, thread->itemsdone, |
| 354 | 358 | (double)thread->runtime * 100.0 / (double)total, |
| 355 | 359 | (double)thread->actruntime * 100.0 / (double)total, |
| 356 | 360 | (double)thread->spintime * 100.0 / (double)total, |
| 357 | | (double)thread->waittime * 100.0 / (double)total); |
| 361 | (double)thread->waittime * 100.0 / (double)total, |
| 362 | (UINT32) total); |
| 358 | 363 | } |
| 359 | 364 | #endif |
| 360 | 365 | } |
| r32109 | r32110 | |
| 559 | 564 | |
| 560 | 565 | static int effective_num_processors(void) |
| 561 | 566 | { |
| 562 | | SYSTEM_INFO info; |
| 563 | | // fetch the info from the system |
| 564 | | GetSystemInfo(&info); |
| 567 | int physprocs = osd_get_num_processors(); |
| 565 | 568 | |
| 569 | // osd_num_processors == 0 for 'auto' |
| 566 | 570 | if (osd_num_processors > 0) |
| 567 | 571 | { |
| 568 | | return MIN(info.dwNumberOfProcessors * 4, osd_num_processors); |
| 572 | return MIN(4 * physprocs, osd_num_processors); |
| 569 | 573 | } |
| 570 | 574 | else |
| 571 | 575 | { |
| 572 | | TCHAR *procsoverride; |
| 576 | char *procsoverride; |
| 573 | 577 | int numprocs = 0; |
| 574 | 578 | |
| 575 | 579 | // if the OSDPROCESSORS environment variable is set, use that value if valid |
| 576 | 580 | // note that we permit more than the real number of processors for testing |
| 577 | | procsoverride = _tgetenv(_T("OSDPROCESSORS")); |
| 578 | | if (procsoverride != NULL && _stscanf(procsoverride, _T("%d"), &numprocs) == 1 && numprocs > 0) |
| 579 | | return MIN(info.dwNumberOfProcessors * 4, numprocs); |
| 581 | procsoverride = osd_getenv(ENV_PROCESSORS); |
| 582 | if (procsoverride != NULL && sscanf(procsoverride, "%d", &numprocs) == 1 && numprocs > 0) |
| 583 | return MIN(4 * physprocs, numprocs); |
| 580 | 584 | |
| 581 | | return info.dwNumberOfProcessors; |
| 585 | // otherwise, return the info from the system |
| 586 | return physprocs; |
| 582 | 587 | } |
| 583 | 588 | } |
| 584 | 589 | |
trunk/src/osd/windows/winos.c
| r0 | r32110 | |
| 1 | //============================================================ |
| 2 | // |
| 3 | // winos.c - Win32 OS specific low level code |
| 4 | // |
| 5 | //============================================================ |
| 6 | |
| 7 | #define WIN32_LEAN_AND_MEAN |
| 8 | #include <windows.h> |
| 9 | |
| 10 | // MAME headers |
| 11 | #include "osdcore.h" |
| 12 | |
| 13 | //============================================================ |
| 14 | // osd_num_processors |
| 15 | //============================================================ |
| 16 | |
| 17 | int osd_get_num_processors(void) |
| 18 | { |
| 19 | SYSTEM_INFO info; |
| 20 | |
| 21 | // otherwise, fetch the info from the system |
| 22 | GetSystemInfo(&info); |
| 23 | |
| 24 | // max out at 4 for now since scaling above that seems to do poorly |
| 25 | return MIN(info.dwNumberOfProcessors, 4); |
| 26 | } |
| 27 | |
| 28 | //============================================================ |
| 29 | // osd_getenv |
| 30 | //============================================================ |
| 31 | |
| 32 | char *osd_getenv(const char *name) |
| 33 | { |
| 34 | return getenv(name); |
| 35 | } |
| | No newline at end of file |
trunk/src/osd/windows/winos.h
| r0 | r32110 | |
| 1 | //============================================================ |
| 2 | // |
| 3 | // winos.h - Win32 OS specific low level code |
| 4 | // |
| 5 | //============================================================ |
| 6 | |
| 7 | /*----------------------------------------------------------------------------- |
| 8 | osd_num_processors: return the number of processors |
| 9 | |
| 10 | Parameters: |
| 11 | |
| 12 | None. |
| 13 | |
| 14 | Return value: |
| 15 | |
| 16 | Number of processors |
| 17 | -----------------------------------------------------------------------------*/ |
| 18 | int osd_get_num_processors(void); |
| 19 | |
| 20 | |
| 21 | /*----------------------------------------------------------------------------- |
| 22 | osd_getenv: return pointer to environment variable |
| 23 | |
| 24 | Parameters: |
| 25 | |
| 26 | name - name of environment variable |
| 27 | |
| 28 | Return value: |
| 29 | |
| 30 | pointer to value |
| 31 | -----------------------------------------------------------------------------*/ |
| 32 | char *osd_getenv(const char *name); |
| | No newline at end of file |
trunk/src/osd/sdl/sdlos_win32.c
| r32109 | r32110 | |
| 20 | 20 | #include "osdcore.h" |
| 21 | 21 | #include "strconv.h" |
| 22 | 22 | |
| 23 | #include "../windows/winos.c" |
| 24 | |
| 23 | 25 | //============================================================ |
| 24 | 26 | // PROTOTYPES |
| 25 | 27 | //============================================================ |
| r32109 | r32110 | |
| 158 | 160 | } |
| 159 | 161 | |
| 160 | 162 | //============================================================ |
| 161 | | // osd_num_processors |
| 162 | | //============================================================ |
| 163 | | |
| 164 | | int osd_get_num_processors(void) |
| 165 | | { |
| 166 | | SYSTEM_INFO info; |
| 167 | | |
| 168 | | // otherwise, fetch the info from the system |
| 169 | | GetSystemInfo(&info); |
| 170 | | |
| 171 | | // max out at 4 for now since scaling above that seems to do poorly |
| 172 | | return MIN(info.dwNumberOfProcessors, 4); |
| 173 | | } |
| 174 | | |
| 175 | | //============================================================ |
| 176 | 163 | // osd_malloc |
| 177 | 164 | //============================================================ |
| 178 | 165 | |
| r32109 | r32110 | |
| 254 | 241 | } |
| 255 | 242 | |
| 256 | 243 | //============================================================ |
| 257 | | // osd_getenv |
| 258 | | //============================================================ |
| 259 | | |
| 260 | | char *osd_getenv(const char *name) |
| 261 | | { |
| 262 | | return getenv(name); |
| 263 | | } |
| 264 | | |
| 265 | | //============================================================ |
| 266 | 244 | // osd_setenv |
| 267 | 245 | //============================================================ |
| 268 | 246 | |
trunk/src/osd/sdl/sdlwork.c
| r32109 | r32110 | |
| 44 | 44 | // PARAMETERS |
| 45 | 45 | //============================================================ |
| 46 | 46 | |
| 47 | | #define SDLENV_PROCESSORS "OSDPROCESSORS" |
| 48 | | #define SDLENV_CPUMASKS "OSDCPUMASKS" |
| 47 | #define ENV_PROCESSORS "OSDPROCESSORS" |
| 48 | #define ENV_CPUMASKS "OSDCPUMASKS" |
| 49 | #define ENV_WORKQUEUEMAXTHREADS "OSDWORKQUEUEMAXTHREADS" |
| 49 | 50 | |
| 50 | 51 | #define INFINITE (osd_ticks_per_second() * (osd_ticks_t) 10000) |
| 51 | 52 | #define SPIN_LOOP_TIME (osd_ticks_per_second() / 10000) |
| r32109 | r32110 | |
| 151 | 152 | int numprocs = effective_num_processors(); |
| 152 | 153 | osd_work_queue *queue; |
| 153 | 154 | int threadnum; |
| 155 | char *osdworkqueuemaxthreads = osd_getenv("OSDWORKQUEUEMAXTHREADS"); |
| 154 | 156 | |
| 155 | 157 | // allocate a new queue |
| 156 | 158 | queue = (osd_work_queue *)osd_malloc(sizeof(*queue)); |
| r32109 | r32110 | |
| 181 | 183 | else |
| 182 | 184 | queue->threads = (flags & WORK_QUEUE_FLAG_MULTI) ? (numprocs - 1) : 1; |
| 183 | 185 | |
| 186 | if (osdworkqueuemaxthreads != NULL && sscanf(osdworkqueuemaxthreads, "%d", &threadnum) == 1 && queue->threads > threadnum) |
| 187 | queue->threads = threadnum; |
| 188 | |
| 189 | |
| 184 | 190 | // clamp to the maximum |
| 185 | 191 | queue->threads = MIN(queue->threads, WORK_MAX_THREADS); |
| 186 | 192 | |
| r32109 | r32110 | |
| 564 | 570 | |
| 565 | 571 | static int effective_num_processors(void) |
| 566 | 572 | { |
| 567 | | char *procsoverride; |
| 568 | | int numprocs = 0; |
| 569 | 573 | int physprocs = osd_get_num_processors(); |
| 570 | 574 | |
| 571 | 575 | // osd_num_processors == 0 for 'auto' |
| 572 | 576 | if (osd_num_processors > 0) |
| 577 | { |
| 573 | 578 | return MIN(4 * physprocs, osd_num_processors); |
| 579 | } |
| 574 | 580 | else |
| 575 | 581 | { |
| 582 | char *procsoverride; |
| 583 | int numprocs = 0; |
| 584 | |
| 576 | 585 | // if the OSDPROCESSORS environment variable is set, use that value if valid |
| 577 | | procsoverride = osd_getenv(SDLENV_PROCESSORS); |
| 586 | // note that we permit more than the real number of processors for testing |
| 587 | procsoverride = osd_getenv(ENV_PROCESSORS); |
| 578 | 588 | if (procsoverride != NULL && sscanf(procsoverride, "%d", &numprocs) == 1 && numprocs > 0) |
| 579 | 589 | return MIN(4 * physprocs, numprocs); |
| 580 | 590 | |
| r32109 | r32110 | |
| 593 | 603 | char buf[5]; |
| 594 | 604 | UINT32 mask = 0xFFFF; |
| 595 | 605 | |
| 596 | | s = osd_getenv(SDLENV_CPUMASKS); |
| 606 | s = osd_getenv(ENV_CPUMASKS); |
| 597 | 607 | if (s != NULL && strcmp(s,"none")) |
| 598 | 608 | { |
| 599 | 609 | if (!strcmp(s,"auto")) |