]>
git.saurik.com Git - apple/xnu.git/blob - tools/tests/libMicro/mmap.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 2002 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
40 typedef volatile char vchar_t
;
48 #define DEFF "/dev/zero"
51 static char *optf
= DEFF
;
52 static long long optl
= DEFL
;
62 lm_tsdsize
= sizeof (tsd_t
);
64 (void) sprintf(lm_optstr
, "f:l:rsw");
66 (void) sprintf(lm_usage
,
67 " [-f file-to-map (default %s)]\n"
68 " [-l mapping-length (default %d)]\n"
69 " [-r] (read a byte from each page)\n"
70 " [-w] (write a byte on each page)\n"
71 " [-s] (use MAP_SHARED)\n"
72 "notes: measures mmap()\n",
75 (void) sprintf(lm_header
, "%8s %5s", "length", "flags");
81 benchmark_optswitch(int opt
, char *optarg
)
86 anon
= strcmp(optf
, "MAP_ANON") == 0;
89 optl
= sizetoll(optarg
);
110 fd
= open(optf
, O_RDWR
);
116 benchmark_initbatch(void *tsd
)
118 tsd_t
*ts
= (tsd_t
*)tsd
;
121 if (ts
->ts_once
++ == 0) {
122 ts
->ts_map
= (vchar_t
**)malloc(lm_optB
* sizeof (void *));
123 if (ts
->ts_map
== NULL
) {
132 benchmark(void *tsd
, result_t
*res
)
134 tsd_t
*ts
= (tsd_t
*)tsd
;
137 for (i
= 0; i
< lm_optB
; i
++) {
139 ts
->ts_map
[i
] = (vchar_t
*)mmap(NULL
, optl
,
140 PROT_READ
| PROT_WRITE
,
141 MAP_ANON
| (opts
? MAP_SHARED
: MAP_PRIVATE
),
144 ts
->ts_map
[i
] = (vchar_t
*)mmap(NULL
, optl
,
145 PROT_READ
| PROT_WRITE
,
146 opts
? MAP_SHARED
: MAP_PRIVATE
,
150 if (ts
->ts_map
[i
] == MAP_FAILED
) {
156 for (j
= 0; j
< optl
; j
+= 4096) {
157 ts
->ts_foo
+= ts
->ts_map
[i
][j
];
161 for (j
= 0; j
< optl
; j
+= 4096) {
162 ts
->ts_map
[i
][j
] = 1;
172 benchmark_finibatch(void *tsd
)
174 tsd_t
*ts
= (tsd_t
*)tsd
;
177 for (i
= 0; i
< lm_optB
; i
++) {
178 (void) munmap((void *)ts
->ts_map
[i
], optl
);
186 static char result
[256];
189 flags
[0] = anon
? 'a' : '-';
190 flags
[1] = optr
? 'r' : '-';
191 flags
[2] = optw
? 'w' : '-';
192 flags
[3] = opts
? 's' : '-';
195 (void) sprintf(result
, "%8lld %5s", optl
, flags
);