diff options
author | Juergen Haug | 2020-06-24 11:44:15 +0000 |
---|---|---|
committer | Juergen Haug | 2020-06-29 15:21:12 +0000 |
commit | a60d1b57abcc8aec9e604592794db3990478f411 (patch) | |
tree | 3ef295beb4effa342692c8083f2d61d236f13198 /runtime/org.eclipse.etrice.runtime.c/src/common | |
parent | 5e86a092f843fa16f901704e61941ddc8ba00373 (diff) | |
download | org.eclipse.etrice-a60d1b57abcc8aec9e604592794db3990478f411.tar.gz org.eclipse.etrice-a60d1b57abcc8aec9e604592794db3990478f411.tar.xz org.eclipse.etrice-a60d1b57abcc8aec9e604592794db3990478f411.zip |
[runtime.c] changes for runtime
Change-Id: I27386222ba9db6452d51c7deaf673271d8dbc182
Diffstat (limited to 'runtime/org.eclipse.etrice.runtime.c/src/common')
11 files changed, 253 insertions, 114 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueue.c b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueue.c index 43df6a908..d554ca3a8 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueue.c +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueue.c @@ -20,7 +20,6 @@ void etQueue_init(etQueue* self){ self->first = NULL; self->last = NULL; - self->highWaterMark = 0; self->size = 0; ET_MSC_LOGGER_SYNC_EXIT @@ -40,9 +39,7 @@ void etQueue_push(etQueue* self, etQueueObj* obj){ self->last = obj; } obj->next = NULL; /*TODO: optimization: this line could be removed if we assume that all objects are initialized*/ - - if (++self->size > self->highWaterMark) - self->highWaterMark++; + self->size++; ET_MSC_LOGGER_SYNC_EXIT } @@ -97,8 +94,3 @@ etBool etQueue_isNotEmpty(etQueue* self){ return self->last != NULL; } -etInt16 etQueue_getHighWaterMark(etQueue* self) { - ET_MSC_LOGGER_SYNC_ENTRY("etQueue", "getHightWaterMark") - ET_MSC_LOGGER_SYNC_EXIT - return self->highWaterMark; -} diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueue.h b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueue.h index 89109c64a..f50ba26c8 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueue.h +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueue.h @@ -27,9 +27,7 @@ typedef struct etQueueObj { typedef struct etQueue { etQueueObj* first; etQueueObj* last; - etInt16 highWaterMark; etInt16 size; - } etQueue; void etQueue_init(etQueue* self); @@ -44,8 +42,6 @@ etQueueObj* etQueue_getLast(etQueue* self); etBool etQueue_isNotEmpty(etQueue* self); -etInt16 etQueue_getHighWaterMark(etQueue* self); - etInt16 etQueue_getSize(etQueue* self); ET_EXTERN_C_END diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueue2.c b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueue2.c new file mode 100644 index 000000000..53eb17ee2 --- /dev/null +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueue2.c @@ -0,0 +1,102 @@ +/******************************************************************************* + * Copyright (c) 2011 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * CONTRIBUTORS: + * Thomas Schuetz (initial contribution) + * Juergen Haug + * + *******************************************************************************/ + +#include "base/etQueue2.h" + +#define DO_LOCK \ + if (self->lock!=NULL) { \ + self->lock->lockFct(self->lock->lockData); \ + } + +#define DO_UNLOCK \ + if (self->lock!=NULL) { \ + self->lock->unlockFct(self->lock->lockData); \ + } + +void etQueue2_init(etQueue2* self){ + etQueue_init(&self->queue); + self->lock = NULL; + etQueueStatistics_init(&self->statistics); +} + +void etQueue2_setLock(etQueue2* self, etLock* lock) { + self->lock = lock; +} + +void etQueue2_push(etQueue2* self, etQueueObj* obj) { + DO_LOCK + + etQueue_push(&self->queue, obj); + if(self->queue.size > self->statistics.highWaterMark) { + self->statistics.highWaterMark = self->queue.size; + } + + DO_UNLOCK +} + +etQueueObj* etQueue2_pop(etQueue2* self) { + DO_LOCK + + etQueueObj* pop_msg = etQueue_pop(&self->queue); + if (self->queue.size < self->statistics.lowWaterMark) { + self->statistics.lowWaterMark = self->queue.size; + } + + DO_UNLOCK + return pop_msg; +} + +etInt16 etQueue2_getSize(etQueue2* self) { + DO_LOCK + etInt16 size = self->queue.size; + DO_UNLOCK + + return size; +} + +etQueueObj* etQueue2_getFirst(etQueue2* self) { + DO_LOCK + etQueueObj* obj = self->queue.first; + DO_UNLOCK + + return obj; +} + +etQueueObj* etQueue2_getLast(etQueue2* self) { + DO_LOCK + etQueueObj* obj = self->queue.last; + DO_UNLOCK + + return obj; +} + +etBool etQueue2_isNotEmpty(etQueue2* self) { + DO_LOCK + etBool notEmpty = self->queue.last != NULL; + DO_UNLOCK + + return notEmpty; +} + +const etQueueStatistics* etQueue2_getStatistics(etQueue2* self) { + return &self->statistics; +} + +void etQueue2_resetStatistics(etQueue2* self) { + DO_LOCK + etQueueStatistics_reset(&self->statistics, self->queue.size); + DO_UNLOCK +} + diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueue2.h b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueue2.h new file mode 100644 index 000000000..77884e3a6 --- /dev/null +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueue2.h @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2011 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * CONTRIBUTORS: + * Thomas Schuetz (initial contribution) + * Juergen Haug + * + *******************************************************************************/ + +#ifndef COMMON_BASE_ETQUEUE2_H_ +#define COMMON_BASE_ETQUEUE2_H_ + +#include "base/etQueue.h" +#include "osal/etLock.h" +#include "base/etQueueStatistics.h" + +ET_EXTERN_C_BEGIN + +/** + * etQueue with locking and statistics + */ +typedef struct etQueue2 { + etQueue queue; + etLock* lock; + etQueueStatistics statistics; +} etQueue2; + +void etQueue2_init(etQueue2* self); + +void etQueue2_setLock(etQueue2* self, etLock* lock); + +void etQueue2_push(etQueue2* self, etQueueObj* obj); + +etQueueObj* etQueue2_pop(etQueue2* self); + +etQueueObj* etQueue2_getFirst(etQueue2* self); + +etQueueObj* etQueue2_getLast(etQueue2* self); + +etBool etQueue2_isNotEmpty(etQueue2* self); + +etInt16 etQueue2_getSize(etQueue2* self); + +const etQueueStatistics* etQueue2_getStatistics(etQueue2* self); + +void etQueue2_resetStatistics(etQueue2* self); + + +ET_EXTERN_C_END + +#endif /* COMMON_BASE_ETQUEUE2_H_ */ diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueueStatistics.c b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueueStatistics.c new file mode 100644 index 000000000..2f3ce55cb --- /dev/null +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueueStatistics.c @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2011 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * CONTRIBUTORS: + * Henrik Rentz-Reichert (initial contribution) + * + *******************************************************************************/ + +#include "etQueueStatistics.h" + +void etQueueStatistics_init(etQueueStatistics* self) { + self->highWaterMark = 0; + self->lowWaterMark = 0; + self->nFailingRequests = 0; +} + +void etQueueStatistics_reset(etQueueStatistics* self, etInt16 lowWaterMark) { + self->highWaterMark = 0; + self->lowWaterMark = lowWaterMark; + self->nFailingRequests = 0; +} diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueueStatistics.h b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueueStatistics.h new file mode 100644 index 000000000..c27c93ed5 --- /dev/null +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueueStatistics.h @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2011 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * CONTRIBUTORS: + * Henrik Rentz-Reichert (initial contribution) + * + *******************************************************************************/ + +#ifndef COMMON_BASE_ETQUEUESTATISTICS_H_ +#define COMMON_BASE_ETQUEUESTATISTICS_H_ + +#include "etDatatypes.h" + +ET_EXTERN_C_BEGIN + +/** + * a data structure for the queue statistics + */ +typedef struct etQueueStatistics { + etInt16 highWaterMark; /**< high water mark */ + etInt16 lowWaterMark; /**< low water mark */ + etInt16 nFailingRequests; /**< queue would have exceeded maximum size */ +} +etQueueStatistics; + +void etQueueStatistics_init(etQueueStatistics* self); + +void etQueueStatistics_reset(etQueueStatistics* self, etInt16 lowWaterMark); + +ET_EXTERN_C_END + +#endif /* COMMON_BASE_ETQUEUESTATISTICS_H_ */ diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etMSCLogger.h b/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etMSCLogger.h index aa9d486bc..17ca024b6 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etMSCLogger.h +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etMSCLogger.h @@ -202,6 +202,14 @@ void etMSCLogger_addVisibleComment(const char* comment); * If \ref ET_MSC_LOGGER_ACTIVATE isn't defined this macro is void */ #define ET_MSC_LOGGER_CHANGE_STATE(objectName, stateName) + +/** + * calls \ref etMSCLogger_addVisibleComment(const char*) + * \par + * If \ref ET_MSC_LOGGER_ACTIVATE isn't defined this macro is void + */ +#define ET_MSC_LOGGER_VISIBLE_COMMENT(comment) + #endif ET_EXTERN_C_END diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.c b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.c index 88bb1f38c..fc0a7edb1 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.c +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.c @@ -20,8 +20,6 @@ void etMessageQueue_init(etMessageQueue* self){ ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "init") self->first = NULL; self->last = NULL; - self->statistics.highWaterMark = 0; - self->statistics.lowWaterMark = 0; self->size = 0; ET_MSC_LOGGER_SYNC_EXIT } @@ -40,9 +38,7 @@ void etMessageQueue_push(etMessageQueue* self, etMessage* msg){ self->last = msg; } msg->next = NULL; /*TODO: optimization: this line could be removed if we assume that all messages are initialized*/ - - if (++self->size > self->statistics.highWaterMark) - self->statistics.highWaterMark++; + self->size++; ET_MSC_LOGGER_SYNC_EXIT } @@ -67,9 +63,6 @@ etMessage* etMessageQueue_pop(etMessageQueue* self){ pop_msg->next=NULL; self->size--; - if (self->size < self->statistics.lowWaterMark) - self->statistics.lowWaterMark--; - ET_MSC_LOGGER_SYNC_EXIT return pop_msg; } @@ -98,32 +91,3 @@ etBool etMessageQueue_isNotEmpty(etMessageQueue* self){ return self->last != NULL; } -const etQueueStatistics* etMessageQueue_getStatistics(etMessageQueue* self) { - ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "getHighWaterMark") - ET_MSC_LOGGER_SYNC_EXIT - return &self->statistics; -} - -etInt16 etMessageQueue_getHighWaterMark(etMessageQueue* self) { - ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "getHighWaterMark") - ET_MSC_LOGGER_SYNC_EXIT - return self->statistics.highWaterMark; -} - -void etMessageQueue_resetHighWaterMark(etMessageQueue* self) { - ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "resetHighWaterMark") - self->statistics.highWaterMark = 0; - ET_MSC_LOGGER_SYNC_EXIT -} - -etInt16 etMessageQueue_getLowWaterMark(etMessageQueue* self) { - ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "getLowWaterMark") - ET_MSC_LOGGER_SYNC_EXIT - return self->statistics.lowWaterMark; -} - -void etMessageQueue_resetLowWaterMark(etMessageQueue* self) { - ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "resetLowWaterMark") - self->statistics.lowWaterMark = self->size; - ET_MSC_LOGGER_SYNC_EXIT -} diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.h b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.h index eb3727034..dda05abfa 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.h +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.h @@ -29,22 +29,12 @@ ET_EXTERN_C_BEGIN /** - * a data structure for the queue statistics - */ -typedef struct etQueueStatistics { - etInt16 highWaterMark; /**< high water mark */ - etInt16 lowWaterMark; /**< low water mark */ -} -etQueueStatistics; - -/** * the message queue data structure */ typedef struct etMessageQueue { etMessage* first; /**< the head of the list */ etMessage* last; /**< the tail of the list */ etInt16 size; /**< the size of the list */ - etQueueStatistics statistics; /**< high water mark for statistical purposes */ } etMessageQueue; @@ -99,39 +89,6 @@ etBool etMessageQueue_isNotEmpty(etMessageQueue* self); * \return the size of the message queue */ etInt16 etMessageQueue_getSize(etMessageQueue* self); -/** - * returns the statistics of the queue - * \param self the this pointer - * \return the statistics of the queue (immutable) - */ -const etQueueStatistics* etMessageQueue_getStatistics(etMessageQueue* self); -/** - * returns the high water mark of the message queue - * - * \param self the this pointer - * \return the high water mark of the message queue - */ -etInt16 etMessageQueue_getHighWaterMark(etMessageQueue* self); -/** - * resets the high water mark of the message queue to 0 - * - * \param self the this pointer - */ -void etMessageQueue_resetHighWaterMark(etMessageQueue* self); -/** - * returns the low water mark of the message queue - * - * \param self the this pointer - * \return the low water mark of the message queue - */ -etInt16 etMessageQueue_getLowWaterMark(etMessageQueue* self); -/** - * resets the low water mark of the message queue to the current - * position (size) of the queue - * - * \param self the this pointer - */ -void etMessageQueue_resetLowWaterMark(etMessageQueue* self); ET_EXTERN_C_END diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c index e7298885c..d752e465a 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c @@ -90,7 +90,10 @@ void etMessageService_initx( /* init statistics */ self->statistics.highWaterMark = 0; - self->statistics.queueStatistics = &self->messageQueue.statistics; + self->statistics.queueStatistics.highWaterMark = 0; + self->statistics.queueStatistics.lowWaterMark = 0; + self->statistics.queueStatistics.nFailingRequests = 0; + self->resetStatistics = ET_FALSE; /* register with runtime */ @@ -152,7 +155,6 @@ void etMessageService_initMessagePool(etMessageService* self){ etMessage* block = (etMessage*) &self->messageBuffer.buffer[i*self->messageBuffer.blockSize]; etMessageQueue_push(&self->messagePool, block); } - etMessageQueue_resetLowWaterMark(&self->messagePool); ET_MSC_LOGGER_SYNC_EXIT } @@ -184,14 +186,19 @@ etMessage* etMessageService_getMessageBuffer(etMessageService* self, etUInt16 si if (self->messagePool.size>0){ etMessage* msg = etMessageQueue_pop(&self->messagePool); etMutex_leave(&self->poolMutex); + if((self->messageBuffer.maxBlocks - self->messagePool.size) > self->statistics.queueStatistics.highWaterMark) { + self->statistics.queueStatistics.highWaterMark++; + } ET_MSC_LOGGER_SYNC_EXIT return msg; } else { - etLogger_logErrorF("etMessageService_getMessageBuffer: message pool empty: %d", etMessageService_getMessagePoolLowWaterMark(self)); + self->statistics.queueStatistics.nFailingRequests++; + etLogger_logErrorF("etMessageService_getMessageBuffer: message pool empty: %d", self->statistics.queueStatistics.lowWaterMark); } } else { + self->statistics.queueStatistics.nFailingRequests++; etLogger_logErrorF("etMessageService_getMessageBuffer: message too big: %d, blockSize: %d", size, self->messageBuffer.blockSize); } etMutex_leave(&self->poolMutex); @@ -203,6 +210,9 @@ void etMessageService_returnMessageBuffer(etMessageService* self, etMessage* buf ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "returnMessageBuffer") etMutex_enter(&self->poolMutex); etMessageQueue_push(&self->messagePool, buffer); + if ((self->messageBuffer.maxBlocks - self->messagePool.size) < self->statistics.queueStatistics.lowWaterMark) { + self->statistics.queueStatistics.lowWaterMark--; + } etMutex_leave(&self->poolMutex); ET_MSC_LOGGER_SYNC_EXIT } @@ -273,8 +283,9 @@ static void etMessageService_deliverAllMessages(etMessageService* self){ self->resetStatistics = ET_FALSE; self->statistics.highWaterMark = 0; - etMessageQueue_resetHighWaterMark(&self->messageQueue); - etMessageQueue_resetLowWaterMark(&self->messageQueue); + self->statistics.queueStatistics.highWaterMark = 0; + self->statistics.queueStatistics.lowWaterMark = (self->messageBuffer.maxBlocks - self->messagePool.size); + self->statistics.queueStatistics.nFailingRequests = 0; } while (etMessageQueue_isNotEmpty(&self->messageQueue) && cont){ @@ -290,13 +301,6 @@ static void etMessageService_deliverAllMessages(etMessageService* self){ ET_MSC_LOGGER_SYNC_EXIT } -etInt16 etMessageService_getMessagePoolLowWaterMark(etMessageService* self){ - ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "getMessagePoolLowWaterMark") - etInt16 lowWaterMark = etMessageQueue_getLowWaterMark(&self->messagePool); - ET_MSC_LOGGER_SYNC_EXIT - return lowWaterMark; -} - static void etMessageService_timerCallback(void* data) { ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "timerCallback") { diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.h b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.h index 1d52a5f3c..2a50e55b6 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.h +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.h @@ -27,6 +27,8 @@ #include "etDatatypes.h" #include "messaging/etMessageQueue.h" #include "messaging/etMessageReceiver.h" +#include "base/etQueue.h" +#include "base/etQueueStatistics.h" #include "osal/etMutex.h" #include "osal/etThread.h" @@ -71,7 +73,7 @@ struct etHighPrioFunc{ */ typedef struct etMessageServiceStatistics { etTimeDiff highWaterMark; /** high water mark */ - etQueueStatistics* queueStatistics; /** a pointer to the queue statistics */ + etQueueStatistics queueStatistics; /** a pointer to the queue statistics */ } etMessageServiceStatistics; @@ -211,14 +213,6 @@ etMessage* etMessageService_getMessageBuffer(etMessageService* self, etUInt16 si */ void etMessageService_returnMessageBuffer(etMessageService* self, etMessage* buffer); -/** - * returns the low water mark of the message pool - * - * \param self the this pointer - * \return the low water mark of the message pool - */ -etInt16 etMessageService_getMessagePoolLowWaterMark(etMessageService* self); - /* functions to register and unregister high prio functions */ void etMessageService_registerHighPrioFunc(etMessageService* self, etHighPrioFunc* func); void etMessageService_unregisterHighPrioFunc(etMessageService* self, etHighPrioFunc* func); |