Confused - Should I loop on pbufs in my receive callback?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Confused - Should I loop on pbufs in my receive callback?

lauziepi
Hello,

I am seeing very slow response times from my device running lwip after
awhile. I have tried various settings as recommended here and elsewhere, and
the issue does not appear to be linked to an incorrect lwip configuration.

When searching around, I have seen a few people mentioning that the
interrupt can be raised when receiving a packet, but it does not guarantee
that only a single packet has been received (for example, a new packet could
be received before the interrupt is handled).

Below is my receive callback function. I have some custom error handling and
packet parsing / handling, but anyone familiar with lwip should recognize
the lwip function calls. Basically, my packets are supposed to match a
command, and the device running lwip is supposed to send a reply to the
"core" (a computer). Please note that I used example code provided by Xiling
as a starting point, as I am running lwip in a FPGA.

Here are 3 questions I have:

1 - Is it ok to reply to the packet directly in the receive callback? See
/errTcp = Eth_ControlPanel_SendPacket(&packet, tpcb);/ Would it be better to
raise a flag and send the response in my main loop?

2 - Am I supposed to add a loop somewhere in the receive callback to handle
the case where I can receive multiple packets before I can handle the
interrupt? I feel like I have more and more packets waiting in my queues,
and since I only read 1 packet each time I get an interrupt, this is why the
response time gets slower each time. What would be my looping conditions if
so?

3 - Does anything else appear wrong with this receive callback?

Thanks in advance, hopefully someone more experienced can shed some light on
this.

err_t ControlPanel_rcv_callback(void* arg, struct tcp_pcb *tpcb, struct
pbuf* p, err_t err)
{
        if (!p) {
                tcp_close(tpcb);
                tcp_recv(tpcb, NULL);
                return ERR_CONN;
        }
        tcp_recved(tpcb, p->len);

        ParsedPacket packet;
        bool hasBeenParsed = false;
        u32 packetPayLoadSizePacket = p->len;
        if((packetPayLoadSizePacket >=  BASE_COMMAND_SIZE) &&
(packetPayLoadSizePacket <= (MAX_RX_DATA_RECEIVED_FROM_CORE +
BASE_COMMAND_SIZE)))
        {
                //xil_printf("Parsing packet received from core \n\r");
                parseRxCmdFromCore(p->payload, &packet);
                hasBeenParsed = true;
        }

        if(hasBeenParsed && (packet.packetSize == packetPayLoadSizePacket))
        {
                //xil_printf("The command from Core is now processed \n\r");
                LabPETIICoreCmdProcessing(&packet);
        }
        else
        {
                //xil_printf("Error has been detected regarding packet size \n\r");
                packet.type = b_ERROR;
                packet.data1 = e_BOARD_CMD_PACKETSIZE;
                packet.errorFlag = b_ERROR;
                packet.packetSize = BASE_COMMAND_SIZE;
        }

        pbuf_free(p);
        buildResponsePacketForCore(&packet);

        err_t errTcp;
        errTcp = Eth_ControlPanel_SendPacket(&packet, tpcb);
        tcp_close(tpcb);

        return errTcp;
}




--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Confused - Should I loop on pbufs in my receive callback?

goldsimon@gmx.de
Am 30.07.2019 um 03:37 schrieb lauziepi:

> Hello,
>
> I am seeing very slow response times from my device running lwip after
> awhile. I have tried various settings as recommended here and elsewhere, and
> the issue does not appear to be linked to an incorrect lwip configuration.
>
> When searching around, I have seen a few people mentioning that the
> interrupt can be raised when receiving a packet, but it does not guarantee
> that only a single packet has been received (for example, a new packet could
> be received before the interrupt is handled).
>
> Below is my receive callback function. I have some custom error handling and
> packet parsing / handling, but anyone familiar with lwip should recognize
> the lwip function calls. Basically, my packets are supposed to match a
> command, and the device running lwip is supposed to send a reply to the
> "core" (a computer). Please note that I used example code provided by Xiling
> as a starting point, as I am running lwip in a FPGA.
>
> Here are 3 questions I have:
>
> 1 - Is it ok to reply to the packet directly in the receive callback? See
> /errTcp = Eth_ControlPanel_SendPacket(&packet, tpcb);/ Would it be better to
> raise a flag and send the response in my main loop?

By even sending the packet into lwIP directly in the RX interrupt,
you'll most probably get concurrency issues. Since I don't know the
function you mentioned, I cannot tell if that's ok.

>
> 2 - Am I supposed to add a loop somewhere in the receive callback to handle
> the case where I can receive multiple packets before I can handle the
> interrupt? I feel like I have more and more packets waiting in my queues,
> and since I only read 1 packet each time I get an interrupt, this is why the
> response time gets slower each time. What would be my looping conditions if
> so?

Yes. One interrupt does *not* mean one packet. It means a trigger from
the hardware "there's something to do". If you get there too late, there
may be more than one packet. You certainly need to handle this.

>
> 3 - Does anything else appear wrong with this receive callback?

See inline below.

>
> Thanks in advance, hopefully someone more experienced can shed some light on
> this.
>
> err_t ControlPanel_rcv_callback(void* arg, struct tcp_pcb *tpcb, struct
> pbuf* p, err_t err)
> {
> if (!p) {
> tcp_close(tpcb);
> tcp_recv(tpcb, NULL);
> return ERR_CONN;

Return ERR_OK here. This is a standard "FIN received".

> }
> tcp_recved(tpcb, p->len);
>
> ParsedPacket packet;
> bool hasBeenParsed = false;
> u32 packetPayLoadSizePacket = p->len;
> if((packetPayLoadSizePacket >=  BASE_COMMAND_SIZE) &&
> (packetPayLoadSizePacket <= (MAX_RX_DATA_RECEIVED_FROM_CORE +
> BASE_COMMAND_SIZE)))
> {
> //xil_printf("Parsing packet received from core \n\r");
> parseRxCmdFromCore(p->payload, &packet);
> hasBeenParsed = true;
> }
>
> if(hasBeenParsed && (packet.packetSize == packetPayLoadSizePacket))
> {
> //xil_printf("The command from Core is now processed \n\r");
> LabPETIICoreCmdProcessing(&packet);
> }
> else
> {
> //xil_printf("Error has been detected regarding packet size \n\r");
> packet.type = b_ERROR;
> packet.data1 = e_BOARD_CMD_PACKETSIZE;
> packet.errorFlag = b_ERROR;
> packet.packetSize = BASE_COMMAND_SIZE;
> }
>
> pbuf_free(p);
> buildResponsePacketForCore(&packet);
>
> err_t errTcp;
> errTcp = Eth_ControlPanel_SendPacket(&packet, tpcb);
> tcp_close(tpcb);
>
> return errTcp;

Return ERR_OK here. You handled the RX packet correctly. TX path is
something different.

Regards,
Simon

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Confused - Should I loop on pbufs in my receive callback?

lauziepi
Hello,

thanks for the reply! Regarding question #2, would you (or someone else) be
kind enough to tell me how to verify if there is more than one packet to
handle? What should be my looping condition(s)?



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Confused - Should I loop on pbufs in my receive callback?

goldsimon@gmx.de
Am 02.08.2019 um 17:34 schrieb lauziepi:
> Hello,
>
> thanks for the reply! Regarding question #2, would you (or someone else) be
> kind enough to tell me how to verify if there is more than one packet to
> handle? What should be my looping condition(s)?

This is a mailing list. You're using a forum as a frontend to this list
only. Please do those people using their mailers a favor and include
older mails as citation.

I'll now go searching what "question #2" was...

Regards,
Simon

>
>
>
> --
> Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html
>
> _______________________________________________
> lwip-users mailing list
> [hidden email]
> https://lists.nongnu.org/mailman/listinfo/lwip-users
>


_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Confused - Should I loop on pbufs in my receive callback?

goldsimon@gmx.de
Am 02.08.2019 um 20:29 schrieb [hidden email]:

> Am 02.08.2019 um 17:34 schrieb lauziepi:
>> Hello,
>>
>> thanks for the reply! Regarding question #2, would you (or someone else) be
>> kind enough to tell me how to verify if there is more than one packet to
>> handle? What should be my looping condition(s)?
>
> This is a mailing list. You're using a forum as a frontend to this list
> only. Please do those people using their mailers a favor and include
> older mails as citation.
>
> I'll now go searching what "question #2" was...

OK. After re-reading your original post, I'm not sure what "question #2"
really was about. The rx callback (lwIP raw API) or your driver interrupt?

Please try to explain again.

Regards,
Simon

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Confused - Should I loop on pbufs in my receive callback?

lauziepi
Hello,

Regarding question #2 I am talking about the rx callback (lwIP raw API).


[hidden email] wrote
> Am 02.08.2019 um 20:29 schrieb

> goldsimon@

> :
>> Am 02.08.2019 um 17:34 schrieb lauziepi:
>>> Hello,
>>>
>>> thanks for the reply! Regarding question #2, would you (or someone else)
>>> be
>>> kind enough to tell me how to verify if there is more than one packet to
>>> handle? What should be my looping condition(s)?
>>
>> This is a mailing list. You're using a forum as a frontend to this list
>> only. Please do those people using their mailers a favor and include
>> older mails as citation.
>>
>> I'll now go searching what "question #2" was...
>
> OK. After re-reading your original post, I'm not sure what "question #2"
> really was about. The rx callback (lwIP raw API) or your driver interrupt?
>
> Please try to explain again.
>
> Regards,
> Simon
>
> _______________________________________________
> lwip-users mailing list

> lwip-users@

> https://lists.nongnu.org/mailman/listinfo/lwip-users





--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Confused - Should I loop on pbufs in my receive callback?

goldsimon@gmx.de


Am 5. August 2019 17:40:51 MESZ schrieb lauziepi <[hidden email]>:
>Hello,
>
>Regarding question #2 I am talking about the rx callback (lwIP raw
>API).

I'm not absolutely sure what you mean, but p->next can contain another pbuf and so on, yes.

Regards,
Simon

>
>
>[hidden email] wrote
>> Am 02.08.2019 um 20:29 schrieb
>
>> goldsimon@
>
>> :
>>> Am 02.08.2019 um 17:34 schrieb lauziepi:
>>>> Hello,
>>>>
>>>> thanks for the reply! Regarding question #2, would you (or someone
>else)
>>>> be
>>>> kind enough to tell me how to verify if there is more than one
>packet to
>>>> handle? What should be my looping condition(s)?
>>>
>>> This is a mailing list. You're using a forum as a frontend to this
>list
>>> only. Please do those people using their mailers a favor and include
>>> older mails as citation.
>>>
>>> I'll now go searching what "question #2" was...
>>
>> OK. After re-reading your original post, I'm not sure what "question
>#2"
>> really was about. The rx callback (lwIP raw API) or your driver
>interrupt?
>>
>> Please try to explain again.
>>
>> Regards,
>> Simon
>>
>> _______________________________________________
>> lwip-users mailing list
>
>> lwip-users@
>
>> https://lists.nongnu.org/mailman/listinfo/lwip-users
>
>
>
>
>
>--
>Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html
>
>_______________________________________________
>lwip-users mailing list
>[hidden email]
>https://lists.nongnu.org/mailman/listinfo/lwip-users

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users