From 4dc971ba562929ad849d9f90392febc2e73e4de9 Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Thu, 18 Feb 2021 16:37:02 +0100 Subject: [PATCH] - MMS server: better data model lock handling for performance improvements --- src/mms/inc_private/iso_server_private.h | 12 ---------- src/mms/iso_mms/server/mms_read_service.c | 8 +++++++ src/mms/iso_mms/server/mms_server.c | 10 ++------ src/mms/iso_mms/server/mms_write_service.c | 11 ++++++--- src/mms/iso_server/iso_connection.c | 4 ---- src/mms/iso_server/iso_server.c | 28 ---------------------- 6 files changed, 18 insertions(+), 55 deletions(-) diff --git a/src/mms/inc_private/iso_server_private.h b/src/mms/inc_private/iso_server_private.h index dac94c72..6249255e 100644 --- a/src/mms/inc_private/iso_server_private.h +++ b/src/mms/inc_private/iso_server_private.h @@ -70,18 +70,6 @@ private_IsoServer_decreaseConnectionCounter(IsoServer self); LIB61850_INTERNAL int private_IsoServer_getConnectionCounter(IsoServer self); -/** - * \brief User provided lock that will be called when higher layer (MMS) is called - */ -LIB61850_INTERNAL void -IsoServer_setUserLock(IsoServer self, Semaphore userLock); - -LIB61850_INTERNAL void -IsoServer_userLock(IsoServer self); - -LIB61850_INTERNAL void -IsoServer_userUnlock(IsoServer self); - LIB61850_INTERNAL bool IsoConnection_isRunning(IsoConnection self); diff --git a/src/mms/iso_mms/server/mms_read_service.c b/src/mms/iso_mms/server/mms_read_service.c index 13d7adce..3fb97675 100644 --- a/src/mms/iso_mms/server/mms_read_service.c +++ b/src/mms/iso_mms/server/mms_read_service.c @@ -928,11 +928,19 @@ mmsServer_handleReadRequest( request = &(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.read); if (request->variableAccessSpecification.present == VariableAccessSpecification_PR_listOfVariable) { + MmsServer_lockModel(connection->server); + handleReadListOfVariablesRequest(connection, request, invokeId, response); + + MmsServer_unlockModel(connection->server); } #if (MMS_DATA_SET_SERVICE == 1) else if (request->variableAccessSpecification.present == VariableAccessSpecification_PR_variableListName) { + MmsServer_lockModel(connection->server); + handleReadNamedVariableListRequest(connection, request, invokeId, response); + + MmsServer_unlockModel(connection->server); } #endif else { diff --git a/src/mms/iso_mms/server/mms_server.c b/src/mms/iso_mms/server/mms_server.c index 80af245b..0908babb 100644 --- a/src/mms/iso_mms/server/mms_server.c +++ b/src/mms/iso_mms/server/mms_server.c @@ -81,10 +81,6 @@ MmsServer_create(MmsDevice* device, TLSConfiguration tlsConfiguration) if (isoServer == NULL) goto exit_error; - #if (CONFIG_MMS_THREADLESS_STACK != 1) - IsoServer_setUserLock(isoServer, self->modelMutex); - #endif - LinkedList_add(self->isoServerList, isoServer); } @@ -132,8 +128,6 @@ MmsServer_addAP(MmsServer self, const char* ipAddr, int tcpPort, TLSConfiguratio if (isoServer) { - IsoServer_setUserLock(isoServer, self->modelMutex); - IsoServer_setLocalIpAddress(isoServer, ipAddr); if (tcpPort != -1) @@ -479,7 +473,8 @@ mmsServer_setValue(MmsServer self, MmsDomain* domain, char* itemId, MmsValue* va if (self->writeHandler != NULL) { indication = self->writeHandler(self->writeHandlerParameter, domain, itemId, value, connection); - } else { + } + else { MmsValue* cachedValue; if (domain == NULL) @@ -497,7 +492,6 @@ mmsServer_setValue(MmsServer self, MmsDomain* domain, char* itemId, MmsValue* va return indication; } - MmsValue* mmsServer_getValue(MmsServer self, MmsDomain* domain, char* itemId, MmsServerConnection connection, bool isDirectAccess) { diff --git a/src/mms/iso_mms/server/mms_write_service.c b/src/mms/iso_mms/server/mms_write_service.c index ad1fbf6a..31a171e4 100644 --- a/src/mms/iso_mms/server/mms_write_service.c +++ b/src/mms/iso_mms/server/mms_write_service.c @@ -501,6 +501,8 @@ mmsServer_handleWriteRequest( goto exit_function; } + MmsServer_lockModel(connection->server); + WriteRequest_t* writeRequest = &(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.write); if (writeRequest->variableAccessSpecification.present == VariableAccessSpecification_PR_variableListName) { @@ -695,13 +697,16 @@ end_of_main_loop: if (sendResponse) mmsServer_createMmsWriteResponse(connection, invokeId, response, numberOfWriteItems, accessResults); } - else { /* unknown request type */ + else { /* unknown request type */ mmsMsg_createMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_REQUEST_INVALID_ARGUMENT, response); goto exit_function; - } + } exit_function: - asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0); + + MmsServer_unlockModel(connection->server); + + asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0); } #endif /* (MMS_WRITE_SERVICE == 1) */ diff --git a/src/mms/iso_server/iso_connection.c b/src/mms/iso_server/iso_connection.c index 5f5b70dc..3551acc6 100644 --- a/src/mms/iso_server/iso_connection.c +++ b/src/mms/iso_server/iso_connection.c @@ -329,7 +329,6 @@ IsoConnection_handleTcpConnection(IsoConnection self, bool isSingleThread) ByteBuffer mmsResponseBuffer; #if (CONFIG_MMS_THREADLESS_STACK != 1) - IsoServer_userLock(self->isoServer); IsoConnection_lock(self); #endif @@ -370,7 +369,6 @@ IsoConnection_handleTcpConnection(IsoConnection self, bool isSingleThread) #if (CONFIG_MMS_THREADLESS_STACK != 1) IsoConnection_unlock(self); - IsoServer_userUnlock(self->isoServer); #endif } else { @@ -389,7 +387,6 @@ IsoConnection_handleTcpConnection(IsoConnection self, bool isSingleThread) printf("ISO_SERVER: iso_connection: presentation ok\n"); #if (CONFIG_MMS_THREADLESS_STACK != 1) - IsoServer_userLock(self->isoServer); IsoConnection_lock(self); #endif @@ -418,7 +415,6 @@ IsoConnection_handleTcpConnection(IsoConnection self, bool isSingleThread) #if (CONFIG_MMS_THREADLESS_STACK != 1) IsoConnection_unlock(self); - IsoServer_userUnlock(self->isoServer); #endif } diff --git a/src/mms/iso_server/iso_server.c b/src/mms/iso_server/iso_server.c index e45224f9..8501e41b 100644 --- a/src/mms/iso_server/iso_server.c +++ b/src/mms/iso_server/iso_server.c @@ -84,11 +84,6 @@ struct sIsoServer { IsoConnection openClientConnections[CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS]; #endif /* (CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS == -1) */ -#if (CONFIG_MMS_THREADLESS_STACK != 1) - /* used to control access to server data model */ - Semaphore userLock; -#endif - #if (CONFIG_MMS_THREADLESS_STACK != 1) && (CONFIG_MMS_SINGLE_THREADED == 0) Semaphore openClientConnectionsMutex; /* mutex for openClientConnections list */ Semaphore connectionCounterMutex; @@ -878,26 +873,3 @@ private_IsoServer_getConnectionCounter(IsoServer self) return connectionCounter; } -#if (CONFIG_MMS_THREADLESS_STACK != 1) - -void -IsoServer_setUserLock(IsoServer self, Semaphore userLock) -{ - self->userLock = userLock; -} - -void -IsoServer_userLock(IsoServer self) -{ - if (self->userLock != NULL) - Semaphore_wait(self->userLock); -} - -void -IsoServer_userUnlock(IsoServer self) -{ - if (self->userLock != NULL) - Semaphore_post(self->userLock); -} - -#endif /* (CONFIG_MMS_THREADLESS_STACK != 1) */