4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
39 main(int argc, char *argv[])
41 char *testdir = getenv("TESTDIR");
43 fprintf(stderr, "environment variable TESTDIR not set\n");
49 if (stat(testdir, &st) != 0 &&
50 mkdir(testdir, 0777) != 0) {
56 fprintf(stderr, "usage: %s "
58 "[max msync time in ms]\n", argv[0]);
62 int run_time_mins = 1;
64 run_time_mins = atoi(argv[1]);
67 int max_msync_time_ms = 1000;
69 max_msync_time_ms = atoi(argv[2]);
74 char *file = &filepath[0];
76 (void) snprintf(file, 512, "%s/msync_file", testdir);
81 int fd = open(file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR |
85 (void) fprintf(stderr, "%s: %s: ", argv[0], file);
90 if (ftruncate(fd, LEN) != 0) {
96 void *ptr = mmap(NULL, LEN, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
98 if (ptr == MAP_FAILED) {
104 struct timeval tstart;
105 gettimeofday(&tstart, NULL);
110 *((long long *)ptr) = x;
113 struct timeval t1, t2;
114 gettimeofday(&t1, NULL);
115 if (msync(ptr, LEN, MS_SYNC|MS_INVALIDATE) != 0) {
121 gettimeofday(&t2, NULL);
123 double elapsed = (t2.tv_sec - t1.tv_sec) * 1000.0;
124 elapsed += ((t2.tv_usec - t1.tv_usec) / 1000.0);
125 if (elapsed > max_msync_time_ms) {
126 fprintf(stderr, "slow msync: %f ms\n", elapsed);
127 if (munmap(ptr, LEN) != 0)
133 double elapsed_start = (t2.tv_sec - tstart.tv_sec) * 1000.0;
134 elapsed_start += ((t2.tv_usec - tstart.tv_usec) / 1000.0);
135 if (elapsed_start > run_time_mins * 60 * 1000) {
140 if (munmap(ptr, LEN) != 0) {
146 if (close(fd) != 0) {