Hi Raveendranath,

 

Uze gave pseudo code, there is no is_queue_empty() method in IoTivity. What he meant was OCProcess() is used for processing any incoming request/responses added to receive queue in message handler and OCProcess() thread can be signaled to wake up only when there any messages received. But OCProcess() is used for checking timeout for presence callbacks and keepalive sessions also. I think your problem would be solved if OCProcess() thread wakes up only when any message received or near timeout of either presence callback or keepalive session.

 

 

Regards,

Harish Kumara M

 

 

 

--------- Original Message ---------

Sender : Ravee <[email protected]>

Date : 2018-11-28 11:52 (GMT+5:30)

Title : Re: [dev] Thread wake up every 10ms

 

Hi,

I can try a fix here. But probably, missing some insights here. If someone, can shed more light, I'm willing to give it a try.

    ts = OCProcess();
    pthread_mutex_lock(&mutex);

if (is_queue_empty()) {
   if (ts) {
      pthread_cond_wait(&cv, &mutex);
    } else {
      pthread_cond_timedwait(&cv, &mutex, &ts);
    }

}


I don't see any is_queue_empty API in InProcServerWrapper.h? What does this queue represents, incoming message queue??


-Ravee

On Wed, Nov 28, 2018 at 11:25 AM 최우제 (Uze Choi) <[email protected]> wrote:

Oh~, I have assumed you try to fix it.

BTW, replacing polling is definitely required.

 

BR, Uze Choi

From: [email protected] [mailto:[email protected]] On Behalf Of Ravee
Sent: Wednesday, November 28, 2018 2:25 PM
To: [email protected]
Cc: [email protected]
Subject: Re: [dev] Thread wake up every 10ms

 

Are we planning to get this change to mainline?

 

On Tue, Nov 27, 2018 at 8:15 AM 최우제 (Uze Choi) <[email protected]> wrote:

Sorry, Let me abort point 2 below, only single execution is guaranteed from the code.

2.There are two points calling OCProcess() periodically which is InProcServerWrapper::processFunc() and InProcClientWrapper::listeningFunc().

   Two entities will receive the signal and race to execute the OCProcess() and they are locked with recursive mutex. This may need another structure change.

 

BR, Uze Choi

From: [email protected] [mailto:[email protected]] On Behalf Of 최우제 (Uze Choi)
Sent: Tuesday, November 27, 2018 10:58 AM
To: 'Ravee'; [email protected]
Subject: Re: [dev] Thread wake up every 10ms

 

Apply Wait and signal awake is my suggestion.

Before wait, it need to check the receive queue and awake from wait when received message happen.

 

But there three point to consider.

1. From OCProcess some internal call exists which requires timeout check. This mean OCProcess should be called after each timeout happens.

This may requires timeout management logic as like IoTivty-Lite with returning remaining timeout period from OCProcess().

2.There are two points calling OCProcess() periodically which is InProcServerWrapper::processFunc() and InProcClientWrapper::listeningFunc().

   Two entities will receive the signal and race to execute the OCProcess() and they are locked with recursive mutex. This may need another structure change.

3. OCProcess() and other OC API call are synchronized with recursive mutex. I don’t know detail if this may requires additional consideration.

 

    ts = OCProcess();
    pthread_mutex_lock(&mutex);

if (is_queue_empty()) {
   if (ts) {
      pthread_cond_wait(&cv, &mutex);
    } else {
      pthread_cond_timedwait(&cv, &mutex, &ts);
    }

}

 

BR, Uze Choi

From: [email protected] [mailto:[email protected]] On Behalf Of Ravee
Sent: Friday, November 23, 2018 11:04 PM
To: [email protected]
Subject: Re: [dev] Thread wake up every 10ms

 

Any suggestions, or patches to try async mechanism instead of polling?

 

On Fri, Nov 23, 2018 at 5:37 PM Raveendranath Kondrakunta <[email protected]> wrote:

Hi,

 

I found a function where the thread wakes up every 10ms, On IoT devices, we except to save power, however this function is waking up every 10ms and defeating the purpose. We need to relook at the design here.

 

    void InProcServerWrapper::processFunc()

    {

        auto cLock = m_csdkLock.lock();

        while(cLock && m_threadRun)

        {

            OCStackResult result;

 

            {

                std::lock_guard<std::recursive_mutex> lock(*cLock);

                result = OCProcess();

            }

 

            if(OC_STACK_ERROR == result)

            {

                oclog() << "OCProcess failed with result " << result <<std::flush;

                // ...the value of variable result is simply ignored for now.

            }

 

            std::this_thread::sleep_for(std::chrono::milliseconds(10));

        }

    }

-Ravee

 

 

 

 

 

 

_._,_._,_

Links:

You receive all messages sent to this group.

View/Reply Online (#10033) | Reply To Sender | Reply To Group | Mute This Topic | New Topic

Your Subscription | Contact Group Owner | Unsubscribe [[email protected]]

_._,_._,_

Reply via email to