]>
git.saurik.com Git - apple/xnu.git/blob - tools/tests/libMicro/msync.c
4 * The contents of this file are subject to the terms
5 * of the Common Development and Distribution License
6 * (the "License"). You may not use this file except
7 * in compliance with the License.
9 * You can obtain a copy of the license at
10 * src/OPENSOLARIS.LICENSE
11 * or http://www.opensolaris.org/os/licensing.
12 * See the License for the specific language governing
13 * permissions and limitations under the License.
15 * When distributing Covered Code, include this CDDL
16 * HEADER in each file and include the License file at
17 * usr/src/OPENSOLARIS.LICENSE. If applicable,
18 * add the following below this CDDL HEADER, with the
19 * fields enclosed by brackets "[]" replaced with your
20 * own identifying information: Portions Copyright [yyyy]
21 * [name of copyright owner]
27 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
42 int ts_foo
; /* defeat optimizers */
45 #define DEFF "/dev/zero"
48 static char *optf
= DEFF
;
49 static long long optl
= DEFL
;
53 static int opta
= MS_SYNC
;
61 lm_tsdsize
= sizeof (tsd_t
);
63 (void) sprintf(lm_optstr
, "af:il:rsw");
65 (void) sprintf(lm_usage
,
66 " [-f file-to-map (default %s)]\n"
67 " [-l mapping-length (default %d)]\n"
68 " [-r] (read a byte from each page between msyncs)\n"
69 " [-w] (write a byte to each page between msyncs)\n"
70 " [-s] (use MAP_SHARED instead of MAP_PRIVATE)\n"
71 " [-a (specify MS_ASYNC rather than default MS_SYNC)\n"
72 " [-i (specify MS_INVALIDATE)\n"
73 "notes: measures msync()\n",
76 (void) sprintf(lm_header
, "%8s %6s", "length", "flags");
82 benchmark_optswitch(int opt
, char *optarg
)
98 optl
= sizetoll(optarg
);
113 pagesize
= getpagesize();
119 benchmark_initworker(void *tsd
)
121 tsd_t
*ts
= (tsd_t
*)tsd
;
125 if ((fd
= open(optf
, O_RDWR
)) < 0) {
130 (void) ftruncate(fd
, optl
);
132 if ((ts
->ts_map
= (char *)mmap(NULL
, optl
,
133 PROT_READ
| PROT_WRITE
, opts
? MAP_SHARED
: MAP_PRIVATE
,
134 fd
, 0L)) == MAP_FAILED
) {
144 benchmark(void *tsd
, result_t
*res
)
146 tsd_t
*ts
= (tsd_t
*)tsd
;
149 for (i
= 0; i
< lm_optB
; i
++) {
151 if (msync(ts
->ts_map
, optl
, opta
| opti
) < 0) {
158 for (j
= 0; j
< optl
; j
+= pagesize
) {
159 ts
->ts_foo
+= ts
->ts_map
[j
];
164 for (j
= 0; j
< optl
; j
+= pagesize
) {
177 static char result
[256];
180 flags
[0] = anon
? 'a' : '-';
181 flags
[1] = optr
? 'r' : '-';
182 flags
[2] = optw
? 'w' : '-';
183 flags
[3] = opts
? 's' : '-';
184 flags
[4] = opti
? 'i' : '-';
187 (void) sprintf(result
, "%8lld %6s", optl
, flags
);