summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksandar Donchev <Aleksander.Donchev@partner.bmw.de>2017-10-12 13:02:09 +0200
committerAleksandar Donchev <Aleksander.Donchev@partner.bmw.de>2017-12-01 15:32:07 +0100
commit185746ea67a1f4256a4cde77bbee5dc634408228 (patch)
treee925bfc4acf5964397d94a7a7ebd3fc32a7f713b
parent955847cc5bb490d768a2282ea396b7ef16319631 (diff)
downloadaudiomanager-185746ea67a1f4256a4cde77bbee5dc634408228.tar.gz
Real time scheduler added, capi wrapper timeout return value considered in registerTimeout, only requested revent passed from within the camsockethandler instead of all
Signed-off-by: Christian Linke <christian.linke@bmw.de> Change-Id: I2d9d2c424ac3fac62c76a66545a531c518edb2e8
-rwxr-xr-xAudioManagerDaemon/src/main.cpp8
-rw-r--r--AudioManagerUtilities/include/CAmSocketHandler.h7
-rw-r--r--AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp43
-rw-r--r--AudioManagerUtilities/src/CAmSocketHandler.cpp51
-rw-r--r--AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp48
5 files changed, 90 insertions, 67 deletions
diff --git a/AudioManagerDaemon/src/main.cpp b/AudioManagerDaemon/src/main.cpp
index 5c0582e..22470e9 100755
--- a/AudioManagerDaemon/src/main.cpp
+++ b/AudioManagerDaemon/src/main.cpp
@@ -384,6 +384,14 @@ iControlSender.setControllerReady();
*/
int main(int argc, char *argv[], char** envp)
{
+ struct sched_param param;
+ param.sched_priority = 50;//mid rt proprity
+ if (sched_setscheduler(0, SCHED_FIFO, & param) != 0)
+ {
+ std::cerr <<"sched_setscheduler:"<<strerror(errno)<<std::endl;
+ std::cerr << "Try running as root"<<std::endl;
+ }
+
(void) envp;
listCommandPluginDirs.push_back(std::string(DEFAULT_PLUGIN_COMMAND_DIR));
listRoutingPluginDirs.push_back(std::string(DEFAULT_PLUGIN_ROUTING_DIR));
diff --git a/AudioManagerUtilities/include/CAmSocketHandler.h b/AudioManagerUtilities/include/CAmSocketHandler.h
index 8809a30..53010ba 100644
--- a/AudioManagerUtilities/include/CAmSocketHandler.h
+++ b/AudioManagerUtilities/include/CAmSocketHandler.h
@@ -422,13 +422,6 @@ private:
inline static void fire(const sh_poll_s* a);
/**
- * functor to return all fired events
- * @param a
- * @return
- */
- inline static bool eventFired(const pollfd& a);
-
- /**
* functor to help find the items that do not need dispatching
* @param a
* @return
diff --git a/AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp b/AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp
index 126b649..caa7aa8 100644
--- a/AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp
+++ b/AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp
@@ -207,20 +207,37 @@ void CAmCommonAPIWrapper::registerTimeout(CommonAPI::Timeout* timeout, const Com
{
timespec pollTimeout;
int64_t localTimeout = timeout->getTimeoutInterval();
-
- pollTimeout.tv_sec = localTimeout / 1000;
- pollTimeout.tv_nsec = (localTimeout % 1000) * 1000000;
+
+ if(CommonAPI::TIMEOUT_INFINITE==localTimeout)//dispatch never
+ {
+ pollTimeout.tv_sec = localTimeout;
+ pollTimeout.tv_nsec = 0;
+ }
+ else if(CommonAPI::TIMEOUT_NONE==localTimeout)//dispatch immediately
+ {
+ pollTimeout.tv_sec = 0;
+ pollTimeout.tv_nsec = 1000000;
+ }
+ else
+ {
+ pollTimeout.tv_sec = localTimeout / 1000;
+ pollTimeout.tv_nsec = (localTimeout % 1000) * 1000000;
+ }
//prepare handle and callback. new is eval, but there is no other choice because we need the pointer!
sh_timerHandle_t handle;
//add the timer to the pollLoop
- mpSocketHandler->addTimer(pollTimeout, &pCommonTimerCallback, handle, timeout);
-
- timerHandles myHandle({handle,timeout});
- mpListTimerhandles.push_back(myHandle);
-
- return;
+ am_Error_e error = mpSocketHandler->addTimer(pollTimeout, &pCommonTimerCallback, handle, timeout);
+ if (error != am_Error_e::E_OK || handle == 0)
+ {
+ logError(__func__,"adding timer failed");
+ }
+ else
+ {
+ timerHandles myHandle({handle,timeout});
+ mpListTimerhandles.push_back(myHandle);
+ }
}
void CAmCommonAPIWrapper::deregisterTimeout(CommonAPI::Timeout* timeout)
@@ -243,10 +260,12 @@ void CAmCommonAPIWrapper::registerWatch(CommonAPI::Watch* watch, const CommonAPI
am_Error_e error = mpSocketHandler->addFDPoll(pollfd_.fd, pollfd_.events, &pCommonPrepareCallback, &pCommonFireCallback, &pCommonCheckCallback, &pCommonDispatchCallback, watch, handle);
//if everything is alright, add the watch and the handle to our map so we know this relationship
- if (error == !am_Error_e::E_OK || handle == 0)
+ if (error != am_Error_e::E_OK || handle == 0)
+ {
logError(__func__,"entering watch failed");
-
- mMapWatches.insert(std::make_pair(pollfd_.fd,watch));
+ }
+ else
+ mMapWatches.insert(std::make_pair(pollfd_.fd,watch));
}
void CAmCommonAPIWrapper::commonTimerCallback(sh_timerHandle_t handle, void *)
diff --git a/AudioManagerUtilities/src/CAmSocketHandler.cpp b/AudioManagerUtilities/src/CAmSocketHandler.cpp
index 6809902..250d731 100644
--- a/AudioManagerUtilities/src/CAmSocketHandler.cpp
+++ b/AudioManagerUtilities/src/CAmSocketHandler.cpp
@@ -31,7 +31,7 @@
#include <features.h>
#include <csignal>
#include <unistd.h>
-
+#include <string.h>
#include "CAmDltWrapper.h"
#include "CAmSocketHandler.h"
@@ -180,7 +180,8 @@ void CAmSocketHandler::start_listenting()
//stage 0+1, call firedCB
for (itMfdPollingArray = fdPollingArray.begin(); itMfdPollingArray != fdPollingArray.end(); itMfdPollingArray++)
{
- if (CAmSocketHandler::eventFired(*itMfdPollingArray))
+ itMfdPollingArray->revents &= itMfdPollingArray->events | POLLERR | POLLHUP;
+ if ( itMfdPollingArray->revents!=0 )
{
listmPollIt = mListActivePolls.begin();
std::advance(listmPollIt, std::distance(fdPollingArray.begin(), itMfdPollingArray));
@@ -189,7 +190,6 @@ void CAmSocketHandler::start_listenting()
listPoll.push_back(&pollObj);
CAmSocketHandler::fire(&pollObj);
-
itMfdPollingArray->revents = 0;
}
}
@@ -312,31 +312,19 @@ am_Error_e CAmSocketHandler::listenToSignals(const std::vector<uint8_t> & listSi
return (E_NOT_POSSIBLE);
}
- int signalHandlerFd;
+ sh_poll_s sgPollData;
if(mSignalFdHandle)
{
- sh_poll_s sgPollData;
if(E_OK!=getFDPollData(mSignalFdHandle, sgPollData))
{
- removeFDPoll(mSignalFdHandle);
- mSignalFdHandle = 0;
- }
- else
- {
- int signalHandlerFd = signalfd(sgPollData.pollfdValue.fd, &sigset, 0);
- if (signalHandlerFd == -1)
- {
- logError("Could not update signal fd!");
- return (E_NOT_POSSIBLE);
- }
- return E_OK;
+ mSignalFdHandle = 0;
}
}
if(0==mSignalFdHandle)
{
/* Create the signalfd */
- signalHandlerFd = signalfd(-1, &sigset, 0);
+ int signalHandlerFd = signalfd(-1, &sigset, 0);
if (signalHandlerFd == -1)
{
logError("Could not open signal fd!");
@@ -356,10 +344,19 @@ am_Error_e CAmSocketHandler::listenToSignals(const std::vector<uint8_t> & listSi
it.callback(it.handle, info, it.userData);
};
/* We're going to add the signal fd through addFDPoll. At this point we don't have any signal listeners. */
- am_Error_e shFdError = addFDPoll(signalHandlerFd, POLLIN | POLLERR | POLLHUP, NULL, actionPoll, [](const sh_pollHandle_t, void*)
+ return addFDPoll(signalHandlerFd, POLLIN | POLLERR | POLLHUP, NULL, actionPoll, [](const sh_pollHandle_t, void*)
{ return (false);}, NULL, NULL, mSignalFdHandle);
- return shFdError;
}
+ else
+ {
+ int signalHandlerFd = signalfd(sgPollData.pollfdValue.fd, &sigset, 0);
+ if (signalHandlerFd == -1)
+ {
+ logError("Could not update signal fd!", strerror(errno));
+ return (E_NOT_POSSIBLE);
+ }
+ return E_OK;
+ }
}
/**
@@ -611,7 +608,7 @@ am_Error_e CAmSocketHandler::addTimer(const timespec & timeouts, std::function<v
return err;
}
- static auto actionPoll = [](const pollfd pollfd, const sh_pollHandle_t handle, void* userData)
+ auto actionPoll = [](const pollfd pollfd, const sh_pollHandle_t handle, void* userData)
{
uint64_t mExpirations;
if (read(pollfd.fd, &mExpirations, sizeof(uint64_t)) == -1)
@@ -1068,14 +1065,6 @@ bool CAmSocketHandler::dispatchingFinished(const sh_poll_s* a)
}
/**
- * event triggered
- */
-bool CAmSocketHandler::eventFired(const pollfd& a)
-{
- return (a.revents == 0 ? false : true);
-}
-
-/**
* is used to set the pointer for the ppoll command
* @param buffertime
* @return
@@ -1088,8 +1077,8 @@ inline timespec* CAmSocketHandler::insertTime(timespec& buffertime)
buffertime = mListActiveTimer.front().countdown;
return (&buffertime);
}
- else
-#endif
+ else
+#endif
{
return (NULL);
}
diff --git a/AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp b/AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp
index 7e03f6e..b0c00d4 100644
--- a/AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp
+++ b/AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp
@@ -42,7 +42,7 @@
#define SOCK_PATH "/tmp/mysock"
#define SOCKET_TEST_LOOPS_COUNT 50
-#define TIMERS_TO_TEST 500
+#define TIMERS_TO_TEST 100
using namespace testing;
using namespace am;
@@ -194,10 +194,16 @@ void am::CAmTimerStressTest2::timerCallback(sh_timerHandle_t handle, void* pUser
CAmTimerMeasurment::CAmTimerMeasurment(CAmSocketHandler *myHandler, const timespec &timeout, const std::string & label, const int32_t repeats, void * userData) :
- MockIAmTimerCb(), pTimerCallback(this, &CAmTimerMeasurment::timerCallback), //
- mSocketHandler(myHandler), mUpdateTimeout(timeout), mUpdateTimePoint(std::chrono::seconds
- { mUpdateTimeout.tv_sec } + std::chrono::nanoseconds
- { mUpdateTimeout.tv_nsec }), mLastInvocationTime(), mExpected(mUpdateTimePoint - TP_ZERO), mRepeats(repeats), mpUserData(userData), mDebugText(label)
+ MockIAmTimerCb()
+ , pTimerCallback(this, &CAmTimerMeasurment::timerCallback)
+ , mSocketHandler(myHandler)
+ , mUpdateTimeout(timeout)
+ , mUpdateTimePoint(std::chrono::seconds{ mUpdateTimeout.tv_sec } + std::chrono::nanoseconds{ mUpdateTimeout.tv_nsec })
+ , mLastInvocationTime()
+ , mExpected(mUpdateTimePoint - TP_ZERO)
+ , mRepeats(repeats)
+ , mpUserData(userData)
+ , mDebugText(label)
{
}
@@ -245,7 +251,7 @@ void am::CAmTimerMeasurment::timerCallback(sh_timerHandle_t handle, void* userDa
std::cout << mDebugText << " Init measurment " << std::endl;
#endif
mLastInvocationTime = t_end;
- mSocketHandler->updateTimer(handle, mUpdateTimeout);
+ mSocketHandler->updateTimer( handle, mUpdateTimeout);
}
}
@@ -531,17 +537,17 @@ TEST(CAmSocketHandlerTest, timersStressTest)
timespec timeoutTime11, timeout12, timeout13;
timeoutTime11.tv_sec = 1;
timeoutTime11.tv_nsec = 34000000;
- CAmTimerMeasurment testCallback11(&myHandler, timeoutTime11, "repeatedCallback 1", std::numeric_limits<int32_t>::max());
+ CAmTimerMeasurment testCallback11(&myHandler, timeoutTime11, "repeated 1", std::numeric_limits<int32_t>::max());
- timeout12.tv_nsec = 2000000;
+ timeout12.tv_nsec = 100000000;
timeout12.tv_sec = 0;
- CAmTimerMeasurment testCallback12(&myHandler, timeout12, "repeatedCallback 2", std::numeric_limits<int32_t>::max());
+ CAmTimerMeasurment testCallback12(&myHandler, timeout12, "repeated 2", std::numeric_limits<int32_t>::max());
timeout13.tv_nsec = 333000000;
timeout13.tv_sec = 3;
- CAmTimerMeasurment testCallback13(&myHandler, timeout13, "oneshotCallback 3");
+ CAmTimerMeasurment testCallback13(&myHandler, timeout13, "oneshot 3");
- myHandler.addTimer(timeoutTime, &testCallback11.pTimerCallback, handle, NULL, true);
+ myHandler.addTimer(timeoutTime11, &testCallback11.pTimerCallback, handle, NULL, true);
EXPECT_CALL(testCallback11,timerCallback(_,NULL)).Times(AnyNumber());
myHandler.addTimer(timeout12, &testCallback12.pTimerCallback, handle, NULL, true);
@@ -557,8 +563,8 @@ TEST(CAmSocketHandlerTest, timersStressTest)
EXPECT_CALL(testCallback4,timerCallback(_,NULL)).Times(1);
myHandler.start_listenting();
-
- for(int i=0;i<TIMERS_TO_TEST;i++)
+
+ for(int i=0;i<timers.size();i++)
{
if(timers[i])
delete timers[i], timers[i]=NULL;
@@ -573,15 +579,15 @@ TEST(CAmSocketHandlerTest,playWithTimers)
timespec timeoutTime, timeout2, timeout3, timeout4;
timeoutTime.tv_sec = 1;
timeoutTime.tv_nsec = 34000000;
- CAmTimerMeasurment testCallback1(&myHandler, timeoutTime, "repeatedCallback 1", std::numeric_limits<int32_t>::max());
+ CAmTimerMeasurment testCallback1(&myHandler, timeoutTime, "repeated 1", std::numeric_limits<int32_t>::max());
timeout2.tv_nsec = 2000000;
timeout2.tv_sec = 0;
- CAmTimerMeasurment testCallback2(&myHandler, timeout2, "repeatedCallback 2", std::numeric_limits<int32_t>::max());
+ CAmTimerMeasurment testCallback2(&myHandler, timeout2, "repeated 2", std::numeric_limits<int32_t>::max());
timeout3.tv_nsec = 333000000;
timeout3.tv_sec = 3;
- CAmTimerMeasurment testCallback3(&myHandler, timeout3, "oneshotCallback 3");
+ CAmTimerMeasurment testCallback3(&myHandler, timeout3, "oneshot 3");
timeout4.tv_nsec = 0;
timeout4.tv_sec = 8;
CAmTimerSockethandlerController testCallback4(&myHandler, timeout4);
@@ -609,7 +615,7 @@ TEST(CAmSocketHandlerTest,playWithTimers)
#else
ASSERT_EQ(handle, 4);
#endif
- EXPECT_CALL(testCallback3,timerCallback(handle,NULL)).Times(2); //+1 because of measurment
+ EXPECT_CALL(testCallback3,timerCallback(handle,NULL)).Times(2);
myHandler.addTimer(timeout4, &testCallback4.pTimerCallback, handle, NULL);
#ifndef WITH_TIMERFD
@@ -753,6 +759,14 @@ TEST(CAmSocketHandlerTest,playWithSockets)
int main(int argc, char **argv)
{
+ struct sched_param param;
+ param.sched_priority = 50;//mid rt proprity
+ if (sched_setscheduler(0, SCHED_FIFO, & param) != 0)
+ {
+ std::cerr <<"sched_setscheduler:"<<strerror(errno)<<std::endl;
+ std::cerr << "Try running as root"<<std::endl;
+ }
+
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}