diff options
| author | 杨威 <[email protected]> | 2023-06-20 16:01:35 +0800 |
|---|---|---|
| committer | 杨威 <[email protected]> | 2023-06-26 20:18:26 +0800 |
| commit | 096bbda71ea301fe6dbdc603b5cbf06bfc0d73ed (patch) | |
| tree | 7009752d8a71c4f7f4aafcce6263464d5277be80 /src/support | |
| parent | acc0ee76193f032c64dca379acad9c7256d6e13f (diff) | |
🦄 refactor(Remove obsolete code): makefile and dictator
Diffstat (limited to 'src/support')
34 files changed, 0 insertions, 4054 deletions
diff --git a/src/support/CMakeLists.txt b/src/support/CMakeLists.txt index d1fb998..270f71d 100644 --- a/src/support/CMakeLists.txt +++ b/src/support/CMakeLists.txt @@ -5,7 +5,6 @@ add_subdirectory(symbol_check) add_subdirectory(MESA_sleep) add_subdirectory(md5) add_subdirectory(MESA_socket_wrap/src) -add_subdirectory(dictator2/src) add_subdirectory(tomlc99_wrap) add_subdirectory(dpdk_rte_hash) add_subdirectory(cpu_limit) diff --git a/src/support/MESA_sleep/Makefile b/src/support/MESA_sleep/Makefile deleted file mode 100644 index 9315625..0000000 --- a/src/support/MESA_sleep/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -all:demo libMESA_sleep.so libMESA_sleep.a
-
-
-
-demo:demo.o libMESA_sleep.so
- gcc -g -Wall demo.o -o demo -lpthread ./libMESA_sleep.so
-demo.o: demo.c
- gcc -g -c demo.c -o demo.o -W
-
-libMESA_sleep.so:MESA_sleep.o
- gcc -o $@ -fPIC -shared $^ -lpthread
-
-libMESA_sleep.a:MESA_sleep.o
- ar -cr $@ $^
- cp $@ ../../lib/
-
-#MESA_sleep.o:MESA_sleep.c
-MESA_sleep.o:mesa_sleep_nowatchBGT.c
- gcc -g -Wall -fPIC -shared -c $^ -o $@
-clean:
- rm -f *.o demo libMESA_sleep.so libMESA_sleep.a
-
diff --git a/src/support/MESA_socket_wrap/Makefile b/src/support/MESA_socket_wrap/Makefile deleted file mode 100644 index 2f9c182..0000000 --- a/src/support/MESA_socket_wrap/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -CFLAGS = -O2 -Wall -export CFLAGS - -all: - cd src; $(MAKE) - cd example;$(MAKE) -clean: - cd src; $(MAKE) clean - cd example; $(MAKE) clean diff --git a/src/support/MESA_socket_wrap/example/Makefile b/src/support/MESA_socket_wrap/example/Makefile deleted file mode 100644 index a1279a4..0000000 --- a/src/support/MESA_socket_wrap/example/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -CC=gcc -CCC=gcc - -TARGET=MESA_sock_example multi_thread_example udp_example test_read tcp_example - -all:$(TARGET) - -INC=-I../include -LIBPATH=-L../lib -LIB=-lpthread ../lib/libMESA_socket_wrap.a - -multi_thread_example:multi_thread_example.c - $(CC) $(CFLAGS) -o $@ $(INC) $^ $(LIBPATH) $(LIB) - -MESA_sock_example:MESA_sock_example.c - $(CC) $(CFLAGS) -o $@ $(INC) $^ $(LIBPATH) $(LIB) - -tcp_example:tcp_example.c - $(CC) $(CFLAGS) -o $@ $(INC) $^ $(LIBPATH) $(LIB) - -udp_example:udp_example.c - $(CC) $(CFLAGS) -o $@ $(INC) $^ $(LIBPATH) $(LIB) - -test_read:test_read.c - $(CC) $(CFLAGS) -o $@ $(INC) $^ $(LIBPATH) $(LIB) - -clean: - rm -f *.o $(TARGET) diff --git a/src/support/MESA_socket_wrap/src/Makefile b/src/support/MESA_socket_wrap/src/Makefile deleted file mode 100644 index dddf620..0000000 --- a/src/support/MESA_socket_wrap/src/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -CC=gcc -g -fPIC -CCC=gcc -g -fPIC - -TARGET=libMESA_socket_wrap.a libMESA_socket_wrap.so -INC=-I../include -LIBPATH=../lib - -OBJS=MESA_socket_wrap.o - -all:$(TARGET) - -.c.o: - $(CC) -c $(CFLAGS) -I. $(INC) $< - -.cpp.o: - $(CCC) -c $(CFLAGS) -I. $(INC) $< - -libMESA_socket_wrap.a: $(OBJS) - echo making lib ... - (rm -f $@ ;ar -r $@ $^; cp $@ $(LIBPATH); cp $@ ../../../lib/) - -libMESA_socket_wrap.so: $(OBJS) - $(CC) -o $@ $^ -shared - -clean: - rm -f *.o $(TARGET) diff --git a/src/support/dictator2/lib/.gitignore b/src/support/dictator2/lib/.gitignore deleted file mode 100644 index 1c2ee5e..0000000 --- a/src/support/dictator2/lib/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -SI/
-*.log
-*.o
-*.so
-bin/avrule/
-bin/avlog/
diff --git a/src/support/dictator2/readme.txt b/src/support/dictator2/readme.txt deleted file mode 100644 index 247b571..0000000 --- a/src/support/dictator2/readme.txt +++ /dev/null @@ -1,4 +0,0 @@ -LDDICTATOR = -Wl,-wrap,malloc -Wl,-wrap,calloc -Wl,-wrap,free -Wl,-wrap,realloc
-Define above variable in Makefile,then use this variable as a ld parameter to enable dictator.
-This is enough for shared dynamic library(.so).
-Further more,final executable file need to link with libdictator.a or libdictator_debug.a to include dictator binary.
\ No newline at end of file diff --git a/src/support/dictator2/src/CMakeLists.txt b/src/support/dictator2/src/CMakeLists.txt deleted file mode 100644 index d5f0315..0000000 --- a/src/support/dictator2/src/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8...3.10) - -include_directories(${MESA_SDK_PREFIX}/include) -include_directories(${MESA_SDK_PREFIX}/include/MESA) -#include_directories(${CMAKE_SOURCE_DIR}/packet_io) -#include_directories(${CMAKE_SOURCE_DIR}/project) -#include_directories(${CMAKE_SOURCE_DIR}/include) -#include_directories(${CMAKE_SOURCE_DIR}/include/support) -#include_directories(${CMAKE_SOURCE_DIR}/dealpkt) - -add_definitions(${MEM_POOL_DEFINITIONS} -D_DEFAULT_SOURCE -D_DEFAULT_SOURCE -D__DEFAULT_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H) -add_library(dictator2 STATIC dictator.cpp dictator_debuger.cpp - D_internal/D_kernel_list.cpp D_internal/list_common.cpp - D_internal/MESA_hash_v2.cpp D_internal/MESA_list_v2.cpp) - -add_library(dictator2_debug STATIC dictator.cpp dictator_debuger.cpp - D_internal/D_kernel_list.cpp D_internal/list_common.cpp - D_internal/MESA_hash_v2.cpp D_internal/MESA_list_v2.cpp) -target_compile_definitions(dictator2_debug PRIVATE "-DDICTATOR_DEBUG")
\ No newline at end of file diff --git a/src/support/dictator2/src/D_internal/D_kernel_list.cpp b/src/support/dictator2/src/D_internal/D_kernel_list.cpp deleted file mode 100644 index d1131e8..0000000 --- a/src/support/dictator2/src/D_internal/D_kernel_list.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include <stdio.h>
-#include <assert.h>
-#include "D_kernel_list.h"
-
-void D_kernel_list_init(struct D_kernel_list_head *head)
-{
- assert(head);
- head->next = head;
- head->prev = head;
-}
-
-void D_kernel_list_destroy(struct D_kernel_list_head *head,\
- void (*my_list_free_cb)(struct D_kernel_list_head *del))
-{
- struct D_kernel_list_head *cur, *next;
-
- assert(head && my_list_free_cb);
-
- cur = head->next;
- while(head != cur)
- {
- next = cur->next;
- my_list_free_cb(cur);
- cur = next;
- }
-}
-
-inline static void __D_kernel_list_delete(struct D_kernel_list_head *prev, struct D_kernel_list_head *next)
-{
- next->prev = prev;
- prev->next = next;
-}
-
-void D_kernel_list_delete(struct D_kernel_list_head *head,struct D_kernel_list_head *del)
-{
- __D_kernel_list_delete(del->prev, del->next);
-}
-
-inline static void __D_kernel_list_insert(struct D_kernel_list_head *new_node,
- struct D_kernel_list_head *prev, struct D_kernel_list_head *next)
-{
- next->prev = new_node;
- new_node->next = next;
- new_node->prev = prev;
- prev->next = new_node;
-}
-
-void D_kernel_list_add_head(struct D_kernel_list_head *head,
- struct D_kernel_list_head *new_node)
-{
- __D_kernel_list_insert(new_node, head, head->next);
-}
-
-void D_kernel_list_add_tail(struct D_kernel_list_head *head,
- struct D_kernel_list_head *new_node)
-{
- __D_kernel_list_insert(new_node, head->prev, head);
-}
-
-struct D_kernel_list_head * D_kernel_list_get_head(struct D_kernel_list_head *head)
-{
- struct D_kernel_list_head*p=NULL;
- if(LIST_IS_EMPTY(head))
- {
- return NULL;
- }
- p=head->next;
- D_kernel_list_delete(head, p);
- return p;
-}
-struct D_kernel_list_head * D_kernel_list_get_tail(struct D_kernel_list_head *head)
-{
- struct D_kernel_list_head*p=NULL;
- if(LIST_IS_EMPTY(head))
- {
- return NULL;
- }
- p=head->prev;
- D_kernel_list_delete(head, p);
- return p;
-}
-void D_kernel_list_move_head(struct D_kernel_list_head *head,
- struct D_kernel_list_head *node)
-{
- D_kernel_list_delete(node->prev, node->next);
- __D_kernel_list_insert(node, head, head->next);
-}
-
diff --git a/src/support/dictator2/src/D_internal/D_kernel_list.h b/src/support/dictator2/src/D_internal/D_kernel_list.h deleted file mode 100644 index 6968f03..0000000 --- a/src/support/dictator2/src/D_internal/D_kernel_list.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef _D_KERNEL_LIST_
-#define _D_KERNEL_LIST_
-
-#include <pthread.h>
-
-struct D_kernel_list_head{
- struct D_kernel_list_head *next, *prev;
-};
-
-#ifndef offsetof
-#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
-#endif
-
-#ifndef container_of
-#define container_of(ptr, type, member) ({ \
- const typeof( ((type *)0)->member ) *__mptr = (ptr); \
- (type *)( (char *)__mptr - offsetof(type,member) );})
-#endif
-
-
-#define D_kernel_list_entry(ptr, type, member) container_of(ptr, type, member)
-
-#define LIST_IS_EMPTY(_head) (((_head)->next == (_head)) ? 1 : 0 )
-
-#define D_kernel_list_for_each_safe(pos, n, head) \
- for (pos = (head)->next, n = pos->next; pos != (head); \
- pos = n, n = pos->next)
-
-void D_kernel_list_init(struct D_kernel_list_head *head);
-void D_kernel_list_add_head(struct D_kernel_list_head *head, struct D_kernel_list_head *new_node);
-void D_kernel_list_add_tail(struct D_kernel_list_head *head,struct D_kernel_list_head *new_node);
-void D_kernel_list_delete(struct D_kernel_list_head *head,struct D_kernel_list_head *del);
-void D_kernel_list_move_head(struct D_kernel_list_head *head, struct D_kernel_list_head *node);
-void D_kernel_list_destroy(struct D_kernel_list_head *head, void (*my_list_free)(struct D_kernel_list_head *del));
-struct D_kernel_list_head * D_kernel_list_get_head(struct D_kernel_list_head *head);
-struct D_kernel_list_head * D_kernel_list_get_tail(struct D_kernel_list_head *head);
-
-#endif
-
diff --git a/src/support/dictator2/src/D_internal/MESA_hash_v2.cpp b/src/support/dictator2/src/D_internal/MESA_hash_v2.cpp deleted file mode 100644 index d6b9219..0000000 --- a/src/support/dictator2/src/D_internal/MESA_hash_v2.cpp +++ /dev/null @@ -1,655 +0,0 @@ -#include <stdio.h>
-#include <time.h>
-#include <unistd.h>
-#include "MESA_hash_v2.h"
-#include "MESA_list_v2.h"
-#include "list_common.h"
-#include "../dictator.h"
-
-#if MESA_HASH_DEBUG
-static int *hash_slot_list_num; /* ���ڼ�¼ÿ��slot�ҽ������ڵ����� */
-static int max_slot_list_num = 0; /* ÿ��slot����ͻ�� */
-#endif
-#ifndef MAX
-#define MAX(a, b) (((a) > (b)) ? (a) : (b))
-#endif
-
-#ifndef MIN
-#define MIN(a, b) (((a) < (b)) ? (a) : (b))
-#endif
-/*
- * hash implementation, xh, 2001-07-26
- */
-
-/*Developer Notice:
- in hash_add function,hash table MALLOC memory for keys and RECORD data pointer,
- which means need NOT malloc memory for keys before call hash_add. zhengchao
-
- 2013-05, LiJia, add thread safe implement.
-*/
-
-
-/*
- �����ܼ�������ͻ��ÿN��Hash-slot����һ��������,
- (HASH_Index % HASH_TABLE_MUTEX_NUM)��ֵ��ͬ��item����һ��mutex.
-*/
-#define HASH_TABLE_MUTEX_NUM (256)
-
-
-static HASH_INLINE int D_INTERNAL___MESA_hash_mutex_unlock(MESA_hash_tab_v2_t * table,uint index)
-{
- if(table->is_thread_safe){
- return pthread_mutex_unlock(&table->htable_mutex[index%HASH_TABLE_MUTEX_NUM]);
- }
- return 0;
-}
-
-
-static HASH_INLINE int D_INTERNAL___MESA_hash_mutex_lock(MESA_hash_tab_v2_t * table, uint index)
-{
- if(table->is_thread_safe){
- return pthread_mutex_lock(&table->htable_mutex[index%HASH_TABLE_MUTEX_NUM]);
- }
- return 0;
-}
-
-static int D_INTERNAL___MESA_hash_time_list_insert(MESA_hash_tab_v2_t *table,
- hash_elem_v2_t *hash_elem, uint index)
-{
- int ret = 0;
- MESA_queue_head_v2_t *list_head;
-
- if(table->is_thread_safe){
- list_head = &table->hlist_head[index%HASH_TABLE_MUTEX_NUM];
- }else{
- list_head = &table->hlist_head[0];
- }
-
- D_INTERNAL_MESA_q_join_tail_v2(list_head, &hash_elem->list_node);
-
- return ret;
-}
-
-static HASH_INLINE void D_INTERNAL___MESA_hash_time_list_delete(MESA_hash_tab_v2_t *table,
- hash_elem_v2_t *hash_elem, uint index)
-{
- MESA_queue_head_v2_t *list_head;
-
- if(table->is_thread_safe){
- list_head = &table->hlist_head[index%HASH_TABLE_MUTEX_NUM];
- }else{
- list_head = &table->hlist_head[0];
- }
- D_INTERNAL_MESA_q_leave_list_v2(list_head, &hash_elem->list_node);
-
- return;
-}
-
-static HASH_INLINE int D_INTERNAL___MESA_hash_time_list_lru(MESA_hash_tab_v2_t *table,
- hash_elem_v2_t *hash_elem, uint index)
-{
- int ret = 0;
- MESA_queue_head_v2_t *list_head;
-
- if(table->is_thread_safe){
- list_head = &table->hlist_head[index%HASH_TABLE_MUTEX_NUM];
- }else{
- list_head = &table->hlist_head[0];
- }
-
- D_INTERNAL_MESA_q_move_tail_v2(list_head, &hash_elem->list_node);
-
- return ret;
-}
-
-
-/*
- search HASH-table whether has duplicate key.
-*/
-static HASH_INLINE hash_elem_v2_t *D_INTERNAL___MESA_hash_key_search(MESA_hash_tab_v2_t * table,
- uchar * key, uint size, uint index)
-{
- hash_elem_v2_t * ptr;
- for(ptr = table->elems[index]; NULL != ptr; ptr = ptr->next) {
- if(!table->key_comp(ptr->key, ptr->size, key, size))
- break;
- }
-
- return ptr;
-}
-
-static HASH_INLINE void D_INTERNAL___MESA_hash_list_insert(MESA_hash_tab_v2_t * table,
- hash_elem_v2_t * ptr, uint index)
-{
- ptr->prev = NULL;
- ptr->next = table->elems[index];
- if(NULL != table->elems[index]){
- table->elems[index]->prev = ptr;
- }
- table->elems[index] = ptr;
-
- table->elem_count++;
-}
-
-static HASH_INLINE void D_INTERNAL___MESA_hash_list_delete(MESA_hash_tab_v2_t * table,
- hash_elem_v2_t * ptr, uint index)
-{
- if(NULL != ptr->prev){
- ptr->prev->next = ptr->next;
- }else{
- table->elems[index] = ptr->next;
- }
-
- if(NULL != ptr->next){
- ptr->next->prev = ptr->prev;
- }
-
- table->elem_count--;
-}
-
-static HASH_INLINE hash_elem_v2_t *D_INTERNAL___MESA_hash_alloc_resource(
- uchar * key, uint size, void * data, uint index
- ,IMP_t*p_mempool)
-{
- hash_elem_v2_t *ptr = NULL;
- if(NULL == (ptr = (hash_elem_v2_t*)block_alloc(sizeof(hash_elem_v2_t),p_mempool))){
- goto err_1;
- }
- if(NULL == (ptr->key = (unsigned char*)block_alloc(size,p_mempool))) {
- goto err_2;
- }
- memcpy(ptr->key, key, size);
- ptr->size = size;
- ptr->data = data; /* lijia comment, dataָ����ڴ��ǵ���������� */
- ptr->list_node.nextele = NULL;
- ptr->list_node.preele = NULL;
- ptr->list_node.quiddity = (void *)ptr;
- ptr->op_time = HASH_TIME_NOW();
- ptr->hash_index = index;
- return ptr;
-
-err_2:
- block_free(ptr,p_mempool);
-err_1:
- return NULL;
-}
-
-
-static HASH_INLINE void D_INTERNAL___MESA_hash_free_resource(MESA_hash_tab_v2_t * table,
- hash_elem_v2_t *ptr, void (* func)(void *))
-{
- IMP_t *p_mempool=table->p_mempool;
- if(NULL != func){
- func(ptr->data);
- }else if(NULL != table->free){
- table->free(ptr->data);
- }
- block_free(ptr->key,p_mempool);
- block_free(ptr,p_mempool);
-}
-
-
-static HASH_INLINE void D_INTERNAL___MESA_hash_del_node(MESA_hash_tab_v2_t * table,
- hash_elem_v2_t * ptr, uint index, void (* func)(void *))
-{
- D_INTERNAL___MESA_hash_list_delete(table, ptr, index);
- D_INTERNAL___MESA_hash_time_list_delete(table, ptr, index);
- D_INTERNAL___MESA_hash_free_resource(table, ptr, func);
-}
-
-/*
- kick out a oldest node from HASH-table if elements number exceed threshold,
- or the node's operate time expired.
-*/
-static void D_INTERNAL___MESA_hash_eliminate(MESA_hash_tab_v2_t *table, uint index)
-{
- MESA_list_index_v2_t *list_head, *oldest_node;
- hash_elem_v2_t *hash_elem;
- int do_eliminate = 0;
- if(table->is_thread_safe){
- list_head = &table->hlist_head[index%HASH_TABLE_MUTEX_NUM];
- }else{
- list_head = &table->hlist_head[0];
- }
-
- oldest_node = D_INTERNAL_MESA_q_read_head_v2(list_head);
- if(oldest_node){
- hash_elem = (hash_elem_v2_t *)oldest_node->quiddity;
- if((table->max_elem_num != 0)
- && (table->elem_count > table->max_elem_num)){ /* too many elements */
- do_eliminate |= 0x01;
- }else if((table->expire_time != 0)
- &&(hash_elem->op_time + table->expire_time < HASH_TIME_NOW())){ /* time expired */
- do_eliminate |= 0x10;
- }
- if(do_eliminate != 0){
- if(table->expire){
- table->expire(hash_elem->data);
- }
- D_INTERNAL___MESA_hash_del_node(table ,hash_elem, hash_elem->hash_index, NULL);
- //printf("eliminate a oldest element!\n");
- }
- }
-}
-
-/*
- * name: D_INTERNAL___default_hash_key2index
- * functionality: computes index from key, default key2index implementation
- * if previous hash_create() call did not provide such a function;
- * params:
- * table: with which table are you dealing, we want this param be present
- * because we may need size of table to compute the key;
- * key: what is the label;
- * size: how long is the label;
- * returns:
- * index in given table for given key, never fails;
- */
-#if 0
-static uint D_INTERNAL___default_hash_key2index(MESA_hash_tab_v2_t * table, uchar * key, uint size)
-{
- uchar * c;
- uint h, g;
-
- for (c = key, h = 0; c - key < size; c ++) {
- h = (h << 2) + c[0];
- if(0 != (g = (h & 0xf0000000))) {
- h = h ^ (g >> 24);
- h = h ^ g;
- }
- }
- return h % table->size;
-}
-#else
-/* BKDR Hash Function */
-static uint D_INTERNAL___default_hash_key2index(MESA_hash_tab_v2_t * table, uchar *str, uint size)
-{
- uint i;
- uint seed = 131; // 31 131 1313 13131 131313 etc..
- uint hash = 0;
- uint cmp_size=MIN(size,96);
- for(i = 0; i < cmp_size; i++){
- if((i&0x7)<3)
- hash = hash * seed + (*str++);
- else
- *str++;
- }
-
- return (hash % table->size);
-}
-#endif
-
-/*
- * name: D_INTERNAL___default_hash_key_comp
- * functionality: compares two key;
- * params:
- * key1, key2: what are the labels;
- * size1, size2: how long are them;
- * returns:
- * 0, if two keys are identical; (just a simple memcmp() );
- * 1, no.
- */
-static int D_INTERNAL___default_hash_key_comp(uchar * key1, uint size1, uchar * key2, uint size2)
-{
- if(size1 != size2) return 1;
- return memcmp(key1, key2, size1);
-}
-
-/* �����Ƿ�2��N�η� */
-static HASH_INLINE int D_INTERNAL_number_is_2N(uint n)
-{
-#if 0
- uint s;
- for(s = n; s != 0; ) {
- if(0x01 != s && 0x01 == (0x01 & s)) return 0;
- s = s >> 1;
- }
-#else
- if(n & (n-1)){
- return 0;
- }
-#endif
-
- return 1;
-}
-
-/*
- * name: hash_create
- * functionality: allocats memory for hash slots, and fill in hash structure;
- * param:
- * table: caller allocated hash table structure, gets filled in;
- * is_thread_safe:1:create thread safe hashtable; 0:create hashtable without thread safe insurance;
- * size: how big do you want the table to be, must be 2^N;
- * max_elem_num: the maximum elements of the HASH-table,0 means infinite;
- * key_comp: hash key compare function, use default function if NULL;
- * key2index: hash key->index computing function, use default function if NULL;
- * data_free: release resources function, only free attached data pointer if NULL;
- * data_expire: if expire_time > 0, call this function when a element expire, can be NULL;
- * eliminate_type: the algorithm of elimanate a expired element, 0:FIFO; 1:LRU.
- * expire_time: the element expire time in second, 0 means infinite.
- * returns:
- * 0, success;
- * -1, memory failure;
- * -2, parameter not acceptable;
- */
-int D_INTERNAL_MESA_hash_create_v2(MESA_hash_tab_v2_t * table, uint is_thread_safe,
- uint size, uint max_elem_num,
- key_comp_t * key_comp,
- key2index_t * key2index,
- void (* data_free)(void *),
- void (* data_expire)(void *),
- int eliminate_type,
- int expire_time,
- IMP_t* p_mempool)
-{
- int i=0,j, ret = 0;
-
- if(D_INTERNAL_number_is_2N(size) == 0){
- return -2;
- }
-
- table->elems = (hash_elem_v2_t**)mmap_alloc(sizeof(hash_elem_v2_t *) * size);
- if(NULL == table->elems)
- return -1;
- memset(table->elems, 0, sizeof(hash_elem_v2_t *) * size);
- table->size = size;
- if(NULL == key_comp) table->key_comp = D_INTERNAL___default_hash_key_comp;
- else table->key_comp = key_comp;
- if(NULL == key2index) table->key2index = D_INTERNAL___default_hash_key2index;
- else table->key2index = key2index;
- table->expire = data_expire;
- //if(NULL == data_free) return -1; /* 2013-05-06 modify, can be NULL */
- table->free = data_free;
- table->elem_count = 0;
- table->max_elem_num = max_elem_num;
- //table->threshold_lo = 0;
- //table->threshold_hi = size;
- table->eliminate_type = eliminate_type;
- table->expire_time = expire_time;
- table->is_thread_safe = is_thread_safe;
- table->p_mempool=p_mempool;
- if(table->is_thread_safe){
- table->htable_mutex = (pthread_mutex_t *)mmap_alloc(sizeof(pthread_mutex_t) * HASH_TABLE_MUTEX_NUM);
- if(NULL == table->htable_mutex){
- ret = -1;
- goto err_1;
- }
- for(i = 0; i < HASH_TABLE_MUTEX_NUM; i++){
- if(pthread_mutex_init(&table->htable_mutex[i], NULL)!=0){
- ret = -1;
- goto err_2;
- }
- }
- table->hlist_head = (MESA_list_index_v2_t *)mmap_alloc(sizeof(MESA_list_index_v2_t) * HASH_TABLE_MUTEX_NUM);
- if(NULL == table->hlist_head){
- ret = -1;
- goto err_2;
- }
- for(i=0;i<HASH_TABLE_MUTEX_NUM;i++){
- D_INTERNAL_MESA_list_init_v2(&table->hlist_head[i]);
- }
- }else{
- table->hlist_head = (MESA_list_index_v2_t *)mmap_alloc(sizeof(MESA_list_index_v2_t));
- if(NULL == table->hlist_head){
- ret = -1;
- goto err_2;
- }
- D_INTERNAL_MESA_list_init_v2(&table->hlist_head[0]);
- }
-
- return 0;
-
-err_2:
- for(j = 0; j < i; j++){
- pthread_mutex_destroy(&table->htable_mutex[j]);
- }
- mmap_free(table->htable_mutex);
-err_1:
- mmap_free(table->elems);
- return ret;
-}
-
-/*
- * frees table->elems and chains attached to each element of it.
- * always returns 0.
- */
-int D_INTERNAL_MESA_hash_destroy_v2(MESA_hash_tab_v2_t * table, void (* func)(void *))
-{
- int i;
- hash_elem_v2_t * cur;
- IMP_t* p_mempool=table->p_mempool;
- for(i = 0; i < (int)table->size; i ++) {
- while(NULL != table->elems[i]) {
- cur = table->elems[i];
- if(NULL != func) func(cur->data);
- else if(NULL != table->free) table->free(cur->data);
- table->elems[i] = (table->elems[i])->next;
- block_free(cur->key,p_mempool);
- block_free(cur,p_mempool);
- }
- }
- if(table->is_thread_safe){
- for(i=0;i<HASH_TABLE_MUTEX_NUM;i++)
- pthread_mutex_destroy(&table->htable_mutex[i]);
- mmap_free(table->htable_mutex);
- }
- mmap_free(table->hlist_head);
- mmap_free(table->elems);
- table->elems = NULL;
- table->size = 0;
-
- return 0;
-}
-
-/*
- * adds data identified by key to table.
- * table->elems always points to the newest added element.
- * no two elements should have a same key, although them may have a same index.
- * returns:
- * -1, if duplicate is found;
- * -2, if memory fails;
- * 0, success.
- */
-int D_INTERNAL_MESA_hash_add_v2(MESA_hash_tab_v2_t * table, uchar * key, uint size,
- void * data)
-{
- uint index;
- hash_elem_v2_t * ptr;
- int ret = 0;
- IMP_t *p_mempool=table->p_mempool;
- index = table->key2index(table, key, size);
-
- D_INTERNAL___MESA_hash_mutex_lock(table,index);
- if(D_INTERNAL___MESA_hash_key_search(table,key,size,index)){ /* already exist */
- ret = -1;
- goto err;
- }
- ptr = D_INTERNAL___MESA_hash_alloc_resource(key, size, data, index,p_mempool);
- if(NULL == ptr){
- ret = -2;
- goto err;
- }
- D_INTERNAL___MESA_hash_list_insert(table, ptr, index);
- D_INTERNAL___MESA_hash_time_list_insert(table, ptr, index);
-
- D_INTERNAL___MESA_hash_eliminate(table,index);
-
- D_INTERNAL___MESA_hash_mutex_unlock(table,index);
-
-#if MESA_HASH_DEBUG
- hash_slot_list_num[index]++;
- if(max_slot_list_num < hash_slot_list_num[index]){
- max_slot_list_num = hash_slot_list_num[index];
- printf("Hash table max list num:%d\n", max_slot_list_num);
- }
-#endif
-
- return 0;
-
-err:
- D_INTERNAL___MESA_hash_mutex_unlock(table,index);
- return ret;
-}
-
-
-
-/*
- * name: hash_del
- * functionality: deletes item from table.
- * param:
- * table: from which table do you want to delete;
- * key : what is the label;
- * size : how long is the label;
- * func : callback function to clean up data attached to hash items,
- if this pointer is NULL will call "data_free" in MESA_hash_create(),
- * returns:
- * 0, success;
- * -1, no such thing;
- */
-int D_INTERNAL_MESA_hash_del_v2(MESA_hash_tab_v2_t * table, uchar * key, uint size,
- void (* func)(void *))
-{
- uint index;
- hash_elem_v2_t * ptr;
- int ret = 0;
- index = table->key2index(table, key, size);
-
- D_INTERNAL___MESA_hash_mutex_lock(table,index);
- ptr = D_INTERNAL___MESA_hash_key_search(table,key,size,index);
- if(NULL == ptr){
- ret = -1;
- goto err; /* success, maybe? why? */
- }
-
- D_INTERNAL___MESA_hash_del_node(table ,ptr, index, func);
-
- //D_INTERNAL___MESA_hash_eliminate(table,index);
-
- D_INTERNAL___MESA_hash_mutex_unlock(table,index);
-
- return ret;
-
-err:
- D_INTERNAL___MESA_hash_mutex_unlock(table,index);
- return ret;
-}
-
-/*
- * name: hash_sel
- * functionality: selects item from table;
- * param:
- * table: from which table do you want to select;
- * key: what is the label;
- * size: how long is the label;
- *
- * return:
- * not NULL :pointer to attached data;
- * NULL :not found(thus be careful if you are attaching NULL data on purpose).
- */
-void *D_INTERNAL_MESA_hash_sel_v2(MESA_hash_tab_v2_t * table, uchar * key, uint size)
-{
- uint index;
- hash_elem_v2_t * ptr;
- void *ret;
- index = table->key2index(table, key, size);
- D_INTERNAL___MESA_hash_mutex_lock(table,index);
- D_INTERNAL___MESA_hash_eliminate(table,index); /* 2013-09-12 LiJia modify, ����̭�ٲ���,����Ὣ�鵽�Ľ����̭���ַ��ظ��˵����� */
- ptr = D_INTERNAL___MESA_hash_key_search(table,key,size,index);
- if(NULL != ptr){
- ret = ptr->data;
- if(HASH_ELIMINATE_ALGO_LRU==table->eliminate_type){
- ptr->op_time = HASH_TIME_NOW();
- D_INTERNAL___MESA_hash_time_list_lru(table, ptr, index);
- }
- }else{
- ret = NULL;
- }
-
- D_INTERNAL___MESA_hash_mutex_unlock(table,index);
-
- return ret;
-}
-
-/*
- * name: hash_sel
- * functionality: selects item from table;
- * in param:
- * table: from which table do you want to select;
- * key : what is the label;
- * size : how long is the label;
- * cb : call this function when found the attached data;
- * arg : the argument of "cb" function.
- * out param:
- * cb_ret: the return value of the function "cb".
- * return:
- * not NULL :pointer to attached data;
- * NULL :not found(thus be careful if you are attaching NULL data on purpose).
- */
-void *D_INTERNAL_MESA_hash_sel_with_cb_v2(MESA_hash_tab_v2_t * table, uchar * key, uint size,
- hash_cb_t *cb, void *arg, int *cb_ret)
-{
- uint index;
- hash_elem_v2_t * ptr;
- void *ret;
-
- index = table->key2index(table, key, size);
- D_INTERNAL___MESA_hash_mutex_lock(table,index);
- D_INTERNAL___MESA_hash_eliminate(table,index);/* 2013-09-12 LiJia modify, ����̭�ٲ���,����Ὣ�鵽�Ľ����̭���ַ��ظ��˵����� */
- ptr = D_INTERNAL___MESA_hash_key_search(table,key,size,index);
- if(NULL != ptr){
- ret = ptr->data;
- if(HASH_ELIMINATE_ALGO_LRU == table->eliminate_type){
- ptr->op_time = HASH_TIME_NOW();
- D_INTERNAL___MESA_hash_time_list_lru(table, ptr, index);
- }
- if(cb){
- *cb_ret = cb(ptr->data, arg);
- }
- }else{
- ret = NULL;
- if(cb){
- *cb_ret = cb(NULL, arg);
- }
- }
-
- D_INTERNAL___MESA_hash_mutex_unlock(table,index);
-
- return ret;
-}
-
-int D_INTERNAL_MESA_hash_iterate_v2(MESA_hash_tab_v2_t * table, void (* func)(uchar * key, uint size, void * data))
-{
- int i;
- hash_elem_v2_t * ptr;
-
- if(NULL == func){
- return 0;
- }
-
- for(i = 0; i < (int)table->size; i++) {
- D_INTERNAL___MESA_hash_mutex_lock(table, i/(table->size/HASH_TABLE_MUTEX_NUM));
- for(ptr = table->elems[i]; NULL != ptr; ptr = ptr->next)
- func(ptr->key, ptr->size, ptr->data);
- D_INTERNAL___MESA_hash_mutex_unlock(table, i/(table->size/HASH_TABLE_MUTEX_NUM));
- }
-
- return 0;
-}
-
-int D_INTERNAL_MESA_hash_iterate_v2_2(MESA_hash_tab_v2_t * table, void (* func)(uchar * key, uint size, void * data, void * u), void * user)
-{
- int i;
- hash_elem_v2_t * ptr;
-
- if(NULL == func){
- return 0;
- }
- for(i = 0; i < (int)table->size; i ++) {
- D_INTERNAL___MESA_hash_mutex_lock(table, i/(table->size/HASH_TABLE_MUTEX_NUM));
- for(ptr = table->elems[i]; NULL != ptr; ptr = ptr->next)
- func(ptr->key, ptr->size, ptr->data, user);
- D_INTERNAL___MESA_hash_mutex_unlock(table, i/(table->size/HASH_TABLE_MUTEX_NUM));
- }
-
- return 0;
-}
-
diff --git a/src/support/dictator2/src/D_internal/MESA_hash_v2.h b/src/support/dictator2/src/D_internal/MESA_hash_v2.h deleted file mode 100644 index 52d5c19..0000000 --- a/src/support/dictator2/src/D_internal/MESA_hash_v2.h +++ /dev/null @@ -1,262 +0,0 @@ -#ifndef _LIB_HASH_H_INCLUDED_
-#define _LIB_HASH_H_INCLUDED_
-
-
-/*
- * general purpose hash table implementation.
- *
- * xiang hong
- * 2002-07-28
- *History:
- *2012-03-23 zhengchao add thread safe option and link expire feature;
- */
-
-
-
-#include <errno.h>
-#include <string.h>
-#include <pthread.h>
-#include "MESA_list_v2.h"
-#include "list_common.h"
-#include "../internal_mp.h"
-#define MESA_HASH_DEBUG (0)
-
-#if MESA_HASH_DEBUG
-#define HASH_INLINE
-#else
-#define HASH_INLINE inline
-#endif
-
-
-/*
- �˺궨���������ȡ��ǰʱ�䣬���Բ��Ǿ���ʱ�䣬����һ��ÿ��1������������
- Ϊ�˼��ٵ���time(NULL)�����Ĵ���.
- �Ƽ�����:
- �½�һ���̣߳���ij������ÿ��һ������һ��.
-*/
-#if 1
-#define HASH_TIME_NOW() time(NULL)
-#else
-extern volatile unsigned int G_TIMER; /* �˱�������һ���߳���ÿ��1������һ�� */
-#define HASH_TIME_NOW() (time_t)G_TIMER
-#endif
-
-#ifndef uchar
-#define uchar unsigned char
-#endif
-#ifndef uint
-#define uint unsigned int
-#endif
-
-#define HASH_THRESHOLD_MAX 65536
-#define HASH_THRESHOLD_MIN 0
-#define HASH_THRESHOLD_MAX_DELTA 32768
-#define HASH_THRESHOLD_MIN_DELTA 16
-
-#define HASH_ELIMINATE_ALGO_FIFO (0) /* by default */
-#define HASH_ELIMINATE_ALGO_LRU (1)
-
-struct __hash_tab_v2;
-
-/*
- * hash key compare function prototype, see hash_key_comp().
- * return value:
- * 0:key1 and key2 are equal;
- * other:key1 and key2 not equal.
- */
-typedef int key_comp_t(uchar * key1, uint size1, uchar * key2, uint size2);
-
-/*
- * hash key->index computing function prototype, see hash_key2index().
- */
-typedef uint key2index_t(struct __hash_tab_v2 * tab, uchar * key, uint size);
-
-typedef int hash_cb_t(void *data, void *arg);
-
-/*
- * hash element structure.
- *
- * key : a copy of key;
- * size: size of key;
- * hash_index: index which use this key and key2index_t() calculated;
- * data: pointer to attached data;
- * prev, next: pointer to prev and next item;
- */
-typedef struct struct_hash_elem {
- uchar *key;
- void *data;
- uint size;
- uint hash_index;
- time_t op_time;
- struct struct_hash_elem *prev;
- struct struct_hash_elem *next;
- MESA_list_index_v2_t list_node;
-} hash_elem_v2_t;
-
-/*
- * hash structure.
- *
- * size: number of slots;
- * key_comp: pointer to the function that compares 2 keys;
- * key2index: pointer to the function that computes index from key;
- * expire: pointer to the function that do somthing when data expired;
- * free: pointer to the function that cleans up attached data;
- * elems: array of slots;
- * elem_count: number of items;
- * threshold_lo, threshold_hi: low and high threshold; when elem_count reaches
- * one of them, an iteration will be launched to clean up expired items;
- */
-typedef struct __hash_tab_v2 {
- uint size;
- uint is_thread_safe;
- key_comp_t * key_comp;
- key2index_t * key2index;
- void (* expire)(void * data);
- void (* free)(void * data);
- hash_elem_v2_t ** elems;
- unsigned int max_elem_num;
- volatile uint elem_count;
- //uint threshold_lo;
- //uint threshold_hi;
- int eliminate_type;
- int expire_time;
- pthread_mutex_t *htable_mutex;
- //MESA_queue_head_t *hlist_head;
- MESA_list_index_v2_t *hlist_head;
- IMP_t* p_mempool;
-} MESA_hash_tab_v2_t;
-
-/*
- * name: hash_create
- * functionality: allocats memory for hash slots, and fill in hash structure;
- * param:
- * table: caller allocated hash table structure, gets filled in;
- * is_thread_safe:1:create thread safe hashtable; 0:create hashtable without thread safe insurance;
- * size: how big do you want the table to be, must be 2^N;
- * max_elem_num: the maximum elements of the HASH-table,0 means infinite;
- * key_comp: hash key compare function, use default function if NULL;
- * key2index: hash key->index computing function, use default function if NULL;
- * data_free: release resources function, only free attached data pointer if NULL;
- * data_expire: if expire_time > 0, call this function when a element expire, can be NULL;
- * eliminate_type: the algorithm of elimanate a expired element, 0:FIFO; 1:LRU.
- * expire_time: the element expire time in second, 0 means infinite.
- * returns:
- * 0, success;
- * -1, memory failure;
- * -2, parameter not acceptable;
- */
-int D_INTERNAL_MESA_hash_create_v2(MESA_hash_tab_v2_t * table,
- uint is_thread_safe ,
- uint size,
- uint max_elem_num,
- key_comp_t * key_comp,
- key2index_t * key2index,
- void (* data_free)(void *),
- void (* data_expire)(void *),
- int eliminate_type,
- int expire_time,
- IMP_t * mempool);
-
-/*
- * name: hash_destroy
- * functionality: cleans up hash structure, frees memory occupied;
- * param:
- * table: who is the victim;
- * func: callback function to clean up data attached to hash items;
- * returns:
- * always returns 0;
- */
-int D_INTERNAL_MESA_hash_destroy_v2(MESA_hash_tab_v2_t * table, void (* func)(void *));
-
-/*
- * name: hash_add
- * functionality: adds item to table, call hash_expire() if elem_count gets
- * bigger than threshold_hi, and adjust threshold;
- * param:
- * table: to which table do you want to add;
- * key: what is the label;
- * size: how long is the label;
- * data: what data do you want to attach;
- * returns:
- * >0 success,return hash elems' linklist size
- * -1, duplicates found and can't add this one;
- * -2, memory failure;
- */
-int D_INTERNAL_MESA_hash_add_v2(MESA_hash_tab_v2_t * table, uchar * key, uint size, void * data);
-
-/*
- * name: hash_del
- * functionality: deletes item from table.
- * param:
- * table: from which table do you want to delete;
- * key : what is the label;
- * size : how long is the label;
- * func : callback function to clean up data attached to hash items,
- if this pointer is NULL will call "data_free" in MESA_hash_create(),
- * returns:
- * 0, success;
- * -1, no such thing;
- */
-int D_INTERNAL_MESA_hash_del_v2(MESA_hash_tab_v2_t * table, uchar * key, uint size,
- void (* func)(void *));
-
-/*
- * name: hash_sel
- * functionality: selects item from table;
- * param:
- * table: from which table do you want to select;
- * key : what is the label;
- * size : how long is the label;
- *
- * return:
- * not NULL :pointer to attached data;
- * NULL :not found(thus be careful if you are attaching NULL data on purpose).
- */
-void * D_INTERNAL_MESA_hash_sel_v2(MESA_hash_tab_v2_t * table, uchar * key, uint size);
-
-/*
- * name: hash_sel
- * functionality: selects item from table;
- * in param:
- * table: from which table do you want to select;
- * key : what is the label;
- * size : how long is the label;
- * cb : call this function when found the attached data;
- * arg : the argument of "cb" function.
- * out param:
- * cb_ret: the return value of the function "cb".
- * return:
- * not NULL :pointer to attached data;
- * NULL :not found(thus be careful if you are attaching NULL data on purpose).
- */
-void *D_INTERNAL_MESA_hash_sel_with_cb_v2(MESA_hash_tab_v2_t * table, uchar * key, uint size,
- hash_cb_t *cb, void *arg, int *cb_ret);
-
-/*
- * name: hash_iterate
- * functionality: iterates each hash item;
- * params:
- * table: what table is to be iterated;
- * func: what do you want to do to each attached data item;
- * returns:
- * 0: iterates all items;
- * -3: can't get lock in non-block mode;
- */
-int D_INTERNAL_MESA_hash_iterate_v2(MESA_hash_tab_v2_t * table, void (* func)(uchar * key, uint size, void * data));
-int D_INTERNAL_MESA_hash_iterate_v2_2(MESA_hash_tab_v2_t * table, void (* func)(uchar * key, uint size, void * data, void * u), void * user);
-
-#if 0
-/*
- * name: hash_expire
- * functionality: iterates each item and deletes those that are expired;
- * params:
- * table: what table do you want to check;
- * returns:
- * always 0;
- */
-int MESA_hash_expire(MESA_hash_tab_v2_t * table);
-#endif
-
-#endif /* _LIB_HASH_H_INCLUDED_ */
-
-
diff --git a/src/support/dictator2/src/D_internal/MESA_list_v2.cpp b/src/support/dictator2/src/D_internal/MESA_list_v2.cpp deleted file mode 100644 index bd5a22d..0000000 --- a/src/support/dictator2/src/D_internal/MESA_list_v2.cpp +++ /dev/null @@ -1,361 +0,0 @@ -#include <stdlib.h>
-#include <string.h>
-#include <linux/types.h>
-#include <linux/stddef.h>
-#include <assert.h>
-#include "MESA_list_v2.h"
-#include "list_common.h"
-
-
-
-extern void D_INTERNAL_list_count_init(void **list_count);
-extern void D_INTERNAL_list_count_inc(void **list_count);
-extern void D_INTERNAL_list_count_dec(void **list_count);
-
-#if MESA_LIST_CHECK != 0
-/*Function:Check the intergrity of the list,to dectect memory mess.
-*Input: Queue Head,data check call back function
-*Output: return a number below zero,if the queue got a problem,else return 0;
-*Author:[email protected] at 20100913
-*/
-#if 0
-static int MESA_q_list_check(const MESA_queue_head_v2_t *qhead_obj,int(*quiddity_check)(const void *))
-{
- MESA_list_index_v2_t *p=NULL, *head=NULL;
-// int linked_ele_number=0;
- int ret=0;
-// return 0;
- if(qhead_obj->listcount==0)
- {
- if(qhead_obj->head!=NULL||qhead_obj->head!=NULL)
- {
- ret=-1;
- }
- goto exit;
- }
-
- if(qhead_obj->head==NULL||qhead_obj->tail==NULL)
- {
- ret=-2;
- goto exit;
- }
- if(qhead_obj->listcount>1){
- if(qhead_obj->head->preele!=NULL||qhead_obj->head->nextele==NULL)
- {
- ret=-3;
- goto exit;
- }
- if(qhead_obj->tail->preele==NULL||qhead_obj->tail->nextele!=NULL)
- {
- ret=-4;
- goto exit;
- }
-
- head = p = qhead_obj->head;
- p = p->nextele;
- while(p != head)
- {
- if(p == NULL) break;
- if(p == head){
- ret = -5; /* has a cycle */
- goto exit;
- }
- p = p->nextele;
- }
- }
- /*
- pre=qhead_obj->head;
- p=pre->nextele;
- while(p!=NULL){
- linked_ele_number++;
-
- //Is the declared size equal to element linked number;
- if(linked_ele_number > qhead_obj->listcount)
- {
- ret=-5;
- goto exit;
- }
-
- //Is element's preele pointer equal to its preele
- if(pre!=p->preele)
- {
- ret=-6;
- goto exit;
- }
- if(quiddity_check!=NULL){
- if(0>quiddity_check(p->quiddity))
- {
- ret =-7;
- goto exit;
- }
- }
- pre=p;
- p=p->nextele;
- }
- //Is the last element equal to tail
- if(pre!=qhead_obj->tail)
- {
- ret=-8;
- goto exit;
- }
- if(linked_ele_number !=qhead_obj->listcount-1)
- {
- ret=-9;
- goto exit;
- }
- */
-exit:
- if(ret<0)
- {
- return ret;
- }
- else
- {
- return 1;
- }
-
-}
-#endif
-
-#if 2==MESA_LIST_CHECK
-/*Simple check,not raversal*/
-static int D_INTERNAL_MESA_q_is_item_in_list_v2(MESA_queue_head_v2_t *qhead_obj, MESA_list_index_v2_t *lindex_obj){
-// MESA_list_index_v2_t* pre=lindex_obj->preele;
-// MESA_list_index_v2_t*next=lindex_obj->nextele;
- MESA_list_index_v2_t*p=NULL;
- int i, num;
-
- if(D_INTERNAL_common_list_empty_careful(qhead_obj)){
- return 0;
- }
-
- p = qhead_obj->nextele;
- num = D_INTERNAL_MESA_get_list_count_v2(qhead_obj);
- i = 0;
- while((p != qhead_obj) && (i <= num))
- {
- if(p == lindex_obj)
- {
- return 1;
- }
- p=p->nextele;
- i++;
- }
-
- return 0;
-
-}
-#endif
-
-/*every MESA_list_index_v2_t leaves list,its pre and next will be set NULL
- * In Configuration Transmiiter project, not null element will consider in list,
- * pre and next is NULL only if there's one element in list only*/
-static int D_INTERNAL_MESA_q_is_item_in_list_quick_v2(MESA_queue_head_v2_t *qhead_obj, MESA_list_index_v2_t *lindex_obj)
-{
- //empty list
- if(D_INTERNAL_common_list_empty_careful((struct common_list_index *)qhead_obj)){
- return 0;
- }
-
- //have more element
- if(lindex_obj->nextele==NULL || lindex_obj->preele==NULL){
- return 0;
- }
- if(lindex_obj->nextele->preele != lindex_obj){
- return 0;
- }
- if(lindex_obj->preele->nextele != lindex_obj){
- return 0;
- }
-
- return 1;
-
-}
-#endif
-
-void D_INTERNAL_list_count_init(void **list_count)
-{
- long *p_c = (long *)list_count;
- *p_c = 0;
-}
-
-void D_INTERNAL_list_count_inc(void **list_count)
-{
- long *p_c = (long *)list_count;
- long c = *p_c;
- *p_c = c + 1;
-}
-
-void D_INTERNAL_list_count_dec(void **list_count)
-{
- long *p_c = (long *)list_count;
- long c = *p_c;
- *p_c = c - 1;
-}
-
-
-/*************************** �ⲿ���ýӿ� ********************************/
-
-
-/*
- ��һ��ʹ��MESA_listģ��ʱ��������ô˳�ʼ��ģ��.
-*/
-int D_INTERNAL_MESA_list_init_v2(MESA_queue_head_v2_t *head)
-{
- D_INTERNAL_COMMON_LIST_INIT_HEAD((struct common_list_index *)head);
- D_INTERNAL_list_count_init(&head->quiddity);
- return 0;
-}
-
-/* ��Ϊheadʹ��ʱ, "quiddity"��Ϊһ��long�ͱ���,���ڴ洢����Ԫ������ */
-long D_INTERNAL_MESA_get_list_count_v2(const MESA_queue_head_v2_t *head)
-{
- return (long)head->quiddity;
-}
-
-MESA_list_index_v2_t *D_INTERNAL_MESA_q_read_next_v2(MESA_queue_head_v2_t *head,MESA_list_index_v2_t *lindex_obj)
-{
- return (lindex_obj->nextele == head) ? NULL: lindex_obj->nextele;
-}
-
-MESA_list_index_v2_t *D_INTERNAL_MESA_q_read_pre_v2(MESA_queue_head_v2_t *head, MESA_list_index_v2_t *lindex_obj)
-{
- return (lindex_obj->preele == head) ? NULL: lindex_obj->nextele;
-}
-
-MESA_list_index_v2_t *D_INTERNAL_MESA_q_read_head_v2(const MESA_queue_head_v2_t *qhead_obj)
-{
- if(D_INTERNAL_common_list_empty_careful((struct common_list_index *)qhead_obj)){
- return NULL;
- }
- return qhead_obj->nextele;
-}
-
-
-MESA_list_index_v2_t *D_INTERNAL_MESA_q_get_head_v2(MESA_queue_head_v2_t *qhead_obj)
-{
- MESA_list_index_v2_t *out;
- if(D_INTERNAL_common_list_empty_careful((struct common_list_index *)qhead_obj)){
- return NULL;
- }
- out = qhead_obj->nextele;
- D_INTERNAL_common_list_del((struct common_list_index *)out);
- D_INTERNAL_list_count_dec(&qhead_obj->quiddity);
-
- return out;
-}
-
-MESA_list_index_v2_t *D_INTERNAL_MESA_q_get_tail_v2(MESA_queue_head_v2_t *qhead_obj)
-{
- MESA_list_index_v2_t *out;
- if(D_INTERNAL_common_list_empty_careful((struct common_list_index *)qhead_obj)){
- return NULL;
- }
- out = qhead_obj->preele;
- D_INTERNAL_common_list_del((struct common_list_index *)out);
- D_INTERNAL_list_count_dec(&qhead_obj->quiddity);
-
- return out;
-}
-
-MESA_list_index_v2_t *D_INTERNAL_MESA_q_join_tail_v2(MESA_queue_head_v2_t *qhead_obj, MESA_list_index_v2_t *lindex_obj)
-{
- D_INTERNAL_common_list_add_tail((struct common_list_index *)lindex_obj, (struct common_list_index *)qhead_obj);
- D_INTERNAL_list_count_inc(&qhead_obj->quiddity);
-
- return lindex_obj;
-}
-
-MESA_list_index_v2_t *D_INTERNAL_MESA_q_join_head_v2(MESA_queue_head_v2_t *qhead_obj, MESA_list_index_v2_t *lindex_obj)
-{
- D_INTERNAL_common_list_add((struct common_list_index *)lindex_obj, (struct common_list_index *)qhead_obj);
- D_INTERNAL_list_count_inc(&qhead_obj->quiddity);
-
- return lindex_obj;
-}
-
-MESA_list_index_v2_t *D_INTERNAL_MESA_q_join_list_n_v2(MESA_queue_head_v2_t *qhead_obj, MESA_list_index_v2_t *place_next, MESA_list_index_v2_t *new_obj)
-{
- D_INTERNAL_common_list_add((struct common_list_index *)new_obj, (struct common_list_index *)place_next);
- D_INTERNAL_list_count_inc(&qhead_obj->quiddity);
- return new_obj;
-}
-
-MESA_list_index_v2_t *D_INTERNAL_MESA_q_join_list_p_v2(MESA_queue_head_v2_t *qhead_obj, MESA_list_index_v2_t *new_obj, MESA_list_index_v2_t *place_pre)
-{
- D_INTERNAL_common_list_add((struct common_list_index *)new_obj, (struct common_list_index *)place_pre->preele);
- D_INTERNAL_list_count_inc(&qhead_obj->quiddity);
- return new_obj;
-}
-
-MESA_list_index_v2_t *D_INTERNAL_MESA_q_leave_list_v2(MESA_queue_head_v2_t *qhead_obj, MESA_list_index_v2_t *lindex_obj)
-{
-#if 1==MESA_LIST_CHECK
- if(0 == D_INTERNAL_MESA_q_is_item_in_list_quick_v2(qhead_obj, lindex_obj)){
- //return NULL;
- assert(0); //critical
- }
-#elif 2==MESA_LIST_CHECK
- if(0 == D_INTERNAL_MESA_q_is_item_in_list_v2(qhead_obj, lindex_obj)){
- //return NULL;
- assert(0); //critical
- }
-#endif
- D_INTERNAL_common_list_del((struct common_list_index *)lindex_obj);
- D_INTERNAL_list_count_dec(&qhead_obj->quiddity);
-
- return lindex_obj;
-}
-
-MESA_list_index_v2_t *D_INTERNAL_MESA_q_move_head_v2(MESA_queue_head_v2_t *qhead_obj, MESA_list_index_v2_t *lindex_obj)
-{
-#if 1==MESA_LIST_CHECK
- if(0 == D_INTERNAL_MESA_q_is_item_in_list_quick_v2(qhead_obj, lindex_obj)){
- //return NULL;
- assert(0); //critical
- }
-#elif 2==MESA_LIST_CHECK
- if(0 == D_INTERNAL_MESA_q_is_item_in_list_v2(qhead_obj, lindex_obj)){
- //return NULL;
- assert(0); //critical
- }
-#endif
- D_INTERNAL_common_list_move((struct common_list_index *)lindex_obj, (struct common_list_index *)qhead_obj);
-
- return lindex_obj;
-}
-
-MESA_list_index_v2_t *D_INTERNAL_MESA_q_move_tail_v2(MESA_queue_head_v2_t *qhead_obj, MESA_list_index_v2_t *lindex_obj)
-{
-#if 1==MESA_LIST_CHECK
- if(0 == D_INTERNAL_MESA_q_is_item_in_list_quick_v2(qhead_obj,lindex_obj)){
- //return NULL;
- assert(0); //critical
- }
-#elif 2==MESA_LIST_CHECK
- if(0 == D_INTERNAL_MESA_q_is_item_in_list_v2(qhead_obj, lindex_obj)){
- //return NULL;
- assert(0); //critical
- }
-#endif
- D_INTERNAL_common_list_move_tail((struct common_list_index *)lindex_obj, (struct common_list_index *)qhead_obj);
-
- return lindex_obj;
-}
-
-void D_INTERNAL_MESA_q_destroy_v2(MESA_queue_head_v2_t *qhead_obj, void (* cb)(MESA_list_index_v2_t *))
-{
- MESA_list_index_v2_t *del;
-
- while(!D_INTERNAL_common_list_empty_careful((struct common_list_index *)qhead_obj)){
- del = qhead_obj->nextele;
- D_INTERNAL_common_list_del((struct common_list_index *)del);
- if(del->quiddity && cb){
- cb(del);
- }
- }
-
- return;
-}
-
-
diff --git a/src/support/dictator2/src/D_internal/MESA_list_v2.h b/src/support/dictator2/src/D_internal/MESA_list_v2.h deleted file mode 100644 index 8dbb098..0000000 --- a/src/support/dictator2/src/D_internal/MESA_list_v2.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef _MESA_LIST_V2_H_
-#define _MESA_LIST_V2_H_
-
-
-#define MESA_LIST_CHECK (1) /* 0:no check; 1:quick check; 2:careful check */
-
-typedef struct list_index_v2{
- struct list_index_v2 *nextele;
- struct list_index_v2 *preele;
- void *quiddity;
-}MESA_list_index_v2_t;
-
-typedef struct list_index_v2 MESA_queue_head_v2_t;
-
-
-/*
- ��һ��ʹ��MESA_listģ��ʱ��������ô˳�ʼ��ģ��!!!
-*/
-int D_INTERNAL_MESA_list_init_v2(MESA_queue_head_v2_t *head);
-
-long D_INTERNAL_MESA_get_list_count_v2(const MESA_queue_head_v2_t *head);
-MESA_list_index_v2_t *D_INTERNAL_MESA_q_read_head_v2(const MESA_queue_head_v2_t *qhead_obj);
-MESA_list_index_v2_t *D_INTERNAL_MESA_q_get_head_v2(MESA_queue_head_v2_t *qhead_obj);
-MESA_list_index_v2_t *D_INTERNAL_MESA_q_get_tail_v2(MESA_queue_head_v2_t *qhead_obj);
-MESA_list_index_v2_t *D_INTERNAL_MESA_q_join_tail_v2(MESA_queue_head_v2_t *qhead_obj, MESA_list_index_v2_t *lindex_obj);
-MESA_list_index_v2_t *D_INTERNAL_MESA_q_join_head_v2(MESA_queue_head_v2_t *qhead_obj, MESA_list_index_v2_t *lindex_obj);
-MESA_list_index_v2_t *D_INTERNAL_MESA_q_leave_list_v2(MESA_queue_head_v2_t *qhead_obj, MESA_list_index_v2_t *lindex_obj);
-MESA_list_index_v2_t *D_INTERNAL_MESA_q_move_head_v2(MESA_queue_head_v2_t *qhead_obj, MESA_list_index_v2_t *lindex_obj);
-MESA_list_index_v2_t *D_INTERNAL_MESA_q_move_tail_v2(MESA_queue_head_v2_t *qhead_obj, MESA_list_index_v2_t *lindex_obj);
-void D_INTERNAL_MESA_q_destroy_v2(MESA_queue_head_v2_t *qhead_obj, void (* cb)(MESA_list_index_v2_t *));
-
-/* insert "new_obj" between "op_place" and "op_place->nextele" */
-MESA_list_index_v2_t *D_INTERNAL_MESA_q_join_list_n_v2(MESA_queue_head_v2_t *qhead_obj, MESA_list_index_v2_t *op_place, MESA_list_index_v2_t *new_obj);
-
-/* insert "new_obj" between "op_place->preele" and "op_place" */
-MESA_list_index_v2_t *D_INTERNAL_MESA_q_join_list_p_v2(MESA_queue_head_v2_t *qhead_obj, MESA_list_index_v2_t *new_obj, MESA_list_index_v2_t *op_place);
-
-MESA_list_index_v2_t *D_INTERNAL_MESA_q_read_next_v2(MESA_queue_head_v2_t *qhead_obj, MESA_list_index_v2_t *lindex_obj);
-MESA_list_index_v2_t *D_INTERNAL_MESA_q_read_pre_v2(MESA_queue_head_v2_t *qhead_obj, MESA_list_index_v2_t *lindex_obj);
-
-#endif
-
-
diff --git a/src/support/dictator2/src/D_internal/Makefile b/src/support/dictator2/src/D_internal/Makefile deleted file mode 100644 index 4432e91..0000000 --- a/src/support/dictator2/src/D_internal/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -CC=gcc
-CCC=g++ -O2
-
-CFLAGS=-g -Wall -fPIC
-LIBPATH=../
-
-OBJS=MESA_hash_v2.o D_kernel_list.o MESA_list_v2.o list_common.o
-
-.c.o:
- $(CC) -c $(CFLAGS) -I. $(H_DIR) $<
-
-.cpp.o:
- $(CCC) -c $(CFLAGS) -I. $(H_DIR) $<
-
-libMESA_hash_v2.a: $(OBJS)
- echo making lib ...
- (rm -f $@ ;ar -r $@ $^; cp $(OBJS) $(LIBPATH);)
-
-clean:
- rm -f *.o libMESA_hash_v2.a
diff --git a/src/support/dictator2/src/D_internal/list_common.cpp b/src/support/dictator2/src/D_internal/list_common.cpp deleted file mode 100644 index ca6a1b0..0000000 --- a/src/support/dictator2/src/D_internal/list_common.cpp +++ /dev/null @@ -1,155 +0,0 @@ -#include <stdio.h>
-#include "list_common.h"
-
-
-/*************************** �ڲ�ʵ�ֽӿ� ********************************/
-
-/*
- * Simple doubly linked list implementation.
- *
- * Some of the internal functions ("__xxx") are useful when
- * manipulating whole lists rather than single entries, as
- * sometimes we already know the next/prev entries and we can
- * generate better code by using them directly rather than
- * using the generic single-entry routines.
- */
-
-void D_INTERNAL_COMMON_LIST_INIT_HEAD(struct common_list_index *head)
-{
- head->nextele = head;
- head->preele = head;
-}
-
-
-/*
- * Insert a new entry between two known consecutive entries.
- *
- * This is only for internal list manipulation where we know
- * the prev/next entries already!
- */
-static inline void D_INTERNAL___common_list_add(struct common_list_index *new_list,
- struct common_list_index *prev,
- struct common_list_index *next)
-{
- next->preele = new_list;
- new_list->nextele = next;
- new_list->preele = prev;
- prev->nextele = new_list;
-}
-
-/**
- * list_add - add a new entry
- * @new: new entry to be added
- * @head: list head to add it after
- *
- * Insert a new entry after the specified head.
- * This is good for implementing stacks.
- * lijia comment: list_add()���½ڵ����head��head->next֮��.
- */
-void D_INTERNAL_common_list_add(struct common_list_index *new_list, struct common_list_index *head)
-{
- D_INTERNAL___common_list_add(new_list, head, head->nextele);
-}
-
-
-/**
- * list_add_tail - add a new entry
- * @new: new entry to be added
- * @head: list head to add it before
- *
- * Insert a new entry before the specified head.
- * This is useful for implementing queues.
- * lijia comment: list_add_tail()���½ڵ����head��head->prev֮��.
- */
-void D_INTERNAL_common_list_add_tail(struct common_list_index *new_list, struct common_list_index *head)
-{
- D_INTERNAL___common_list_add(new_list, head->preele, head);
-}
-
-/*
- * Delete a list entry by making the prev/next entries
- * point to each other.
- *
- * This is only for internal list manipulation where we know
- * the prev/next entries already!
- */
-static inline void D_INTERNAL___common_list_del(struct common_list_index * prev, struct common_list_index * next)
-{
- next->preele = prev;
- prev->nextele = next;
-}
-
-static inline void D_INTERNAL___common_list_del_entry(struct common_list_index *entry)
-{
- D_INTERNAL___common_list_del(entry->preele, entry->nextele);
- entry->nextele = NULL;
- entry->preele = NULL;
-}
-
-/**
- * list_del - deletes entry from list.
- * @entry: the element to delete from the list.
- * Note: list_empty() on entry does not return true after this, the entry is
- * in an undefined state.
- */
-
-void D_INTERNAL_common_list_del(struct common_list_index *entry)
-{
- D_INTERNAL___common_list_del(entry->preele, entry->nextele);
- entry->nextele = NULL;
- entry->preele = NULL;
-}
-
-
-/**
- * list_move - delete from one list and add as another's head
- * @list: the entry to move
- * @head: the head that will precede our entry
- */
-void D_INTERNAL_common_list_move(struct common_list_index *list, struct common_list_index *head)
-{
- D_INTERNAL___common_list_del_entry(list);
- D_INTERNAL_common_list_add(list, head);
-}
-
-/**
- * list_move_tail - delete from one list and add as another's tail
- * @list: the entry to move
- * @head: the head that will follow our entry
- */
-void D_INTERNAL_common_list_move_tail(struct common_list_index *list, struct common_list_index *head)
-{
- D_INTERNAL___common_list_del_entry(list);
- D_INTERNAL_common_list_add_tail(list, head);
-}
-
-#if 0
-/**
- * list_empty - tests whether a list is empty
- * @head: the list to test.
- */
-static int list_empty(const struct common_list_index *head)
-{
- return head->nextele == head;
-}
-#endif
-
-/**
- * list_empty_careful - tests whether a list is empty and not being modified
- * @head: the list to test
- *
- * Description:
- * tests whether a list is empty _and_ checks that no other CPU might be
- * in the process of modifying either member (next or prev)
- *
- * NOTE: using list_empty_careful() without synchronization
- * can only be safe if the only activity that can happen
- * to the list entry is list_del_init(). Eg. it cannot be used
- * if another CPU could re-list_add() it.
- */
-int D_INTERNAL_common_list_empty_careful(const struct common_list_index *head)
-{
- struct common_list_index *next = head->nextele;
- return (next == head) && (next == head->preele);
-}
-
diff --git a/src/support/dictator2/src/D_internal/list_common.h b/src/support/dictator2/src/D_internal/list_common.h deleted file mode 100644 index 6ef3dd0..0000000 --- a/src/support/dictator2/src/D_internal/list_common.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _LIST_COMMON_H_
-#define _LIST_COMMON_H_
-
-struct common_list_index{
- struct common_list_index *nextele;
- struct common_list_index *preele;
-};
-
-void D_INTERNAL_COMMON_LIST_INIT_HEAD(struct common_list_index *head);
-int D_INTERNAL_common_list_empty_careful(const struct common_list_index *head);
-void D_INTERNAL_common_list_add(struct common_list_index *new_list, struct common_list_index *head);
-void D_INTERNAL_common_list_add_tail(struct common_list_index *new_list, struct common_list_index *head);
-void D_INTERNAL_common_list_del(struct common_list_index *entry);
-void D_INTERNAL_common_list_move(struct common_list_index *list, struct common_list_index *head);
-void D_INTERNAL_common_list_move_tail(struct common_list_index *list, struct common_list_index *head);
-
-#endif
-
diff --git a/src/support/dictator2/src/D_internal/readme.txt b/src/support/dictator2/src/D_internal/readme.txt deleted file mode 100644 index fc87961..0000000 --- a/src/support/dictator2/src/D_internal/readme.txt +++ /dev/null @@ -1,4 +0,0 @@ -���ļ������ڲ�Դ���룬��Ϊ����.a�⣬һ�㲻���ⷢ����
-�����ṩlibMESA_hash_v2.a��MESA_list.h��MESA_hash_v2.h
-
-MESA_list_v2Ϊ�������̰߳�ȫ�Ķ���,�ֽ�������.
\ No newline at end of file diff --git a/src/support/dictator2/src/Makefile b/src/support/dictator2/src/Makefile deleted file mode 100644 index c7c9137..0000000 --- a/src/support/dictator2/src/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -all:
- cp dictator.h ../../../../include/support/
- make clean&&make -f Makefile_nodebug
- #make clean&&make -f Makefile_debug
-clean:
- rm -f D_internal/*.o
- rm *.o -f
diff --git a/src/support/dictator2/src/Makefile_debug b/src/support/dictator2/src/Makefile_debug deleted file mode 100644 index e8d7fc6..0000000 --- a/src/support/dictator2/src/Makefile_debug +++ /dev/null @@ -1,43 +0,0 @@ -#################################################
-# #
-# dictator, version 0.01 #
-# #
-# Software Division, ICT, 2010.11 #
-# #
-#################################################
-
-#CC=gcc -g
-CC = g++
-
-INCLUDES =
-LIBS = -lpthread -ldl
-CFLAGS = -g -Wall -fPIC
-
-
-SOURCES = dictator.cpp
-OBJECTS = dictator.o dictator_debuger.o
-TARGET = EXEditctator
-TARGETLIB = libdictator.a
-
-.PHONY: all dep clean install
-
-.c.o:
- $(CC) -c -o $@ $(CFLAGS) -I. $(INCS) $< -DDICTATOR_DEBUG
-
-.cpp.o:
- $(CC) -c -o $@ $(CFLAGS) -I. $(INCS) $< -DDICTATOR_DEBUG
-all:$(OBJECTS)
- cd D_internal/ && $(MAKE) clean && $(MAKE)
- ar cqs $(TARGETLIB) *.o
- cp $(TARGETLIB) ../lib/
- cp $(TARGETLIB) ../../../lib/
-dictator.o: dictator.cpp dictator.h dictator_core.h
- $(CC) -c -o $@ $(CFLAGS) $< -DDICTATOR_DEBUG
-dictator_debuger.o: dictator_debuger.cpp dictator.h dictator_core.h
- $(CC) -c -o $@ $(CFLAGS) $< -DDICTATOR_DEBUG
-# $(CC) $(OBJECTS) -o $(TARGET) $(LIBS)
-# ld dictator.o $(LIBS)
-clean:
- rm -f *.o $(TARGETLIB)
- cd D_internal && $(MAKE) clean
-
diff --git a/src/support/dictator2/src/Makefile_nodebug b/src/support/dictator2/src/Makefile_nodebug deleted file mode 100644 index 8884569..0000000 --- a/src/support/dictator2/src/Makefile_nodebug +++ /dev/null @@ -1,44 +0,0 @@ -#################################################
-# #
-# dictator, version 0.01 #
-# #
-# Software Division, ICT, 2010.11 #
-# #
-#################################################
-
-#CC=gcc -g
-CC = g++
-
-INCLUDES =
-LIBS = -lpthread -ldl
-CFLAGS = -g -Wall -fPIC
-
-
-
-SOURCES = dictator.cpp
-OBJECTS = dictator.o dictator_debuger.o
-TARGET = EXEditctator
-TARGETLIB = libdictator.a
-
-.PHONY: all dep clean install
-
-.c.o:
- $(CC) -c -o $@ $(CFLAGS) -I. $(INCS) $<
-
-.cpp.o:
- $(CC) -c -o $@ $(CFLAGS) -I. $(INCS) $<
-all:$(OBJECTS)
- cd D_internal/ && $(MAKE) clean && $(MAKE)
- ar cqs $(TARGETLIB) *.o
- cp $(TARGETLIB) ../lib/
- cp $(TARGETLIB) ../../../lib/
-dictator.o: dictator.cpp dictator.h dictator_core.h
- $(CC) -c -o $@ $(CFLAGS) $<
-dictator_debuger.o: dictator_debuger.cpp dictator.h dictator_core.h
- $(CC) -c -o $@ $(CFLAGS) $<
-# $(CC) $(OBJECTS) -o $(TARGET) $(LIBS)
-# ld dictator.o $(LIBS)
-clean:
- rm -f *.o $(TARGETLIB)
- cd D_internal && $(MAKE) clean
-
diff --git a/src/support/dictator2/src/dictator.cpp b/src/support/dictator2/src/dictator.cpp deleted file mode 100644 index 2de2deb..0000000 --- a/src/support/dictator2/src/dictator.cpp +++ /dev/null @@ -1,866 +0,0 @@ -/*
- * Manage program memory,for high perfomance and exclusive application.
- * The dictator will hoard memory for program to reduce malloc time cost.
- * Version : 2014-12-15
- * Usage:LD_DICTATOR = -Wl,-wrap,malloc -Wl,-wrap,calloc -Wl,-wrap,free -Wl,-wrap,realloc,add LD_DICTATOR as ld parameter.
- * Zheng Chao, [email protected]
- *
- * History:
- * 2010-11-30 first build
- * 2010-12-14 to reduce memory waste,change block list from exponential(e.g.64,128,256,512...)to linearity (e.g. 64,128,192,256...)
- * 2010-12-16 to resolve productor and consumer problem, thread 1 free thread 2's mem block,add block to thread 2's tail,
- * use mutex to protect the block queues tail.
- * 2010-12-20 fix core_realloc memcpy read out line.
- * 2010-12-29 use gcc buildin atomic operation to proctec chain ele_cnt,use volatile to describe thread stat value
- * 2010-12-30 redesigned mem_info_t struct,reduce mem used from 40 to 8;not suport slice;
- * 2011-01-05 change block assigned strategy,POWER[].
- * 2011-01-28 use <alsa/iatomic.h> as atomic operation
- * 2011-02-14 check block's tid,if from unactivated thread
- * 2011-11-21 strict check block size ,whether it suit chain index in free with assert
- * 2013-12-26 DICTATOR2 first build.
- * 2014-01-17 DICTATOR2 v1.0 released.
- * 2014-06-18 fix realloc memcpy over read ptr bug.
- * 2014-12-02 use mesa_backtrace(student [email protected]) replace glibc backtrace or libunwind backtrace.
- * 2014-12-08 use array replace hash to implement tid2idx and tseq2idx.
- * Notes:
- *
- * block(dictator manged) < chunk (system mmap alloced)
- *
- */
-
-#include <stdio.h>
-#include <sys/syscall.h>
-#include <unistd.h>
-#include <assert.h>
-#include <string.h>//using memset
-#include <malloc.h>
-#include <time.h>
-#include <new>
-#include <pthread.h>
-#include <sys/mman.h>
-//#define DPDK_HUGE_PAGE
-
-#ifdef DPDK_HUGE_PAGE
-#include <marsio.h>
-#endif
-
-#include "internal_mp.h"
-#include "dictator.h"
-#include "dictator_core.h"
-#include "dummy_hash.h"
-
-
-#ifdef DICTATOR_DEBUG
-const char* DICTATOR2_VERSION_20170910_DEBUG="DICTATOR2_VERSION_1_3_20170910_DEBUG";
-#else
-const char* DICTATOR2_VERSION_20170910="DICTATOR2_VERSION_1_3_20170910";
-#endif
-#define FREE_MEM_HEAD_LEN (sizeof(mem_info_t))
-struct dictator_space_t D_SPACE;
-#define D_THREAD_HASH_SIZE 4*1024
-int is_first=0;
-const unsigned int LINEAR_1_BOUNDARY=1024;
-const unsigned int LINEAR_2_FACTOR=8;
-
-char boundary_marker[D_MARKER_SIZE]={'d'};
-#define PAGE_SIZE 4096
-#define ELF_MIN_ALIGN PAGE_SIZE
-#define ELF_PAGEALIGN(_v) (((_v)+ELF_MIN_ALIGN-1)&~(ELF_MIN_ALIGN-1))
-
-static inline pid_t dictator_gettid(void){
- pid_t ret=(pid_t)pthread_self();
- return ret;
-}
-mem_info_t* fill_empty_block(mem_info_t* block,unsigned int blk_num,unsigned short D_id){
- block->blk_num=blk_num;
- block->D_id=D_id;
-#ifdef DICTATOR_DEBUG
- block->magic=DICTATOR_MAGIC;
- block->idx=NULL;
-#endif
- block->next=NULL;
- block->type=0;
- return block;
-}
-inline int D_hash_key_comp(uchar * key1, uint size1, uchar * key2, uint size2)
-{
- assert(size1==sizeof(int)&&size2==sizeof(int));
- if(*(int*)key1==*(int*)key2)
- {
- return 0;
- }
- else
- {
- return 1;
- }
-}
-inline unsigned int D_hash_key2index(MESA_hash_tab_v2_t * table, uchar *str, uint size)
-{
- assert(size==sizeof(int));
- return (*(unsigned int*)str % table->size);
-}
-inline static int tid2idx(pthread_t * array,int size,pthread_t tid)
-{
- int i=0;
- for(i=size-1;i>=0;i--)
- {
- if(array[i]==tid)
- {
- return i;
- }
- }
- return -1;
-}
-
-inline static thread_mem_pool_t* locate_mp_by_tseq(int t_seq)
-{
- long idx=0;
- int ret=0;
- pthread_t tid=0;
- thread_mem_pool_t* p_mempool=NULL;
- idx=D_SPACE.tseq2idx[t_seq];
- if(idx>=0)
- {
- p_mempool=D_SPACE.thread_mem_info[idx];
- }
- if(p_mempool==NULL)
- {
- tid=pthread_self();
- ret=dummy_htable_read(&(D_SPACE.tid2idx), (long)tid,&idx);
- if(ret==1)
- {
- p_mempool=D_SPACE.thread_mem_info[idx];
- }
- if(p_mempool==NULL)
- {
- atomic_inc(&(D_SPACE.used_mem_pool_counter));//here is not thread safe but __sync_add_and_fetch not support in all OS
- idx = atomic_read(&(D_SPACE.used_mem_pool_counter));
- p_mempool=create_mem_pool(idx);
- p_mempool->tid=tid;
-#ifdef DICTATOR_DEBUG
- init_debugger(&(p_mempool->debugger),p_mempool);
-#endif
- D_SPACE.thread_mem_info[idx]=p_mempool;
- dummy_htable_add(&(D_SPACE.tid2idx),tid,idx);
- D_SPACE.tseq2idx[t_seq]=idx;
- }
- p_mempool->t_seq=t_seq;
- }
-#ifdef DICTATOR_DEBUG
- tid=pthread_self();
- assert(p_mempool->t_seq==t_seq);
- assert(tid==p_mempool->tid);
-#endif
- return p_mempool;
-}
-inline static thread_mem_pool_t* locate_mp_by_tid(pthread_t tid)
-{
- thread_mem_pool_t* p_mempool=NULL;
- long idx=0;
- int ret=0;
- ret=dummy_htable_read(&(D_SPACE.tid2idx), tid, &idx);
- if(ret==1)
- {
- p_mempool=D_SPACE.thread_mem_info[idx];
- }
- if(p_mempool==NULL)
- {
- atomic_inc(&(D_SPACE.used_mem_pool_counter));
- idx = atomic_read(&(D_SPACE.used_mem_pool_counter));
- p_mempool=create_mem_pool(idx);
- p_mempool->tid=tid;
-#ifdef DICTATOR_DEBUG
- init_debugger(&(p_mempool->debugger),p_mempool);
-#endif
- D_SPACE.thread_mem_info[idx]=p_mempool;
- dummy_htable_add(&(D_SPACE.tid2idx), tid, idx);
- }
- return p_mempool;
-}
-thread_mem_pool_t* init_dictator(pthread_t tid)
-{
- unsigned int i=1;
- thread_mem_pool_t* p_mempool=NULL;
- is_first=1;
- D_SPACE.INIT_THREAD_BLOCK_NUM=0;
- assert(getpagesize()==PAGE_SIZE);
- D_SPACE.POWER[0]=1;
- for(i=1;i<MAX_CHAIN_NUM_SUPPORT;i++)
- {
- if((i+1)*DICTATOR_UNIT_SIZE<=LINEAR_1_BOUNDARY)
- {
- D_SPACE.POWER[i]=i+1;
- }
- else
- {
- D_SPACE.POWER[i]=D_SPACE.POWER[i-1]+LINEAR_2_FACTOR;
- }
- D_SPACE.INIT_THREAD_BLOCK_NUM+=D_SPACE.POWER[i];
- }
- D_SPACE.INIT_THREAD_BLOCK_NUM*=2;
-
- //biggest block num
- assert(D_SPACE.POWER[MAX_CHAIN_NUM_SUPPORT-1]<65535);
- memset((void*)D_SPACE.thread_mem_info,0,sizeof(D_SPACE.thread_mem_info));
- atomic_set(&(D_SPACE.used_mem_pool_counter),-1);
- for(i=0;i<MAX_TRHEAD_NUM_SUPPORT;i++)
- {
- D_SPACE.tseq2idx[i]=-1;
- }
- dummy_htable_init(&(D_SPACE.tid2idx));
- p_mempool=locate_mp_by_tid(tid);
-#ifdef DICTATOR_DEBUG
- pthread_t thread_desc;
- pthread_attr_t attr;
- memset(&thread_desc, 0, sizeof(thread_desc));
- memset(&attr, 0, sizeof(attr));
-
- if(0 != pthread_attr_init(&(attr))) {
- fprintf(stderr,"pthread_attr_init(): %d %s", errno, strerror(errno));
- return NULL;
- }
- if(0 != pthread_attr_setdetachstate(&(attr), PTHREAD_CREATE_DETACHED)) {
- fprintf(stderr,"pthread_attr_setdetachstate(): %d %s", errno, strerror(errno));
- return NULL;
- }
- if(0 != pthread_create(&(thread_desc), &(attr), (void *(*)(void *))(dictator_debug_thread), NULL)) {
- fprintf(stderr,"pthread_create(): %d %s", errno, strerror(errno));
- pthread_attr_destroy(&(attr));
- return NULL;
- }
- pthread_attr_destroy(&(attr));
- memset(boundary_marker,'d',D_MARKER_SIZE);
-#else
- ;//fprintf(stderr,"Using DICTATOR2 memory manager\n");
-#endif
- return p_mempool;
-}
-inline int select_chain(unsigned int block_num){
- assert(block_num<=D_SPACE.POWER[MAX_CHAIN_NUM_SUPPORT-1]);
- if(block_num*DICTATOR_UNIT_SIZE<=LINEAR_1_BOUNDARY)
- {
- return block_num-1;
- }
- else
- {
- if((block_num-LINEAR_1_BOUNDARY/DICTATOR_UNIT_SIZE)%LINEAR_2_FACTOR==0)
- return (block_num-LINEAR_1_BOUNDARY/DICTATOR_UNIT_SIZE)/LINEAR_2_FACTOR+LINEAR_1_BOUNDARY/DICTATOR_UNIT_SIZE-1;
- else
- return (block_num-LINEAR_1_BOUNDARY/DICTATOR_UNIT_SIZE)/LINEAR_2_FACTOR+LINEAR_1_BOUNDARY/DICTATOR_UNIT_SIZE;
- }
-
-}
-thread_mem_pool_t *create_mem_pool(unsigned short D_id)
-{
- unsigned int i=0,assigned_blk_num=0;
- mem_info_t *target_block=NULL;
- thread_mem_pool_t *p=(thread_mem_pool_t *)mmap_alloc(sizeof(thread_mem_pool_t));
- p->block_buffer_container.buffer=(char*)mmap_alloc(DICTATOR_UNIT_SIZE*D_SPACE.INIT_THREAD_BLOCK_NUM);
- if(NULL==p->block_buffer_container.buffer){
- fprintf(stderr,"malloc failed in dictator %s : %d\n",__FILE__,__LINE__);
- assert(0);
- }
- p->raw_mem_header[0]=p->block_buffer_container.buffer;
- p->rawmem_idx=1;
- p->block_buffer_container.available_size=DICTATOR_UNIT_SIZE*D_SPACE.INIT_THREAD_BLOCK_NUM;
- p->D_id=D_id;
- p->t_seq=-1;
- p->tid=0;
-
- //assigned a suitable block for each chain
- for(i=0;i<MAX_CHAIN_NUM_SUPPORT;i++)
- {
- //get a block
- assigned_blk_num=D_SPACE.POWER[i];
- target_block=(mem_info_t*)(p->block_buffer_container.buffer);
- fill_empty_block(target_block,assigned_blk_num ,D_id);
- p->block_buffer_container.buffer+=assigned_blk_num*DICTATOR_UNIT_SIZE;
- p->block_buffer_container.available_size-=assigned_blk_num*DICTATOR_UNIT_SIZE;
-
- //restore this block
- p->block_chain[i].head=target_block;
- p->block_chain[i].tail=p->block_chain[i].head;
- atomic_set(&(p->block_chain[i].ele_cnt),1);
- pthread_mutex_init(&(p->block_chain[i].mutex_tail_lock), NULL);
- }
- return p;
-
-}
-
-
-
-
-mem_info_t* get_chunk(unsigned short D_id,unsigned int blk_num){
- mem_info_t* block=NULL;
- size_t assigned_size=blk_num*DICTATOR_UNIT_SIZE;
- int is_dpdk_hugepage=0;
-#ifdef DPDK_HUGE_PAGE
- if(marsio_is_hugepage_available()==1)
- {
- block=(mem_info_t*)marsio_hugepage_malloc(assigned_size, D_SPACE.thread_mem_info[D_id]->t_seq);
- is_dpdk_hugepage=1;
- }
- else
- {
- block=(mem_info_t*)mmap(NULL,assigned_size,PROT_WRITE|PROT_READ,MAP_ANONYMOUS|MAP_PRIVATE,-1,0);
- }
-#else
- block=(mem_info_t*)mmap(NULL,assigned_size,PROT_WRITE|PROT_READ,MAP_ANONYMOUS|MAP_PRIVATE,-1,0);
-#endif
-
-
- if(-1==(long)block)
- {
- fprintf(stderr,"mmap/hugepage failed: %s ,at dictator %s : %d\n",strerror(errno),__FILE__,__LINE__);
- _exit(-1);
- }
- fill_empty_block(block,blk_num,D_id);
- block->type=is_dpdk_hugepage;
- if(block->type==0)
- {
- assert((unsigned long)block%PAGE_SIZE==0);
- }
- return block;
-}
-void* mmap_alloc(size_t size)
-{
- mem_info_t*p=NULL;
- unsigned int block_num=0;
- unsigned long assigned_size=0;
- block_num=calc_block_num(size+USED_MEM_HEAD_LEN);
- assigned_size=ELF_PAGEALIGN((unsigned long)block_num*(unsigned long)DICTATOR_UNIT_SIZE);
- block_num=assigned_size/DICTATOR_UNIT_SIZE;
- p=get_chunk(0, block_num);
- return D_MEM(p);
-}
-void mmap_free(void*p)
-{
- mem_info_t* block=D_HEADER(p);
- size_t len=block->blk_num*DICTATOR_UNIT_SIZE;
- int ret=0;
-#ifdef DPDK_HUGE_PAGE
- if(block->type==1)
- {
- marsio_hugepage_free(block);
- }
- else
- {
- ret=munmap(block,len);
- }
-#else
- ret=munmap(block,len);
-#endif
- if(ret!=0)
- {
- fprintf(stderr,"munmap failed: %s ,at dictator %s : %d\n",strerror(errno),__FILE__,__LINE__);
- }
- assert(ret==0);
- return;
-}
-void* block_alloc(size_t size,IMP_t *imp)
-{
- mem_info_t* p=NULL;
- thread_mem_pool_t *p_mempool=(thread_mem_pool_t *)imp;
- unsigned int block_num=calc_block_num(size+USED_MEM_HEAD_LEN);
- assert(!IS_CHUNK(block_num));
- p=get_block(p_mempool,block_num);
-#ifdef DICTATOR_DEBUG
- atomic_add(&(p_mempool->debugger.selfcost_mem),p->blk_num*DICTATOR_UNIT_SIZE);
- atomic_sub(&(p_mempool->debugger.cached_mem), p->blk_num*DICTATOR_UNIT_SIZE);
-#endif
- return D_MEM(p);
-}
-void block_free(void*p,IMP_t* imp)
-{
- mem_info_t *block=D_HEADER(p);
- thread_mem_pool_t *p_mempool=(thread_mem_pool_t *)imp;
-#ifdef DICTATOR_DEBUG
- atomic_sub(&(p_mempool->debugger.selfcost_mem),block->blk_num*DICTATOR_UNIT_SIZE);
- atomic_add(&(p_mempool->debugger.cached_mem), block->blk_num*DICTATOR_UNIT_SIZE);
-#endif
- restore_block(p_mempool, block);
- //restore_other_block(p_mempool, block);
-
- return;
-}
-
-// own block add to chain head
-inline void add_block_to_chain_head(thread_mem_pool_t* thread_info,int chain_idx,mem_info_t* block)
-{
- block->next=thread_info->block_chain[chain_idx].head;
- thread_info->block_chain[chain_idx].head=block;
- atomic_inc(&(thread_info->block_chain[chain_idx].ele_cnt));
-}
-inline void join_block_to_chain_tail(thread_mem_pool_t* thread_info,int chain_idx,mem_info_t* block)
-{
- thread_info->block_chain[chain_idx].tail->next=block;
- block->next=NULL;
- thread_info->block_chain[chain_idx].tail=block;
- atomic_inc(&(thread_info->block_chain[chain_idx].ele_cnt));
-}
-inline void restore_block(thread_mem_pool_t* thread_info,mem_info_t *block)
-{
- unsigned int chain_idx=0;
- chain_idx=select_chain(block->blk_num);
- assert(block->blk_num==D_SPACE.POWER[chain_idx]);
- add_block_to_chain_head(thread_info, chain_idx, block);
- return;
-}
-inline void restore_other_block(thread_mem_pool_t* thread_info,mem_info_t *block)
-{
- unsigned int chain_idx=0;
- chain_idx=select_chain(block->blk_num);
- assert(block->blk_num==D_SPACE.POWER[chain_idx]);
- pthread_mutex_lock(&(thread_info->block_chain[chain_idx].mutex_tail_lock));
- join_block_to_chain_tail(thread_info, chain_idx, block);
- pthread_mutex_unlock(&(thread_info->block_chain[chain_idx].mutex_tail_lock));
-
- return;
-}
-inline mem_info_t *get_block_from_chain(thread_mem_pool_t* thread_info,int chain_idx)
-{
- mem_info_t *target=NULL;
-#ifdef DICTATOR_DEBUG
- assert(thread_info->block_chain[chain_idx].head!=thread_info->block_chain[chain_idx].tail);
- assert(atomic_read(&(thread_info->block_chain[chain_idx].ele_cnt))>1);
-#endif
- target=thread_info->block_chain[chain_idx].head;
- thread_info->block_chain[chain_idx].head=target->next;
- atomic_dec(&(thread_info->block_chain[chain_idx].ele_cnt));
- return target;
-}
-inline mem_info_t *get_block(thread_mem_pool_t *thread_info,unsigned int block_num)
-{
-
- mem_info_t* target_block=NULL,*tmp;
- unsigned int assigned_chain=0;
- unsigned int assigned_size=0;
- assigned_chain=select_chain(block_num);
- assigned_size=D_SPACE.POWER[assigned_chain]*DICTATOR_UNIT_SIZE;
- int i=0;
- assert(assigned_size!=0);
- //block chain is available
- if(thread_info->block_chain[assigned_chain].head!=thread_info->block_chain[assigned_chain].tail&&
- atomic_read(&(thread_info->block_chain[assigned_chain].ele_cnt))>1)
- {
- target_block=get_block_from_chain(thread_info,assigned_chain);
- }
- else
- {
- //block buffer is not enough for this request
- if(thread_info->block_buffer_container.available_size<assigned_size)
- {
- //put left buffer into chain
- assert(thread_info->block_buffer_container.available_size%DICTATOR_UNIT_SIZE==0);
- if(thread_info->block_buffer_container.available_size>0)
- {
- for(i=0;thread_info->block_buffer_container.available_size>0;i++)
- {
- tmp=(mem_info_t *)(thread_info->block_buffer_container.buffer);
- thread_info->block_buffer_container.available_size-=DICTATOR_UNIT_SIZE;
- thread_info->block_buffer_container.buffer+=DICTATOR_UNIT_SIZE;
- fill_empty_block(tmp, 1, thread_info->D_id);
- restore_block(thread_info,tmp);
- }
- }
- //malloc a new buffer
- thread_info->block_buffer_container.buffer=(char *)mmap_alloc(D_SPACE.INIT_THREAD_BLOCK_NUM*DICTATOR_UNIT_SIZE);
- if(NULL==thread_info->block_buffer_container.buffer)
- {
- fprintf(stderr,"malloc failed in dictator %s : %d\n",__FILE__,__LINE__);
- return NULL;
- }
- thread_info->block_buffer_container.available_size=D_SPACE.INIT_THREAD_BLOCK_NUM*DICTATOR_UNIT_SIZE;
- thread_info->raw_mem_header[thread_info->rawmem_idx]=thread_info->block_buffer_container.buffer;
- thread_info->rawmem_idx++;
-#ifdef DICTATOR_DEBUG
- atomic_add(&(thread_info->debugger.cached_mem),D_SPACE.INIT_THREAD_BLOCK_NUM*DICTATOR_UNIT_SIZE);
-#endif
- }
- //cut a block from buffer
- target_block=(mem_info_t*)(thread_info->block_buffer_container.buffer);
- fill_empty_block(target_block, D_SPACE.POWER[assigned_chain],thread_info->D_id);
- thread_info->block_buffer_container.buffer+=assigned_size;
- thread_info->block_buffer_container.available_size-=assigned_size;
- }
- return target_block;
-
-
-}
-
-void *core_alloc(thread_mem_pool_t *p_mempool,size_t size)
-{
- unsigned int block_num=0;
- unsigned long assigned_size=0;
- mem_info_t *target_mem=NULL;
- if(0==size)
- {
- return NULL;
- }
- block_num=calc_block_num(size+USED_MEM_HEAD_LEN);
- if(block_num>D_SPACE.POWER[MAX_CHAIN_NUM_SUPPORT-1])
- {
- assigned_size=ELF_PAGEALIGN((unsigned long)block_num*(unsigned long)DICTATOR_UNIT_SIZE);
- block_num=assigned_size/DICTATOR_UNIT_SIZE;
- //malloc with mmap
- target_mem=get_chunk(p_mempool->D_id, block_num);
- }
- else
- {
- target_mem=get_block(p_mempool,block_num);
- }
-#ifdef DICTATOR_DEBUG
- backtrace_info_t *caller_bt;
- struct dbg_index_t* dbg_idx=NULL;
- assigned_size=target_mem->blk_num*DICTATOR_UNIT_SIZE;
- dbg_idx=get_dbg_index(&(p_mempool->debugger));
- target_mem->idx=dbg_idx;
- dbg_idx->mem_info=(void*)target_mem;
-
-
- //use by thread self and debug thread's threadsafe callback, no need to protect with mutex;
- caller_bt=backtrace_ref_inc(&((p_mempool->debugger.malloc_backtrace_hash)),size,p_mempool);
-
-
- target_mem->idx->p_backtrace=caller_bt;
- target_mem->idx->used_size=size;
- target_mem->idx->assigned_size=assigned_size;
-
- pthread_mutex_lock(&(p_mempool->debugger.mutex_malloced_in_reach_list));
- D_kernel_list_add_tail(&(p_mempool->debugger.malloced_in_reach_list),&(target_mem->idx->malloced_in_reach_hook));
- pthread_mutex_unlock(&(p_mempool->debugger.mutex_malloced_in_reach_list));
-
- int boundary_len=assigned_size-size-USED_MEM_HEAD_LEN;
- memset(D_MEM(target_mem)+target_mem->idx->used_size,'d',boundary_len);
- atomic_add(&(p_mempool->debugger.app_mem),size);
- atomic_add(&(p_mempool->debugger.assigned_mem),assigned_size);
- atomic_inc(&(p_mempool->debugger.inuse_num));
- atomic_inc(&(p_mempool->debugger.malloc_cnt));
- if(IS_CHUNK(target_mem->blk_num))
- {
- //no need do free_backtrace_hash ,index for double free check;
- }
- else
- {
- atomic_sub(&(p_mempool->debugger.cached_mem), target_mem->blk_num*DICTATOR_UNIT_SIZE);
- }
-#endif
- return D_MEM(target_mem);
-}
-void core_free(unsigned short caller_Did,void *p)
-{
- mem_info_t *block=D_HEADER(p);
- thread_mem_pool_t* p_mempool=D_SPACE.thread_mem_info[block->D_id];
-#ifdef DICTATOR_DEBUG
- thread_mem_pool_t* caller_mp=D_SPACE.thread_mem_info[caller_Did];
- backtrace_info_t *caller_bt;
- assert(block->magic==DICTATOR_MAGIC);
- const char* user_boundary=(char*)block+block->idx->used_size+USED_MEM_HEAD_LEN;
- int boundary_len=0;
- unsigned int assigned_size=block->blk_num*DICTATOR_UNIT_SIZE;
- assert(block->idx->assigned_size==assigned_size);
- if(!IS_CHUNK(block->blk_num))//not a chunk
- {
- atomic_add(&(p_mempool->debugger.cached_mem),assigned_size);
- }
- pthread_mutex_lock(&(p_mempool->debugger.mutex_malloced_in_reach_list));
- D_kernel_list_delete(&(p_mempool->debugger.malloced_in_reach_list),&(block->idx->malloced_in_reach_hook));
- pthread_mutex_unlock(&(p_mempool->debugger.mutex_malloced_in_reach_list));
-
- atomic_sub(&(p_mempool->debugger.app_mem),block->idx->used_size);
- atomic_sub(&(p_mempool->debugger.assigned_mem),assigned_size);
- atomic_dec(&(block->idx->p_backtrace->ref_cnt));
- atomic_sub(&(block->idx->p_backtrace->ref_bytes),block->idx->used_size);
- atomic_dec(&(p_mempool->debugger.inuse_num));
- atomic_inc(&(p_mempool->debugger.free_cnt));
- caller_bt=backtrace_ref_inc(&(caller_mp->debugger.free_backtrace_hash),assigned_size,caller_mp);
- block->idx->p_backtrace=caller_bt;
-
- boundary_len=MIN(assigned_size-block->idx->used_size-USED_MEM_HEAD_LEN,D_MARKER_SIZE);
- assert(0==memcmp(user_boundary,boundary_marker,boundary_len));
- restore_dbg_index(&(p_mempool->debugger), block->idx);
- block->idx=NULL;
-#endif
- if(IS_CHUNK(block->blk_num))
- {
- //a chunk
- mmap_free(D_MEM(block));
- }
- else
- {
- if(block->D_id==caller_Did)
- {
- restore_block(p_mempool, block);
-
- }
- else
- {
- restore_other_block(p_mempool, block);
- }
- }
-
-}
-void *core_realloc(unsigned short caller_Did,void *ptr, size_t size)
-{
- mem_info_t *block=D_HEADER(ptr);
- mem_info_t *new_block=NULL;
- void* new_mem=NULL;
- size_t old_size=0;
-#ifdef DICTATOR_DEBUG
- size_t new_size=0;
- thread_mem_pool_t* orginal_mempool=D_SPACE.thread_mem_info[block->D_id];
- struct dbg_index_t* tmp_idx=NULL;
- assert(block->magic==DICTATOR_MAGIC);
-#endif
- old_size=(block->blk_num*DICTATOR_UNIT_SIZE)-USED_MEM_HEAD_LEN;
-
- if(IS_CHUNK(block->blk_num))
- {
-#ifdef DICTATOR_DEBUG
- size_t orginal_size=0;
- orginal_size=block->blk_num*DICTATOR_UNIT_SIZE;
- atomic_sub(&(block->idx->p_backtrace->ref_bytes),block->idx->used_size);
- pthread_mutex_lock(&(orginal_mempool->debugger.mutex_malloced_in_reach_list));
- D_kernel_list_delete(&(orginal_mempool->debugger.malloced_in_reach_list),&(block->idx->malloced_in_reach_hook));
- pthread_mutex_unlock(&(orginal_mempool->debugger.mutex_malloced_in_reach_list));
- atomic_sub(&(orginal_mempool->debugger.app_mem),block->idx->used_size);
- atomic_sub(&(orginal_mempool->debugger.assigned_mem),orginal_size);
- tmp_idx=block->idx;
-#endif
- if(old_size>=size)
- {
- new_block=block;
- }
- else
- {
- new_block=D_HEADER(mmap_alloc(size));
- memcpy(D_MEM(new_block),D_MEM(block),old_size);
- mmap_free(D_MEM(block));
- }
- new_mem=D_MEM(new_block);
-#ifdef DICTATOR_DEBUG
- new_size=new_block->blk_num*DICTATOR_UNIT_SIZE;
- new_block->idx=tmp_idx;
- new_block->idx->used_size=size;
- new_block->idx->assigned_size=new_size;
- new_block->idx->mem_info=new_block;
- atomic_add(&(new_block->idx->p_backtrace->ref_bytes),size);
- if(atomic_read(&(new_block->idx->p_backtrace->maxsize))<(signed long)size)
- {
- atomic_set(&(new_block->idx->p_backtrace->maxsize),(signed long)size);
- }
- pthread_mutex_lock(&(orginal_mempool->debugger.mutex_malloced_in_reach_list));
- D_kernel_list_add_tail(&(orginal_mempool->debugger.malloced_in_reach_list),&(new_block->idx->malloced_in_reach_hook));
- pthread_mutex_unlock(&(orginal_mempool->debugger.mutex_malloced_in_reach_list));
-
- memset((char*)new_mem+size,'d',new_size-size-USED_MEM_HEAD_LEN);
- atomic_add(&(orginal_mempool->debugger.app_mem),size);
- atomic_add(&(orginal_mempool->debugger.assigned_mem),new_size);
-#endif
- block=NULL;
- }
- else
- {
- if(old_size>=size)
- {
- new_mem=ptr;
-#ifdef DICTATOR_DEBUG
- atomic_sub(&(orginal_mempool->debugger.app_mem),block->idx->used_size-size);
- atomic_sub(&(block->idx->p_backtrace->ref_bytes),block->idx->used_size-size);
- block->idx->used_size=size;
-#endif
- }
- else
- {
- new_mem=core_alloc(D_SPACE.thread_mem_info[caller_Did],size);
- new_block=D_HEADER(new_mem);
- memcpy((char*)new_mem,
- (char*)ptr,
- old_size);
- core_free(caller_Did,ptr);
- }
- }
- return new_mem;
-}
-
-void *__wrap_malloc(size_t size)
-{
- thread_mem_pool_t* p_mempool=NULL;
- pthread_t tid=pthread_self();
- if(is_first==0)
- {
- p_mempool=init_dictator(tid);
- }
- else
- {
- p_mempool=locate_mp_by_tid(tid);
- }
- return core_alloc(p_mempool,size);
-
-}
-
-//If ptr is NULL, no operation is performed.
-void __wrap_free(void *p)
-{
- thread_mem_pool_t* p_mempool=NULL;
- if(p==NULL)
- return;
- pthread_t tid=pthread_self();
- p_mempool=locate_mp_by_tid(tid);
- core_free(p_mempool->D_id,p);
- return;
-}
-
-#if 0// close by lijia
-void* operator new(size_t size)
-{
- if(size==0)
- {
- size=1;
- }
- return __wrap_malloc(size);
-}
-void* operator new(size_t size,const std::nothrow_t ¬hrow_const)
-{
- if(size==0)
- {
- size=1;
- }
- return __wrap_malloc(size);
-}
-void operator delete(void*p)
-{
- __wrap_free(p);
-}
-#endif
-
-//The contents will be unchanged to the minimum of the old and new sizes;
-//If ptr is NULL, the call is equivalent to malloc(size); if size is equal to zero, the call is equivalent to free(ptr).
-//Unless ptr is NULL, it must have been returned by an earlier call to malloc(), calloc() or realloc().
-void *__wrap_realloc(void *ptr, size_t size)
-{
- pthread_t tid=pthread_self();
- thread_mem_pool_t* p_mempool=NULL;
- if(is_first==0)
- {
- p_mempool=init_dictator(tid);
- }
- else
- {
- p_mempool=locate_mp_by_tid(tid);
- }
- if(size==0&&ptr!=NULL)
- {
- core_free(p_mempool->D_id,ptr);
- return NULL;
- }
- if(ptr==NULL)
- {
- return core_alloc(p_mempool,size);
- }
- return core_realloc(p_mempool->D_id,ptr,size);
-}
-/* Maybe conflict with DPDK
-void *malloc(size_t size)
-{
- return __wrap_malloc(size);
-}
-void *realloc(void *ptr, size_t size)
-{
- return __wrap_realloc(ptr, size);
-}
-void *calloc(size_t nmemb, size_t size)
-{
- return __wrap_calloc(nmemb, size);
-}
-void free(void *p)
-{
- return __wrap_free(p);
-}*/
-void *__wrap_calloc(size_t nmemb, size_t size)
-{
- thread_mem_pool_t* p_mempool=NULL;
- void* p=NULL;
- pthread_t tid=pthread_self();
- if(is_first==0)
- {
- p_mempool=init_dictator(tid);
- }
- else
- {
- p_mempool=locate_mp_by_tid(tid);
- }
- p=core_alloc(p_mempool,nmemb*size);
- if(p!=NULL)
- {
- memset(p,0,nmemb*size);
- }
- return p;
-}
-void *__dictator_malloc(int t_seq,size_t size)
-{
- thread_mem_pool_t* p_mempool=NULL;
- pthread_t tid=0;
- if(is_first==0)
- {
- tid=pthread_self();
- p_mempool=init_dictator(tid);
- }
- else
- {
- p_mempool=locate_mp_by_tseq(t_seq);
- }
- return core_alloc(p_mempool,size);
-}
-void __dictator_free(int t_seq,void*p)
-{
- unsigned short this_D_id=0;
- if(p==NULL)
- {
- return;
- }
- thread_mem_pool_t* p_mempool=NULL;
- p_mempool=locate_mp_by_tseq(t_seq);
- this_D_id=p_mempool->D_id;
- core_free(this_D_id,p);
- return;
-}
-void *__dictator_realloc(int t_seq,void*ptr,size_t size)
-{
- thread_mem_pool_t* p_mempool=NULL;
- pthread_t tid=0;
- if(is_first==0)
- {
- tid=pthread_self();
- p_mempool=init_dictator(tid);
- }
- else
- {
- p_mempool=locate_mp_by_tseq(t_seq);
- }
- if(size==0&&ptr!=NULL){
- core_free(p_mempool->D_id,ptr);
- return NULL;
- }
- if(ptr==NULL)
- {
- return core_alloc(p_mempool,size);
- }
- return core_realloc(p_mempool->D_id,ptr,size);
-}
-void *__dictator_calloc(int t_seq,size_t nmemb, size_t size)
-{
- thread_mem_pool_t* p_mempool=NULL;
- pthread_t tid=0;
- if(is_first==0)
- {
- tid=pthread_self();
- p_mempool=init_dictator(tid);
- }
- else
- {
- p_mempool=locate_mp_by_tseq(t_seq);
- }
- return core_alloc(p_mempool,nmemb*size);
-}
-
diff --git a/src/support/dictator2/src/dictator.h b/src/support/dictator2/src/dictator.h deleted file mode 100644 index 5a95132..0000000 --- a/src/support/dictator2/src/dictator.h +++ /dev/null @@ -1,30 +0,0 @@ -/* DICATATOR Memory Manager -* Version 20141115 -*/ -#ifndef _DICTATOR2_H_ -#define _DICTATOR2_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -void *__wrap_malloc(size_t size); -void __wrap_free(void *p); -void *__wrap_realloc(void *ptr, size_t size); -void *__wrap_calloc(size_t nmemb, size_t size); - -void *__dictator_malloc(int t_seq,size_t size); -void __dictator_free(int t_seq,void*p); -void *__dictator_realloc(int t_seq,void *ptr, size_t size); -void *__dictator_calloc(int t_seq,size_t nmemb, size_t size); - -void *malloc(size_t size); -void *calloc(size_t nmemb, size_t size); -void free(void *p); - -#ifdef __cplusplus -} -#endif// end extern "C" - -#endif diff --git a/src/support/dictator2/src/dictator_core.h b/src/support/dictator2/src/dictator_core.h deleted file mode 100644 index be11cdc..0000000 --- a/src/support/dictator2/src/dictator_core.h +++ /dev/null @@ -1,191 +0,0 @@ -#ifndef _DICTATOR2_CORE_H_
-#define _DICTATOR2_CORE_H_
-
-#include <pthread.h>
-#include "internal_mp.h"
-#include "dummy_hash.h"
-
-#define DICTATOR2_VERSION "v1.3"
-#if(__GNUC__ * 100 + __GNUC_MINOR__ * 10 + __GNUC_PATCHLEVEL__ >= 410)
-#define atomic_inc(x) __sync_add_and_fetch((x),1)
-#define atomic_dec(x) __sync_sub_and_fetch((x),1)
-#define atomic_add(x,y) __sync_add_and_fetch((x),(y))
-#define atomic_sub(x,y) __sync_sub_and_fetch((x),(y))
-typedef long atomic_t;
-#define ATOMIC_INIT(i) { (i) }
-#define atomic_read(x) __sync_add_and_fetch((x),0)
-#define atomic_set(x,y) __sync_lock_test_and_set((x),y)
-#else
-typedef long atomic_t;
-#define atomic_inc(x) ((*(x))++)
-#define atomic_dec(x) ((*(x))--)
-#define atomic_add(x,y) ((*(x))+=(y))
-#define atomic_sub(x,y) ((*(x))-=(y))
-#define ATOMIC_INIT(i) { (i) }
-#define atomic_read(x) (*(x))
-#define atomic_set(x,y) ((*(x))=(y))
-#endif
-#include "D_internal/D_kernel_list.h"
-#include "D_internal/MESA_hash_v2.h"
-
-const unsigned int MAX_CHAIN_NUM_SUPPORT=128*3;
-const unsigned int MAX_TRHEAD_NUM_SUPPORT=1024;
-const unsigned int MAX_THREAD_RAWMEM_CNT=1024*4;
-const unsigned int DICTATOR_UNIT_SIZE=32;
-const unsigned int BATCH_DBG_IDX_NUM=MAX_CHAIN_NUM_SUPPORT*256;
-
-
-#ifndef MAX
-#define MAX(a, b) (((a) > (b)) ? (a) : (b))
-#endif
-
-#ifndef MIN
-#define MIN(a, b) (((a) < (b)) ? (a) : (b))
-#endif
-
-const unsigned int DICTATOR_MAGIC=0x5210;
-#define MAX_BACKTRACE_DEPTH 32
-#define MALLOC_SELF_DEPTH 3
-#define FREE_SEFL_DEPTH 3
-
-#define D_MARKER_SIZE 1024
-enum CHUNK_STATE
-{
- CHUNK_STATE_MALLOC=0,
- CHUNK_STATE_FREE,
- CHUNK_STATE_VIGRIN,
- CHUNK_STATE_REALLOC
-};
-struct backtrace_info_t
-{
- atomic_t ref_cnt;
- atomic_t ref_bytes;
- atomic_t maxsize;
- void** bt_array;
- size_t array_size;
- IMP_t* p_mempool;
-};
-struct dbg_index_t
-{
- unsigned int used_size;
- unsigned int assigned_size;
- struct D_kernel_list_head malloced_in_reach_hook;
- struct backtrace_info_t* p_backtrace;
- void* mem_info;
-};
-typedef struct mem_info{
-
-#ifdef DICTATOR_DEBUG
- unsigned short magic;
- unsigned short D_id;
- unsigned int blk_num:31;
- unsigned short type:1; // 0:mmap, 1:DPDK_HUGEPAGE
- struct dbg_index_t* idx;
-#else
- unsigned int blk_num;
- unsigned short D_id;
- unsigned short type; // 0:mmap, 1:DPDK_HUGEPAGE
-#endif
-
- struct mem_info *next;//used only if free
-} mem_info_t;
-//__attribute__((packed))
-typedef struct buffer_container{
- size_t available_size;
- char *buffer;
-}buffer_container_t;
-
-typedef struct mem_queue{
- mem_info_t * head;
- mem_info_t * tail;
- atomic_t ele_cnt;
- pthread_mutex_t mutex_tail_lock;
-}mem_queue_t;
-
-typedef struct _thread_mem_debugger
-{
- atomic_t cached_mem;//dictator managed mem,less than total mem
- atomic_t app_mem; //application applied mem size,inlucding not managed mem,less than total_mem
- atomic_t assigned_mem;//dictator assigned to application
- atomic_t inuse_num;
- atomic_t malloc_cnt;
- atomic_t free_cnt;
- atomic_t selfcost_mem;//used by dictator itself
- MESA_hash_tab_v2_t malloc_backtrace_hash;
- MESA_hash_tab_v2_t free_backtrace_hash;
- pthread_mutex_t mutex_malloced_in_reach_list;
- struct D_kernel_list_head malloced_in_reach_list;
-
- atomic_t pool_unit_cnt;
- struct D_kernel_list_head index_pool;
- pthread_mutex_t mutex_pool_tail;
- unsigned int rawmem_idx;
- void* raw_mem_header[MAX_THREAD_RAWMEM_CNT];
-}thread_mem_debugger_t;
-
-typedef struct thread_mem_pool{
- unsigned short D_id;
- pthread_t tid;
- int t_seq;
- int rawmem_idx;
- mem_queue_t block_chain[MAX_CHAIN_NUM_SUPPORT];
- buffer_container_t block_buffer_container;
- void* raw_mem_header[MAX_THREAD_RAWMEM_CNT];
-#ifdef DICTATOR_DEBUG
- thread_mem_debugger_t debugger;
-#endif
-}thread_mem_pool_t;
-
-struct dictator_space_t
-{
- unsigned int POWER[MAX_CHAIN_NUM_SUPPORT];
- unsigned int INIT_THREAD_BLOCK_NUM;
-
- struct dummy_htable_t tid2idx;
- int tseq2idx[MAX_TRHEAD_NUM_SUPPORT];
-
- thread_mem_pool_t *thread_mem_info[MAX_TRHEAD_NUM_SUPPORT];
- atomic_t used_mem_pool_counter;
- int page_size;
-};
-
-inline mem_info_t *get_block(thread_mem_pool_t *thread_info,unsigned int block_num);
-inline void restore_block(thread_mem_pool_t* thread_info,mem_info_t *block);
-
-unsigned int calc_block_num(size_t alloc_size);
-inline mem_info_t* fill_empty_block(mem_info_t* block,unsigned int blk_num,unsigned short D_id);
-
-thread_mem_pool_t *create_mem_pool(unsigned short D_id);
-backtrace_info_t* create_bt_info(void** bt_array,int size);
-backtrace_info_t* backtrace_ref_inc(MESA_hash_tab_v2_t* hash,size_t inc_size,thread_mem_pool_t *p_mempool);
-struct dbg_index_t* get_dbg_index(thread_mem_debugger_t* debugger);
-void restore_dbg_index(thread_mem_debugger_t* debugger,struct dbg_index_t*idx);
-thread_mem_pool_t *create_mem_pool(unsigned short D_id);
-void init_debugger(thread_mem_debugger_t* debugger,thread_mem_pool_t* p_mp);
-
-void * dictator_debug_thread(void* param);
-void D_check_mem(int sd,int is_scheduled);
-#define USED_MEM_HEAD_LEN (sizeof(mem_info_t)-sizeof(struct mem_info *))
-#define D_HEADER(ptr) ((mem_info_t *)((char*)(ptr)-USED_MEM_HEAD_LEN))
-#define D_MEM(ptr) ((char*)(ptr)+USED_MEM_HEAD_LEN)
-#define IS_CHUNK(x) ((x)>(D_SPACE.POWER[MAX_CHAIN_NUM_SUPPORT-1]))
-
-inline unsigned int calc_block_num(size_t alloc_size){
- unsigned int block_num=0;
- if(alloc_size%DICTATOR_UNIT_SIZE==0)
- {
- block_num = alloc_size/DICTATOR_UNIT_SIZE;
-#ifdef DICTATOR_DEBUG
- block_num++;
-#endif
- }
- else
- {
- block_num = (alloc_size/DICTATOR_UNIT_SIZE)+1;
- }
- return block_num;
-}
-
-
-#endif
-
diff --git a/src/support/dictator2/src/dictator_debuger.cpp b/src/support/dictator2/src/dictator_debuger.cpp deleted file mode 100644 index db8b621..0000000 --- a/src/support/dictator2/src/dictator_debuger.cpp +++ /dev/null @@ -1,816 +0,0 @@ -#include <stdio.h>
-#include <sys/syscall.h>
-#include <unistd.h>
-#include <assert.h>
-#include <string.h>//using memset
-#include <time.h>
-#include <errno.h>
-#include <stdio.h>
-//#include <execinfo.h>//backtrace
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <net/if.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <sys/un.h>
-//#include <libunwind.h>
-
-#include "dictator.h"
-#include "dictator_core.h"
-#ifdef DICTATOR_DEBUG
-extern struct dictator_space_t D_SPACE;
-thread_mem_pool_t* DEBUGGER_MP=NULL;
-extern char boundary_marker[D_MARKER_SIZE];
-
-#define D_CMD_HELP 0
-#define D_CMD_STAT 1
-#define D_CMD_LIST_MALLOC 2
-#define D_CMD_CHECK 3
-#define D_CMD_LIST_LARGE_M 4
-const char* support_cmd_full[]={"help","stat memory","list malloc","check memory","list large","\0"};
-const char support_cmd_short[]={'h','s','l','c','m','\0'};
-const char* cmd_introduce[]={"Print this text",
- "Statistic memory usage",
- "List 'max_num' and 'minmum_bytes' malloc backtrace,list all as default",
- "Check 'times' and 'interval us' to find if any memroy corrupt,check 1 time and 100*1000 us as default",
- "List 'max_num' and 'minmum_bytes' of SINGLE malloc backtrace which size is larger than 'minmum_bytes',list 65535(64KB) as default",
- "\0"};
-
-backtrace_info_t* create_bt_info(void** bt_array,int size,thread_mem_pool_t *p_mempool)
-{
- backtrace_info_t*caller_bt=NULL;
- unsigned int memsize=sizeof(backtrace_info_t)+sizeof(void**)*size;
- caller_bt=(backtrace_info_t*)block_alloc(memsize,(IMP_t*)p_mempool);
- atomic_set(&(caller_bt->ref_cnt),0);
- atomic_set(&(caller_bt->ref_bytes),0);
- atomic_set(&(caller_bt->maxsize),0);
- caller_bt->bt_array=(void**)((char*)caller_bt+sizeof(backtrace_info_t));
- memcpy(caller_bt->bt_array,bt_array,sizeof(void**)*size);
- caller_bt->array_size=size;
- caller_bt->p_mempool=(IMP_t*)p_mempool;
- return caller_bt;
-}
-void destroy_bt_info(void* bt_info)
-{
- backtrace_info_t*caller_bt=(backtrace_info_t*)bt_info;
- block_free(caller_bt,caller_bt->p_mempool);
- return;
-}
-void init_debugger(thread_mem_debugger_t* debugger,thread_mem_pool_t* p_mp)
-{
- unsigned int i=0;
- int ret=0;
- struct dbg_index_t* idx_pool_buff=NULL;
-
- D_kernel_list_init(&(debugger->malloced_in_reach_list));
- pthread_mutex_init(&(debugger->mutex_malloced_in_reach_list),NULL);
- pthread_mutex_init(&(debugger->mutex_pool_tail),NULL);
- atomic_set(&(debugger->app_mem),0);
- atomic_set(&(debugger->assigned_mem),0);
- atomic_set(&(debugger->inuse_num),0);
- atomic_set(&(debugger->malloc_cnt),0);
- atomic_set(&(debugger->free_cnt),0);
- atomic_set(&(debugger->selfcost_mem),sizeof(thread_mem_pool_t));
- debugger->cached_mem=DICTATOR_UNIT_SIZE*D_SPACE.INIT_THREAD_BLOCK_NUM;
-
-
- idx_pool_buff=(struct dbg_index_t*)mmap_alloc(D_SPACE.INIT_THREAD_BLOCK_NUM*sizeof(struct dbg_index_t));
- atomic_add(&(debugger->selfcost_mem),D_SPACE.INIT_THREAD_BLOCK_NUM*sizeof(struct dbg_index_t));
-
- debugger->raw_mem_header[0]=idx_pool_buff;
- debugger->rawmem_idx=1;
- D_kernel_list_init(&(debugger->index_pool));
- for(i=0;i<D_SPACE.INIT_THREAD_BLOCK_NUM;i++)
- {
- D_kernel_list_add_tail(&(debugger->index_pool), &(idx_pool_buff[i].malloced_in_reach_hook));
- }
- atomic_set(&(debugger->pool_unit_cnt),D_SPACE.INIT_THREAD_BLOCK_NUM);
- ret=D_INTERNAL_MESA_hash_create_v2(&(debugger->malloc_backtrace_hash),
- 1,//thread safe
- 1024*32,
- 0,//unlimited max element num
- NULL,
- NULL,
- destroy_bt_info,
- NULL,
- 0,
- 0,//never expire
- (IMP_t*)p_mp);
- assert(ret==0);
- ret=D_INTERNAL_MESA_hash_create_v2(&(debugger->free_backtrace_hash),
- 1,//thread safe
- 1024*32,
- 0,//unlimited max element num
- NULL,
- NULL,
- destroy_bt_info,
- NULL,
- 0,
- 0,//never expire
- (IMP_t*)p_mp);
- assert(ret==0);
- return;
-}
-void destroy_thread_mem_debugger(thread_mem_debugger_t* debugger)
-{
- unsigned int i=0;
- D_INTERNAL_MESA_hash_destroy_v2(&(debugger->malloc_backtrace_hash),NULL);
- D_INTERNAL_MESA_hash_destroy_v2(&(debugger->free_backtrace_hash),NULL);
- for(i=0;i<debugger->rawmem_idx;i++)
- {
- mmap_free(debugger->raw_mem_header[i]);
- debugger->raw_mem_header[i]=NULL;
- }
- pthread_mutex_destroy(&(debugger->mutex_malloced_in_reach_list));
- pthread_mutex_destroy(&(debugger->mutex_pool_tail));
- return;
-}
-struct dbg_index_t* get_dbg_index(thread_mem_debugger_t* debugger)
-{
- struct dbg_index_t* p;
- struct D_kernel_list_head* elem=NULL;
- struct dbg_index_t* idx_pool_buff=NULL;
- unsigned int i=0;
- if(atomic_read(&(debugger->pool_unit_cnt))<2)
- {
- idx_pool_buff=(struct dbg_index_t*)mmap_alloc(BATCH_DBG_IDX_NUM*sizeof(struct dbg_index_t));
- atomic_add(&(debugger->selfcost_mem),BATCH_DBG_IDX_NUM*sizeof(struct dbg_index_t));
- assert(debugger->rawmem_idx<MAX_THREAD_RAWMEM_CNT);
- debugger->raw_mem_header[debugger->rawmem_idx]=idx_pool_buff;
- debugger->rawmem_idx++;
- for(i=0;i<BATCH_DBG_IDX_NUM;i++)
- {
- D_kernel_list_add_head(&(debugger->index_pool), &(idx_pool_buff[i].malloced_in_reach_hook));
- }
- atomic_add(&(debugger->pool_unit_cnt),BATCH_DBG_IDX_NUM);
- }
- elem=D_kernel_list_get_head(&(debugger->index_pool));
- p=container_of(elem,struct dbg_index_t,malloced_in_reach_hook);
- atomic_dec(&(debugger->pool_unit_cnt));
- p->used_size=0;
- p->p_backtrace=NULL;
- p->mem_info=0;
- return p;
-}
-void restore_dbg_index(thread_mem_debugger_t* debugger,struct dbg_index_t*idx)
-{
- pthread_mutex_lock(&(debugger->mutex_pool_tail));
- D_kernel_list_add_tail(&(debugger->index_pool),&(idx->malloced_in_reach_hook));
- atomic_inc(&(debugger->pool_unit_cnt));
- pthread_mutex_unlock(&(debugger->mutex_pool_tail));
- return;
-}
-struct sort_data_t
-{
- long val;
- void* data;
-};
-static int sort_data_pos=0;
-
-void quick_sort(struct sort_data_t *a,int i,int j)
-{
-
- int m,n;
- struct sort_data_t temp;
- int k;
- m=i;
- n=j;
- k=a[(i+j)/2].val; /*ѡȡ�IJ���*/
- do {
- while(a[m].val<k&&m<j)
- m++; /* �������ұ�k���Ԫ��*/
- while(a[n].val>k&&n>i)
- n--; /* ���ҵ����ұ�kС��Ԫ��*/
- if(m<=n)
- { /*���ҵ���������������*/
- temp=a[m];
- a[m]=a[n];
- a[n]=temp;
- m++;
- n--;
- }
-
- }while(m<=n);
-
- if(m<j)
- quick_sort(a,m,j); /*���õݹ�*/
- if(n>i)
- quick_sort(a,i,n);
-
-}
-void show_help(int sd)
-{
- int i=0;
- char buff[4096]={0};
- unsigned int printed=0;
- printed+=snprintf(buff,sizeof(buff)-printed,"Command Usage:\n");
- while(strlen(support_cmd_full[i])>1&&printed<sizeof(buff))
- {
- printed+=snprintf(buff+printed,sizeof(buff)-printed,"\t%s(or '%c'):\t\t\t%s\n",support_cmd_full[i],
- support_cmd_short[i],
- cmd_introduce[i]);
- i++;
- }
- write(sd,buff,printed);
-}
-void stat_memory(int sd)
-{
- int i=0;
- char buff[4096]={0};
- unsigned int printed=0;
- unsigned long long app_mem=0,assigned_mem=0,cached_mem=0;
- unsigned long long inuse_num=0,malloc_cnt=0,free_cnt=0;
- unsigned long long num_malloced_places=0,num_freed_places=0;
- unsigned long long selfcost_mem=0;
- for(i=0;i<=atomic_read(&(D_SPACE.used_mem_pool_counter));i++)
- {
- if(D_SPACE.thread_mem_info[i]==NULL)
- {
- continue;
- }
- app_mem+=atomic_read(&(D_SPACE.thread_mem_info[i]->debugger.app_mem));
- cached_mem+=atomic_read(&(D_SPACE.thread_mem_info[i]->debugger.cached_mem));
- assigned_mem+=atomic_read(&(D_SPACE.thread_mem_info[i]->debugger.assigned_mem));
- num_malloced_places+=D_SPACE.thread_mem_info[i]->debugger.malloc_backtrace_hash.elem_count;
- num_freed_places+=D_SPACE.thread_mem_info[i]->debugger.free_backtrace_hash.elem_count;
- inuse_num+=atomic_read(&(D_SPACE.thread_mem_info[i]->debugger.inuse_num));
- malloc_cnt+=atomic_read(&(D_SPACE.thread_mem_info[i]->debugger.malloc_cnt));
- free_cnt+=atomic_read(&(D_SPACE.thread_mem_info[i]->debugger.free_cnt));
- selfcost_mem+=atomic_read(&(D_SPACE.thread_mem_info[i]->debugger.selfcost_mem));
- }
- printed+=snprintf(buff+printed,sizeof(buff)-printed,"pool num:%d inuse %llu block\n",i,inuse_num);
- printed+=snprintf(buff+printed,sizeof(buff)-printed,"malloced %llu times in %llu context(s)\n",malloc_cnt,num_malloced_places);
- printed+=snprintf(buff+printed,sizeof(buff)-printed,"freed %llu times in %llu context(s)\n",free_cnt,num_freed_places);
- printed+=snprintf(buff+printed,sizeof(buff)-printed,"app used:%llu bytes/%lluMB\n",app_mem,app_mem/(1024*1024));
- printed+=snprintf(buff+printed,sizeof(buff)-printed,"assigned:%llu bytes/%lluMB\n",assigned_mem,assigned_mem/(1024*1024));
- printed+=snprintf(buff+printed,sizeof(buff)-printed,"cached :%llu bytes/%lluMB\n",cached_mem,cached_mem/(1024*1024));
- printed+=snprintf(buff+printed,sizeof(buff)-printed,"selfcost:%llu bytes/%lluMB\n",selfcost_mem,selfcost_mem/(1024*1024));
- write(sd,buff,printed);
-}
-
-/*
-int unw_backtrace(void **bt_array,int number)
-{
- unw_cursor_t cursor;
- unw_context_t uc;
- unw_word_t ip;
-
- unw_getcontext(&uc);
- unw_init_local(&cursor, &uc);
- int ret_cnt=0;
- while (unw_step(&cursor) > 0) {
- unw_get_reg(&cursor, UNW_REG_IP, &ip);
- if(ret_cnt<number)
- {
- bt_array[ret_cnt]=(void*)ip;
- ret_cnt++;
- }
- else
- {
- break;
- }
- }
- if(ret_cnt>0)//make exception for unw_backtrace
- {
- return ret_cnt-1;
- }
- else
- {
- return 0;
- }
-}
-*/
-#define STACKCALL __attribute__((regparm(1),noinline))
-void ** STACKCALL getEBP(void){
- void **ebp=NULL;
- __asm__ __volatile__("mov %%rbp, %0;\n\t"
- :"=m"(ebp) /* ��� */
- : /* ���� */
- :"memory"); /* ����Ӱ��ļĴ��� */
- return (void **)(*ebp);
-}
-int mesa_backtrace(void **buffer,int size){
-
- int frame=0;
- void ** ebp;
- void **ret=NULL;
- unsigned long long func_frame_distance=0;
- if(buffer!=NULL && size >0)
- {
- ebp=getEBP();
- func_frame_distance=(unsigned long long)(*ebp) - (unsigned long long)ebp;
- while(ebp&& frame<size
- &&(func_frame_distance< (1ULL<<24))//assume function ebp more than 16M
- &&(func_frame_distance>0))
- {
- ret=ebp+1;
- buffer[frame++]=*ret;
- ebp=(void**)(*ebp);
- func_frame_distance=(unsigned long long)(*ebp) - (unsigned long long)ebp;
- }
- }
- return frame;
-}
-
-
-backtrace_info_t* backtrace_ref_inc(MESA_hash_tab_v2_t* hash,size_t inc_size,thread_mem_pool_t *p_mempool)
-{
- void *bt_array[MAX_BACKTRACE_DEPTH];
- void** except_self_bt_array;
- size_t bt_depth,except_self_bt_depths;
- bt_depth = mesa_backtrace(bt_array, MAX_BACKTRACE_DEPTH);
-// bt_depth = backtrace(bt_array, MAX_BACKTRACE_DEPTH);
-// bt_depth = unw_backtrace(bt_array, MAX_BACKTRACE_DEPTH);
- backtrace_info_t *caller_bt;
- if(bt_depth<=MALLOC_SELF_DEPTH)
- {
- bt_depth=MALLOC_SELF_DEPTH+1;
- memset(bt_array,0,sizeof(bt_array));
- }
- except_self_bt_array=bt_array+MALLOC_SELF_DEPTH;
- except_self_bt_depths=bt_depth-MALLOC_SELF_DEPTH;
- caller_bt=(backtrace_info_t *)D_INTERNAL_MESA_hash_sel_v2(hash,
- (uchar*)(except_self_bt_array),
- sizeof(void*)*(except_self_bt_depths));
- if(caller_bt==NULL)
- {
- caller_bt=create_bt_info(except_self_bt_array, except_self_bt_depths,p_mempool);
- D_INTERNAL_MESA_hash_add_v2(hash,
- (uchar*)except_self_bt_array,
- sizeof(void*)*except_self_bt_depths,
- caller_bt);
- }
- atomic_inc(&(caller_bt->ref_cnt));
- atomic_add(&(caller_bt->ref_bytes),inc_size);
- if(atomic_read(&(caller_bt->maxsize))<(signed long)inc_size)
- {
- atomic_set(&(caller_bt->maxsize),(signed long)inc_size);
- }
- return caller_bt;
-}
-void merge_mp_hash(uchar * key, uint size, void * data, void * u)
-{
- MESA_hash_tab_v2_t* target_hash=(MESA_hash_tab_v2_t*)u;
- backtrace_info_t* tmp_bt_info=(backtrace_info_t*)data;
- if(0==atomic_read(&(tmp_bt_info->ref_bytes)))
- {
- return;
- }
- backtrace_info_t* target_bt_info=(backtrace_info_t *)D_INTERNAL_MESA_hash_sel_v2(target_hash,
- (uchar*)key,
- size);
- if(target_bt_info==NULL)
- {
- target_bt_info=create_bt_info(tmp_bt_info->bt_array, tmp_bt_info->array_size,DEBUGGER_MP);
-
- D_INTERNAL_MESA_hash_add_v2(target_hash,
- key,
- size,
- target_bt_info);
- }
- atomic_add(&(target_bt_info->ref_bytes),atomic_read(&(tmp_bt_info->ref_bytes)));
- atomic_add(&(target_bt_info->ref_cnt),atomic_read(&(tmp_bt_info->ref_cnt)));
- if(atomic_read(&(target_bt_info->maxsize))<atomic_read(&(tmp_bt_info->maxsize)))
- {
- atomic_set(&(target_bt_info->maxsize),atomic_read(&(tmp_bt_info->maxsize)));
- }
- return;
-}
-void dump2array_by_refbytes(uchar * key, uint size, void * data, void * u)
-{
-
- backtrace_info_t* bt_info=(backtrace_info_t*)data;
- struct sort_data_t* sort_array=(struct sort_data_t*)u;
- sort_array[sort_data_pos].val=atomic_read(&(bt_info->ref_bytes));
- sort_array[sort_data_pos].data=data;
- sort_data_pos++;
- return;
-}
-void dump2array_by_maxsize(uchar * key, uint size, void * data, void * u)
-{
-
- backtrace_info_t* bt_info=(backtrace_info_t*)data;
- struct sort_data_t* sort_array=(struct sort_data_t*)u;
- sort_array[sort_data_pos].val=atomic_read(&(bt_info->maxsize));
- sort_array[sort_data_pos].data=data;
- sort_data_pos++;
- return;
-}
-int exec_shell(const char*cmd ,char* buff,int buff_size)
-{
- FILE* fp = popen(cmd, "r");
- if(fp==NULL)
- {
- return -1;
- }
- memset(buff,0,buff_size);
- fgets(buff,buff_size,fp);
- pclose(fp);
- return strlen(buff);
-}
-int get_backtrace_string(void* bt,char* buff,int buff_size)
-{
- char cmd[128] = {0};
- char property[256]={0};
- char not_care1[128]={0},not_care2[128]={0},not_care3[128]={0};
- char library_path[256]={0};
- char exe_path[256]={0},function_name[256]={0};
- char maps_line[1024]={0};
- void* offset_start,*offset_end;
- int maps_column_num=0;
- FILE* fd_maps=NULL;
- fd_maps=fopen("/proc/self/maps","r");
- unsigned long exe_symbol_offset=0;
- const char* unknow_position="??:0\n";
- if(fd_maps==NULL)
- {
- return -1;
- }
- while(NULL!=fgets(maps_line,sizeof(maps_line),fd_maps))
- {
- maps_column_num=sscanf(maps_line,"%p-%p\t%s\t%s\t%s\t%s\t%s"
- ,&offset_start
- ,&offset_end
- ,property
- ,not_care1
- ,not_care2
- ,not_care3
- ,library_path);
- if(maps_column_num==7&&bt>=offset_start&&bt<=offset_end)
- {
- break;
- }
-
- }
- fclose(fd_maps);
- memset(exe_path,0,sizeof(exe_path));
- readlink("/proc/self/exe", exe_path, sizeof(exe_path));
- if(exe_path[strlen(exe_path)-1]=='\n')
- {
- exe_path[strlen(exe_path)-1]='\0';
- }
- if(0==strcmp(exe_path,library_path))
- {
- exe_symbol_offset=(unsigned long)bt;
- }
- else
- {
- exe_symbol_offset=(char*)bt-(char*)offset_start;
- }
- snprintf(cmd,sizeof(cmd),"addr2line -C -e %s 0x%lx",library_path,exe_symbol_offset);
- exec_shell(cmd, buff, buff_size);
- if(0==strcmp(buff,unknow_position))
- {
- snprintf(cmd,sizeof(cmd),"addr2line -Cif -e %s 0x%lx",library_path,exe_symbol_offset);
- exec_shell(cmd, function_name, sizeof(function_name));
- function_name[strlen(function_name)-1]='\0';
- snprintf(buff,buff_size,"%s(%s+0x%lx)\n",library_path,function_name,exe_symbol_offset);
- }
- return 0;
-}
-
-int merge_malloc_bt(MESA_hash_tab_v2_t *merged_hash)
-{
- int ret=0,i=0;
- MESA_hash_tab_v2_t* mp_malloc_hash;
- int to_sort_size=0;
- ret=D_INTERNAL_MESA_hash_create_v2(merged_hash,
- 1,//thread safe
- 1024*32,
- 0,//unlimited max element num
- NULL,
- NULL,
- destroy_bt_info,
- NULL,
- 0,
- 0,//never expire
- (IMP_t*)DEBUGGER_MP);
- assert(ret==0);
- for(i=0;i<=atomic_read(&(D_SPACE.used_mem_pool_counter));i++)
- {
- if(D_SPACE.thread_mem_info[i]==NULL)
- {
- continue;
- }
- mp_malloc_hash=&(D_SPACE.thread_mem_info[i]->debugger.malloc_backtrace_hash);
- D_INTERNAL_MESA_hash_iterate_v2_2(mp_malloc_hash, merge_mp_hash,merged_hash);
- }
-
- to_sort_size=merged_hash->elem_count;
- return to_sort_size;
-}
-
-
-void list_malloc_bt(int sd,const char*args,int CMD)
-{
- int i=0,printed=0,list_cnt=0;
- unsigned int j=0;
- backtrace_info_t* bt_info=NULL;
- long ref_bytes=0,ref_cnt=0;
- struct sort_data_t* sort_array=NULL;
- int to_sort_size=0;
- char buff[4096]={0},bt_string[1024]={0};
- pid_t pid=getpid();
- int max_list_num=-1,min_list_size=-1;
- MESA_hash_tab_v2_t merged_hash;
- sscanf(args,"%d %d",&max_list_num,&min_list_size);
- if(CMD!=D_CMD_LIST_LARGE_M&&CMD!=D_CMD_LIST_MALLOC)
- {
- assert(0);
- }
- to_sort_size=merge_malloc_bt(&merged_hash);
- sort_array=(struct sort_data_t*)mmap_alloc(to_sort_size*sizeof(struct sort_data_t));
-
- if(CMD==D_CMD_LIST_LARGE_M)
- {
- D_INTERNAL_MESA_hash_iterate_v2_2(&merged_hash, dump2array_by_maxsize,sort_array);
-
- }
- else if(CMD==D_CMD_LIST_MALLOC)
- {
- D_INTERNAL_MESA_hash_iterate_v2_2(&merged_hash, dump2array_by_refbytes,sort_array);
- }
- sort_data_pos=0;
- quick_sort(sort_array, 0,to_sort_size-1);
- for(i=to_sort_size-1;i>=0;i--)
- {
- printed=0;
- memset(buff,0,sizeof(buff));
- bt_info=(backtrace_info_t*)(sort_array[i].data);
- if(list_cnt>=max_list_num&&max_list_num>0)
- {
- break;
- }
- if(CMD==D_CMD_LIST_LARGE_M)
- {
- if(atomic_read(&(bt_info->maxsize))<min_list_size&&min_list_size>0)
- {
- break;
- }
- }
- else if(CMD==D_CMD_LIST_MALLOC)
- {
- if(atomic_read(&(bt_info->ref_bytes))<min_list_size&&min_list_size>0)
- {
- break;
- }
- }
-
- ref_bytes=atomic_read(&(bt_info->ref_bytes));
- ref_cnt=atomic_read(&(bt_info->ref_cnt));
- printed+=snprintf(buff+printed,sizeof(buff)-printed,
- "=%u=\t malloc %ld bytes(%ldMB) and %ld times in contexts (MAX %ld bytes,AVG %ld bytes)\n",
- pid,
- ref_bytes,
- ref_bytes/(1024*1024),
- ref_cnt,
- atomic_read(&(bt_info->maxsize)),
- ref_bytes/ref_cnt);
- for(j=0;j<bt_info->array_size;j++)
- {
- memset(bt_string,0,sizeof(bt_string));
- get_backtrace_string(bt_info->bt_array[j],bt_string,sizeof(bt_string));
- printed+=snprintf(buff+printed,sizeof(buff)-printed,"=%u=\tby %s",pid,bt_string);
- }
- printed+=snprintf(buff+printed,sizeof(buff)-printed,"\n");
- write(sd,buff,printed);
- list_cnt++;
- }
- D_INTERNAL_MESA_hash_destroy_v2(&merged_hash,NULL);
- mmap_free(sort_array);
-}
-int d_chk_one_mem(struct dbg_index_t* idx,char* err_string,int size)
-{
- int printed=0,invalid_write_size=0,i=0;
- unsigned int assigned_size=0;
- const char* user_boundary=NULL;
- mem_info_t* block=(mem_info_t*)(idx->mem_info);
- int boundary_len=0,is_corrupt=0;
- if(block->magic!=DICTATOR_MAGIC)
- {
- printed+=snprintf(err_string+printed,size-printed,"Magic Error|");
- is_corrupt=1;
- }
- assigned_size=block->blk_num*DICTATOR_UNIT_SIZE;
- if(assigned_size<idx->used_size+USED_MEM_HEAD_LEN)
- {
- printed+=snprintf(err_string+printed,size-printed,"Corrupt mem head usd(%lu)>assigned(%u)|"
- ,idx->used_size+USED_MEM_HEAD_LEN
- ,assigned_size);
- is_corrupt=1;
- }
- user_boundary=(char*)block+USED_MEM_HEAD_LEN+idx->used_size;
- boundary_len=MIN(assigned_size-idx->used_size-USED_MEM_HEAD_LEN,D_MARKER_SIZE);
- if(0!=memcmp(user_boundary,boundary_marker,boundary_len))
- {
- for(i=0;i<boundary_len;i++)
- {
- if(user_boundary[i]!='d')
- {
- invalid_write_size++;
- }
- }
- printed+=snprintf(err_string+printed,size-printed,"Invaid write %d bytes after %p|",invalid_write_size,user_boundary);
- if(invalid_write_size==boundary_len)
- {
- printed+=snprintf(err_string+printed,size-printed,"May stack overflow|");
-
- }
- is_corrupt=1;
- }
- return is_corrupt;
-}
-void D_check_mem(int sd,int is_scheduled)
-{
- int i=0;
- unsigned int j=0;
- int is_corrupt=0,printed=0;
- unsigned long chked_blk_sum=0,chked_bytes_sum=0,corrupt_sum=0;
- struct D_kernel_list_head* to_check_list=NULL,*to_check_elem=NULL;
- struct dbg_index_t* to_chk_idx=NULL;
- mem_info_t* block=NULL;
- char err_string[256]={0},bt_string[1024]={0};;
- char buff[4096]={0};
- pid_t pid=getpid();
- for(i=0;i<=atomic_read(&(D_SPACE.used_mem_pool_counter));i++)
- {
- if(D_SPACE.thread_mem_info[i]==NULL)
- {
- continue;
- }
- pthread_mutex_lock(&(D_SPACE.thread_mem_info[i]->debugger.mutex_malloced_in_reach_list));
- to_check_list=&(D_SPACE.thread_mem_info[i]->debugger.malloced_in_reach_list);
- to_check_elem=to_check_list->next;
- while(to_check_elem!=to_check_list)
- {
- printed=0;
- to_chk_idx=container_of(to_check_elem,struct dbg_index_t, malloced_in_reach_hook);
- chked_blk_sum++;
- chked_bytes_sum+=to_chk_idx->used_size;
- is_corrupt=d_chk_one_mem(to_chk_idx, err_string,sizeof(err_string));
- if(is_corrupt==1)
- {
- block=(mem_info_t*)to_chk_idx->mem_info;
- corrupt_sum++;
- printed=snprintf(buff+printed,sizeof(buff)-printed,"Mem %p size %d(%s) D_id %u %s in context\n",
- (char*)block+USED_MEM_HEAD_LEN,
- to_chk_idx->used_size,
- block->blk_num?"block":"chunk",
- block->D_id,
- err_string);
-
- for(j=0;j<to_chk_idx->p_backtrace->array_size;j++)
- {
- memset(bt_string,0,sizeof(bt_string));
- get_backtrace_string(to_chk_idx->p_backtrace->bt_array[j],bt_string,sizeof(bt_string));
- printed+=snprintf(buff+printed,sizeof(buff)-printed,"=%u=\tby %s",pid,bt_string);
- }
-
- write(sd,buff,printed);
- }
- to_check_elem=to_check_elem->next;
- }
- pthread_mutex_unlock(&(D_SPACE.thread_mem_info[i]->debugger.mutex_malloced_in_reach_list));
-
- }
- printed=0;
- printed+=snprintf(buff+printed,sizeof(buff)-printed,"Corrutp Sumary:\n\tChecked %d threads.\n\tChecked %lu block,%lu bytes(%luMB).\n\t%lu block(s) Corrupt.\n",
- i,
- chked_blk_sum,
- chked_bytes_sum,
- chked_bytes_sum/(1024*1024),
- corrupt_sum);
- if(!is_scheduled)
- {
- write(sd,buff,printed);
- }
- return;
-
-}
-int dictator_parse_cmd(const char* cmd,const char**args)
-{
- int i=0,ret=0;
- while(strlen(support_cmd_full[i])>1)
- {
- ret=strncasecmp(cmd,support_cmd_full[i],strlen(support_cmd_full[i]));
- if(ret==0)
- {
- *args=cmd+strlen(support_cmd_full[i])+1;
- break;
- }
- else if((cmd[0]==support_cmd_short[i])&&(cmd[1]=='\n'||cmd[1]==' '))
- {
- *args=cmd+2;
- break;
- }
- i++;
- }
- return i;
-}
-void * dictator_debug_thread(void* param)
-{
- pid_t app_pid=0;
- char listen_path[64];
- char cmd_buff[1024],debug_cmd[1024];
- app_pid=getpid();
- char banner[1024]={0};
- const char* unknown_cmd="UNKNOWN CMD.\n";
- const char* shell="dictator2>";
- const char* schedule_checking="Schedule Checking";
- snprintf(listen_path,sizeof(listen_path),"/tmp/dictator_%u",app_pid);
- snprintf(banner,sizeof(banner),"WELCOME TO DICTATOR2(%s) DEBUG CONSOLE.\n",
- DICTATOR2_VERSION);
- DEBUGGER_MP=create_mem_pool(-1);
- struct sockaddr_un address;
- int sock, conn,cmd_id=0;
- int check_times=-1,check_interval_us=1000*100;
- int i=0,ret=-1;
- size_t addrLength;
- const char *args=NULL;
-
- if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0)
- {
- fprintf(stderr,"DICTATOR2 INIT FAILED!\n");
- }
-
- unlink(listen_path);
-
- address.sun_family = AF_UNIX;
- strcpy(address.sun_path,listen_path);
-
- addrLength = sizeof(address.sun_family) + strlen(address.sun_path);
-
- if (bind(sock, (struct sockaddr *) &address, addrLength))
- {
- fprintf(stderr,"DICTATOR2 bind %s FAILED!\n",listen_path);
- }
- if (listen(sock, 1))
- {
- fprintf(stderr,"DICTATOR2 listen %s FAILED!\n",listen_path);
- }
- fprintf(stderr,"Using DICTATOR2 memory debugger (%s)\n",listen_path);
- while ((conn = accept(sock, (struct sockaddr *) &address,(socklen_t*)&addrLength)) >= 0)
- {
- write(conn,banner,strlen(banner));
- memset(debug_cmd,0,sizeof(debug_cmd));
- write(conn,shell,strlen(shell));
- while(read(conn,cmd_buff,sizeof(cmd_buff))>0)
- {
- if(cmd_buff[0]!='\n')
- {
- memcpy(debug_cmd,cmd_buff,sizeof(debug_cmd));
- cmd_id=dictator_parse_cmd(debug_cmd,&args);
- }
- check_times=-1;
- check_interval_us=1000*100;
- switch(cmd_id)
- {
- case D_CMD_HELP:
- show_help(conn);
- break;
- case D_CMD_STAT:
- stat_memory(conn);
- break;
- case D_CMD_LIST_MALLOC:
- case D_CMD_LIST_LARGE_M:
- list_malloc_bt(conn,args,cmd_id);
- break;
- case D_CMD_CHECK:
- sscanf(args,"%d %d",&check_times,&check_interval_us);
- if(check_times>0)
- {
- write(conn,schedule_checking,strlen(schedule_checking));
- for(i=0;i<check_times;i++)
- {
- D_check_mem(conn,1);
- ret=write(conn,".",1);
- if(ret<=0)
- {
- break;
- }
- usleep(check_interval_us);
- }
- write(conn,"\n",1);
- }
- else
- {
- D_check_mem(conn,0);
- }
- break;
- default:
- write(conn,unknown_cmd,strlen(unknown_cmd));
- break;
- }
- memset(cmd_buff,0,sizeof(cmd_buff));
- write(conn,shell,strlen(shell));
- }
- close(conn);
- }
- return NULL;
-}
-#endif //end of DICTATOR_DEBUG
-
diff --git a/src/support/dictator2/src/dummy_hash.h b/src/support/dictator2/src/dummy_hash.h deleted file mode 100644 index 02dd580..0000000 --- a/src/support/dictator2/src/dummy_hash.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef _DUMMY_HTABLE_H_
-#define _DUMMY_HTABLE_H_
-#include <string.h>//using memset
-#define DUMMY_HASH_SIZE 2048
-#define DUMMY_COLLISION_SIZE 2048
-struct dummy_pair_t
-{
- long key;
- long value;
-};
-struct dummy_htable_t
-{
- struct dummy_pair_t array[DUMMY_HASH_SIZE+DUMMY_COLLISION_SIZE];
- long collision_cnt;
-};
-inline void dummy_htable_init(struct dummy_htable_t* table)
-{
- memset(table,0,sizeof(struct dummy_htable_t));
- return;
-}
-inline long dummy_htable_read(struct dummy_htable_t* table,long key,long *value)
-{
- int i=0;
- int idx=key%DUMMY_HASH_SIZE;
- if(table->array[idx].key==key)
- {
- *value=table->array[idx].value;
- return 1;
- }
- else if(table->array[idx].key==0)
- {
- return 0;
- }
- else
- {
- for(i=DUMMY_HASH_SIZE;i<DUMMY_HASH_SIZE+table->collision_cnt;i++)
- {
- if(table->array[i].key==key)
- {
- *value=table->array[i].value;
- return 1;
- }
- }
- return 0;
- }
-}
-inline int dummy_htable_add(struct dummy_htable_t* table,long key,long value)
-{
- int idx=key%DUMMY_HASH_SIZE;
- long previous_key=0,previous_value=0;
- assert(key!=0);
- previous_key=__sync_lock_test_and_set(&(table->array[idx].key),key);
- if(previous_key==0)
- {
- return 0;
- }
- previous_value=table->array[idx].value;
- table->array[idx].value=value;
-
- assert(table->collision_cnt<DUMMY_COLLISION_SIZE);
- idx=DUMMY_HASH_SIZE+__sync_fetch_and_add(&(table->collision_cnt),1);
- previous_key=__sync_fetch_and_add(&(table->array[idx].key),previous_key);
- table->array[idx].value=previous_value;
- assert(previous_key==0);
- return idx;
-}
-#endif
diff --git a/src/support/dictator2/src/internal_mp.h b/src/support/dictator2/src/internal_mp.h deleted file mode 100644 index 40796cd..0000000 --- a/src/support/dictator2/src/internal_mp.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef __INTERNAL_MEM_POOL_H_INCLUDE_
-#define __INTERNAL_MEM_POOL_H_INCLUDE_
-typedef struct
-{
-}IMP_t;
-void* mmap_alloc(size_t size);
-void mmap_free(void*p);
-void* block_alloc(size_t size,IMP_t *imp);
-void block_free(void*p,IMP_t* imp);
-#endif //end of __INTERNAL_MEM_POOL_H_INCLUDE_
-
diff --git a/src/support/dictator2/src/mr_hugepage.h b/src/support/dictator2/src/mr_hugepage.h deleted file mode 100644 index d853e86..0000000 --- a/src/support/dictator2/src/mr_hugepage.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -/* 申请大页内存函数 - * @note: 不要在数据面频繁使用!! - */ -int marsio_is_hugepage_available(void); -void * marsio_hugepage_malloc(size_t size, int seq); -void * marsio_hugepage_calloc(size_t num, size_t size, int seq); -void * marsio_hugepage_realloc(void * ptr, size_t size); - -/* 释放大页内存函数 */ -void marsio_hugepage_free(void * mem); - -#ifdef __cplusplus -} -#endif
\ No newline at end of file diff --git a/src/support/dictator2/test/Makefile b/src/support/dictator2/test/Makefile deleted file mode 100644 index 682b906..0000000 --- a/src/support/dictator2/test/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -all:
- g++ -o test -g -Wall test.cpp ../lib/libdictator_debug.a -lpthread
-clean:
- rm test -f
diff --git a/src/support/dictator2/test/test.cpp b/src/support/dictator2/test/test.cpp deleted file mode 100644 index 504dcb0..0000000 --- a/src/support/dictator2/test/test.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include <pthread.h>
-#if 0 // for EAL check, Delete code temporary
-#define TEST_CNT (8)
-#define TEST_THREAD (4)
-struct test_case_t
-{
- void *mem;
- unsigned int size;
-};
-unsigned int g_used_mem_size=0;
-
-void mem_test(void*)
-{
- struct test_case_t test_array[TEST_CNT];
- int i=0;
- for(i=1;i<TEST_CNT;i++)
- {
- test_array[i].size=i*64;
- test_array[i].mem=malloc(test_array[i].size);
- g_used_mem_size+=test_array[i].size;
- }
- sleep(10);
- for(i=1;i<TEST_CNT;i++)
- {
- switch(i%10)
- {
- case 5:
- g_used_mem_size-=test_array[i].size;
- test_array[i].size+=1500;
- test_array[i].mem=realloc(test_array[i].mem,test_array[i].size);
- g_used_mem_size+=test_array[i].size;
- break;
- case 2:
- free(test_array[i].mem);
- g_used_mem_size-=test_array[i].size;
- test_array[i].size=0;
- test_array[i].mem=NULL;
- break;
- default:
- break;
- }
- }
-
- for(i=1;i<TEST_CNT;i++){
- free(test_array[i].mem);
- }
-}
-int main(int argc,char* argv[])
-{
- pthread_t thread_desc[TEST_THREAD];
- pthread_attr_t attr;
- int i=0;
- memset(&thread_desc, 0, sizeof(thread_desc));
- memset(&attr, 0, sizeof(attr));
-
- if(0 != pthread_attr_init(&(attr)))
- {
- fprintf(stderr,"pthread_attr_init(): %d %s", errno, strerror(errno));
- return -1;
- }
- if(0 != pthread_attr_setdetachstate(&(attr), PTHREAD_CREATE_DETACHED))
- {
- fprintf(stderr,"pthread_attr_setdetachstate(): %d %s", errno, strerror(errno));
- return -1 ;
- }
- for(i=0;i<TEST_THREAD;i++)
- {
- if(0 != pthread_create(&(thread_desc[i]), &(attr), (void *(*)(void *))(mem_test), NULL))
- {
- fprintf(stderr,"pthread_create(): %d %s", errno, strerror(errno));
- pthread_attr_destroy(&(attr));
- return -1;
- }
- }
- sleep(5);
- return 0;
-}
-#else
-int main(int argc,char* argv[])
-{
- return 0;
-}
-
-#endif
-
diff --git a/src/support/md5/Makefile b/src/support/md5/Makefile deleted file mode 100644 index 6dac19a..0000000 --- a/src/support/md5/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -all:libmd5.a
-CFLAGS = -D__FAVOR_BSD=1 -D__USE_BSD=1 -D_GNU_SOURCE=1 -fPIC
-
-libmd5.a:md5.o
- ar -cr $@ $^
- cp $@ ../../lib
-
-md5.o:md5.c
- gcc -c -o $@ $(CFLAGS) $^
-
-clean:
- rm -f *.o libmd5.a
-
diff --git a/src/support/symbol_check/Makefile b/src/support/symbol_check/Makefile deleted file mode 100644 index 57a5540..0000000 --- a/src/support/symbol_check/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -all:libsymbol_check.a
-
-INC=-I./
-INC+=-I/opt/MESA/include
-INC+=-I/opt/MESA/include/MESA
-INC+=-I../../../include/
-INC+=-I../../../include/public
-INC+=-I../../../include/private
-INC+=-I../../../include/support
-LIBS = -L/opt/MESA/lib
-CFLAGS = -D__FAVOR_BSD=1 -D__USE_BSD=1 -D_GNU_SOURCE=1 -fPIC
-
-test_symbol_check:test_symbol_check.c libsymbol_check.a
- gcc -o $@ $(INC) $^ -g -D_GNU_SOURCE=1 -ldl -lpthread -lMESA_htable
-
-libsymbol_check.a:libsymbol_check.o
- ar -cr $@ $^
- cp $@ ../../lib/
-
-libsymbol_check.o:libsymbol_check.cpp
- g++ -c $^ $(INC) $(CFLAGS) -ldl -g
-
-clean:
- rm -f test_symbol_check *.o *.a
diff --git a/src/support/timestamp_record/Makefile b/src/support/timestamp_record/Makefile deleted file mode 100644 index 1e80c4d..0000000 --- a/src/support/timestamp_record/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -all:libtimestamp_record.a
-
-INC = -I../../../include
-INC += -I../../../include/public
-INC += -I../../../include/private
-INC += -I../../../include/support
-INC += -I/opt/MESA/include
-INC += -I/opt/MESA/include/MESA
-
-libtimestamp_record.a:timestamp_record.o
- ar -cr $@ $^
- cp $@ ../../lib
-
-timestamp_record.o:timestamp_record.cpp
- g++ -c $(CFLAGS) -fPIC $(INC) -o $@ $^
-
-clean:
- rm -f *.o libtimestamp_record.a
-
diff --git a/src/support/tomlc99_wrap/Makefile b/src/support/tomlc99_wrap/Makefile deleted file mode 100644 index f754bb4..0000000 --- a/src/support/tomlc99_wrap/Makefile +++ /dev/null @@ -1,49 +0,0 @@ -CC = gcc -CCC = g++ -CFILES = toml.c - -CFLAGS = -D_GNU_SOURCE -D_DEFAULT_SOURCE -std=c99 -Wall -Wextra -fPIC -# to compile for debug: make DEBUG=1 -# to compile for no debug: make -CFLAGS += -O0 -g - -EXEC = test_toml - -LIB = libtoml.a libtomlc99_wrap.so libtomlc99_wrap.a -LIB_PATH = -L/opt/MESA/lib - -#all: $(LIB) $(EXEC) -all: $(LIB) - -libtoml.a: toml.o - ar -rcs $@ $^; - -toml_json: toml_json.c $(LIB) - -toml_cat: toml_cat.c $(LIB) - -test_toml: test_toml.c - gcc -o $@ $(LIB_PATH) -ltomlc99_wrap $^ - -libtomlc99_wrap.so:tomlc99_wrap.o toml.o - gcc -o $@ -shared -fPIC $^; cp tomlc99_wrap.h ../../../include/support/; - -libtomlc99_wrap.a:tomlc99_wrap.o toml.o - ar -rcs $@ $^; cp tomlc99_wrap.h ../../../include/support/; cp $@ ../../lib/ - -.c.o: - $(CC) -c $(CFLAGS) -I. $< - -.cpp.o: - $(CCC) -c $(CFLAGS) -I. $< - - -prefix ?= /usr/local - -install: all - install -d ${prefix}/include ${prefix}/lib - install toml.h ${prefix}/include - install libtoml.a ${prefix}/lib - -clean: - rm -f *.o $(EXEC) $(LIB) |
