mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-05-13 17:39:19 +08:00
Implemented a version of rmlock using rwlock.
This commit is contained in:
parent
362782eb25
commit
459afb1c76
2
Makefile
2
Makefile
@ -324,6 +324,7 @@ C_FILES = \
|
||||
freebsd/netinet/tcp_hostcache.c \
|
||||
freebsd/dev/pci/pci.c \
|
||||
freebsd/kern/uipc_accf.c \
|
||||
freebsd/kern/kern_ntptime.c \
|
||||
freebsd/dev/re/if_re.c \
|
||||
freebsd/dev/fxp/if_fxp.c \
|
||||
freebsd/dev/e1000/e1000_80003es2lan.c \
|
||||
@ -392,6 +393,7 @@ C_FILES += \
|
||||
rtemsbsd/src/rtems-bsd-uma.c \
|
||||
rtemsbsd/src/rtems-bsd-taskqueue.c \
|
||||
rtemsbsd/src/rtems-bsd-timesupport.c \
|
||||
rtemsbsd/src/rtems-bsd-timeout.c \
|
||||
rtemsbsd/src/rtems-bsd-newproc.c \
|
||||
rtemsbsd/src/rtems-bsd-vm_glue.c
|
||||
|
||||
|
@ -533,6 +533,7 @@ rtems_sourceFiles = [
|
||||
'src/rtems-bsd-uma.c',
|
||||
'src/rtems-bsd-taskqueue.c',
|
||||
'src/rtems-bsd-timesupport.c',
|
||||
'src/rtems-bsd-timeout.c',
|
||||
'src/rtems-bsd-newproc.c',
|
||||
'src/rtems-bsd-vm_glue.c',
|
||||
]
|
||||
@ -1140,6 +1141,7 @@ devNic.addSourceFiles(
|
||||
'netinet/tcp_hostcache.c',
|
||||
'dev/pci/pci.c',
|
||||
'kern/uipc_accf.c',
|
||||
'kern/kern_ntptime.c',
|
||||
]
|
||||
)
|
||||
|
||||
|
1045
freebsd/kern/kern_ntptime.c
Normal file
1045
freebsd/kern/kern_ntptime.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -43,6 +43,7 @@
|
||||
|
||||
LIST_HEAD(rmpriolist,rm_priotracker);
|
||||
|
||||
#ifndef __rtems__
|
||||
struct rmlock {
|
||||
struct lock_object lock_object;
|
||||
volatile int rm_noreadtoken;
|
||||
@ -50,6 +51,10 @@ struct rmlock {
|
||||
struct mtx rm_lock;
|
||||
|
||||
};
|
||||
#else /* __rtems__ */
|
||||
#include <freebsd/sys/rwlock.h>
|
||||
#define rmlock rwlock
|
||||
#endif /* __rtems__ */
|
||||
|
||||
struct rm_priotracker {
|
||||
struct rm_queue rmp_cpuQueue; /* Must be first */
|
||||
|
@ -44,6 +44,7 @@
|
||||
#define RM_NOWITNESS 0x00000001
|
||||
#define RM_RECURSE 0x00000002
|
||||
|
||||
#ifndef __rtems__
|
||||
void rm_init(struct rmlock *rm, const char *name);
|
||||
void rm_init_flags(struct rmlock *rm, const char *name, int opts);
|
||||
void rm_destroy(struct rmlock *rm);
|
||||
@ -84,6 +85,22 @@ void _rm_runlock(struct rmlock *rm, struct rm_priotracker *tracker);
|
||||
#define rm_runlock(rm,tracker) _rm_runlock((rm), (tracker))
|
||||
#endif
|
||||
|
||||
#else /* __rtems__ */
|
||||
#define rm_init(rm, name) rw_init(rm, name)
|
||||
#define rm_init_flags(rm, name, opts) rw_init_flags(rm, name, opts)
|
||||
#define rm_destroy(rm) rw_destroy(rm)
|
||||
#define rm_wowned(rm) rw_wowned(rm)
|
||||
#define rm_sysinit(arg) rw_sysinit(arg)
|
||||
#define rm_sysinit_flags(arg) rw_sysinit_flags(arg)
|
||||
|
||||
#define rm_wlock(rm) rw_wlock((rm))
|
||||
#define rm_wunlock(rm) rw_wunlock((rm))
|
||||
#define rm_rlock(rm,tracker) rw_rlock((rm))
|
||||
#define rm_runlock(rm,tracker) rw_runlock((rm))
|
||||
#endif /* __rtems__ */
|
||||
|
||||
|
||||
|
||||
struct rm_args {
|
||||
struct rmlock *ra_rm;
|
||||
const char *ra_desc;
|
||||
|
@ -39,7 +39,7 @@ struct lock_class *lock_classes[LOCK_CLASS_MAX + 1] = {
|
||||
&lock_class_mtx_spin,
|
||||
&lock_class_mtx_sleep,
|
||||
&lock_class_sx,
|
||||
&lock_class_rm,
|
||||
&lock_class_rw,
|
||||
&lock_class_rw,
|
||||
};
|
||||
|
||||
|
@ -1,92 +0,0 @@
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_bsd_rtems
|
||||
*
|
||||
* @brief TODO.
|
||||
*/
|
||||
|
||||
/*
|
||||
* COPYRIGHT (c) 2012.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
|
||||
#include <freebsd/machine/rtems-bsd-config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <freebsd/sys/param.h>
|
||||
#include <freebsd/sys/types.h>
|
||||
#include <freebsd/sys/systm.h>
|
||||
#include <freebsd/sys/lock.h>
|
||||
#include <freebsd/sys/rmlock.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#define RMPF_ONQUEUE 1
|
||||
#define RMPF_SIGNAL 2
|
||||
|
||||
/*
|
||||
* To support usage of rmlock in CVs and msleep yet another list for the
|
||||
* priority tracker would be needed. Using this lock for cv and msleep also
|
||||
* does not seem very useful
|
||||
*/
|
||||
|
||||
static __inline void compiler_memory_barrier(void) {
|
||||
__asm __volatile("":::"memory");
|
||||
}
|
||||
|
||||
static void assert_rm(struct lock_object *lock, int what);
|
||||
static void lock_rm(struct lock_object *lock, int how);
|
||||
#ifdef KDTRACE_HOOKS
|
||||
static int owner_rm(struct lock_object *lock, struct thread **owner);
|
||||
#endif
|
||||
static int unlock_rm(struct lock_object *lock);
|
||||
|
||||
struct lock_class lock_class_rm = {
|
||||
.lc_name = "rm",
|
||||
.lc_flags = LC_SLEEPLOCK | LC_RECURSABLE,
|
||||
.lc_assert = assert_rm,
|
||||
#if 0
|
||||
#ifdef DDB
|
||||
.lc_ddb_show = db_show_rwlock,
|
||||
#endif
|
||||
#endif
|
||||
.lc_lock = lock_rm,
|
||||
.lc_unlock = unlock_rm,
|
||||
#ifdef KDTRACE_HOOKS
|
||||
.lc_owner = owner_rm,
|
||||
#endif
|
||||
};
|
||||
|
||||
static void
|
||||
assert_rm(struct lock_object *lock, int what)
|
||||
{
|
||||
|
||||
panic("assert_rm called");
|
||||
}
|
||||
|
||||
static void
|
||||
lock_rm(struct lock_object *lock, int how)
|
||||
{
|
||||
|
||||
panic("lock_rm called");
|
||||
}
|
||||
|
||||
static int
|
||||
unlock_rm(struct lock_object *lock)
|
||||
{
|
||||
|
||||
panic("unlock_rm called");
|
||||
}
|
||||
|
||||
#ifdef KDTRACE_HOOKS
|
||||
static int
|
||||
owner_rm(struct lock_object *lock, struct thread **owner)
|
||||
{
|
||||
|
||||
panic("owner_rm called");
|
||||
}
|
||||
#endif
|
111
rtemsbsd/src/rtems-bsd-timeout.c
Normal file
111
rtemsbsd/src/rtems-bsd-timeout.c
Normal file
@ -0,0 +1,111 @@
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_bsd_rtems
|
||||
*
|
||||
* @brief TODO.
|
||||
*/
|
||||
|
||||
/*
|
||||
* COPYRIGHT (c) 1989-2012.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
|
||||
#include <freebsd/machine/rtems-bsd-config.h>
|
||||
#include <freebsd/sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <freebsd/sys/param.h>
|
||||
#include <freebsd/sys/systm.h>
|
||||
#include <freebsd/sys/bus.h>
|
||||
#include <freebsd/sys/callout.h>
|
||||
#include <freebsd/sys/condvar.h>
|
||||
#include <freebsd/sys/interrupt.h>
|
||||
#include <freebsd/sys/kernel.h>
|
||||
#include <freebsd/sys/ktr.h>
|
||||
#include <freebsd/sys/lock.h>
|
||||
#include <freebsd/sys/malloc.h>
|
||||
#include <freebsd/sys/mutex.h>
|
||||
#include <freebsd/sys/proc.h>
|
||||
#include <freebsd/sys/sdt.h>
|
||||
|
||||
static int timeout_cpu;
|
||||
/*
|
||||
* There is one struct callout_cpu per cpu, holding all relevant
|
||||
* state for the callout processing thread on the individual CPU.
|
||||
* In particular:
|
||||
* cc_ticks is incremented once per tick in callout_cpu().
|
||||
* It tracks the global 'ticks' but in a way that the individual
|
||||
* threads should not worry about races in the order in which
|
||||
* hardclock() and hardclock_cpu() run on the various CPUs.
|
||||
* cc_softclock is advanced in callout_cpu() to point to the
|
||||
* first entry in cc_callwheel that may need handling. In turn,
|
||||
* a softclock() is scheduled so it can serve the various entries i
|
||||
* such that cc_softclock <= i <= cc_ticks .
|
||||
* XXX maybe cc_softclock and cc_ticks should be volatile ?
|
||||
*
|
||||
* cc_ticks is also used in callout_reset_cpu() to determine
|
||||
* when the callout should be served.
|
||||
*/
|
||||
struct callout_cpu {
|
||||
struct mtx cc_lock;
|
||||
struct callout *cc_callout;
|
||||
struct callout_tailq *cc_callwheel;
|
||||
struct callout_list cc_callfree;
|
||||
struct callout *cc_next;
|
||||
struct callout *cc_curr;
|
||||
void *cc_cookie;
|
||||
int cc_ticks;
|
||||
int cc_softticks;
|
||||
int cc_cancel;
|
||||
int cc_waiting;
|
||||
};
|
||||
|
||||
/*
|
||||
* timeout --
|
||||
* Execute a function after a specified length of time.
|
||||
*
|
||||
* untimeout --
|
||||
* Cancel previous timeout function call.
|
||||
*
|
||||
* callout_handle_init --
|
||||
* Initialize a handle so that using it with untimeout is benign.
|
||||
*
|
||||
* See AT&T BCI Driver Reference Manual for specification. This
|
||||
* implementation differs from that one in that although an
|
||||
* identification value is returned from timeout, the original
|
||||
* arguments to timeout as well as the identifier are used to
|
||||
* identify entries for untimeout.
|
||||
*/
|
||||
|
||||
struct callout_handle
|
||||
timeout(ftn, arg, to_ticks)
|
||||
timeout_t *ftn;
|
||||
void *arg;
|
||||
int to_ticks;
|
||||
{
|
||||
struct callout_cpu *cc;
|
||||
struct callout *new;
|
||||
struct callout_handle handle;
|
||||
|
||||
#if 0
|
||||
cc = CC_CPU(timeout_cpu);
|
||||
CC_LOCK(cc);
|
||||
/* Fill in the next free callout structure. */
|
||||
new = SLIST_FIRST(&cc->cc_callfree);
|
||||
if (new == NULL)
|
||||
/* XXX Attempt to malloc first */
|
||||
panic("timeout table full");
|
||||
SLIST_REMOVE_HEAD(&cc->cc_callfree, c_links.sle);
|
||||
callout_reset(new, to_ticks, ftn, arg);
|
||||
handle.callout = new;
|
||||
CC_UNLOCK(cc);
|
||||
#endif
|
||||
return (handle);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user