diff options
author | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2011-09-23 20:03:38 +0200 |
---|---|---|
committer | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2011-09-23 20:03:38 +0200 |
commit | 0eaf6ec6b762018db31f7626bbc6e2cdfc374c5c (patch) | |
tree | b422bd734daedbd2e5fbd9b17f53dbc86d144c6c | |
parent | 92e89722f952c156254ff752d75edfdb26474ff6 (diff) | |
parent | 7d6dab10064a6fc0c1902f8a747afb5ae0290eb6 (diff) | |
download | DLT-daemon-0eaf6ec6b762018db31f7626bbc6e2cdfc374c5c.tar.gz |
Merge branch 'develop_performance' into develop
Conflicts:
include/dlt/dlt_version.h
src/daemon/dlt-daemon.c
-rwxr-xr-x | include/dlt/CMakeLists.txt | 2 | ||||
-rwxr-xr-x | include/dlt/dlt_user.h | 3 | ||||
-rwxr-xr-x | src/daemon/CMakeLists.txt | 2 | ||||
-rwxr-xr-x | src/daemon/dlt-daemon.c | 297 | ||||
-rwxr-xr-x | src/daemon/dlt-daemon.h | 1 | ||||
-rwxr-xr-x | src/lib/CMakeLists.txt | 2 | ||||
-rwxr-xr-x | src/lib/dlt_user.c | 36 | ||||
-rwxr-xr-x | src/lib/dlt_user_cfg.h | 3 | ||||
-rwxr-xr-x | src/tests/dlt-test-stress.c | 9 |
9 files changed, 201 insertions, 154 deletions
diff --git a/include/dlt/CMakeLists.txt b/include/dlt/CMakeLists.txt index 6ddcfad..95b9929 100755 --- a/include/dlt/CMakeLists.txt +++ b/include/dlt/CMakeLists.txt @@ -35,6 +35,6 @@ # @licence end@ ######## -install(FILES dlt.h dlt_user.h dlt_user_macros.h dlt_client.h dlt_protocol.h dlt_common.h dlt_types.h dlt_version.h +install(FILES dlt.h dlt_user.h dlt_user_macros.h dlt_client.h dlt_protocol.h dlt_common.h dlt_types.h dlt_version.h dlt_shm.h DESTINATION include/dlt COMPONENT devel) diff --git a/include/dlt/dlt_user.h b/include/dlt/dlt_user.h index 263a5f2..095bd45 100755 --- a/include/dlt/dlt_user.h +++ b/include/dlt/dlt_user.h @@ -91,6 +91,7 @@ #include "dlt_types.h" #include "dlt_common.h" #include "dlt_user_macros.h" +#include "dlt_shm.h" #if !defined (__WIN32__) #include <semaphore.h> @@ -226,6 +227,8 @@ typedef struct int8_t local_print_mode; /**< Local print mode, controlled by environment variable */ DltRingBuffer rbuf; /**< Ring-buffer for buffering messages during startup and missing connection */ + + DltShm dlt_shm; } DltUser; /************************************************************************************************** diff --git a/src/daemon/CMakeLists.txt b/src/daemon/CMakeLists.txt index c9f0162..5c3c25e 100755 --- a/src/daemon/CMakeLists.txt +++ b/src/daemon/CMakeLists.txt @@ -35,7 +35,7 @@ # @licence end@ ######## -set(dlt_daemon_SRCS dlt-daemon dlt_daemon_common ${CMAKE_SOURCE_DIR}/src/shared/dlt_user_shared.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_common.c) +set(dlt_daemon_SRCS dlt-daemon dlt_daemon_common ${CMAKE_SOURCE_DIR}/src/shared/dlt_user_shared.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_common.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_shm.c) add_executable(dlt-daemon ${dlt_daemon_SRCS}) IF(GPROF_DLT_DAEMON) SET(CMAKE_C_FLAGS "-pg") diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c index 41ef12b..831506c 100755 --- a/src/daemon/dlt-daemon.c +++ b/src/daemon/dlt-daemon.c @@ -677,6 +677,13 @@ int dlt_daemon_local_init_p2(DltDaemon *daemon, DltDaemonLocal *daemon_local, in sprintf(str,"Ringbuffer size: %d bytes\n",daemon_local->ringbufferSize); dlt_log(LOG_NOTICE, str); + /* init shared memory */ + if (dlt_shm_init_server(&(daemon_local->dlt_shm),DLT_SHM_KEY,DLT_SHM_SIZE)==-1) + { + dlt_log(LOG_ERR,"Could not initialize shared memory\n"); + return -1; + } + /* prepare main loop */ if (dlt_message_init(&(daemon_local->msg),daemon_local->flags.vflag)==-1) { @@ -918,6 +925,9 @@ void dlt_daemon_local_cleanup(DltDaemon *daemon, DltDaemonLocal *daemon_local, i /* Try to delete existing pipe, ignore result of unlink() */ unlink(DLT_USER_FIFO); + /* free shared memory */ + dlt_shm_free_server(&(daemon_local->dlt_shm)); + /* Try to delete lock file, ignore result of unlink() */ unlink(DLT_DAEMON_LOCK_FILE); } @@ -1752,6 +1762,8 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemo int bytes_to_be_removed; int j,sent,third_value; ssize_t ret; + char rcv_buffer[10000]; + int size; static char text[DLT_DAEMON_TEXTSIZE]; @@ -1763,169 +1775,180 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemo return -1; } - if (dlt_message_read(&(daemon_local->msg),(unsigned char*)daemon_local->receiver.buf+sizeof(DltUserHeader),daemon_local->receiver.bytesRcvd-sizeof(DltUserHeader),0,verbose)==0) + //dlt_shm_status(&(daemon_local->dlt_shm)); + while ( (size = dlt_shm_pull(&(daemon_local->dlt_shm),rcv_buffer,10000)) > 0) { - /* set overwrite ecu id */ - if (daemon_local->flags.evalue[0]) - { - /* Set header extra parameters */ - dlt_set_id(daemon_local->msg.headerextra.ecu, daemon->ecuid ); - //msg.headerextra.seid = 0; - if (dlt_message_set_extraparameters(&(daemon_local->msg),0)==-1) - { - dlt_log(LOG_ERR,"Can't set message extra parameters in process user message log\n"); - return -1; - } - - /* Correct value of timestamp, this was changed by dlt_message_set_extraparameters() */ - daemon_local->msg.headerextra.tmsp = DLT_BETOH_32(daemon_local->msg.headerextra.tmsp); - } + if (dlt_message_read(&(daemon_local->msg),rcv_buffer,size,0,verbose)==0) + { + /* set overwrite ecu id */ + if (daemon_local->flags.evalue!=0) + { + /* Set header extra parameters */ + dlt_set_id(daemon_local->msg.headerextra.ecu, daemon->ecuid ); + //msg.headerextra.seid = 0; + if (dlt_message_set_extraparameters(&(daemon_local->msg),0)==-1) + { + dlt_log(LOG_ERR,"Can't set message extra parameters in process user message log\n"); + return -1; + } - /* prepare storage header */ - if (DLT_IS_HTYP_WEID(daemon_local->msg.standardheader->htyp)) - { - if (dlt_set_storageheader(daemon_local->msg.storageheader,daemon_local->msg.headerextra.ecu)==-1) - { - dlt_log(LOG_ERR,"Can't set storage header in process user message log\n"); - return -1; - } - } - else - { - if (dlt_set_storageheader(daemon_local->msg.storageheader,daemon->ecuid)==-1) - { - dlt_log(LOG_ERR,"Can't set storage header in process user message log\n"); - return -1; - } - } + /* Correct value of timestamp, this was changed by dlt_message_set_extraparameters() */ + daemon_local->msg.headerextra.tmsp = DLT_BETOH_32(daemon_local->msg.headerextra.tmsp); + } - if ((daemon_local->flags.fvalue[0]==0) || - (daemon_local->flags.fvalue[0] && (dlt_message_filter_check(&(daemon_local->msg),&(daemon_local->filter),verbose)==1))) - { - /* if no filter set or filter is matching display message */ - if (daemon_local->flags.xflag) - { - if (dlt_message_print_hex(&(daemon_local->msg),text,DLT_DAEMON_TEXTSIZE,verbose)==-1) + /* prepare storage header */ + if (DLT_IS_HTYP_WEID(daemon_local->msg.standardheader->htyp)) + { + if (dlt_set_storageheader(daemon_local->msg.storageheader,daemon_local->msg.headerextra.ecu)==-1) { - dlt_log(LOG_ERR,"dlt_message_print_hex() failed!\n"); + dlt_log(LOG_ERR,"Can't set storage header in process user message log\n"); + return -1; } - } /* if */ - else if (daemon_local->flags.aflag) - { - if (dlt_message_print_ascii(&(daemon_local->msg),text,DLT_DAEMON_TEXTSIZE,verbose)==-1) - { - dlt_log(LOG_ERR,"dlt_message_print_ascii() failed!\n"); - } - } /* if */ - else if (daemon_local->flags.sflag) - { - if (dlt_message_print_header(&(daemon_local->msg),text,DLT_DAEMON_TEXTSIZE,verbose)==-1) + } + else + { + if (dlt_set_storageheader(daemon_local->msg.storageheader,daemon->ecuid)==-1) { - dlt_log(LOG_ERR,"dlt_message_print_header() failed!\n"); + dlt_log(LOG_ERR,"Can't set storage header in process user message log\n"); + return -1; } - /* print message header only */ - } /* if */ + } - /* if file output enabled write message */ - if (daemon_local->flags.ovalue[0]) - { - /* write message to output buffer */ - if (dlt_user_log_out2(daemon_local->ohandle, - daemon_local->msg.headerbuffer, - daemon_local->msg.headersize, - daemon_local->msg.databuffer, - daemon_local->msg.datasize) !=DLT_RETURN_OK) - { - dlt_log(LOG_ERR,"Writing to output file failed!\n"); - } - } /* if */ + if ((daemon_local->flags.fvalue==0) || + (daemon_local->flags.fvalue && (dlt_message_filter_check(&(daemon_local->msg),&(daemon_local->filter),verbose)==1))) + { + /* if no filter set or filter is matching display message */ + if (daemon_local->flags.xflag) + { + if (dlt_message_print_hex(&(daemon_local->msg),text,DLT_DAEMON_TEXTSIZE,verbose)==-1) + { + dlt_log(LOG_ERR,"dlt_message_print_hex() failed!\n"); + } + } /* if */ + else if (daemon_local->flags.aflag) + { + if (dlt_message_print_ascii(&(daemon_local->msg),text,DLT_DAEMON_TEXTSIZE,verbose)==-1) + { + dlt_log(LOG_ERR,"dlt_message_print_ascii() failed!\n"); + } + } /* if */ + else if (daemon_local->flags.sflag) + { + if (dlt_message_print_header(&(daemon_local->msg),text,DLT_DAEMON_TEXTSIZE,verbose)==-1) + { + dlt_log(LOG_ERR,"dlt_message_print_header() failed!\n"); + } + /* print message header only */ + } /* if */ + + /* if file output enabled write message */ + if (daemon_local->flags.ovalue) + { + /* write message to output buffer */ + if (dlt_user_log_out2(daemon_local->ohandle, + daemon_local->msg.headerbuffer, + daemon_local->msg.headersize, + daemon_local->msg.databuffer, + daemon_local->msg.datasize) !=DLT_RETURN_OK) + { + dlt_log(LOG_ERR,"Writing to output file failed!\n"); + } + } /* if */ - sent=0; + sent=0; - /* look if TCP connection to client is available */ - for (j = 0; j <= daemon_local->fdmax; j++) - { - /* send to everyone! */ - if (FD_ISSET(j, &(daemon_local->master))) - { - /* except the listener and ourselves */ - if (daemon_local->flags.yvalue[0]) - { - third_value = daemon_local->fdserial; - } - else - { - third_value = daemon_local->sock; - } + /* look if TCP connection to client is available */ + for (j = 0; j <= daemon_local->fdmax; j++) + { + /* send to everyone! */ + if (FD_ISSET(j, &(daemon_local->master))) + { + /* except the listener and ourselves */ + if (daemon_local->flags.yvalue!=0) + { + third_value = daemon_local->fdserial; + } + else + { + third_value = daemon_local->sock; + } - if ((j != daemon_local->fp) && (j != daemon_local->sock) && (j != third_value)) - { - DLT_DAEMON_SEM_LOCK(); + if ((j != daemon_local->fp) && (j != daemon_local->sock) && (j != third_value)) + { + DLT_DAEMON_SEM_LOCK(); - if (daemon_local->flags.lflag) - { - send(j,dltSerialHeader,sizeof(dltSerialHeader),0); - } + if (daemon_local->flags.lflag) + { + send(j,dltSerialHeader,sizeof(dltSerialHeader),0); + } - send(j,daemon_local->msg.headerbuffer+sizeof(DltStorageHeader),daemon_local->msg.headersize-sizeof(DltStorageHeader),0); - send(j,daemon_local->msg.databuffer,daemon_local->msg.datasize,0); + send(j,daemon_local->msg.headerbuffer+sizeof(DltStorageHeader),daemon_local->msg.headersize-sizeof(DltStorageHeader),0); + send(j,daemon_local->msg.databuffer,daemon_local->msg.datasize,0); - DLT_DAEMON_SEM_FREE(); + DLT_DAEMON_SEM_FREE(); - sent=1; - } /* if */ - else if ((j == daemon_local->fdserial) && (daemon_local->flags.yvalue[0])) - { - DLT_DAEMON_SEM_LOCK(); + sent=1; + } /* if */ + else if ((j == daemon_local->fdserial) && (daemon_local->flags.yvalue!=0)) + { + DLT_DAEMON_SEM_LOCK(); - if (daemon_local->flags.lflag) - { - ret=write(j,dltSerialHeader,sizeof(dltSerialHeader)); - } + if (daemon_local->flags.lflag) + { + ret=write(j,dltSerialHeader,sizeof(dltSerialHeader)); + } - ret=write(j,daemon_local->msg.headerbuffer+sizeof(DltStorageHeader),daemon_local->msg.headersize-sizeof(DltStorageHeader)); - ret=write(j,daemon_local->msg.databuffer,daemon_local->msg.datasize); + ret=write(j,daemon_local->msg.headerbuffer+sizeof(DltStorageHeader),daemon_local->msg.headersize-sizeof(DltStorageHeader)); + ret=write(j,daemon_local->msg.databuffer,daemon_local->msg.datasize); - DLT_DAEMON_SEM_FREE(); + DLT_DAEMON_SEM_FREE(); - sent=1; - } - } /* if */ - } /* for */ + sent=1; + } + } /* if */ + } /* for */ - /* Message was not sent to client, so store it in client ringbuffer */ - if (sent==0) - { - if (dlt_ringbuffer_put3(&(daemon->client_ringbuffer), - daemon_local->msg.headerbuffer+sizeof(DltStorageHeader),daemon_local->msg.headersize-sizeof(DltStorageHeader), - daemon_local->msg.databuffer,daemon_local->msg.datasize, - 0, 0 - )<0) + /* Message was not sent to client, so store it in client ringbuffer */ + if (sent==0) { - dlt_log(LOG_ERR,"Storage of message in history buffer failed! Message discarded.\n"); + if (dlt_ringbuffer_put3(&(daemon->client_ringbuffer), + daemon_local->msg.headerbuffer+sizeof(DltStorageHeader),daemon_local->msg.headersize-sizeof(DltStorageHeader), + daemon_local->msg.databuffer,daemon_local->msg.datasize, + 0, 0 + )<0) + { + dlt_log(LOG_ERR,"Storage of message in history buffer failed! Message discarded.\n"); + } } - } - } - /* keep not read data in buffer */ - bytes_to_be_removed = daemon_local->msg.headersize+daemon_local->msg.datasize-sizeof(DltStorageHeader)+sizeof(DltUserHeader); - if (daemon_local->msg.found_serialheader) - { - bytes_to_be_removed += sizeof(dltSerialHeader); - } + } + /* keep not read data in buffer */ + /*bytes_to_be_removed = daemon_local->msg.headersize+daemon_local->msg.datasize-sizeof(DltStorageHeader)+sizeof(DltUserHeader); + if (daemon_local->msg.found_serialheader) + { + bytes_to_be_removed += sizeof(dltSerialHeader); + } - if (dlt_receiver_remove(&(daemon_local->receiver),bytes_to_be_removed)==-1) - { - dlt_log(LOG_ERR,"Can't remove bytes from receiver\n"); - return -1; - } - } - else + if (dlt_receiver_remove(&(daemon_local->receiver),bytes_to_be_removed)==-1) + { + dlt_log(LOG_ERR,"Can't remove bytes from receiver\n"); + return -1; + }*/ + } + else + { + dlt_log(LOG_ERR,"Can't read messages from receiver\n"); + return -1; + } + } + + /* keep not read data in buffer */ + if (dlt_receiver_remove(&(daemon_local->receiver),sizeof(DltUserHeader))==-1) { - dlt_log(LOG_ERR,"Can't read messages from receiver\n"); - return -1; + dlt_log(LOG_ERR,"Can't remove bytes from receiver for user message overflow\n"); + return -1; } - + return 0; } diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h index 97357e1..2c8e1ca 100755 --- a/src/daemon/dlt-daemon.h +++ b/src/daemon/dlt-daemon.h @@ -130,6 +130,7 @@ typedef struct int client_connections; /**< counter for nr. of client connections */
size_t baudrate; /**< Baudrate of serial connection */
size_t ringbufferSize; /**< Size of the ringbuffer */
+ DltShm dlt_shm;
} DltDaemonLocal;
typedef struct
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 8e81cfb..1d33d21 100755 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -35,7 +35,7 @@ # @licence end@ ######## -set(dlt_LIB_SRCS dlt_user dlt_client ${CMAKE_SOURCE_DIR}/src/shared/dlt_common.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_user_shared.c ) +set(dlt_LIB_SRCS dlt_user dlt_client ${CMAKE_SOURCE_DIR}/src/shared/dlt_common.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_user_shared.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_shm.c) add_library(dlt ${dlt_LIB_SRCS}) diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c index 0764efc..ebba325 100755 --- a/src/lib/dlt_user.c +++ b/src/lib/dlt_user.c @@ -159,9 +159,17 @@ int dlt_init(void) dlt_user.dlt_is_file = 0; dlt_user.overflow = 0; + /* init shared memory */ + if (dlt_shm_init_client(&dlt_user.dlt_shm,DLT_SHM_KEY,DLT_SHM_SIZE) < 0) + { + sprintf(str,"Loging disabled, Shared memory %d cannot be created!\n",DLT_SHM_KEY); + dlt_log(LOG_WARNING, str); + return 0; + } + /* create and open DLT user FIFO */ sprintf(filename,"%s/dlt%d",DLT_USER_DIR,getpid()); - + /* Try to delete existing pipe, ignore result of unlink */ unlink(filename); @@ -197,12 +205,18 @@ int dlt_init(void) return -1; } - /* Initialize thread */ + /* Set default thread stack size */ if (pthread_attr_init(&dlt_receiverthread_attr)<0) { - dlt_log(LOG_WARNING, "Initialization of thread failed!\n"); - return -1; - } + dlt_log(LOG_WARNING, "Initialization of default thread stack size failed!\n"); + } + else + { + if (pthread_attr_setstacksize(&dlt_receiverthread_attr,DLT_USER_RECEIVERTHREAD_STACKSIZE)<0) + { + dlt_log(LOG_WARNING, "Setting of default thread stack size failed!\n"); + } + } /* Start receiver thread */ if (pthread_create(&(dlt_receiverthread_handle), @@ -352,6 +366,9 @@ int dlt_free(void) unlink(filename); } + /* free shared memory */ + dlt_shm_free_client(&dlt_user.dlt_shm); + if (dlt_user.dlt_log_handle!=-1) { /* close log file/output fifo to daemon */ @@ -2151,12 +2168,15 @@ int dlt_user_log_send_log(DltContextData *log, int mtype) } } + dlt_shm_push(&dlt_user.dlt_shm,msg.headerbuffer+sizeof(DltStorageHeader), msg.headersize-sizeof(DltStorageHeader), + log->buffer, log->size,0,0); + /* log to FIFO */ ret = dlt_user_log_out3(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), - msg.headerbuffer+sizeof(DltStorageHeader), msg.headersize-sizeof(DltStorageHeader), - log->buffer, log->size); - + 0, 0, + 0, 0); + /* store message in ringbuffer, if an error has occured */ if (ret!=DLT_RETURN_OK) { diff --git a/src/lib/dlt_user_cfg.h b/src/lib/dlt_user_cfg.h index 31af24d..5b1e71e 100755 --- a/src/lib/dlt_user_cfg.h +++ b/src/lib/dlt_user_cfg.h @@ -106,6 +106,9 @@ /* Length of buffer for constructing text output */
#define DLT_USER_TEXT_LENGTH 10024
+/* Stack size of receiver thread */
+#define DLT_USER_RECEIVERTHREAD_STACKSIZE 100000
+
/* default value for storage to file, not used in daemon connection */
#define DLT_USER_DEFAULT_ECU_ID "ECU1"
diff --git a/src/tests/dlt-test-stress.c b/src/tests/dlt-test-stress.c index ea17857..07b3ae9 100755 --- a/src/tests/dlt-test-stress.c +++ b/src/tests/dlt-test-stress.c @@ -98,7 +98,7 @@ typedef struct } thread_data_t; #define STRESS1_NUM_CONTEXTS 3000 -#define STRESS2_MAX_NUM_THREADS 256 +#define STRESS2_MAX_NUM_THREADS 64 #define STRESS3_MAX_NUM_MESSAGES 512 #define MAX_TESTS 3 @@ -319,10 +319,7 @@ void stress2(void) for (index=0;index<STRESS2_MAX_NUM_THREADS;index++) { - if (thread[index]!=0) - { - pthread_join(thread[index], NULL); - } + pthread_join(thread[index], NULL); } printf("Finished stress test2 \n\n"); @@ -366,7 +363,7 @@ void stress3(void) { buffer[num] = num; DLT_LOG(context_stress3,DLT_LOG_INFO,DLT_INT(num),DLT_RAW(buffer,num)); - usleep(1); + usleep(10000); } printf("Finished stress test3 \n\n"); |