Previous 199869 Revisions Next

r32110 Saturday 13th September, 2014 at 19:59:51 UTC by Oliver Stöneberg
more sdlwork.c and winwork.c consolidation / SDL now supports envrionment variable OSDWORKQUEUEMAXTHREADS (nw)
[src/osd/sdl]sdlos_win32.c sdlwork.c
[src/osd/windows]windows.mak winos.c* winos.h* winwork.c

trunk/src/osd/windows/windows.mak
r32109r32110
340340   $(WINOBJ)/winsocket.o \
341341   $(WINOBJ)/winwork.o \
342342   $(WINOBJ)/winptty.o \
343   $(WINOBJ)/winos.o \
343344
344345
345346#-------------------------------------------------
trunk/src/osd/windows/winwork.c
r32109r32110
2121#include "osdcore.h"
2222
2323#include "winsync.h"
24#include "winos.h"
2425
2526#include "eminline.h"
2627
r32109r32110
3536//  PARAMETERS
3637//============================================================
3738
39#define ENV_PROCESSORS               "OSDPROCESSORS"
40#define ENV_WORKQUEUEMAXTHREADS      "OSDWORKQUEUEMAXTHREADS"
41
3842#define SPIN_LOOP_TIME          (osd_ticks_per_second() / 1000)
3943
4044
r32109r32110
156160   int numprocs = effective_num_processors();
157161   osd_work_queue *queue;
158162   int threadnum;
159   TCHAR *osdworkqueuemaxthreads = _tgetenv(_T("OSDWORKQUEUEMAXTHREADS"));
163   char *osdworkqueuemaxthreads = osd_getenv("OSDWORKQUEUEMAXTHREADS");
160164
161165   // allocate a new queue
162166   queue = (osd_work_queue *)osd_malloc(sizeof(*queue));
r32109r32110
187191   else
188192      queue->threads = (flags & WORK_QUEUE_FLAG_MULTI) ? numprocs : 1;
189193
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)
191195      queue->threads = threadnum;
192196
193197   // multi-queues with high frequency items should top out at 4 for now
r32109r32110
349353      {
350354         work_thread_info *thread = &queue->thread[threadnum];
351355         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",
353357               threadnum, thread->itemsdone,
354358               (double)thread->runtime * 100.0 / (double)total,
355359               (double)thread->actruntime * 100.0 / (double)total,
356360               (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);
358363      }
359364#endif
360365   }
r32109r32110
559564
560565static int effective_num_processors(void)
561566{
562   SYSTEM_INFO info;
563   // fetch the info from the system
564   GetSystemInfo(&info);
567   int physprocs = osd_get_num_processors();
565568
569   // osd_num_processors == 0 for 'auto'
566570   if (osd_num_processors > 0)
567571   {
568      return MIN(info.dwNumberOfProcessors * 4, osd_num_processors);
572      return MIN(4 * physprocs, osd_num_processors);
569573   }
570574   else
571575   {
572      TCHAR *procsoverride;
576      char *procsoverride;
573577      int numprocs = 0;
574578
575579      // if the OSDPROCESSORS environment variable is set, use that value if valid
576580      // 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);
580584
581      return info.dwNumberOfProcessors;
585      // otherwise, return the info from the system
586      return physprocs;
582587   }
583588}
584589
trunk/src/osd/windows/winos.c
r0r32110
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
17int 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
32char *osd_getenv(const char *name)
33{
34   return getenv(name);
35}
No newline at end of file
Property changes on: trunk/src/osd/windows/winos.c
Added: svn:mime-type
   + text/plain
Added: svn:eol-style
   + native
trunk/src/osd/windows/winos.h
r0r32110
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-----------------------------------------------------------------------------*/
18int 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-----------------------------------------------------------------------------*/
32char *osd_getenv(const char *name);
No newline at end of file
Property changes on: trunk/src/osd/windows/winos.h
Added: svn:mime-type
   + text/plain
Added: svn:eol-style
   + native
trunk/src/osd/sdl/sdlos_win32.c
r32109r32110
2020#include "osdcore.h"
2121#include "strconv.h"
2222
23#include "../windows/winos.c"
24
2325//============================================================
2426//  PROTOTYPES
2527//============================================================
r32109r32110
158160}
159161
160162//============================================================
161//  osd_num_processors
162//============================================================
163
164int 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//============================================================
176163//  osd_malloc
177164//============================================================
178165
r32109r32110
254241}
255242
256243//============================================================
257//  osd_getenv
258//============================================================
259
260char *osd_getenv(const char *name)
261{
262   return getenv(name);
263}
264
265//============================================================
266244//  osd_setenv
267245//============================================================
268246
trunk/src/osd/sdl/sdlwork.c
r32109r32110
4444//  PARAMETERS
4545//============================================================
4646
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"
4950
5051#define INFINITE                (osd_ticks_per_second() *  (osd_ticks_t) 10000)
5152#define SPIN_LOOP_TIME          (osd_ticks_per_second() / 10000)
r32109r32110
151152   int numprocs = effective_num_processors();
152153   osd_work_queue *queue;
153154   int threadnum;
155   char *osdworkqueuemaxthreads = osd_getenv("OSDWORKQUEUEMAXTHREADS");
154156
155157   // allocate a new queue
156158   queue = (osd_work_queue *)osd_malloc(sizeof(*queue));
r32109r32110
181183   else
182184      queue->threads = (flags & WORK_QUEUE_FLAG_MULTI) ? (numprocs - 1) : 1;
183185
186   if (osdworkqueuemaxthreads != NULL && sscanf(osdworkqueuemaxthreads, "%d", &threadnum) == 1 && queue->threads > threadnum)
187      queue->threads = threadnum;
188
189
184190   // clamp to the maximum
185191   queue->threads = MIN(queue->threads, WORK_MAX_THREADS);
186192
r32109r32110
564570
565571static int effective_num_processors(void)
566572{
567   char *procsoverride;
568   int numprocs = 0;
569573   int physprocs = osd_get_num_processors();
570574
571575   // osd_num_processors == 0 for 'auto'
572576   if (osd_num_processors > 0)
577   {
573578      return MIN(4 * physprocs, osd_num_processors);
579   }
574580   else
575581   {
582      char *procsoverride;
583      int numprocs = 0;
584
576585      // 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);
578588      if (procsoverride != NULL && sscanf(procsoverride, "%d", &numprocs) == 1 && numprocs > 0)
579589         return MIN(4 * physprocs, numprocs);
580590
r32109r32110
593603   char    buf[5];
594604   UINT32  mask = 0xFFFF;
595605
596   s = osd_getenv(SDLENV_CPUMASKS);
606   s = osd_getenv(ENV_CPUMASKS);
597607   if (s != NULL && strcmp(s,"none"))
598608   {
599609      if (!strcmp(s,"auto"))

Previous 199869 Revisions Next


© 1997-2024 The MAME Team