@ -41,11 +41,17 @@
static int barrier ;
static int threads ;
static unsigned int flag CK_CC_CACHELINE ;
static ck_rwlock_t rwlock = CK_RWLOCK_INITIALIZER ;
static struct {
ck_rwlock_t lock ;
} rw CK_CC_CACHELINE = {
. lock = CK_RWLOCK_INITIALIZER
} ;
static struct affinity affinity ;
# ifdef CK_F_PR_RTM
static void *
thread_rwlock ( void * pun )
thread_ lock_rtm ( void * pun )
{
uint64_t s_b , e_b , a , i ;
uint64_t * value = pun ;
@ -61,38 +67,38 @@ thread_rwlock(void *pun)
for ( i = 1 , a = 0 ; ; i + + ) {
s_b = rdtsc ( ) ;
ck_rwlock_read_lock ( & rw lock) ;
ck_rwlock_read_unlock ( & rw lock) ;
ck_rwlock_read_lock ( & rw lock) ;
ck_rwlock_read_unlock ( & rw lock) ;
ck_rwlock_read_lock ( & rw lock) ;
ck_rwlock_read_unlock ( & rw lock) ;
ck_rwlock_read_lock ( & rw lock) ;
ck_rwlock_read_unlock ( & rw lock) ;
ck_rwlock_read_lock ( & rw lock) ;
ck_rwlock_read_unlock ( & rw lock) ;
ck_rwlock_read_lock ( & rw lock) ;
ck_rwlock_read_unlock ( & rw lock) ;
ck_rwlock_read_lock ( & rw lock) ;
ck_rwlock_read_unlock ( & rw lock) ;
ck_rwlock_read_lock ( & rw lock) ;
ck_rwlock_read_unlock ( & rw lock) ;
ck_rwlock_read_lock ( & rw lock) ;
ck_rwlock_read_unlock ( & rw lock) ;
ck_rwlock_read_lock ( & rw lock) ;
ck_rwlock_read_unlock ( & rw lock) ;
ck_rwlock_read_lock ( & rw lock) ;
ck_rwlock_read_unlock ( & rw lock) ;
ck_rwlock_read_lock ( & rw lock) ;
ck_rwlock_read_unlock ( & rw lock) ;
ck_rwlock_read_lock ( & rw lock) ;
ck_rwlock_read_unlock ( & rw lock) ;
ck_rwlock_read_lock ( & rw lock) ;
ck_rwlock_read_unlock ( & rw lock) ;
ck_rwlock_read_lock ( & rw lock) ;
ck_rwlock_read_unlock ( & rw lock) ;
ck_rwlock_read_lock ( & rw lock) ;
ck_rwlock_read_unlock ( & rw lock) ;
ck_rwlock_read_lock _rtm ( & rw . lock) ;
ck_rwlock_read_unlock _rtm ( & rw . lock) ;
ck_rwlock_read_lock _rtm ( & rw . lock) ;
ck_rwlock_read_unlock _rtm ( & rw . lock) ;
ck_rwlock_read_lock _rtm ( & rw . lock) ;
ck_rwlock_read_unlock _rtm ( & rw . lock) ;
ck_rwlock_read_lock _rtm ( & rw . lock) ;
ck_rwlock_read_unlock _rtm ( & rw . lock) ;
ck_rwlock_read_lock _rtm ( & rw . lock) ;
ck_rwlock_read_unlock _rtm ( & rw . lock) ;
ck_rwlock_read_lock _rtm ( & rw . lock) ;
ck_rwlock_read_unlock _rtm ( & rw . lock) ;
ck_rwlock_read_lock _rtm ( & rw . lock) ;
ck_rwlock_read_unlock _rtm ( & rw . lock) ;
ck_rwlock_read_lock _rtm ( & rw . lock) ;
ck_rwlock_read_unlock _rtm ( & rw . lock) ;
ck_rwlock_read_lock _rtm ( & rw . lock) ;
ck_rwlock_read_unlock _rtm ( & rw . lock) ;
ck_rwlock_read_lock _rtm ( & rw . lock) ;
ck_rwlock_read_unlock _rtm ( & rw . lock) ;
ck_rwlock_read_lock _rtm ( & rw . lock) ;
ck_rwlock_read_unlock _rtm ( & rw . lock) ;
ck_rwlock_read_lock _rtm ( & rw . lock) ;
ck_rwlock_read_unlock _rtm ( & rw . lock) ;
ck_rwlock_read_lock _rtm ( & rw . lock) ;
ck_rwlock_read_unlock _rtm ( & rw . lock) ;
ck_rwlock_read_lock _rtm ( & rw . lock) ;
ck_rwlock_read_unlock _rtm ( & rw . lock) ;
ck_rwlock_read_lock _rtm ( & rw . lock) ;
ck_rwlock_read_unlock _rtm ( & rw . lock) ;
ck_rwlock_read_lock _rtm ( & rw . lock) ;
ck_rwlock_read_unlock _rtm ( & rw . lock) ;
e_b = rdtsc ( ) ;
a + = ( e_b - s_b ) > > 4 ;
@ -108,39 +114,87 @@ thread_rwlock(void *pun)
* value = ( a / i ) ;
return NULL ;
}
# endif /* CK_F_PR_RTM */
int
main( int argc , char * argv [ ] )
static void *
thread_lock( void * pun )
{
int t ;
pthread_t * p ;
uint64_t * latency ;
uint64_t s_b , e_b , a , i ;
uint64_t * value = pun ;
if ( argc ! = 3 ) {
ck_error ( " Usage: throughput <delta> <threads> \n " ) ;
if ( aff_iterate ( & affinity ) ! = 0 ) {
perror ( " ERROR: Could not affine thread " ) ;
exit ( EXIT_FAILURE ) ;
}
threads = atoi ( argv [ 2 ] ) ;
if ( threads < = 0 ) {
ck_error ( " ERROR: Threads must be a value > 0. \n " ) ;
}
ck_pr_inc_int ( & barrier ) ;
while ( ck_pr_load_int ( & barrier ) ! = threads )
ck_pr_stall ( ) ;
p = malloc ( sizeof ( pthread_t ) * threads ) ;
if ( p = = NULL ) {
ck_error ( " ERROR: Failed to initialize thread. \n " ) ;
}
for ( i = 1 , a = 0 ; ; i + + ) {
s_b = rdtsc ( ) ;
ck_rwlock_read_lock ( & rw . lock ) ;
ck_rwlock_read_unlock ( & rw . lock ) ;
ck_rwlock_read_lock ( & rw . lock ) ;
ck_rwlock_read_unlock ( & rw . lock ) ;
ck_rwlock_read_lock ( & rw . lock ) ;
ck_rwlock_read_unlock ( & rw . lock ) ;
ck_rwlock_read_lock ( & rw . lock ) ;
ck_rwlock_read_unlock ( & rw . lock ) ;
ck_rwlock_read_lock ( & rw . lock ) ;
ck_rwlock_read_unlock ( & rw . lock ) ;
ck_rwlock_read_lock ( & rw . lock ) ;
ck_rwlock_read_unlock ( & rw . lock ) ;
ck_rwlock_read_lock ( & rw . lock ) ;
ck_rwlock_read_unlock ( & rw . lock ) ;
ck_rwlock_read_lock ( & rw . lock ) ;
ck_rwlock_read_unlock ( & rw . lock ) ;
ck_rwlock_read_lock ( & rw . lock ) ;
ck_rwlock_read_unlock ( & rw . lock ) ;
ck_rwlock_read_lock ( & rw . lock ) ;
ck_rwlock_read_unlock ( & rw . lock ) ;
ck_rwlock_read_lock ( & rw . lock ) ;
ck_rwlock_read_unlock ( & rw . lock ) ;
ck_rwlock_read_lock ( & rw . lock ) ;
ck_rwlock_read_unlock ( & rw . lock ) ;
ck_rwlock_read_lock ( & rw . lock ) ;
ck_rwlock_read_unlock ( & rw . lock ) ;
ck_rwlock_read_lock ( & rw . lock ) ;
ck_rwlock_read_unlock ( & rw . lock ) ;
ck_rwlock_read_lock ( & rw . lock ) ;
ck_rwlock_read_unlock ( & rw . lock ) ;
ck_rwlock_read_lock ( & rw . lock ) ;
ck_rwlock_read_unlock ( & rw . lock ) ;
e_b = rdtsc ( ) ;
latency = malloc ( sizeof ( uint64_t ) * threads ) ;
if ( latency = = NULL ) {
ck_error ( " ERROR: Failed to create latency buffer. \n " ) ;
a + = ( e_b - s_b ) > > 4 ;
if ( ck_pr_load_uint ( & flag ) = = 1 )
break ;
}
affinity . delta = atoi ( argv [ 1 ] ) ;
ck_pr_inc_int ( & barrier ) ;
while ( ck_pr_load_int ( & barrier ) ! = threads * 2 )
ck_pr_stall ( ) ;
* value = ( a / i ) ;
return NULL ;
}
static void
rwlock_test ( pthread_t * p , int d , uint64_t * latency , void * ( * f ) ( void * ) , const char * label )
{
int t ;
ck_pr_store_int ( & barrier , 0 ) ;
ck_pr_store_uint ( & flag , 0 ) ;
affinity . delta = d ;
affinity . request = 0 ;
fprintf ( stderr , " Creating threads (rwlock)... " ) ;
fprintf ( stderr , " Creating threads ( %s)..." , label ) ;
for ( t = 0 ; t < threads ; t + + ) {
if ( pthread_create ( & p [ t ] , NULL , thread_rwlock , latency + t ) ! = 0 ) {
if ( pthread_create ( & p [ t ] , NULL , f , latency + t ) ! = 0 ) {
ck_error ( " ERROR: Could not create thread %d \n " , t ) ;
}
}
@ -157,6 +211,44 @@ main(int argc, char *argv[])
for ( t = 1 ; t < = threads ; t + + )
printf ( " %10u %20 " PRIu64 " \n " , t , latency [ t - 1 ] ) ;
return ( 0 ) ;
fprintf ( stderr , " \n " ) ;
return ;
}
int
main ( int argc , char * argv [ ] )
{
int d ;
pthread_t * p ;
uint64_t * latency ;
if ( argc ! = 3 ) {
ck_error ( " Usage: throughput <delta> <threads> \n " ) ;
}
threads = atoi ( argv [ 2 ] ) ;
if ( threads < = 0 ) {
ck_error ( " ERROR: Threads must be a value > 0. \n " ) ;
}
p = malloc ( sizeof ( pthread_t ) * threads ) ;
if ( p = = NULL ) {
ck_error ( " ERROR: Failed to initialize thread. \n " ) ;
}
latency = malloc ( sizeof ( uint64_t ) * threads ) ;
if ( latency = = NULL ) {
ck_error ( " ERROR: Failed to create latency buffer. \n " ) ;
}
d = atoi ( argv [ 1 ] ) ;
rwlock_test ( p , d , latency , thread_lock , " rwlock " ) ;
# ifdef CK_F_PR_RTM
rwlock_test ( p , d , latency , thread_lock_rtm , " rwlock, rtm " ) ;
# endif /* CK_F_PR_RTM */
return 0 ;
}