3 * Copyright (c) 2006 Red Hat, Inc.
7 * Author: Steven Dake (sdake@mvista.com)
9 * This software licensed under BSD license, the text of which follows:
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
14 * - Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 * - Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 * - Neither the name of the MontaVista Software, Inc. nor the names of its
20 * contributors may be used to endorse or promote products derived from this
21 * software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33 * THE POSSIBILITY OF SUCH DAMAGE.
45 #include <sys/types.h>
46 #include <sys/socket.h>
47 #include <sys/select.h>
49 #include <sys/socket.h>
50 #include <netinet/in.h>
51 #include <arpa/inet.h>
56 #ifdef OPENAIS_SOLARIS
57 #define timersub(a, b, result) \
59 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
60 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
61 if ((result)->tv_usec < 0) { \
63 (result)->tv_usec += 1000000; \
70 void cpg_bm_confchg_fn (
72 struct cpg_name
*group_name
,
73 struct cpg_address
*member_list
, int member_list_entries
,
74 struct cpg_address
*left_list
, int left_list_entries
,
75 struct cpg_address
*joined_list
, int joined_list_entries
)
79 unsigned int write_count
;
81 void cpg_bm_deliver_fn (
83 struct cpg_name
*group_name
,
92 cpg_callbacks_t callbacks
= {
93 .cpg_deliver_fn
= cpg_bm_deliver_fn
,
94 .cpg_confchg_fn
= cpg_bm_confchg_fn
103 struct timeval tv1
, tv2
, tv_elapsed
;
106 cpg_flow_control_state_t flow_control_state
;
110 iov
.iov_len
= write_size
;
115 gettimeofday (&tv1
, NULL
);
118 * Test checkpoint write
120 cpg_flow_control_state_get (handle
, &flow_control_state
);
121 if (flow_control_state
== CPG_FLOW_CONTROL_DISABLED
) {
123 res
= cpg_mcast_joined (handle
, CPG_TYPE_AGREED
, &iov
, 1);
124 if (res
== CPG_ERR_TRY_AGAIN
) {
128 res
= cpg_dispatch (handle
, CPG_DISPATCH_ALL
);
130 printf ("cpg dispatch returned error %d\n", res
);
133 } while (alarm_notice
== 0);
134 gettimeofday (&tv2
, NULL
);
135 timersub (&tv2
, &tv1
, &tv_elapsed
);
137 printf ("%5d messages received ", write_count
);
138 printf ("%5d bytes per write ", write_size
);
139 printf ("%7.3f Seconds runtime ",
140 (tv_elapsed
.tv_sec
+ (tv_elapsed
.tv_usec
/ 1000000.0)));
141 printf ("%9.3f TP/s ",
142 ((float)write_count
) / (tv_elapsed
.tv_sec
+ (tv_elapsed
.tv_usec
/ 1000000.0)));
143 printf ("%7.3f MB/s.\n",
144 ((float)write_count
) * ((float)write_size
) / ((tv_elapsed
.tv_sec
+ (tv_elapsed
.tv_usec
/ 1000000.0)) * 1000000.0));
147 void sigalrm_handler (int num
)
152 static struct cpg_name group_name
= {
159 unsigned int size
= 1;
163 signal (SIGALRM
, sigalrm_handler
);
164 res
= cpg_initialize (&handle
, &callbacks
);
166 printf ("cpg_initialize failed with result %d\n", res
);
170 res
= cpg_join (handle
, &group_name
);
172 printf ("cpg_join failed with result %d\n", res
);
176 for (i
= 0; i
< 50; i
++) { /* number of repetitions - up to 50k */
177 cpg_benchmark (handle
, size
);
181 res
= cpg_finalize (handle
);
183 printf ("cpg_join failed with result %d\n", res
);