⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test1.c

📁 QNX ver4.25 education example code
💻 C
字号:
/****************************************************************************** *  test1.c : show the rdtsc counter on a pentium class machine ******************************************************************************/#ifdef __USAGE%C [ -p priority ]priority   = priority to run at (0 to 29) Default=10e.g. %C -p 29#endif #include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/kernel.h>#include <sys/vc.h>#include <sys/seginfo.h>#include <sys/osinfo.h>#include <sys/name.h>#include <i86.h>#include <sys/irqinfo.h>#include <sys/proxy.h>#include <sys/sched.h>#include <sys/timers.h>#include <sys/name.h>#include <fcntl.h>#include <errno.h>#include <string.h>#include <sys/trace.h>#include <sys/tracecod.h>#include <math.h>#include <time.h>#include <signal.h>#include "64bit.h"/* globals */double   seconds_per_tick;Long     start_time64, stop_time64;int      priority = 10;#define NANOS_PER_SEC    1000000000#define MICROS_PER_SEC   1000000#define MILLIS_PER_SEC   1000#define HIGHEST_PRIORITY     29set_my_priority( int priority ) {	int ret;    ret = setprio( getpid(), priority );    if ( ret == -1 ) {       fprintf(stderr,"Error setting priority. (%s)\n",strerror(errno));       exit(-1);       }	return(ret);	}sync_pentium() {	Long diff;	double ticks_per_second;	int previous_priority;    // get synchronization values for this Pentium	do {        previous_priority = set_my_priority( HIGHEST_PRIORITY );    	rdtsc64( &start_time64 );  // snap time        sleep(1);    	rdtsc64( &stop_time64 );   // snap time        set_my_priority( previous_priority );		} while (start_time64.lo > stop_time64.lo);    _Lsub( &diff, stop_time64, start_time64 ); 	ticks_per_second = (float)diff.lo;    seconds_per_tick = 1.000000000 / ticks_per_second;	printf( "\nPentium Clock Speed Measurement:\n\n" );	printf( "1 second took %lf cycles on this machine.\n", ticks_per_second );	printf( "Each cycle is %18.15lf seconds, or %8.3lf nanoseconds.\n",              seconds_per_tick, seconds_per_tick * NANOS_PER_SEC );	printf( "This is a %3.1f MHz Pentium.\n\n",		(float) ticks_per_second / 1000000.0);    }main(int argc, char **argv) {    int     c;    while ( ( c = getopt( argc, argv, "p:" ) ) != -1 ) {         switch(c) {            case 'p' : priority = atoi(optarg);                       if ( priority < 0 || priority > 29 ) {                          fprintf(stderr,"Invalid priority. Defaulting to 10.\n");                          priority = 10;                          }                       break;            }         }    if ( setprio( getpid(), priority ) == -1 ) {       fprintf(stderr,"Error setting priority. (%s)\n",strerror(errno));       exit(-1);       }	sync_pentium();    go();	}go() {    Long diffl;	double diffd;    while (1) {                 		rdtsc64( &start_time64 );  // snap time		sleep(1);   		rdtsc64( &stop_time64 );   // snap time        _Lsub( &diffl, stop_time64, start_time64 );         diffd = (float)diffl.lo * seconds_per_tick;		printf("%12.9f\n", diffd);		fflush(stdout);		}	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -