]>
git.saurik.com Git - apple/xnu.git/blob - tools/tests/libMicro/cachetocache.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 2007 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
32 * routine to benchmark cache-to-cache transfer times... uses
33 * solaris features to find and bind to cpus in the current
34 * processor set, so not likely to work elsewhere.
43 #include <sys/processor.h>
44 #include <sys/types.h>
51 static long opts
= 1024*512;
56 pthread_mutex_t ts_lock
;
59 static unsigned int ncpu
= 1024;
61 static tsd_t
*thread_data
[1024];
62 static processorid_t cpus
[1024];
64 int traverse_ptrchain(long **, int, int);
69 lm_tsdsize
= sizeof (tsd_t
);
71 (void) sprintf(lm_optstr
, "s:");
73 (void) sprintf(lm_usage
,
74 " [-s size] size of access area in bytes"
76 "notes: measures cache to cache transfer times on Solaris\n",
79 (void) sprintf(lm_header
, "%8s", "size");
85 benchmark_optswitch(int opt
, char *optarg
)
89 opts
= sizetoint(optarg
);
101 if (pset_info(PS_MYID
, NULL
, &ncpu
, cpus
) < 0) {
110 benchmark_initworker(void *tsd
)
112 tsd_t
*ts
= (tsd_t
*)tsd
;
116 ts
->ts_data
= malloc(opts
);
118 if (ts
->ts_data
== NULL
) {
122 (void) pthread_mutex_init(&ts
->ts_lock
, NULL
);
125 if (processor_bind(P_LWPID
, P_MYID
,
126 cpu
= cpus
[(pthread_self() - 1) % ncpu
],
128 perror("processor_bind:");
132 (void) printf("# thread %d using processor %d\n", pthread_self(), cpu
);
135 * use lmbench style backwards stride
138 for (i
= 0; i
< opts
/ sizeof (long); i
++) {
141 j
= j
+ opts
/ sizeof (long);
142 ts
->ts_data
[i
] = (long *)&(ts
->ts_data
[j
]);
145 thread_data
[pthread_self() - 1] = ts
;
151 * here we go in order for each thread, causing inherent serialization
152 * this is normally not a good idea, but in this case we're trying to
153 * measure cache-to-cache transfer times, and if we run threads in
154 * parallel we're likely to see saturation effects rather than cache-to-cache,
155 * esp. on wimpy memory platforms like P4.
161 benchmark(void *tsd
, result_t
*res
)
165 int count
= opts
/ 128 / sizeof (long);
167 for (j
= 0; j
< lm_optB
; j
++)
168 for (i
= 0; i
< lm_optT
; i
++) {
170 (void) pthread_mutex_lock(&ts
->ts_lock
);
171 ts
->ts_result
+= traverse_ptrchain(
172 (long **)ts
->ts_data
, count
, 0);
173 (void) pthread_mutex_unlock(&ts
->ts_lock
);
176 res
->re_count
= lm_optB
* lm_optT
* count
;
182 traverse_ptrchain(long **ptr
, int count
, int value
)
186 for (i
= 0; i
< count
; i
+= 10) {
209 return ((int)*ptr
); /* bogus return */
216 static char result
[256];
218 (void) sprintf(result
, "%8ld ", opts
);