]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/dtrace_ptss.h
xnu-1504.9.17.tar.gz
[apple/xnu.git] / bsd / sys / dtrace_ptss.h
CommitLineData
2d21ac55
A
1/*
2 * Copyright (c) 2000-2006 Apple Computer, 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#ifndef _DTRACE_PTSS_H_
30#define _DTRACE_PTSS_H_
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/*
37 * The pid provider needs a small per thread scratch space,
38 * in the address space of the user task. This code is used to
39 * manage that space.
40 *
41 * High level design:
42 *
43 * To avoid serialization, this is a (mostly) lockless allocator. If
44 * a new page has to be allocated, the process's sprlock will be acquired.
45 *
46 * NOTE: The dtrace copyin/copyout code is still the shared code that
47 * can handle unmapped pages, so the scratch space isn't wired for now.
48 * * Each page in user space is wired. It cannot be paged out, because
49 * * dtrace's copyin/copyout is only guaranteed to handle pages already
50 * * in memory.
51 *
52 * Each page in user space is represented by a dt_ptss_page. Page entries
53 * are chained. Once allocated, a page is not freed until dtrace "cleans up"
54 * that process.
55 *
56 * Clean up works like this:
57 *
58 * At process exit, free all kernel allocated memory, but ignore user pages.
59 * At process exec, free all kernel allocated memory, but ignore user pages.
60 * At process fork, free user pages copied from parent, and do not allocate kernel memory.
61 *
62 * This is making the assumption that it is faster to let the bulk vm_map
63 * operations in exec/exit do their work, instead of explicit page free(s)
64 * via mach_vm_deallocate.
65 *
66 * As each page is allocated, its entries are chained and added to the
67 * free_list. To claim an entry, cas it off the list. When a thread exits,
68 * cas its entry onto the list. We could potentially optimize this by
69 * keeping a head/tail, and cas'ing the frees to the tail instead of the
70 * head. Without evidence to support such a need, it seems better to keep
71 * things simple for now.
72 */
73
74#define DTRACE_PTSS_SCRATCH_SPACE_PER_THREAD 64
75#define DTRACE_PTSS_ENTRIES_PER_PAGE (PAGE_SIZE / DTRACE_PTSS_SCRATCH_SPACE_PER_THREAD)
76
77struct dtrace_ptss_page_entry {
78 struct dtrace_ptss_page_entry* next;
79 user_addr_t addr;
80};
81
82struct dtrace_ptss_page {
83 struct dtrace_ptss_page* next;
84 struct dtrace_ptss_page_entry entries[DTRACE_PTSS_ENTRIES_PER_PAGE];
85};
86
87struct dtrace_ptss_page_entry* dtrace_ptss_claim_entry(struct proc* p); /* sprlock not held */
88struct dtrace_ptss_page_entry* dtrace_ptss_claim_entry_locked(struct proc* p); /* sprlock held */
89void dtrace_ptss_release_entry(struct proc* p, struct dtrace_ptss_page_entry* e);
90
91struct dtrace_ptss_page* dtrace_ptss_allocate_page(struct proc* p);
92void dtrace_ptss_free_page(struct proc* p, struct dtrace_ptss_page* ptss_page);
93
94void dtrace_ptss_enable(struct proc* p);
95void dtrace_ptss_exec_exit(struct proc* p);
96void dtrace_ptss_fork(struct proc* parent, struct proc* child);
97
98#ifdef __cplusplus
99}
100#endif
101
102#endif /* _DTRACE_PTSS_H_ */
103