]>
git.saurik.com Git - apple/xnu.git/blob - tools/tests/darwintests/perf_exit_proc.c
fa157cdd6f98963e6259089de6dc4f2e9a8a6fab
7 #include <mach/mach_vm.h>
9 static void* loop(__attribute__ ((unused
)) void *arg
) {
16 static int run_additional_threads(int nthreads
) {
17 for (int i
= 0; i
< nthreads
; i
++) {
21 err
= pthread_create(&pthread
, NULL
, loop
, NULL
);
30 static int allocate_and_wire_memory(mach_vm_size_t size
) {
32 task_t task
= mach_task_self();
33 mach_vm_address_t addr
;
38 err
= mach_vm_allocate(task
, &addr
, size
, VM_FLAGS_ANYWHERE
);
39 if (err
!= KERN_SUCCESS
) {
40 printf("mach_vm_allocate returned non-zero: %s\n", mach_error_string(err
));
43 err
= mach_vm_protect(task
, addr
, size
, 0, VM_PROT_READ
| VM_PROT_WRITE
);;
44 if (err
!= KERN_SUCCESS
) {
45 printf("mach_vm_protect returned non-zero: %s\n", mach_error_string(err
));
48 host_t host_priv_port
;
49 err
= host_get_host_priv_port(mach_host_self(), &host_priv_port
);
50 if (err
!= KERN_SUCCESS
) {
51 printf("host_get_host_priv_port retruned non-zero: %s\n", mach_error_string(err
));
54 err
= mach_vm_wire(host_priv_port
, task
, addr
, size
, VM_PROT_READ
| VM_PROT_WRITE
);
55 if (err
!= KERN_SUCCESS
) {
56 printf("mach_vm_wire returned non-zero: %s\n", mach_error_string(err
));
63 static int set_thread_priority(int priority
) {
64 struct sched_param param
;
67 int err
= pthread_getschedparam(pthread_self(), &policy
, ¶m
);
70 param
.sched_priority
= priority
;
72 err
= pthread_setschedparam(pthread_self(), policy
, ¶m
);
78 int main(int argc
, char *argv
[]) {
79 int priority
= 47, nthreads
= 0;
81 mach_vm_size_t wired_mem
= 0;
84 priority
= (int)strtoul(argv
[1], NULL
, 10);
87 nthreads
= (int)strtoul(argv
[2], NULL
, 10);
90 wired_mem
= (mach_vm_size_t
)strtoul(argv
[3], NULL
, 10);
93 err
= allocate_and_wire_memory(wired_mem
);
98 err
= set_thread_priority(priority
);
103 err
= run_additional_threads(nthreads
);