]>
git.saurik.com Git - apple/xnu.git/blob - tools/tests/libMicro/apple/vm_allocate.c
0450f7a44dc8e24eaa9f6626bbc24b0fb80c929b
2 * Copyright (c) 2006 Apple Inc. All Rights Reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
39 * benchmark_initworker
45 * benchmark_finibatch, etc.
46 * benchmark_finiworker
58 #pragma ident "@(#)vm_allocate.c 1.0 09/17/06 Apple Inc."
67 #include <mach/mach.h>
69 #include "../libmicro.h"
72 * Your state variables should live in the tsd_t struct below
78 unsigned char * arena
;
79 unsigned int arenaSize
= 1;
85 benchmark_initbatch(void *tsd
)
88 * initialize your state variables here second
90 //tsd_t *ts = (tsd_t *)tsd;
91 //(void) fprintf(stderr, "benchmark_initbatch: ts_once = %i\n",ts->ts_once);
98 (void) fprintf(stderr
, "benchmark_finirun\n");
105 (void) fprintf(stderr
, "benchmark_init\n");
107 * the lm_optstr must be defined here or no options for you
109 * ...and the framework will throw an error
112 (void) sprintf(lm_optstr
, "t:");
114 * working hypothesis:
116 * tsd_t is the struct that we can pass around our
119 * lm_tsdsize will allocate the space we need for this
120 * structure throughout the rest of the framework
122 lm_tsdsize
= sizeof (tsd_t
);
126 (void) sprintf(lm_usage
,
127 " [-t int (default 1)]\n"
128 "notes: measures nothing\n");
135 (void) fprintf(stderr
, "benchmark_fini\n");
140 benchmark_finibatch(void *tsd
)
142 tsd_t
*ts
= (tsd_t
*)tsd
;
144 * more proof of state passing
147 //(void) fprintf(stderr, "benchmark_finibatch: ts_once = %i\n",ts->ts_once);
154 static char result
= '\0';
155 (void) fprintf(stderr
, "benchmark_result\n");
160 benchmark_finiworker(void *tsd
)
162 //tsd_t *ts = (tsd_t *)tsd;
163 //(void) fprintf(stderr, "benchmark_finiworker: ts_once = %i\n",ts->ts_once);
164 //vm_deallocate( mach_task_self(), (vm_address_t) arena, arenaSize * vm_page_size);
170 benchmark_optswitch(int opt
, char *optarg
)
172 (void) fprintf(stderr
, "benchmark_optswitch\n");
176 optt
= sizetoint(optarg
);
185 benchmark_initworker(void *tsd
)
188 * initialize your state variables here first
190 //tsd_t *ts = (tsd_t *)tsd;
191 //ts->ts_once = optt;
192 //(void) fprintf(stderr, "benchmark_initworker: ts_once = %i\n",ts->ts_once);
197 vm_allocate( mach_task_self(), (vm_address_t
*) &arena
, arenaSize
* vm_page_size
, 1);
199 vm_deallocate( mach_task_self(), (vm_address_t
) arena
, arenaSize
* vm_page_size
);
200 //arena = ( unsigned char * )malloc( arenaSize);
207 //(void) fprintf(stderr, "benchmark_initrun\n");
212 benchmark(void *tsd
, result_t
*res
)
215 * initialize your state variables here last
217 * and realize that you are paying for your initialization here
218 * and it is really a bad idea
220 //tsd_t *ts = (tsd_t *)tsd;
223 //(void) fprintf(stderr, "in to benchmark - optB = %i\n", lm_optB);
224 for (i
= 0; i
< lm_optB
; i
++) {
226 * just to show that ts really contains state
228 //(void) fprintf(stderr, "i is %i\n",i);
229 if (vm_allocate( mach_task_self(), (vm_address_t
*) &arena
, arenaSize
* vm_page_size
, 1))
231 if (vm_deallocate( mach_task_self(), (vm_address_t
) arena
, arenaSize
* vm_page_size
))
236 //(void) fprintf(stderr, "out of benchmark - optB = %i : ts_once = %i\n", lm_optB, ts->ts_once);