kjloki 0 Newbie Poster

Please recompile the program to run under Solaris. I would like to compare the results with the QNX.

#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/neutrino.h>
#include <sys/syspage.h>  /* for  cycles_per_second */
#define COUNT 100000
#define THREADS 128
#define PRIO 255

uint64_t measure[THREADS][COUNT];
int tid[THREADS];

void* src ( void* arg ) {
	int i;
	int num = (int) arg;
	for ( i = 0; i < COUNT; i++ ){
		measure[num][i] = ClockCycles();
		sched_yield() ;
	}		
	return NULL;
}

int main ( int argc, char *argv[] ) {
	int i, j;
	int status;
 	int debug = 1;
 	
 	pthread_attr_t attr[THREADS];
 	struct sched_param par;
 
	uint64_t cps;
   	uint64_t diff;
   	float diff_ms;
   	float diff_max = 0;
   
   float average = 0;
   
     if (argc == 2 && !strcmp (argv[1], "print")){
   			debug = 1;
   	}
   	else if (argc > 1) {
   		printf ( "Usage: %s [print]\n", argv[0] );
   		exit ( 0 );
   	}
   	
   	
	sched_getparam ( 0, &par );
	
   	for ( i = 0; i < THREADS; i++ ){
   		pthread_attr_init ( &attr[i] );
   		pthread_attr_setinheritsched ( &attr[i], PTHREAD_EXPLICIT_SCHED );
   		par.sched_priority = PRIO; 
   		pthread_attr_setschedparam ( &attr[i], &par );
   		pthread_create ( &tid[i], NULL, src, (void*) i );
   	}
	
	for (i = 0; i < THREADS; i++ ){
		pthread_join ( tid[i], (void*) &status );
		if (debug)	printf ( "Watek zakonczony. Status %d\n", status ) ;
	}
	
	 cps = SYSPAGE_ENTRY(qtime)->cycles_per_sec;
   if(debug) printf( "cps = %lld\n", cps );
   if (debug) printf( "Count\tDiff\t\tDiff (msec)\n");

   for ( i = 0; i < COUNT; i++ )
   		for (j = 0; j < THREADS - 1; j++){
    	  	diff = measure[j+1][i] - measure[j][i];
      		diff_ms = (float)diff / (float)cps * 1000;
     		if (debug)	printf( "%d\t%lld\t\t%f\n", i*THREADS + j, diff, diff_ms);
	  		if ( diff_max < diff_ms ) diff_max = diff_ms;
	  		average += diff_ms / (COUNT * THREADS);
   		}	
   		
   	printf ( "Maximumm switching latency: %f ms\n", diff_max );
	printf ( "Average switching time: %f ms\n", average );
	return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.