diff options
author | Kozlov Dmitry <dima@server> | 2010-09-23 19:43:39 +0400 |
---|---|---|
committer | Kozlov Dmitry <dima@server> | 2010-09-23 19:43:39 +0400 |
commit | 8681ad6d60565ca2e399156bf721f67f8a8bdc92 (patch) | |
tree | e736428b3d5dcfe52f65d9234b8ebc4ba17259cf /accel-pptpd/triton | |
parent | 82b0f0953159fc9ab8e387f5e6014dc377b14b38 (diff) | |
download | accel-ppp-xebd-8681ad6d60565ca2e399156bf721f67f8a8bdc92.tar.gz accel-ppp-xebd-8681ad6d60565ca2e399156bf721f67f8a8bdc92.zip |
various bug fixes
Diffstat (limited to 'accel-pptpd/triton')
-rw-r--r-- | accel-pptpd/triton/md.c | 9 | ||||
-rw-r--r-- | accel-pptpd/triton/mempool.c | 38 | ||||
-rw-r--r-- | accel-pptpd/triton/triton.c | 62 | ||||
-rw-r--r-- | accel-pptpd/triton/triton.h | 5 | ||||
-rw-r--r-- | accel-pptpd/triton/triton_p.h | 2 |
5 files changed, 80 insertions, 36 deletions
diff --git a/accel-pptpd/triton/md.c b/accel-pptpd/triton/md.c index 133abe8..444aebf 100644 --- a/accel-pptpd/triton/md.c +++ b/accel-pptpd/triton/md.c @@ -137,7 +137,8 @@ int __export triton_md_enable_handler(struct triton_md_handler_t *ud, int mode) if (mode & MD_MODE_WRITE) h->epoll_event.events |= EPOLLOUT; - h->epoll_event.events |= EPOLLET; + if (!h->trig_level) + h->epoll_event.events |= EPOLLET; if (events) r = epoll_ctl(epoll_fd, EPOLL_CTL_MOD, h->ud->fd, &h->epoll_event); @@ -179,3 +180,9 @@ int __export triton_md_disable_handler(struct triton_md_handler_t *ud,int mode) return r; } +void __export triton_md_set_trig(struct triton_md_handler_t *ud, int mode) +{ + struct _triton_md_handler_t *h = (struct _triton_md_handler_t *)ud->tpd; + h->trig_level = mode; +} + diff --git a/accel-pptpd/triton/mempool.c b/accel-pptpd/triton/mempool.c index 34739b4..16d6ab3 100644 --- a/accel-pptpd/triton/mempool.c +++ b/accel-pptpd/triton/mempool.c @@ -7,6 +7,8 @@ #include "memdebug.h" +#define MAGIC1 0x2233445566778899llu + struct _mempool_t { struct list_head entry; @@ -20,7 +22,8 @@ struct _item_t { struct _mempool_t *owner; struct list_head entry; - uint64_t magic; + uint64_t magic2; + uint64_t magic1; char ptr[0]; }; @@ -49,7 +52,7 @@ __export void *mempool_alloc(mempool_t *pool) { struct _mempool_t *p = (struct _mempool_t *)pool; struct _item_t *it; - uint32_t size = sizeof(*it) + p->size; + uint32_t size = sizeof(*it) + p->size + 8; spin_lock(&p->lock); if (!list_empty(&p->items)) { @@ -59,6 +62,8 @@ __export void *mempool_alloc(mempool_t *pool) __sync_fetch_and_sub(&triton_stat.mempool_available, size); + it->magic1 = MAGIC1; + return it->ptr; } spin_unlock(&p->lock); @@ -69,7 +74,9 @@ __export void *mempool_alloc(mempool_t *pool) return NULL; } it->owner = p; - it->magic = p->magic; + it->magic1 = MAGIC1; + it->magic2 = p->magic; + *(uint64_t*)(it->data + p->size) = it->magic2; __sync_fetch_and_add(&triton_stat.mempool_allocated, size); @@ -81,7 +88,7 @@ void __export *mempool_alloc_md(mempool_t *pool, const char *fname, int line) { struct _mempool_t *p = (struct _mempool_t *)pool; struct _item_t *it; - uint32_t size = sizeof(*it) + p->size; + uint32_t size = sizeof(*it) + p->size + 8; spin_lock(&p->lock); if (!list_empty(&p->items)) { @@ -91,6 +98,8 @@ void __export *mempool_alloc_md(mempool_t *pool, const char *fname, int line) __sync_fetch_and_sub(&triton_stat.mempool_available, size); + it->magic1 = MAGIC1; + return it->ptr; } spin_unlock(&p->lock); @@ -101,7 +110,9 @@ void __export *mempool_alloc_md(mempool_t *pool, const char *fname, int line) return NULL; } it->owner = p; - it->magic = p->magic; + it->magic2 = p->magic; + it->magic1 = MAGIC1; + *(uint64_t*)(it->ptr + p->size) = it->magic2; __sync_fetch_and_add(&triton_stat.mempool_allocated, size); @@ -112,12 +123,25 @@ void __export *mempool_alloc_md(mempool_t *pool, const char *fname, int line) __export void mempool_free(void *ptr) { struct _item_t *it = container_of(ptr, typeof(*it), ptr); - uint32_t size = sizeof(*it) + it->owner->size; + uint32_t size = sizeof(*it) + it->owner->size + 8; + + if (it->magic1 != MAGIC1) { + triton_log_error("mempool: memory corruption detected"); + abort(); + } - if (it->magic != it->owner->magic) { + if (it->magic2 != it->owner->magic) { triton_log_error("mempool: memory corruption detected"); abort(); } + + if (it->magic2 != *(uint64_t*)(it->ptr + it->owner->size)) { + triton_log_error("mempool: memory corruption detected"); + abort(); + } + + it->magic1 = 0; + spin_lock(&it->owner->lock); list_add_tail(&it->entry,&it->owner->items); spin_unlock(&it->owner->lock); diff --git a/accel-pptpd/triton/triton.c b/accel-pptpd/triton/triton.c index 2de2e67..ce880e9 100644 --- a/accel-pptpd/triton/triton.c +++ b/accel-pptpd/triton/triton.c @@ -50,11 +50,31 @@ static void* triton_thread(struct _triton_thread_t *thread) sigaddset(&set, SIGQUIT); while (1) { - __sync_fetch_and_sub(&triton_stat.thread_active, 1); - //printf("thread %p: enter sigwait\n", thread); - sigwait(&set, &sig); - //printf("thread %p: exit sigwait\n", thread); - __sync_fetch_and_add(&triton_stat.thread_active, 1); + spin_lock(&threads_lock); + if (!list_empty(&ctx_queue)) { + thread->ctx = list_entry(ctx_queue.next, typeof(*thread->ctx), entry2); + //printf("thread: %p: dequeued ctx %p\n", thread, thread->ctx); + list_del(&thread->ctx->entry2); + spin_unlock(&threads_lock); + spin_lock(&thread->ctx->lock); + thread->ctx->thread = thread; + thread->ctx->queued = 0; + spin_unlock(&thread->ctx->lock); + __sync_fetch_and_sub(&triton_stat.context_pending, 1); + } else { + //printf("thread: %p: sleeping\n", thread); + if (!terminate) + list_add(&thread->entry2, &sleep_threads); + spin_unlock(&threads_lock); + if (terminate) + return NULL; + + __sync_fetch_and_sub(&triton_stat.thread_active, 1); + //printf("thread %p: enter sigwait\n", thread); + sigwait(&set, &sig); + //printf("thread %p: exit sigwait\n", thread); + __sync_fetch_and_add(&triton_stat.thread_active, 1); + } cont: //printf("thread %p: ctx=%p %p\n", thread, thread->ctx, thread->ctx ? thread->ctx->thread : NULL); @@ -89,27 +109,6 @@ cont: } thread->ctx = NULL; - - spin_lock(&threads_lock); - if (!list_empty(&ctx_queue)) { - thread->ctx = list_entry(ctx_queue.next, typeof(*thread->ctx), entry2); - //printf("thread: %p: dequeued ctx %p\n", thread, thread->ctx); - list_del(&thread->ctx->entry2); - spin_unlock(&threads_lock); - spin_lock(&thread->ctx->lock); - thread->ctx->thread = thread; - thread->ctx->queued = 0; - spin_unlock(&thread->ctx->lock); - __sync_fetch_and_sub(&triton_stat.context_pending, 1); - goto cont; - } else { - //printf("thread: %p: sleeping\n", thread); - if (!terminate) - list_add(&thread->entry2, &sleep_threads); - spin_unlock(&threads_lock); - if (terminate) - return NULL; - } } } @@ -179,7 +178,7 @@ static void ctx_thread(struct _triton_context_t *ctx) struct _triton_thread_t *create_thread() { - struct _triton_thread_t *thread = _malloc(sizeof(*thread)); + struct _triton_thread_t *thread = malloc(sizeof(*thread)); if (!thread) return NULL; @@ -230,6 +229,7 @@ int __export triton_context_register(struct triton_context_t *ud, void *bf_arg) memset(ctx, 0, sizeof(*ctx)); ctx->ud = ud; ctx->bf_arg = bf_arg; + ctx->sleeping = 1; spinlock_init(&ctx->lock); INIT_LIST_HEAD(&ctx->handlers); INIT_LIST_HEAD(&ctx->timers); @@ -259,6 +259,7 @@ int __export triton_context_register(struct triton_context_t *ud, void *bf_arg) list_add_tail(&ctx->entry, &ctx_list); spin_unlock(&ctx_list_lock); + __sync_fetch_and_add(&triton_stat.context_sleeping, 1); __sync_fetch_and_add(&triton_stat.context_count, 1); return 0; @@ -314,6 +315,11 @@ void __export triton_context_schedule(struct triton_context_t *ud) ucontext_t *uctx = &ctx->thread->uctx; spin_lock(&ctx->lock); + if (ctx->wakeup) { + ctx->wakeup = 0; + spin_unlock(&ctx->lock); + return; + } ctx->sleeping = 1; ctx->thread = NULL; spin_unlock(&ctx->lock); @@ -337,6 +343,7 @@ int __export triton_context_wakeup(struct triton_context_t *ud) spin_lock(&ctx->lock); if (!ctx->sleeping) { + ctx->wakeup = 1; spin_unlock(&ctx->lock); return -1; } @@ -426,7 +433,6 @@ void __export triton_run() _exit(-1); list_add_tail(&t->entry, &threads); - list_add_tail(&t->entry2, &sleep_threads); } md_run(); diff --git a/accel-pptpd/triton/triton.h b/accel-pptpd/triton/triton.h index 6f70275..6809df0 100644 --- a/accel-pptpd/triton/triton.h +++ b/accel-pptpd/triton/triton.h @@ -76,10 +76,15 @@ int triton_context_call(struct triton_context_t *, void (*func)(void *), void *a #define MD_MODE_READ 1 #define MD_MODE_WRITE 2 + +#define MD_TRIG_EDGE 0 +#define MD_TRIG_LEVEL 1 + void triton_md_register_handler(struct triton_context_t *, struct triton_md_handler_t *); void triton_md_unregister_handler(struct triton_md_handler_t *h); int triton_md_enable_handler(struct triton_md_handler_t *h, int mode); int triton_md_disable_handler(struct triton_md_handler_t *h,int mode); +void triton_md_set_trig(struct triton_md_handler_t *h, int mode); int triton_timer_add(struct triton_context_t *ctx, struct triton_timer_t*,int abs_time); int triton_timer_mod(struct triton_timer_t *,int abs_time); diff --git a/accel-pptpd/triton/triton_p.h b/accel-pptpd/triton/triton_p.h index 7c0615f..c685051 100644 --- a/accel-pptpd/triton/triton_p.h +++ b/accel-pptpd/triton/triton_p.h @@ -40,6 +40,7 @@ struct _triton_context_t int queued:1; int sleeping:1; + int wakeup:1; int need_close:1; int need_free:1; int pending:1; @@ -56,6 +57,7 @@ struct _triton_md_handler_t struct epoll_event epoll_event; uint32_t trig_epoll_events; int pending:1; + int trig_level:1; struct triton_md_handler_t *ud; }; |