xref: /xnu-8020.140.41/bsd/tests/pmap_test_sysctl.c (revision 27b03b360a988dfd3dfdf34262bb0042026747cc)
1 /*
2  * Copyright (c) 2016 Apple Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5  *
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.
14  *
15  * Please obtain a copy of the License at
16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17  *
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.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27  */
28 
29 #include <sys/sysctl.h>
30 
31 extern kern_return_t test_pmap_enter_disconnect(unsigned int);
32 extern kern_return_t test_pmap_iommu_disconnect(void);
33 extern kern_return_t test_pmap_extended(void);
34 extern void test_pmap_call_overhead(unsigned int);
35 extern uint64_t test_pmap_page_protect_overhead(unsigned int, unsigned int);
36 
37 static int
sysctl_test_pmap_enter_disconnect(__unused struct sysctl_oid * oidp,__unused void * arg1,__unused int arg2,struct sysctl_req * req)38 sysctl_test_pmap_enter_disconnect(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
39 {
40 	unsigned int num_loops;
41 	int error, changed;
42 	error = sysctl_io_number(req, 0, sizeof(num_loops), &num_loops, &changed);
43 	if (error || !changed) {
44 		return error;
45 	}
46 	return test_pmap_enter_disconnect(num_loops);
47 }
48 
49 SYSCTL_PROC(_kern, OID_AUTO, pmap_enter_disconnect_test,
50     CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED,
51     0, 0, sysctl_test_pmap_enter_disconnect, "I", "");
52 
53 static int
sysctl_test_pmap_iommu_disconnect(__unused struct sysctl_oid * oidp,__unused void * arg1,__unused int arg2,struct sysctl_req * req)54 sysctl_test_pmap_iommu_disconnect(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
55 {
56 	unsigned int run = 0;
57 	int error, changed;
58 	error = sysctl_io_number(req, 0, sizeof(run), &run, &changed);
59 	if (error || !changed) {
60 		return error;
61 	}
62 	return test_pmap_iommu_disconnect();
63 }
64 
65 SYSCTL_PROC(_kern, OID_AUTO, pmap_iommu_disconnect_test,
66     CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED,
67     0, 0, sysctl_test_pmap_iommu_disconnect, "I", "");
68 
69 static int
sysctl_test_pmap_extended(__unused struct sysctl_oid * oidp,__unused void * arg1,__unused int arg2,struct sysctl_req * req)70 sysctl_test_pmap_extended(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
71 {
72 	unsigned int run = 0;
73 	int error, changed;
74 	error = sysctl_io_number(req, 0, sizeof(run), &run, &changed);
75 	if (error || !changed) {
76 		return error;
77 	}
78 	return test_pmap_extended();
79 }
80 
81 SYSCTL_PROC(_kern, OID_AUTO, pmap_extended_test,
82     CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED,
83     0, 0, sysctl_test_pmap_extended, "I", "");
84 
85 static int
sysctl_test_pmap_call_overhead(__unused struct sysctl_oid * oidp,__unused void * arg1,__unused int arg2,struct sysctl_req * req)86 sysctl_test_pmap_call_overhead(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
87 {
88 	unsigned int num_loops;
89 	int error, changed;
90 	error = sysctl_io_number(req, 0, sizeof(num_loops), &num_loops, &changed);
91 	if (error || !changed) {
92 		return error;
93 	}
94 	test_pmap_call_overhead(num_loops);
95 	return 0;
96 }
97 
98 SYSCTL_PROC(_kern, OID_AUTO, pmap_call_overhead_test,
99     CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED,
100     0, 0, sysctl_test_pmap_call_overhead, "I", "");
101 
102 static int
sysctl_test_pmap_page_protect_overhead(__unused struct sysctl_oid * oidp,__unused void * arg1,__unused int arg2,struct sysctl_req * req)103 sysctl_test_pmap_page_protect_overhead(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
104 {
105 	struct {
106 		unsigned int num_loops;
107 		unsigned int num_aliases;
108 	} ppo_in;
109 
110 	int error;
111 	uint64_t duration;
112 
113 	error = SYSCTL_IN(req, &ppo_in, sizeof(ppo_in));
114 	if (error) {
115 		return error;
116 	}
117 
118 	duration = test_pmap_page_protect_overhead(ppo_in.num_loops, ppo_in.num_aliases);
119 	error = SYSCTL_OUT(req, &duration, sizeof(duration));
120 	return error;
121 }
122 
123 SYSCTL_PROC(_kern, OID_AUTO, pmap_page_protect_overhead_test,
124     CTLTYPE_OPAQUE | CTLFLAG_RW | CTLFLAG_LOCKED, 0, 0, sysctl_test_pmap_page_protect_overhead, "-", "");
125