1/*
2 * CDDL HEADER START
3 *
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.
8 *
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.
14 *
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]
22 *
23 * CDDL HEADER END
24 */
25
26/*
27 * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
28 * Use is subject to license terms.
29 */
30
31/*
32 * memory access time check
33 */
34
35#include <unistd.h>
36#include <stdlib.h>
37#include <stdio.h>
38#include <fcntl.h>
39#include <string.h>
40
41#include "libmicro.h"
42
43static long	opts = 1024*1024;
44
45typedef struct {
46	long			**ts_data;
47	long			ts_result;
48} tsd_t;
49
50int
51benchmark_init()
52{
53	lm_tsdsize = sizeof (tsd_t);
54
55	(void) sprintf(lm_optstr, "s:");
56
57	(void) sprintf(lm_usage,
58	    "       [-s size] number of bytes to "
59	    " access (default %ld)\n"
60	    "notes: measures \"random\" memory access times\n",
61	    opts);
62
63	(void) sprintf(lm_header, "%8s", "size");
64
65	return (0);
66}
67
68int
69benchmark_optswitch(int opt, char *optarg)
70{
71	switch (opt) {
72	case 's':
73		opts = sizetoint(optarg);
74		break;
75	default:
76		return (-1);
77	}
78
79	return (0);
80}
81
82int
83benchmark_initworker(void *tsd)
84{
85	tsd_t			*ts = (tsd_t *)tsd;
86	int i, j;
87
88	ts->ts_data = malloc(opts);
89
90	if (ts->ts_data == NULL) {
91		return (1);
92	}
93
94	/*
95	 * use lmbench style backwards stride
96	 */
97
98	for (i = 0; i < opts / sizeof (long); i++) {
99		j = i - 128;
100		if (j < 0)
101			j = j + opts / sizeof (long);
102		ts->ts_data[i] = (long *)&(ts->ts_data[j]);
103	}
104	return (0);
105}
106
107int
108benchmark(void *tsd, result_t *res)
109{
110	tsd_t			*ts = (tsd_t *)tsd;
111	int			i;
112
113	long **ptr = ts->ts_data;
114
115
116
117	for (i = 0; i < lm_optB; i += 10) {
118		ptr = (long **)*ptr;
119		ptr = (long **)*ptr;
120		ptr = (long **)*ptr;
121		ptr = (long **)*ptr;
122		ptr = (long **)*ptr;
123		ptr = (long **)*ptr;
124		ptr = (long **)*ptr;
125		ptr = (long **)*ptr;
126		ptr = (long **)*ptr;
127		ptr = (long **)*ptr;
128	}
129
130	ts->ts_result = (long)*ptr;
131
132	res->re_count = lm_optB;
133
134	return (0);
135}
136
137char *
138benchmark_result()
139{
140	static char  result[256];
141
142	(void) sprintf(result, "%8ld ", opts);
143
144
145	return (result);
146}
147