Remove proc0 creation

This commit is contained in:
Sebastian Huber
2012-04-26 15:05:52 +02:00
parent 9ee768907e
commit 4c0c5fdb5f
9 changed files with 225 additions and 75 deletions

View File

@@ -593,10 +593,10 @@ rtems.addEmptyHeaderFiles(
#'vm/uma_int.h',
#'vm/uma_dbg.h',
#'vm/vm_extern.h',
#'vm/vm_map.h',
'vm/vm_map.h',
#'vm/vm_object.h',
#'vm/vm_page.h',
#'vm/vm_param.h',
'vm/vm_param.h',
#'vm/vm_kern.h',
'geom/geom_disk.h',
#'sys/kdb.h',
@@ -1098,7 +1098,7 @@ devUsbBase.addHeaderFiles(
'sys/uio.h',
'sys/aio.h',
'sys/unistd.h',
#'sys/vmmeter.h',
'sys/vmmeter.h',
#'sys/vnode.h',
'sys/rman.h',
'sys/reboot.h',

View File

@@ -65,17 +65,13 @@ __FBSDID("$FreeBSD$");
#include <freebsd/sys/resourcevar.h>
#include <freebsd/sys/systm.h>
#include <freebsd/sys/signalvar.h>
#ifndef __rtems__
#include <freebsd/sys/vnode.h>
#endif
#include <freebsd/sys/sysent.h>
#include <freebsd/sys/reboot.h>
#include <freebsd/sys/sched.h>
#include <freebsd/sys/sx.h>
#include <freebsd/sys/sysproto.h>
#ifndef __rtems__
#include <freebsd/sys/vmmeter.h>
#endif
#include <freebsd/sys/unistd.h>
#include <freebsd/sys/malloc.h>
#include <freebsd/sys/conf.h>
@@ -86,12 +82,10 @@ __FBSDID("$FreeBSD$");
#include <freebsd/security/audit/audit.h>
#include <freebsd/security/mac/mac_framework.h>
#ifndef __rtems__
#include <freebsd/vm/vm.h>
#include <freebsd/vm/vm_param.h>
#include <freebsd/vm/pmap.h>
#include <freebsd/vm/vm_map.h>
#endif
#include <freebsd/sys/copyright.h>
#include <freebsd/ddb/ddb.h>
@@ -104,18 +98,13 @@ void mi_startup(void); /* Should be elsewhere */
static struct session session0;
static struct pgrp pgrp0;
struct proc proc0;
#endif /* __rtems__ */
struct thread thread0 __aligned(16);
#ifndef __rtems__
struct vmspace vmspace0;
struct proc *initproc;
int boothowto = 0; /* initialized so that it can be patched */
SYSCTL_INT(_debug, OID_AUTO, boothowto, CTLFLAG_RD, &boothowto, 0, "");
#endif /* __rtems__ */
int bootverbose;
#ifndef __rtems__
SYSCTL_INT(_debug, OID_AUTO, bootverbose, CTLFLAG_RW, &bootverbose, 0, "");
/*
@@ -129,11 +118,6 @@ SYSINIT(placeholder, SI_SUB_DUMMY, SI_ORDER_ANY, NULL, NULL);
* The sysinit table itself. Items are checked off as the are run.
* If we want to register new sysinit types, add them to newsysinit.
*/
#else /* __rtems__ */
struct proc proc0;
#endif /* __rtems__ */
SET_DECLARE(sysinit_set, struct sysinit);
#ifndef __rtems__
@@ -842,41 +826,4 @@ kick_init(const void *udata __unused)
thread_unlock(td);
}
SYSINIT(kickinit, SI_SUB_KTHREAD_INIT, SI_ORDER_FIRST, kick_init, NULL);
#else /* __rtems__ */
/*
***************************************************************************
****
**** The two following SYSINIT's are proc0 specific glue code. I am not
**** convinced that they can not be safely combined, but their order of
**** operation has been maintained as the same as the original init_main.c
**** for right now.
****
**** These probably belong in init_proc.c or kern_proc.c, since they
**** deal with proc0 (the fork template process).
****
***************************************************************************
*/
/* ARGSUSED*/
static void
proc0_init(void *dummy __unused)
{
struct proc *p;
GIANT_REQUIRED;
p = &proc0;
/* Create credentials. */
p->p_ucred = crget();
p->p_ucred->cr_ngroups = 1; /* group 0 */
p->p_ucred->cr_uidinfo = uifind(0);
p->p_ucred->cr_ruidinfo = uifind(0);
p->p_ucred->cr_prison = &prison0;
#ifdef AUDIT
audit_cred_kproc0(p->p_ucred);
#endif
#ifdef MAC
mac_cred_create_swapper(p->p_ucred);
#endif
}
SYSINIT(p0init, SI_SUB_INTRINSIC, SI_ORDER_FIRST, proc0_init, NULL);
#endif /* __rtems__ */

View File

@@ -200,7 +200,9 @@ struct rusage_ext {
struct thread {
#ifndef __rtems__
struct mtx *volatile td_lock; /* replaces sched lock */
#endif /* __rtems__ */
struct proc *td_proc; /* (*) Associated process. */
#ifndef __rtems__
TAILQ_ENTRY(thread) td_plist; /* (*) All threads in this proc. */
TAILQ_ENTRY(thread) td_runq; /* (t) Run queue. */
TAILQ_ENTRY(thread) td_slpq; /* (t) Sleep queue. */
@@ -236,7 +238,9 @@ struct thread {
struct lock_list_entry *td_sleeplocks; /* (k) Held sleep locks. */
int td_intr_nesting_level; /* (k) Interrupt recursion. */
int td_pinned; /* (k) Temporary cpu pin count. */
#endif /* __rtems__ */
struct ucred *td_ucred; /* (k) Reference to credentials. */
#ifndef __rtems__
u_int td_estcpu; /* (t) estimated cpu utilization */
int td_slptick; /* (t) Time at sleep. */
int td_blktick; /* (t) Time spent blocked. */
@@ -285,7 +289,9 @@ struct thread {
TDS_RUNQ,
TDS_RUNNING
} td_state; /* (t) thread state */
#endif /* __rtems__ */
register_t td_retval[2]; /* (k) Syscall aux returns. */
#ifndef __rtems__
struct callout td_slpcallout; /* (h) Callout for sleep. */
struct trapframe *td_frame; /* (k) */
struct vm_object *td_kstack_obj;/* (a) Kstack object. */
@@ -310,10 +316,6 @@ struct thread {
rtems_chain_node td_node;
rtems_id td_id;
char td_name [16];
struct proc *td_proc; /* (*) Associated process. */
struct ucred *td_ucred; /* (k) Reference to credentials. */
register_t td_retval[2]; /* (k) Syscall aux returns. */
void *td_wchan; /* (t) Sleep address. */
#endif /* __rtems__ */
};

206
freebsd/sys/vmmeter.h Normal file
View File

@@ -0,0 +1,206 @@
/*-
* Copyright (c) 1982, 1986, 1993
* The Regents of the University of California. 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.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* @(#)vmmeter.h 8.2 (Berkeley) 7/10/94
* $FreeBSD$
*/
#ifndef _SYS_VMMETER_HH_
#define _SYS_VMMETER_HH_
/*
* System wide statistics counters.
* Locking:
* a - locked by atomic operations
* c - constant after initialization
* f - locked by vm_page_queue_free_mtx
* p - locked by being in the PCPU and atomicity respect to interrupts
* q - locked by vm_page_queue_mtx
*/
struct vmmeter {
/*
* General system activity.
*/
u_int v_swtch; /* (p) context switches */
u_int v_trap; /* (p) calls to trap */
u_int v_syscall; /* (p) calls to syscall() */
u_int v_intr; /* (p) device interrupts */
u_int v_soft; /* (p) software interrupts */
/*
* Virtual memory activity.
*/
u_int v_vm_faults; /* (p) address memory faults */
u_int v_cow_faults; /* (p) copy-on-writes faults */
u_int v_cow_optim; /* (p) optimized copy-on-writes faults */
u_int v_zfod; /* (p) pages zero filled on demand */
u_int v_ozfod; /* (p) optimized zero fill pages */
u_int v_swapin; /* (p) swap pager pageins */
u_int v_swapout; /* (p) swap pager pageouts */
u_int v_swappgsin; /* (p) swap pager pages paged in */
u_int v_swappgsout; /* (p) swap pager pages paged out */
u_int v_vnodein; /* (p) vnode pager pageins */
u_int v_vnodeout; /* (p) vnode pager pageouts */
u_int v_vnodepgsin; /* (p) vnode_pager pages paged in */
u_int v_vnodepgsout; /* (p) vnode pager pages paged out */
u_int v_intrans; /* (p) intransit blocking page faults */
u_int v_reactivated; /* (f) pages reactivated from free list */
u_int v_pdwakeups; /* (f) times daemon has awaken from sleep */
u_int v_pdpages; /* (q) pages analyzed by daemon */
u_int v_tcached; /* (q) total pages cached */
u_int v_dfree; /* (q) pages freed by daemon */
u_int v_pfree; /* (q) pages freed by exiting processes */
u_int v_tfree; /* (p) total pages freed */
/*
* Distribution of page usages.
*/
u_int v_page_size; /* (c) page size in bytes */
u_int v_page_count; /* (c) total number of pages in system */
u_int v_free_reserved; /* (c) pages reserved for deadlock */
u_int v_free_target; /* (c) pages desired free */
u_int v_free_min; /* (c) pages desired free */
u_int v_free_count; /* (f) pages free */
u_int v_wire_count; /* (a) pages wired down */
u_int v_active_count; /* (q) pages active */
u_int v_inactive_target; /* (c) pages desired inactive */
u_int v_inactive_count; /* (q) pages inactive */
u_int v_cache_count; /* (f) pages on cache queue */
u_int v_cache_min; /* (c) min pages desired on cache queue */
u_int v_cache_max; /* (c) max pages in cached obj */
u_int v_pageout_free_min; /* (c) min pages reserved for kernel */
u_int v_interrupt_free_min; /* (c) reserved pages for int code */
u_int v_free_severe; /* (c) severe page depletion point */
/*
* Fork/vfork/rfork activity.
*/
u_int v_forks; /* (p) fork() calls */
u_int v_vforks; /* (p) vfork() calls */
u_int v_rforks; /* (p) rfork() calls */
u_int v_kthreads; /* (p) fork() calls by kernel */
u_int v_forkpages; /* (p) VM pages affected by fork() */
u_int v_vforkpages; /* (p) VM pages affected by vfork() */
u_int v_rforkpages; /* (p) VM pages affected by rfork() */
u_int v_kthreadpages; /* (p) VM pages affected by fork() by kernel */
};
#ifdef _KERNEL
extern struct vmmeter cnt;
/*
* Return TRUE if we are under our severe low-free-pages threshold
*
* This routine is typically used at the user<->system interface to determine
* whether we need to block in order to avoid a low memory deadlock.
*/
static __inline
int
vm_page_count_severe(void)
{
return (cnt.v_free_severe > (cnt.v_free_count + cnt.v_cache_count));
}
/*
* Return TRUE if we are under our minimum low-free-pages threshold.
*
* This routine is typically used within the system to determine whether
* we can execute potentially very expensive code in terms of memory. It
* is also used by the pageout daemon to calculate when to sleep, when
* to wake waiters up, and when (after making a pass) to become more
* desparate.
*/
static __inline
int
vm_page_count_min(void)
{
return (cnt.v_free_min > (cnt.v_free_count + cnt.v_cache_count));
}
/*
* Return TRUE if we have not reached our free page target during
* free page recovery operations.
*/
static __inline
int
vm_page_count_target(void)
{
return (cnt.v_free_target > (cnt.v_free_count + cnt.v_cache_count));
}
/*
* Return the number of pages we need to free-up or cache
* A positive number indicates that we do not have enough free pages.
*/
static __inline
int
vm_paging_target(void)
{
return (
(cnt.v_free_target + cnt.v_cache_min) -
(cnt.v_free_count + cnt.v_cache_count)
);
}
/*
* Returns TRUE if the pagedaemon needs to be woken up.
*/
static __inline
int
vm_paging_needed(void)
{
return (
(cnt.v_free_reserved + cnt.v_cache_min) >
(cnt.v_free_count + cnt.v_cache_count)
);
}
#endif
/* systemwide totals computed every five seconds */
struct vmtotal {
int16_t t_rq; /* length of the run queue */
int16_t t_dw; /* jobs in ``disk wait'' (neg priority) */
int16_t t_pw; /* jobs in page wait */
int16_t t_sl; /* jobs sleeping in core */
int16_t t_sw; /* swapped out runnable/short block jobs */
int32_t t_vm; /* total virtual memory */
int32_t t_avm; /* active virtual memory */
int32_t t_rm; /* total real memory in use */
int32_t t_arm; /* active real memory */
int32_t t_vmshr; /* shared virtual memory */
int32_t t_avmshr; /* active shared virtual memory */
int32_t t_rmshr; /* shared real memory */
int32_t t_armshr; /* active shared real memory */
int32_t t_free; /* free memory pages */
};
#endif

1
freebsd/vm/vm_map.h Normal file
View File

@@ -0,0 +1 @@
/* EMPTY */

1
freebsd/vm/vm_param.h Normal file
View File

@@ -0,0 +1 @@
/* EMPTY */

View File

@@ -310,5 +310,4 @@ void
mutex_init(void)
{
mtx_init(&Giant, "Giant", NULL, MTX_DEF | MTX_RECURSE);
mtx_init(&proc0.p_mtx, "process lock", NULL, MTX_DEF | MTX_DUPOK);
}

View File

@@ -176,19 +176,16 @@ int
_sleep(void *ident, struct lock_object *lock, int priority, const char *wmesg, int timo)
{
struct thread *td;
struct proc *p;
struct lock_class *class;
int catch, flags, lock_state, pri, rval;
td = curthread;
p = td->td_proc;
#ifdef KTRACE
if (KTRPOINT(td, KTR_CSW))
ktrcsw(1, 0);
#endif
KASSERT(timo != 0 || mtx_owned(&Giant) || lock != NULL,
("sleeping without a lock"));
KASSERT(p != NULL, ("msleep1"));
KASSERT(ident != NULL && TD_IS_RUNNING(td), ("msleep"));
if (priority & PDROP)
KASSERT(lock != NULL && lock != &Giant.lock_object,
@@ -214,9 +211,6 @@ _sleep(void *ident, struct lock_object *lock, int priority, const char *wmesg, i
catch = priority & PCATCH;
pri = priority & PRIMASK;
CTR5(KTR_PROC, "sleep: thread %ld (pid %ld, %s) on %s (%p)",
td->td_tid, p->p_pid, td->td_name, wmesg, ident);
if (lock == &Giant.lock_object)
mtx_assert(&Giant, MA_OWNED);
DROP_GIANT();

View File

@@ -31,10 +31,12 @@
RTEMS_CHAIN_DEFINE_EMPTY(rtems_bsd_thread_chain);
/* FIXME: What to do with the credentials? */
static struct ucred FIXME_ucred;
static int
rtems_bsd_thread_start(struct thread **td_ptr, void (*func)(void *), void *arg, int flags, int pages, const char *fmt, va_list ap)
{
struct proc *p = &proc0;;
struct thread *td = malloc(sizeof(struct thread), M_TEMP, M_WAITOK | M_ZERO);
if (td != NULL) {
@@ -86,9 +88,7 @@ rtems_bsd_thread_start(struct thread **td_ptr, void (*func)(void *), void *arg,
td->td_id = id;
vsnprintf(td->td_name, sizeof(td->td_name), fmt, ap);
bzero(&td->td_ru, sizeof(td->td_ru));
td->td_ucred = crhold(p->p_ucred);
td->td_proc = p;
td->td_ucred = &FIXME_ucred;
rtems_chain_append(&rtems_bsd_thread_chain, &td->td_node);