]>
git.saurik.com Git - apple/xnu.git/blob - tools/tests/libMicro/munmap.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 munmap()\n",
75 (void) sprintf(lm_header
, "%8s %5s", "size", "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
;
122 if (ts
->ts_once
++ == 0) {
123 ts
->ts_map
= (vchar_t
**)malloc(lm_optB
* sizeof (void *));
124 if (ts
->ts_map
== NULL
) {
129 for (i
= 0; i
< lm_optB
; i
++) {
131 ts
->ts_map
[i
] = (vchar_t
*)mmap(NULL
, optl
,
132 PROT_READ
| PROT_WRITE
,
133 MAP_ANON
| (opts
? MAP_SHARED
: MAP_PRIVATE
),
136 ts
->ts_map
[i
] = (vchar_t
*)mmap(NULL
, optl
,
137 PROT_READ
| PROT_WRITE
,
138 opts
? MAP_SHARED
: MAP_PRIVATE
,
142 if (ts
->ts_map
[i
] == MAP_FAILED
) {
147 for (j
= 0; j
< optl
; j
+= 4096) {
148 ts
->ts_foo
+= ts
->ts_map
[i
][j
];
152 for (j
= 0; j
< optl
; j
+= 4096) {
153 ts
->ts_map
[i
][j
] = 1;
162 benchmark(void *tsd
, result_t
*res
)
164 tsd_t
*ts
= (tsd_t
*)tsd
;
167 for (i
= 0; i
< lm_optB
; i
++) {
168 if (munmap((void *)ts
->ts_map
[i
], optl
) == -1) {
172 res
->re_count
+= lm_optB
;
180 static char result
[256];
183 flags
[0] = anon
? 'a' : '-';
184 flags
[1] = optr
? 'r' : '-';
185 flags
[2] = optw
? 'w' : '-';
186 flags
[3] = opts
? 's' : '-';
189 (void) sprintf(result
, "%8lld %5s", optl
, flags
);