linux osal output in namespace

This commit is contained in:
Robin Müller 2020-04-29 13:46:30 +02:00
parent 7ec6d2ceaa
commit e1aa285b6d
6 changed files with 67 additions and 41 deletions

View File

@ -43,7 +43,8 @@ uint32_t FixedTimeslotTask::getPeriodMs() const {
ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId,
uint32_t slotTimeMs, int8_t executionStep) {
if (!objectManager->get<ExecutableObjectIF>(componentId)) {
error << "Component " << std::hex << componentId << " not found, not adding it to pst" << std::endl;
sif::error << "Component " << std::hex << componentId
<< " not found, not adding it to pst" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
@ -87,7 +88,7 @@ void FixedTimeslotTask::taskFunctionality() {
void FixedTimeslotTask::missedDeadlineCounter() {
FixedTimeslotTask::deadlineMissedCount++;
if (FixedTimeslotTask::deadlineMissedCount % 10 == 0) {
error << "PST missed " << FixedTimeslotTask::deadlineMissedCount
<< " deadlines." << std::endl;
sif::error << "PST missed " << FixedTimeslotTask::deadlineMissedCount
<< " deadlines." << std::endl;
}
}

View File

@ -17,11 +17,11 @@ MessageQueue::MessageQueue(size_t message_depth, size_t max_message_size) :
attributes.mq_maxmsg = message_depth;
attributes.mq_msgsize = max_message_size;
attributes.mq_flags = 0; //Flags are ignored on Linux during mq_open
//Set the name of the queue
sprintf(name, "/Q%u\n", queueCounter++);
//Create a nonblocking queue if the name is available (the queue is Read and writable for the owner as well as the group)
//Create a nonblocking queue if the name is available (the queue is Read and
// writable for the owner as well as the group)
mqd_t tempId = mq_open(name, O_NONBLOCK | O_RDWR | O_CREAT | O_EXCL,
S_IWUSR | S_IREAD | S_IWGRP | S_IRGRP | S_IROTH | S_IWOTH, &attributes);
if (tempId == -1) {
@ -32,8 +32,8 @@ MessageQueue::MessageQueue(size_t message_depth, size_t max_message_size) :
//We unlink the other queue
int status = mq_unlink(name);
if (status != 0) {
error << "mq_unlink Failed with status: " << strerror(errno)
<< std::endl;
sif::error << "mq_unlink Failed with status: " << strerror(errno)
<< std::endl;
} else {
//Successful unlinking, try to open again
mqd_t tempId = mq_open(name,
@ -47,7 +47,7 @@ MessageQueue::MessageQueue(size_t message_depth, size_t max_message_size) :
}
}
//Failed either the first time or the second time
error << "MessageQueue::MessageQueue: Creating Queue " << std::hex
sif::error << "MessageQueue::MessageQueue: Creating Queue " << std::hex
<< name << std::dec << " failed with status: "
<< strerror(errno) << std::endl;
} else {
@ -59,11 +59,13 @@ MessageQueue::MessageQueue(size_t message_depth, size_t max_message_size) :
MessageQueue::~MessageQueue() {
int status = mq_close(this->id);
if(status != 0){
error << "MessageQueue::Destructor: mq_close Failed with status: " << strerror(errno) <<std::endl;
sif::error << "MessageQueue::Destructor: mq_close Failed with status: "
<< strerror(errno) <<std::endl;
}
status = mq_unlink(name);
if(status != 0){
error << "MessageQueue::Destructor: mq_unlink Failed with status: " << strerror(errno) <<std::endl;
sif::error << "MessageQueue::Destructor: mq_unlink Failed with status: "
<< strerror(errno) <<std::endl;
}
}
@ -93,7 +95,8 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessage* message,
ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessage* message) {
unsigned int messagePriority = 0;
int status = mq_receive(id,reinterpret_cast<char*>(message->getBuffer()),message->MAX_MESSAGE_SIZE,&messagePriority);
int status = mq_receive(id,reinterpret_cast<char*>(message->getBuffer()),
message->MAX_MESSAGE_SIZE,&messagePriority);
if (status > 0) {
this->lastPartner = message->getSender();
//Check size of incoming message.
@ -114,7 +117,8 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessage* message) {
return MessageQueueIF::EMPTY;
case EBADF:
//mqdes doesn't represent a valid queue open for reading.
error << "MessageQueue::receive: configuration error " << strerror(errno) << std::endl;
sif::error << "MessageQueue::receive: configuration error "
<< strerror(errno) << std::endl;
/*NO BREAK*/
case EINVAL:
/*
@ -123,7 +127,8 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessage* message) {
* * The number of bytes requested, msg_len is less than zero.
* * msg_len is anything other than the mq_msgsize of the specified queue, and the QNX extended option MQ_READBUF_DYNAMIC hasn't been set in the queue's mq_flags.
*/
error << "MessageQueue::receive: configuration error " << strerror(errno) << std::endl;
sif::error << "MessageQueue::receive: configuration error "
<< strerror(errno) << std::endl;
/*NO BREAK*/
case EMSGSIZE:
/*
@ -131,7 +136,8 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessage* message) {
* * the QNX extended option MQ_READBUF_DYNAMIC hasn't been set, and the given msg_len is shorter than the mq_msgsize for the given queue.
* * the extended option MQ_READBUF_DYNAMIC has been set, but the given msg_len is too short for the message that would have been received.
*/
error << "MessageQueue::receive: configuration error " << strerror(errno) << std::endl;
sif::error << "MessageQueue::receive: configuration error "
<< strerror(errno) << std::endl;
/*NO BREAK*/
case EINTR:
//The operation was interrupted by a signal.
@ -154,7 +160,8 @@ ReturnValue_t MessageQueue::flush(uint32_t* count) {
switch(errno){
case EBADF:
//mqdes doesn't represent a valid message queue.
error << "MessageQueue::flush configuration error, called flush with an invalid queue ID" << std::endl;
sif::error << "MessageQueue::flush configuration error, "
"called flush with an invalid queue ID" << std::endl;
/*NO BREAK*/
case EINVAL:
//mq_attr is NULL
@ -169,7 +176,8 @@ ReturnValue_t MessageQueue::flush(uint32_t* count) {
switch(errno){
case EBADF:
//mqdes doesn't represent a valid message queue.
error << "MessageQueue::flush configuration error, called flush with an invalid queue ID" << std::endl;
sif::error << "MessageQueue::flush configuration error, "
"called flush with an invalid queue ID" << std::endl;
/*NO BREAK*/
case EINVAL:
/*
@ -237,7 +245,9 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
return MessageQueueIF::FULL;
case EBADF:
//mq_des doesn't represent a valid message queue descriptor, or mq_des wasn't opened for writing.
error << "MessageQueue::sendMessage: Configuration error " << strerror(errno) << " in mq_send mqSendTo: " << sendTo << " sent from " << sentFrom << std::endl;
sif::error << "MessageQueue::sendMessage: Configuration error "
<< strerror(errno) << " in mq_send mqSendTo: " << sendTo
<< " sent from " << sentFrom << std::endl;
/*NO BREAK*/
case EINTR:
//The call was interrupted by a signal.
@ -248,9 +258,11 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
* * msg_len is negative.
* * msg_prio is greater than MQ_PRIO_MAX.
* * msg_prio is less than 0.
* * MQ_PRIO_RESTRICT is set in the mq_attr of mq_des, and msg_prio is greater than the priority of the calling process.
* * MQ_PRIO_RESTRICT is set in the mq_attr of mq_des,
* and msg_prio is greater than the priority of the calling process.
* */
error << "MessageQueue::sendMessage: Configuration error " << strerror(errno) << " in mq_send" << std::endl;
sif::error << "MessageQueue::sendMessage: Configuration error "
<< strerror(errno) << " in mq_send" << std::endl;
/*NO BREAK*/
case EMSGSIZE:
//The msg_len is greater than the msgsize associated with the specified queue.

View File

@ -13,22 +13,22 @@ Mutex::Mutex() {
pthread_mutexattr_t mutexAttr;
int status = pthread_mutexattr_init(&mutexAttr);
if (status != 0) {
error << "Mutex: Attribute init failed with: " << strerror(status) << std::endl;
sif::error << "Mutex: Attribute init failed with: " << strerror(status) << std::endl;
}
status = pthread_mutexattr_setprotocol(&mutexAttr, PTHREAD_PRIO_INHERIT);
if (status != 0) {
error << "Mutex: Attribute set PRIO_INHERIT failed with: " << strerror(status)
sif::error << "Mutex: Attribute set PRIO_INHERIT failed with: " << strerror(status)
<< std::endl;
}
status = pthread_mutex_init(&mutex, &mutexAttr);
if (status != 0) {
error << "Mutex: creation with name, id " << mutex.__data.__count
sif::error << "Mutex: creation with name, id " << mutex.__data.__count
<< ", " << " failed with " << strerror(status) << std::endl;
}
//After a mutex attributes object has been used to initialize one or more mutexes, any function affecting the attributes object (including destruction) shall not affect any previously initialized mutexes.
status = pthread_mutexattr_destroy(&mutexAttr);
if (status != 0) {
error << "Mutex: Attribute destroy failed with " << strerror(status) << std::endl;
sif::error << "Mutex: Attribute destroy failed with " << strerror(status) << std::endl;
}
}

View File

@ -56,9 +56,9 @@ void PeriodicPosixTask::taskFunctionality(void){
char name[20] = {0};
int status = pthread_getname_np(pthread_self(),name,sizeof(name));
if(status==0){
error << "ObjectTask: " << name << " Deadline missed." << std::endl;
sif::error << "ObjectTask: " << name << " Deadline missed." << std::endl;
}else{
error << "ObjectTask: X Deadline missed. " << status << std::endl;
sif::error << "ObjectTask: X Deadline missed. " << status << std::endl;
}
if (this->deadlineMissedFunc != NULL) {
this->deadlineMissedFunc();

View File

@ -22,7 +22,8 @@ ReturnValue_t PosixThread::sleep(uint64_t ns) {
//The nanosleep() function was interrupted by a signal.
return HasReturnvaluesIF::RETURN_FAILED;
case EINVAL:
//The rqtp argument specified a nanosecond value less than zero or greater than or equal to 1000 million.
//The rqtp argument specified a nanosecond value less than zero or
// greater than or equal to 1000 million.
return HasReturnvaluesIF::RETURN_FAILED;
default:
return HasReturnvaluesIF::RETURN_FAILED;
@ -40,8 +41,8 @@ void PosixThread::suspend() {
sigaddset(&waitSignal, SIGUSR1);
sigwait(&waitSignal, &caughtSig);
if (caughtSig != SIGUSR1) {
error << "FixedTimeslotTask: Unknown Signal received: " << caughtSig
<< std::endl;
sif::error << "FixedTimeslotTask: Unknown Signal received: " <<
caughtSig << std::endl;
}
}
@ -112,14 +113,15 @@ uint64_t PosixThread::getCurrentMonotonicTimeMs(){
return currentTime_ms;
}
PosixThread::PosixThread(const char* name_, int priority_, size_t stackSize_):thread(0),priority(priority_),stackSize(stackSize_) {
PosixThread::PosixThread(const char* name_, int priority_, size_t stackSize_):
thread(0),priority(priority_),stackSize(stackSize_) {
strcpy(name,name_);
}
void PosixThread::createTask(void* (*fnc_)(void*), void* arg_) {
debug << "PosixThread::createTask" << std::endl;
//sif::debug << "PosixThread::createTask" << std::endl;
/*
* The attr argument points to a pthread_attr_t structure whose contents
are used at thread creation time to determine attributes for the new
@ -130,35 +132,41 @@ void PosixThread::createTask(void* (*fnc_)(void*), void* arg_) {
pthread_attr_t attributes;
int status = pthread_attr_init(&attributes);
if(status != 0){
error << "Posix Thread attribute init failed with: " << strerror(status) << std::endl;
sif::error << "Posix Thread attribute init failed with: " <<
strerror(status) << std::endl;
}
void* sp;
status = posix_memalign(&sp, sysconf(_SC_PAGESIZE), stackSize);
if(status != 0){
error << "Posix Thread stack init failed with: " << strerror(status) << std::endl;
sif::error << "Posix Thread stack init failed with: " <<
strerror(status) << std::endl;
}
status = pthread_attr_setstack(&attributes, sp, stackSize);
if(status != 0){
error << "Posix Thread attribute setStack failed with: " << strerror(status) << std::endl;
sif::error << "Posix Thread attribute setStack failed with: " <<
strerror(status) << std::endl;
}
status = pthread_attr_setinheritsched(&attributes, PTHREAD_EXPLICIT_SCHED);
if(status != 0){
error << "Posix Thread attribute setinheritsched failed with: " << strerror(status) << std::endl;
sif::error << "Posix Thread attribute setinheritsched failed with: " <<
strerror(status) << std::endl;
}
//TODO FIFO -> This needs root privileges for the process
status = pthread_attr_setschedpolicy(&attributes,SCHED_FIFO);
if(status != 0){
error << "Posix Thread attribute schedule policy failed with: " << strerror(status) << std::endl;
sif::error << "Posix Thread attribute schedule policy failed with: " <<
strerror(status) << std::endl;
}
sched_param scheduleParams;
scheduleParams.__sched_priority = priority;
status = pthread_attr_setschedparam(&attributes, &scheduleParams);
if(status != 0){
error << "Posix Thread attribute schedule params failed with: " << strerror(status) << std::endl;
sif::error << "Posix Thread attribute schedule params failed with: " <<
strerror(status) << std::endl;
}
//Set Signal Mask for suspend until startTask is called
@ -167,22 +175,26 @@ void PosixThread::createTask(void* (*fnc_)(void*), void* arg_) {
sigaddset(&waitSignal, SIGUSR1);
status = pthread_sigmask(SIG_BLOCK, &waitSignal, NULL);
if(status != 0){
error << "Posix Thread sigmask failed failed with: " << strerror(status) << " errno: " << strerror(errno) << std::endl;
sif::error << "Posix Thread sigmask failed failed with: " <<
strerror(status) << " errno: " << strerror(errno) << std::endl;
}
status = pthread_create(&thread,&attributes,fnc_,arg_);
if(status != 0){
error << "Posix Thread create failed with: " << strerror(status) << std::endl;
sif::error << "Posix Thread create failed with: " <<
strerror(status) << std::endl;
}
status = pthread_setname_np(thread,name);
if(status != 0){
error << "Posix Thread setname failed with: " << strerror(status) << std::endl;
sif::error << "Posix Thread setname failed with: " <<
strerror(status) << std::endl;
}
status = pthread_attr_destroy(&attributes);
if(status!=0){
error << "Posix Thread attribute destroy failed with: " << strerror(status) << std::endl;
sif::error << "Posix Thread attribute destroy failed with: " <<
strerror(status) << std::endl;
}
}

View File

@ -9,7 +9,8 @@ Timer::Timer() {
sigEvent.sigev_value.sival_ptr = &timerId;
int status = timer_create(CLOCK_MONOTONIC, &sigEvent, &timerId);
if(status!=0){
error << "Timer creation failed with: " << status << " errno: " << errno << std::endl;
sif::error << "Timer creation failed with: " << status <<
" errno: " << errno << std::endl;
}
}