win-pvdrivers

view liblfds.6/test/src/benchmark_freelist.c @ 1025:aa2e51f67f7c

Fix hibernate under Win8. Change debugprints.
author James Harper <james.harper@bendigoit.com.au>
date Tue Feb 19 15:14:53 2013 +1100 (2013-02-19)
parents 6300617040e0
children
line source
1 #include "internal.h"
7 /****************************************************************************/
8 void benchmark_freelist( void )
9 {
10 unsigned int
11 loop,
12 thread_count,
13 cpu_count;
15 struct freelist_state
16 *fs;
18 struct freelist_benchmark
19 *fb;
21 thread_state_t
22 *thread_handles;
24 atom_t
25 total_operations_for_full_test_for_all_cpus,
26 total_operations_for_full_test_for_all_cpus_for_one_cpu = 0;
28 double
29 mean_operations_per_second_per_cpu,
30 difference_per_second_per_cpu,
31 total_difference_per_second_per_cpu,
32 std_dev_per_second_per_cpu,
33 scalability;
35 /* TRD : here we benchmark the freelist
37 the benchmark is to have a single freelist
38 where a worker thread busy-works popping and then pushing
39 */
41 cpu_count = abstraction_cpu_count();
43 thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count );
45 fb = (struct freelist_benchmark *) malloc( sizeof(struct freelist_benchmark) * cpu_count );
47 // TRD : print the benchmark ID and CSV header
48 printf( "\n"
49 "Release %d Freelist Benchmark #1\n"
50 "CPUs,total ops,mean ops/sec per CPU,standard deviation,scalability\n", LIBLFDS_RELEASE_NUMBER );
52 // TRD : we run CPU count times for scalability
53 for( thread_count = 1 ; thread_count <= cpu_count ; thread_count++ )
54 {
55 // TRD : initialisation
56 freelist_new( &fs, 1000, NULL, NULL );
58 for( loop = 0 ; loop < cpu_count ; loop++ )
59 {
60 (fb+loop)->fs = fs;
61 (fb+loop)->operation_count = 0;
62 }
64 // TRD : main test
65 for( loop = 0 ; loop < thread_count ; loop++ )
66 abstraction_thread_start( &thread_handles[loop], loop, benchmark_freelist_thread_pop_and_push, fb+loop );
68 for( loop = 0 ; loop < thread_count ; loop++ )
69 abstraction_thread_wait( thread_handles[loop] );
71 // TRD : post test math
72 total_operations_for_full_test_for_all_cpus = 0;
73 total_difference_per_second_per_cpu = 0;
75 for( loop = 0 ; loop < thread_count ; loop++ )
76 total_operations_for_full_test_for_all_cpus += (fb+loop)->operation_count;
78 mean_operations_per_second_per_cpu = ((double) total_operations_for_full_test_for_all_cpus / (double) thread_count) / (double) 10;
80 if( thread_count == 1 )
81 total_operations_for_full_test_for_all_cpus_for_one_cpu = total_operations_for_full_test_for_all_cpus;
83 for( loop = 0 ; loop < thread_count ; loop++ )
84 {
85 difference_per_second_per_cpu = ((double) (fb+loop)->operation_count / (double) 10) - mean_operations_per_second_per_cpu;
86 total_difference_per_second_per_cpu += difference_per_second_per_cpu * difference_per_second_per_cpu;
87 }
89 std_dev_per_second_per_cpu = sqrt( (double) total_difference_per_second_per_cpu );
91 scalability = (double) total_operations_for_full_test_for_all_cpus / (double) (total_operations_for_full_test_for_all_cpus_for_one_cpu * thread_count);
93 printf( "%u,%u,%.0f,%.0f,%0.2f\n", thread_count, (unsigned int) total_operations_for_full_test_for_all_cpus, mean_operations_per_second_per_cpu, std_dev_per_second_per_cpu, scalability );
95 // TRD : cleanup
96 freelist_delete( fs, NULL, NULL );
97 }
99 free( fb );
101 free( thread_handles );
103 return;
104 }
110 /****************************************************************************/
111 thread_return_t CALLING_CONVENTION benchmark_freelist_thread_pop_and_push( void *freelist_benchmark )
112 {
113 struct freelist_benchmark
114 *fb;
116 struct freelist_element
117 *fe;
119 time_t
120 start_time;
122 assert( freelist_benchmark != NULL );
124 fb = (struct freelist_benchmark *) freelist_benchmark;
126 time( &start_time );
128 while( time(NULL) < start_time + 10 )
129 {
130 freelist_pop( fb->fs, &fe );
131 freelist_push( fb->fs, fe );
133 fb->operation_count += 2;
134 }
136 return( (thread_return_t) EXIT_SUCCESS );
137 }