3 * Copyright (c) 2002-2004 MontaVista Software, Inc.
4 * Copyright (c) 2006 Sun Microsystems, Inc.
8 * Author: Steven Dake (sdake@mvista.com)
10 * This software licensed under BSD license, the text of which follows:
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions are met:
15 * - Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * - Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * - Neither the name of the MontaVista Software, Inc. nor the names of its
21 * contributors may be used to endorse or promote products derived from this
22 * software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
34 * THE POSSIBILITY OF SUCH DAMAGE.
46 #include <sys/types.h>
47 #include <sys/socket.h>
48 #include <sys/select.h>
50 #include <sys/socket.h>
51 #include <netinet/in.h>
52 #include <arpa/inet.h>
58 #ifdef OPENAIS_SOLARIS
59 #define timersub(a, b, result) \
61 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
62 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
63 if ((result)->tv_usec < 0) { \
65 (result)->tv_usec += 1000000; \
72 void fail_on_error(SaAisErrorT error
, char* opName
) {
73 if (error
!= SA_AIS_OK
) {
74 printf ("%s: result %s\n", opName
, get_sa_error_b(error
));
79 void printSaNameT (SaNameT
*name
)
83 for (i
= 0; i
< name
->length
; i
++) {
84 printf ("%c", name
->value
[i
]);
88 SaVersionT version
= { 'B', 1, 1 };
90 SaCkptCallbacksT callbacks
= {
95 SaNameT checkpointName
= { 5, "abra\0" };
97 SaCkptCheckpointCreationAttributesT checkpointCreationAttributes
= {
98 .creationFlags
= SA_CKPT_WR_ALL_REPLICAS
,
99 .checkpointSize
= 250000,
100 .retentionDuration
= 0,
102 .maxSectionSize
= 250000,
103 .maxSectionIdSize
= 15
106 SaCkptSectionIdT sectionId1
= {
108 (SaUint8T
*) "section ID #1"
111 SaCkptSectionIdT sectionId2
= {
113 (SaUint8T
*) "section ID #2"
115 SaCkptSectionCreationAttributesT sectionCreationAttributes1
= {
120 SaCkptSectionCreationAttributesT sectionCreationAttributes2
= {
125 char readBuffer1
[1025];
127 char readBuffer2
[1025];
129 SaCkptIOVectorElementT ReadVectorElements
[] = {
133 (SaUint8T
*) "section ID #1"
136 sizeof (readBuffer1
),
143 (SaUint8T
*) "section ID #2"
146 sizeof (readBuffer2
),
152 #define DATASIZE 200000
156 SaCkptIOVectorElementT WriteVectorElements
[] = {
160 (SaUint8T
*) "section ID #1"
162 data
, /*"written data #1, this should extend past end of old section data", */
163 DATASIZE
, /*sizeof ("data #1, this should extend past end of old section data") + 1, */
171 (SaUint8T
*) "section ID #2"
173 data
, /*"written data #2, this should extend past end of old section data" */
174 DATASIZE
, /*sizeof ("written data #2, this should extend past end of old section data") + 1, */
181 void ckpt_benchmark (SaCkptCheckpointHandleT checkpointHandle
,
184 struct timeval tv1
, tv2
, tv_elapsed
;
185 SaUint32T erroroneousVectorIndex
= 0;
191 WriteVectorElements
[0].dataSize
= write_size
;
193 gettimeofday (&tv1
, NULL
);
196 * Test checkpoint write
199 error
= saCkptCheckpointWrite (checkpointHandle
,
202 &erroroneousVectorIndex
);
203 if (error
== SA_AIS_ERR_TRY_AGAIN
) {
206 fail_on_error(error
, "saCkptCheckpointWrite");
208 } while (alarm_notice
== 0);
209 gettimeofday (&tv2
, NULL
);
210 timersub (&tv2
, &tv1
, &tv_elapsed
);
212 printf ("%5d Writes ", write_count
);
213 printf ("%5d bytes per write ", write_size
);
214 printf ("%7.3f Seconds runtime ",
215 (tv_elapsed
.tv_sec
+ (tv_elapsed
.tv_usec
/ 1000000.0)));
216 printf ("%9.3f TP/s ",
217 ((float)write_count
) / (tv_elapsed
.tv_sec
+ (tv_elapsed
.tv_usec
/ 1000000.0)));
218 printf ("%7.3f MB/s.\n",
219 ((float)write_count
) * ((float)write_size
) / ((tv_elapsed
.tv_sec
+ (tv_elapsed
.tv_usec
/ 1000000.0)) * 1000000.0));
222 void sigalrm_handler (int num
)
228 SaCkptHandleT ckptHandle
;
229 SaCkptCheckpointHandleT checkpointHandle
;
234 signal (SIGALRM
, sigalrm_handler
);
236 error
= saCkptInitialize (&ckptHandle
, &callbacks
, &version
);
237 fail_on_error(error
, "saCkptInitialize");
239 error
= saCkptCheckpointOpen (ckptHandle
,
241 &checkpointCreationAttributes
,
242 SA_CKPT_CHECKPOINT_CREATE
|SA_CKPT_CHECKPOINT_READ
|SA_CKPT_CHECKPOINT_WRITE
,
245 fail_on_error(error
, "saCkptCheckpointOpen");
246 error
= saCkptSectionCreate (checkpointHandle
,
247 §ionCreationAttributes1
,
249 strlen ("Initial Data #0") + 1);
250 fail_on_error(error
, "saCkptCheckpointSectionCreate");
251 error
= saCkptSectionCreate (checkpointHandle
,
252 §ionCreationAttributes2
,
254 strlen ("Initial Data #0") + 1);
255 fail_on_error(error
, "saCkptCheckpointSectionCreate");
259 for (i
= 0; i
< 50; i
++) { /* number of repetitions - up to 50k */
260 ckpt_benchmark (checkpointHandle
, size
);
264 error
= saCkptFinalize (ckptHandle
);