コード例 #1
0
ファイル: support.c プロジェクト: Yamakuzure/PUAE
int32_t machdep_inithrtimer (void)
{
    static int32_t done = 0;

    if (!done) {
//		rpt_available = 1;

		write_log ("Testing the RDTSC instruction ... ");
		signal (SIGILL, illhandler);
		if (setjmp (catch_test) == 0)
		    read_processor_time ();
		signal (SIGILL, SIG_DFL);
		write_log ("done.\n");

/*		if (! rpt_available) {
		    write_log ("Your processor does not support the RDTSC instruction.\n");
			return 0;
		}*/

		timebase = 0;
#ifdef __linux__
		timebase = linux_get_tsc_freq ();
#else
#ifdef __BEOS__
		timebase = beos_get_tsc_freq ();
#endif
#ifdef __APPLE__
//		timebase = apple_get_tsc_freq ();
#endif
#endif

		if (timebase <= 0) {
		    write_log ("Calibrating TSC frequency...");
		    flush_log ();

		    best_time = MAX_FRAME_TIME;
		    loops_to_go = 5;

#ifdef USE_ALARM
		    signal (SIGALRM, alarmhandler);
#endif

	    /* We want exact values... */
	    sync (); sync (); sync ();

#ifdef USE_ALARM
	    last_time = read_processor_time ();
	    set_the_alarm ();

	    while (loops_to_go != 0)
		uae_msleep (10);
#else
	    int32_t i = loops_to_go;
	    frame_time_t bar;

	    while (i-- > 0) {
		last_time = read_processor_time ();
		uae_msleep (TIME_DELAY);
		bar = read_processor_time ();
		if (i != loops_to_go && bar - last_time < best_time)
		    best_time = bar - last_time;
	    }
#endif

	    timebase = best_time * (1000000.0 / TIME_UNIT);
	}

	write_log ("TSC frequency: %f MHz\n", timebase / 1000000.0);
	done = 1;
     }
     return done;
}
コード例 #2
0
ファイル: support.c プロジェクト: BackupTheBerlios/arp2-svn
int machdep_inithrtimer (void)
{
    static int done = 0;

    if (!done) {
	struct sigaction sa;
	sa.sa_flags = SA_RESTART;
#ifdef SA_ONSTACK
	sa.sa_flags |= SA_ONSTACK;
#endif
	sigemptyset (&sa.sa_mask);
	rpt_available = 1;

	write_log ("Testing the RDTSC instruction ... ");
	sa.sa_handler = illhandler;
	sigaction (SIGILL, &sa, NULL);
	if (setjmp (catch_test) == 0)
	    read_processor_time ();
	sa.sa_handler = SIG_DFL;
	sigaction (SIGILL, &sa, NULL);
	write_log ("done.\n");

	if (! rpt_available) {
	    write_log ("Your processor does not support the RDTSC instruction.\n");
	    return 0;
	}

	timebase = 0;

#ifdef __linux__
	timebase = linux_get_tsc_freq ();
#else
# ifdef __BEOS__
	timebase = beos_get_tsc_freq ();
# endif
#endif

	if (timebase <= 0) {
#ifdef USE_ALARM
	    struct sigaction sa;
	    sa.sa_flags = SA_RESTART;
#ifdef SA_ONSTACK
	    sa.sa_flags |= SA_ONSTACK;
#endif
	    sigemptyset (&sa.sa_mask);
#endif

	    write_log ("Calibrating TSC frequency...");
	    flush_log ();

	    best_time = MAX_FRAME_TIME;
	    loops_to_go = 5;

#ifdef USE_ALARM
	    sa.sa_handler = alarmhandler;
	    sigaction (SIGALRM, &sa, NULL);
#endif

	    /* We want exact values... */
	    sync (); sync (); sync ();

#ifdef USE_ALARM
	    last_time = read_processor_time ();
	    set_the_alarm ();

	    while (loops_to_go != 0)
		uae_msleep (10);
#else
	    int i = loops_to_go;
	    frame_time_t bar;

	    while (i-- > 0) {
		last_time = read_processor_time ();
		uae_msleep (TIME_DELAY);
		bar = read_processor_time ();
		if (i != loops_to_go && bar - last_time < best_time)
		    best_time = bar - last_time;
	    }
#endif

	    timebase = best_time * (1000000.0 / TIME_UNIT);
	}

	write_log ("TSC frequency: %f MHz\n", timebase / 1000000.0);

	done = 1;
     }
     return done;
}