forked from F-Stack/f-stack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathff_freebsd_init.c
133 lines (110 loc) · 3.94 KB
/
ff_freebsd_init.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* Copyright (c) 2010 Kip Macy All rights reserved.
* Copyright (C) 2017-2021 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Derived in part from libplebnet's pn_init.c.
*/
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/pcpu.h>
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/lock.h>
#include <sys/sx.h>
#include <sys/vmmeter.h>
#include <sys/cpuset.h>
#include <sys/sysctl.h>
#include <sys/filedesc.h>
#include <vm/uma.h>
#include <vm/uma_int.h>
#include <vm/vm.h>
#include <vm/vm_extern.h>
#include "ff_host_interface.h"
#include "ff_api.h"
#include "ff_config.h"
int ff_freebsd_init(void);
extern void mutex_init(void);
extern void mi_startup(void);
extern void uma_startup(void *, int);
extern void uma_startup2(void);
extern void ff_init_thread0(void);
struct sx proctree_lock;
struct pcpu *pcpup;
struct uma_page_head *uma_page_slab_hash;
int uma_page_mask;
extern cpuset_t all_cpus;
long physmem;
extern void uma_startup1(vm_offset_t);
int
ff_freebsd_init(void)
{
int boot_pages;
unsigned int num_hash_buckets;
char tmpbuf[32] = {0};
void *bootmem;
int error;
snprintf(tmpbuf, sizeof(tmpbuf), "%u", ff_global_cfg.freebsd.hz);
error = kern_setenv("kern.hz", tmpbuf);
if (error != 0) {
panic("kern_setenv failed: kern.hz=%s\n", tmpbuf);
}
struct ff_freebsd_cfg *cur;
cur = ff_global_cfg.freebsd.boot;
while (cur) {
error = kern_setenv(cur->name, cur->str);
if (error != 0) {
printf("kern_setenv failed: %s=%s\n", cur->name, cur->str);
}
cur = cur->next;
}
physmem = ff_global_cfg.freebsd.physmem;
pcpup = malloc(sizeof(struct pcpu), M_DEVBUF, M_ZERO);
pcpu_init(pcpup, 0, sizeof(struct pcpu));
PCPU_SET(prvspace, pcpup);
CPU_SET(0, &all_cpus);
ff_init_thread0();
boot_pages = 16;
bootmem = (void *)kmem_malloc(boot_pages*PAGE_SIZE, M_ZERO);
//uma_startup(bootmem, boot_pages);
uma_startup1((vm_offset_t)bootmem);
uma_startup2();
num_hash_buckets = 8192;
uma_page_slab_hash = (struct uma_page_head *)kmem_malloc(sizeof(struct uma_page)*num_hash_buckets, M_ZERO);
uma_page_mask = num_hash_buckets - 1;
mutex_init();
mi_startup();
sx_init(&proctree_lock, "proctree");
ff_fdused_range(ff_global_cfg.freebsd.fd_reserve);
cur = ff_global_cfg.freebsd.sysctl;
while (cur) {
error = kernel_sysctlbyname(curthread, cur->name, NULL, NULL,
cur->value, cur->vlen, NULL, 0);
if (error != 0) {
printf("kernel_sysctlbyname failed: %s=%s, error:%d\n",
cur->name, cur->str, error);
}
cur = cur->next;
}
return (0);
}