/* meas.c -- measure qt stuff. */
#include "copyright.h"
/* Need this to get assertions under Mach on the Sequent/i386: */
#ifdef __i386__
#define assert(ex) \
do { \
if (!(ex)) { \
fprintf (stderr, "[%s:%d] Assertion " #ex " failed\n", __FILE__, __LINE__); \
abort(); \
} \
} while (0)
#else
#include <assert.h>
#endif
/* This really ought to be defined in some ANSI include file (*I*
think...), but it's defined here instead, which leads us to another
machine dependency.
The `iaddr_t' type is an integer representation of a pointer,
suited for doing arithmetic on addresses, e.g. to round an address
to an alignment boundary. */
typedef unsigned long iaddr_t;
#include <stdarg.h> /* For varargs tryout. */
#include <stdio.h>
#include "b.h"
#include "qt.h"
#include "stp.h"
extern void exit (int status);
extern int atoi (char const *s);
extern int fprintf (FILE *out, char const *fmt, ...);
extern int fputs (char const *s, FILE *fp);
extern void free (void *sto);
extern void *malloc (unsigned nbytes);
extern void perror (char const *s);
void usage (void);
void tracer(void);
/* Round `v' to be `a'-aligned, assuming `a' is a power of two. */
#define ROUND(v, a) (((v) + (a) - 1) & ~((a)-1))
typedef struct thread_t {
qt_t *qt; /* Pointer to thread of function... */
void *stk;
void *top; /* Set top of stack if reuse. */
struct thread_t *next;
} thread_t;
static thread_t *
t_alloc (void)
{
thread_t *t;
int ssz = 0x1000;
t = malloc (sizeof(thread_t));
if (!t) {
perror ("malloc");
exit (1);
}
assert (ssz > QT_STKBASE);
t->stk = malloc (ssz);
t->stk = (void *)ROUND (((iaddr_t)t->stk), QT_STKALIGN);
if (!t->stk) {
perror ("malloc");
exit (1);
}
assert ((((iaddr_t)t->stk) & (QT_STKALIGN-1)) == 0);
t->top = QT_SP (t->stk, ssz - QT_STKBASE);
return (t);
}
static thread_t *
t_create (qt_only_t *starter, void *p0, qt_userf_t *f)
{
thread_t *t;
t = t_alloc();
t->qt = QT_ARGS (t->top, p0, t, f, starter);
return (t);
}
static void
t_free (thread_t *t)
{
free (t->stk);
free (t);
}
static void *
t_null (qt_t *old, void *p1, void *p2)
{
/* return (garbage); */
}
static void *
t_splat (qt_t *old, void *oldp, void *null)
{
*(qt_t **)oldp = old;
/* return (garbage); */
}
static char const test01_msg[] =
"*QT_SP(sto,sz), QT_ARGS(top,p0,p1,userf,first)";
static char const *test01_descr[] = {
"Performs 1 QT_SP and one QT_ARGS per iteration.",
NULL
};
/* This test gives a guess on how long it takes to initalize
a thread. */
static void
test01 (int n)
{
char stack[QT_STKBASE+QT_STKALIGN];
char *stk;
qt_t *top;
stk = (char *)ROUND (((iaddr_t)stack), QT_STKALIGN);
{
int i;
for (i=0; i<QT_STKBASE; ++i) {
stk[i] = 0;
}
}
while (n>0) {
/* RETVALUSED */
top = QT_SP (stk, QT_STKBASE); QT_ARGS (top, 0, 0, 0, 0);
#ifdef NDEF
top = QT_SP (stk, QT_STKBASE); QT_ARGS (top, 0, 0, 0, 0);
top = QT_SP (stk, QT_STKBASE); QT_ARGS (top, 0, 0, 0, 0);
top = QT_SP (stk, QT_STKBASE); QT_ARGS (top, 0, 0, 0, 0);
top = QT_SP (stk, QT_STKBASE); QT_ARGS (top, 0, 0, 0, 0);
top = QT_SP (stk, QT_STKBASE); QT_ARGS (top, 0, 0, 0, 0);
top = QT_SP (stk, QT_STKBASE); QT_ARGS (top, 0, 0, 0, 0);
top = QT_SP (stk, QT_STKBASE); QT_ARGS (top, 0, 0, 0, 0);
top = QT_SP (stk, QT_STKBASE); QT_ARGS (top, 0, 0, 0, 0);
top = QT_SP (stk, QT_STKBASE); QT_ARGS (top, 0, 0, 0, 0);
n -= 10;
#else
n -= 1;
#endif
}
}
static char const test02_msg[] = "QT_BLOCKI (0, 0, test02_aux, t->qt)";
static qt_t *rootthread;
static void
test02_aux1 (void *pu, void *pt, qt_userf_t *f)
{
QT_ABORT (t_null, 0, 0, rootthread);
}
static void *
test02_aux2 (qt_t *old, void *farg1, void *farg2)
{
rootthread = old;
/* return (garbage); */
}
static void
test02 (int n)
{
thread_t *t;
while (n>0) {
t = t_create (test02_aux1, 0, 0);
QT_BLOCKI (test02_aux2, 0, 0, t->qt);
t_free (t);
t = t_create (test02_aux1, 0, 0);
QT_BLOCKI (test02_aux2, 0, 0, t->qt);
t_free (t);
t = t_create (test02_aux1, 0, 0);
QT_BLOCKI (test02_aux2, 0, 0, t->qt);
t_free (t);
t = t_create (test02_aux1, 0, 0);
QT_BLOCKI (test02_aux2, 0, 0, t->qt);
t_free (t);
t = t_create (test02_aux1, 0, 0);
QT_BLOCKI (test02_aux2, 0, 0, t->qt);
t_free (t);
n -= 5;
}
}
static char const test03_msg[] = "QT_BLOCKI (...) test vals are right.";
/* Called by the thread function when it wants to shut down.
Return a value to the main thread. */
static void *
test03_aux0 (qt_t *old_is_garbage, void *farg1, void *farg2)
{
assert (farg1 == (void *)5);
assert (farg2 == (void *)6);
return ((void *)15); /* Some unlikely value. */
}
/* Called during new thread startup by main thread. Since the new
thread has never run before, return value is ignored. */
static void *
test03_aux1 (qt_t *old, void *farg1, void *farg2)
{
assert (old != NULL);
assert (farg1 == (void *)5);
assert (farg2 == (void *)6);
rootthread = old;
return ((void *)16); /* Different than `15'. */
}
static void
test03_aux2 (void *pu, void *pt, qt_userf_t *f)
{
assert (pu == (void *)1);
assert (f == (qt_userf_t *)4);
QT_ABORT (test03_aux0, (void *)5, (void *)6, rootthread);
}
static void
test03 (int n)
{
thread_t *t;
void *rv;
while (n>0) {
t = t_create (test03_aux2, (void *)1, (qt_userf_t *)4);
rv = QT_BLOCKI (test03_aux1, (void *)5, (void *)6, t->qt);
assert (rv == (void *)15);
t_free (t);
--n;
}
}
static char const test04_msg[] = "stp_start w/ no threads.";
static void
test04 (int n)
{
while (n>0) {
stp_init(); stp_start();
stp_init(); stp_start();
stp_init(); stp_start();
stp_init(); stp_start();
stp_init(); stp_start();
stp_init(); stp_start();
stp_init(); stp_start();
stp_init(); stp_start();
stp_init(); stp_start();
stp_init(); stp_start();
n -= 10;
}
}
static char const test05_msg[] = "stp w/ 2 yielding thread.";
static void
test05_aux (void *null)
{
stp_yield();
stp_yield();
}
static void
test05 (int n)
{
while (n>0) {
stp_init();
stp_create (test05_aux, 0);
stp_create (test05_aux, 0);
stp_start();
--n;
}
}
static char const test06_msg[] = "*QT_ARGS(...), QT_BLOCKI one thread";
static char const *test06_descr[] = {
"Does a QT_ARGS, QT_BLOCKI to a helper function that saves the",
"stack pointer of the main thread, calls an `only' function that",
"saves aborts the thread, calling a null helper function.",
":: start/stop = QT_ARGS + QT_BLOCKI + QT_ABORT + 3 procedure calls.",
NULL
};
/* This test initializes a thread, runs it, then returns to the main
program, which reinitializes the thread, runs it again, etc. Each
iteration corresponds to 1 init, 1 abort, 1 block. */
static qt_t *test06_sp;
static void
test06_aux2 (void *null0a, void *null1b, void *null2b, qt_userf_t *null)
{
QT_ABORT (t_null, 0, 0, test06_sp);
}
static void *
test06_aux3 (qt_t *sp, void *null0c, void *null1c)
{
test06_sp = sp;
/* return (garbage); */
}
static void
test06 (int n)
{
thread_t *t;
t = t_create (0, 0, 0);
while (n>0) {
/* RETVALUSED */
QT_ARGS (t->top, 0, 0, 0, test06_aux2);
QT_BLOCKI (test06_aux3, 0, 0, t->qt);
#ifdef NDEF
/* RETVALUSED */
QT_ARGS (t->top, 0, 0, 0, test06_aux2);
QT_BLOCKI (test06_aux3, 0, 0, t->qt);
/* RETVALUSED */
QT_ARGS (t->top, 0, 0, 0, test06_aux2);
QT_BLOCKI (test06_aux3, 0, 0, t->qt);
/* RETVALUSED */
QT_ARGS (t->top, 0, 0, 0, test06_aux2);
QT_BLOCKI (test06_aux3, 0, 0, t->qt);
/* RETVALUSED */
QT_ARGS (t->top, 0, 0, 0, test06_aux2);
QT_BLOCKI (test06_aux3, 0, 0, t->qt);
n -= 5;
#else
--n;
#endif
}
}
static char test07_msg[] = "*cswap between threads";
static char const *test07_descr[] = {
"Build a chain of threads where each thread has a fixed succe
没有合适的资源?快使用搜索试试~ 我知道了~
SystemC下实现LCR、HS、flood算法代码
共510个文件
h:207个
cpp:85个
hpp:74个
需积分: 9 13 下载量 168 浏览量
2016-06-18
20:11:49
上传
评论
收藏 11.31MB RAR 举报
温馨提示
Leader ElectionSystemC下实现LCR、HS、flood算法代码
资源推荐
资源详情
资源评论
收起资源包目录
SystemC下实现LCR、HS、flood算法代码 (510个子文件)
Makefile.am 4KB
Makefile.am 4KB
Makefile.am 3KB
Makefile.am 3KB
Makefile.am 3KB
Makefile.am 3KB
Makefile.am 2KB
Makefile.am 2KB
Makefile.am 2KB
Makefile.am 2KB
Makefile.am 2KB
assim 750B
Makefile.base 2KB
meas.c 21KB
stp.c 4KB
axp.c 4KB
m88k.c 3KB
powerpc.c 2KB
qt.c 1KB
null.c 623B
CHANGES 570B
config 10KB
sc_int64_mask.cpp 96KB
sc_signed.cpp 88KB
sc_simcontext.cpp 69KB
scfx_rep.cpp 58KB
sc_vcd_trace.cpp 57KB
sc_unsigned.cpp 55KB
sc_wif_trace.cpp 50KB
sc_nbutils.cpp 47KB
sc_thread_process.cpp 36KB
sc_method_process.cpp 32KB
sc_process.cpp 28KB
sc_module.cpp 24KB
sc_event.cpp 21KB
sc_port.cpp 21KB
sc_sensitive.cpp 21KB
sc_nbexterns.cpp 20KB
sc_fxnum.cpp 20KB
sc_report_handler.cpp 19KB
sc_int_base.cpp 18KB
sc_uint_base.cpp 18KB
sc_fxval.cpp 17KB
sc_reset.cpp 16KB
sc_object.cpp 16KB
sc_object_manager.cpp 15KB
sc_hash.cpp 15KB
sc_string.cpp 14KB
sc_clock.cpp 13KB
sc_time.cpp 13KB
sc_wait.cpp 12KB
sc_signal.cpp 12KB
sc_prim_channel.cpp 11KB
sc_signal_ports.cpp 11KB
sc_cor_pthread.cpp 10KB
sc_mempool.cpp 9KB
sc_bv_base.cpp 9KB
sc_int32_mask.cpp 9KB
sc_report.cpp 9KB
sc_phase_callback_registry.cpp 8KB
sc_trace_file_base.cpp 8KB
sc_export.cpp 8KB
sc_ver.cpp 7KB
sc_cor_qt.cpp 7KB
sc_list.cpp 7KB
sc_cor_fiber.cpp 6KB
sc_trace.cpp 6KB
sc_int64_io.cpp 5KB
sc_logic.cpp 5KB
sc_join.cpp 5KB
sc_main_main.cpp 5KB
sc_vector.cpp 5KB
sc_wait_cthread.cpp 5KB
sc_module_registry.cpp 5KB
sc_spawn_options.cpp 5KB
sc_fxdefs.cpp 5KB
sc_lv_base.cpp 5KB
sc_attribute.cpp 5KB
sc_utils_ids.cpp 5KB
sc_cthread_process.cpp 4KB
sc_signal_resolved.cpp 4KB
sc_value_base.cpp 4KB
sc_event_queue.cpp 4KB
sc_module_name.cpp 4KB
sc_semaphore.cpp 4KB
sc_event_finder.cpp 4KB
sc_except.cpp 4KB
sc_mutex.cpp 4KB
scfx_utils.cpp 4KB
sc_stop_here.cpp 4KB
sc_pq.cpp 4KB
sc_signal_resolved_ports.cpp 4KB
sc_bit.cpp 4KB
sc_name_gen.cpp 3KB
scfx_pow10.cpp 3KB
scfx_mant.cpp 3KB
sc_nbdefs.cpp 3KB
sc_interface.cpp 3KB
sc_fxtype_params.cpp 3KB
sc_length_param.cpp 3KB
共 510 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
阿韧LEO
- 粉丝: 0
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功