Previous 199869 Revisions Next

r45443 Thursday 3rd March, 2016 at 14:46:15 UTC by Miodrag Milanović
use chrono calls for time handling in core (nw)
[src/mame/video]igs017_igs031.cpp
[src/osd]eigccppc.h eigccx86.h eivcx86.h osdcore.cpp
[src/osd/modules/debugger]debugqt.cpp
[src/osd/modules/lib]osdlib_macosx.cpp osdlib_unix.cpp osdlib_win32.cpp
[src/osd/sdl]window.cpp

trunk/src/mame/video/igs017_igs031.cpp
r253954r253955
374374      popmessage("a: %08X w: %03X p: %02x-%02x-%02x",a,w,m_sprites_gfx[a/3*3+0],m_sprites_gfx[a/3*3+1],m_sprites_gfx[a/3*3+2]);
375375      m_debug_addr = a;
376376      m_debug_width = w;
377      osd_sleep(200000);
377      osd_sleep(osd_ticks_per_second() / 1000 * 200);
378378      return 1;
379379   }
380380#endif
trunk/src/osd/eigccppc.h
r253954r253955
284284   return result;
285285}
286286
287
288/***************************************************************************
289    INLINE TIMING FUNCTIONS
290***************************************************************************/
291
292/*-------------------------------------------------
293    get_profile_ticks - return a tick counter
294    from the processor that can be used for
295    profiling. It does not need to run at any
296    particular rate.
297-------------------------------------------------*/
298
299#define get_profile_ticks _get_profile_ticks
300static inline INT64 ATTR_UNUSED ATTR_FORCE_INLINE _get_profile_ticks(void)
301{
302   // fix me - should use the time base
303   return osd_ticks();
304}
305
306287#endif /* __EIGCCPPC__ */
trunk/src/osd/eigccx86.h
r253954r253955
521521   return result;
522522}
523523
524/***************************************************************************
525    INLINE TIMING FUNCTIONS
526***************************************************************************/
527
528/*-------------------------------------------------
529    get_profile_ticks - return a tick counter
530    from the processor that can be used for
531    profiling. It does not need to run at any
532    particular rate.
533-------------------------------------------------*/
534
535#define get_profile_ticks _get_profile_ticks
536
537#ifndef __x86_64__
538static inline UINT64 ATTR_UNUSED ATTR_FORCE_INLINE _get_profile_ticks(void)
539{
540   UINT64 result;
541   __asm__ __volatile__ (
542         "rdtsc"
543         : "=A" (result)
544   );
545   return result;
546}
547#else
548static inline UINT64 ATTR_UNUSED ATTR_FORCE_INLINE _get_profile_ticks(void)
549{
550   _x86_union r;
551   __asm__ __volatile__ (
552         "rdtsc"
553         : "=a" (r.u32.l), "=d" (r.u32.h)
554   );
555
556   return (UINT64) r.u64;
557}
558#endif
559
560524#endif /* __EIGCCX86__ */
trunk/src/osd/eivcx86.h
r253954r253955
460460}
461461#endif
462462
463
464
465/***************************************************************************
466    INLINE TIMING FUNCTIONS
467***************************************************************************/
468
469/*-------------------------------------------------
470    get_profile_ticks - return a tick counter
471    from the processor that can be used for
472    profiling. It does not need to run at any
473    particular rate.
474-------------------------------------------------*/
475
476#define get_profile_ticks _get_profile_ticks
477
478#ifdef PTR64
479
480static inline osd_ticks_t _get_profile_ticks(void)
481{
482   return __rdtsc();
483}
484
485#else
486
487static inline osd_ticks_t _get_profile_ticks(void)
488{
489   UINT64 result;
490   UINT64 *presult = &result;
491
492   __asm {
493      __asm _emit 0Fh __asm _emit 031h    // rdtsc
494      mov ebx, presult
495      mov [ebx],eax
496      mov [ebx+4],edx
497   }
498
499   return result;
500}
501
502#endif
503
504463#endif /* __EIVCX86__ */
trunk/src/osd/modules/debugger/debugqt.cpp
r253954r253955
317317   mainQtWindow->setProcessor(&device);
318318
319319   // Run our own QT event loop
320   osd_sleep(50000);
320   osd_sleep(osd_ticks_per_second() / 1000 * 50);
321321   qApp->processEvents(QEventLoop::AllEvents, 1);
322322
323323   // Refresh everyone if requested
trunk/src/osd/modules/lib/osdlib_macosx.cpp
r253954r253955
1414#include <sys/types.h>
1515#include <signal.h>
1616
17#include <mach/mach.h>
18#include <mach/mach_time.h>
19#include <mach/mach_traps.h>
20#include <Carbon/Carbon.h>
21
2217// MAME headers
2318#include "osdcore.h"
2419#include "osdlib.h"
r253954r253955
5550}
5651
5752//============================================================
58//  osd_num_processors
59//============================================================
60
61int osd_get_num_processors(void)
62{
63   int processors = 1;
64
65   struct host_basic_info host_basic_info;
66   unsigned int count;
67   kern_return_t r;
68   mach_port_t my_mach_host_self;
69
70   count = HOST_BASIC_INFO_COUNT;
71   my_mach_host_self = mach_host_self();
72   if ( ( r = host_info(my_mach_host_self, HOST_BASIC_INFO, (host_info_t)(&host_basic_info), &count)) == KERN_SUCCESS )
73   {
74      processors = host_basic_info.avail_cpus;
75   }
76   mach_port_deallocate(mach_task_self(), my_mach_host_self);
77
78   return processors;
79}
80
81//============================================================
8253//  osd_malloc
8354//============================================================
8455
r253954r253955
166137   #endif
167138}
168139
169
170//============================================================
171//  PROTOTYPES
172//============================================================
173
174static osd_ticks_t init_cycle_counter(void);
175static osd_ticks_t mach_cycle_counter(void);
176
177//============================================================
178//  STATIC VARIABLES
179//============================================================
180
181static osd_ticks_t      (*cycle_counter)(void) = init_cycle_counter;
182static osd_ticks_t      (*ticks_counter)(void) = init_cycle_counter;
183static osd_ticks_t      ticks_per_second;
184
185//============================================================
186//  init_cycle_counter
187//
188//  to avoid total grossness, this function is split by subarch
189//============================================================
190
191static osd_ticks_t init_cycle_counter(void)
192{
193   osd_ticks_t start, end;
194   osd_ticks_t a, b;
195
196   cycle_counter = mach_cycle_counter;
197   ticks_counter = mach_cycle_counter;
198
199   // wait for an edge on the timeGetTime call
200   a = SDL_GetTicks();
201   do
202   {
203      b = SDL_GetTicks();
204   } while (a == b);
205
206   // get the starting cycle count
207   start = (*cycle_counter)();
208
209   // now wait for 1/4 second total
210   do
211   {
212      a = SDL_GetTicks();
213   } while (a - b < 250);
214
215   // get the ending cycle count
216   end = (*cycle_counter)();
217
218   // compute ticks_per_sec
219   ticks_per_second = (end - start) * 4;
220
221   // return the current cycle count
222   return (*cycle_counter)();
223}
224
225//============================================================
226//  performance_cycle_counter
227//============================================================
228
229//============================================================
230//  mach_cycle_counter
231//============================================================
232static osd_ticks_t mach_cycle_counter(void)
233{
234   return mach_absolute_time();
235}
236
237//============================================================
238//   osd_ticks
239//============================================================
240
241osd_ticks_t osd_ticks(void)
242{
243   return (*cycle_counter)();
244}
245
246
247//============================================================
248//  osd_ticks_per_second
249//============================================================
250
251osd_ticks_t osd_ticks_per_second(void)
252{
253   if (ticks_per_second == 0)
254   {
255      // if we haven't computed the value yet, there's no time like the present
256      init_cycle_counter();
257   }
258   return ticks_per_second;
259}
260
261
262
263//============================================================
264//  osd_sleep
265//============================================================
266
267void osd_sleep(osd_ticks_t duration)
268{
269   UINT32 msec;
270
271   // make sure we've computed ticks_per_second
272   if (ticks_per_second == 0)
273      (void)osd_ticks();
274
275   // convert to milliseconds, rounding down
276   msec = (UINT32)(duration * 1000 / ticks_per_second);
277
278   // only sleep if at least 2 full milliseconds
279   if (msec >= 2)
280   {
281      // take a couple of msecs off the top for good measure
282      msec -= 2;
283      usleep(msec*1000);
284   }
285}
trunk/src/osd/modules/lib/osdlib_unix.cpp
r253954r253955
1313#include <sys/mman.h>
1414#include <sys/types.h>
1515#include <signal.h>
16#include <time.h>
17#include <sys/time.h>
16
1817#ifdef SDLMAME_EMSCRIPTEN
1918#include <emscripten.h>
2019#endif
r253954r253955
5150}
5251
5352//============================================================
54//  osd_num_processors
55//============================================================
56
57int osd_get_num_processors(void)
58{
59   int processors = 1;
60
61#if defined(_SC_NPROCESSORS_ONLN)
62   processors = sysconf(_SC_NPROCESSORS_ONLN);
63#endif
64   return processors;
65}
66
67//============================================================
6853//  osd_malloc
6954//============================================================
7055
r253954r253955
150135   printf("Ignoring MAME exception: %s\n", message);
151136   #endif
152137}
153
154
155//============================================================
156//   osd_ticks
157//============================================================
158
159osd_ticks_t osd_ticks(void)
160{
161#ifdef SDLMAME_EMSCRIPTEN
162      return (osd_ticks_t)(emscripten_get_now() * 1000.0);
163#else
164      struct timeval    tp;
165      static osd_ticks_t start_sec = 0;
166
167      gettimeofday(&tp, NULL);
168      if (start_sec==0)
169         start_sec = tp.tv_sec;
170      return (tp.tv_sec - start_sec) * (osd_ticks_t) 1000000 + tp.tv_usec;
171#endif
172}
173
174
175//============================================================
176//  osd_ticks_per_second
177//============================================================
178
179osd_ticks_t osd_ticks_per_second(void)
180{
181   return (osd_ticks_t) 1000000;
182}
183
184//============================================================
185//  osd_sleep
186//============================================================
187
188void osd_sleep(osd_ticks_t duration)
189{
190   UINT32 msec;
191
192   // convert to milliseconds, rounding down
193   msec = (UINT32)(duration * 1000 / osd_ticks_per_second());
194
195   // only sleep if at least 2 full milliseconds
196   if (msec >= 2)
197   {
198      // take a couple of msecs off the top for good measure
199      msec -= 2;
200      usleep(msec*1000);
201   }
202}
trunk/src/osd/modules/lib/osdlib_win32.cpp
r253954r253955
101101}
102102
103103//============================================================
104//  osd_num_processors
105//============================================================
106
107int osd_get_num_processors(void)
108{
109   SYSTEM_INFO info;
110
111   // otherwise, fetch the info from the system
112   GetSystemInfo(&info);
113
114   // max out at 4 for now since scaling above that seems to do poorly
115   return MIN(info.dwNumberOfProcessors, 4);
116}
117
118//============================================================
119104//  osd_malloc
120105//============================================================
121106
r253954r253955
256241#endif
257242}
258243
259//============================================================
260//  GLOBAL VARIABLES
261//============================================================
262
263static osd_ticks_t ticks_per_second = 0;
264static osd_ticks_t suspend_ticks = 0;
265static BOOL using_qpc = TRUE;
266
267
268
269//============================================================
270//  osd_ticks
271//============================================================
272
273osd_ticks_t osd_ticks(void)
274{
275   LARGE_INTEGER performance_count;
276
277   // if we're suspended, just return that
278   if (suspend_ticks != 0)
279      return suspend_ticks;
280
281   // if we have a per second count, just go for it
282   if (ticks_per_second != 0)
283   {
284      // QueryPerformanceCounter if we can
285      if (using_qpc)
286      {
287         QueryPerformanceCounter(&performance_count);
288         return (osd_ticks_t)performance_count.QuadPart - suspend_ticks;
289      }
290
291      // otherwise, fall back to timeGetTime
292      else
293         return (osd_ticks_t)timeGetTime() - suspend_ticks;
294   }
295
296   // if not, we have to determine it
297   using_qpc = QueryPerformanceFrequency(&performance_count) && (performance_count.QuadPart != 0);
298   if (using_qpc)
299      ticks_per_second = (osd_ticks_t)performance_count.QuadPart;
300   else
301      ticks_per_second = 1000;
302
303   // call ourselves to get the first value
304   return osd_ticks();
305}
306
307
308//============================================================
309//  osd_ticks_per_second
310//============================================================
311
312osd_ticks_t osd_ticks_per_second(void)
313{
314   if (ticks_per_second == 0)
315      osd_ticks();
316   return ticks_per_second;
317}
318
319//============================================================
320//  osd_sleep
321//============================================================
322
323void osd_sleep(osd_ticks_t duration)
324{
325   DWORD msec;
326
327   // make sure we've computed ticks_per_second
328   if (ticks_per_second == 0)
329      (void)osd_ticks();
330
331   // convert to milliseconds, rounding down
332   msec = (DWORD)(duration * 1000 / ticks_per_second);
333
334   // only sleep if at least 2 full milliseconds
335   if (msec >= 2)
336   {
337      HANDLE current_thread = GetCurrentThread();
338      int old_priority = GetThreadPriority(current_thread);
339
340      // take a couple of msecs off the top for good measure
341      msec -= 2;
342
343      // bump our thread priority super high so that we get
344      // priority when we need it
345      SetThreadPriority(current_thread, THREAD_PRIORITY_TIME_CRITICAL);
346      Sleep(msec);
347      SetThreadPriority(current_thread, old_priority);
348   }
349}
trunk/src/osd/osdcore.cpp
r253954r253955
22// copyright-holders:Aaron Giles
33
44#include "osdcore.h"
5#include <thread>
6#include <chrono>
57
68static const int MAXSTACK = 10;
79static osd_output *m_stack[MAXSTACK];
r253954r253955
141143   va_end(argptr);
142144}
143145#endif
146
147//============================================================
148//  osd_ticks
149//============================================================
150
151osd_ticks_t osd_ticks(void)
152{
153   return std::chrono::high_resolution_clock::now().time_since_epoch().count();
154}
155
156
157//============================================================
158//  osd_ticks_per_second
159//============================================================
160
161osd_ticks_t osd_ticks_per_second(void)
162{
163   return std::chrono::high_resolution_clock::period::den;
164}
165
166//============================================================
167//  osd_sleep
168//============================================================
169
170void osd_sleep(osd_ticks_t duration)
171{
172   std::this_thread::sleep_for(std::chrono::high_resolution_clock::duration(duration));
173}
174
175//============================================================
176//  osd_num_processors
177//============================================================
178
179int osd_get_num_processors(void)
180{
181   // max out at 4 for now since scaling above that seems to do poorly
182   return MIN(std::thread::hardware_concurrency(), 4);
183}
trunk/src/osd/sdl/window.cpp
r253954r253955
310310      while (!osd_work_queue_wait(work_queue, osd_ticks_per_second()*10))
311311      {
312312         osd_printf_warning("sdlwindow_sync: Sleeping...\n");
313         osd_sleep(100000);
313         osd_sleep(osd_ticks_per_second() / 1000 * 100);
314314      }
315315   }
316316}


Previous 199869 Revisions Next


© 1997-2024 The MAME Team