* [Qemu-devel] [PATCH] fix the return value of rtl8139_can_receive()
@ 2011-06-16 8:23 Wen Congyang
2011-06-16 10:39 ` Kevin Wolf
0 siblings, 1 reply; 9+ messages in thread
From: Wen Congyang @ 2011-06-16 8:23 UTC (permalink / raw)
To: Aurelien Jarno, qemu-devel
If rtl8139_can_receive() returns 1, it means that the nic can receive packet,
otherwise, it means the nic can not receive packet.
If !s->clock_enabled or !rtl8139_receiver_enabled(s), it means that the nic
can not receive packet. So the return value should be 0, not 1.
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
hw/rtl8139.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index 2f8db58..9084678 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -810,9 +810,9 @@ static int rtl8139_can_receive(VLANClientState *nc)
/* Receive (drop) packets if card is disabled. */
if (!s->clock_enabled)
- return 1;
+ return 0;
if (!rtl8139_receiver_enabled(s))
- return 1;
+ return 0;
if (rtl8139_cp_receiver_enabled(s)) {
/* ??? Flow control not implemented in c+ mode.
--
1.7.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH] fix the return value of rtl8139_can_receive()
2011-06-16 8:23 [Qemu-devel] [PATCH] fix the return value of rtl8139_can_receive() Wen Congyang
@ 2011-06-16 10:39 ` Kevin Wolf
2011-06-16 12:46 ` Michael S. Tsirkin
2011-06-17 1:49 ` [Qemu-devel] [PATCH] fix the return value of rtl8139_can_receive() Wen Congyang
0 siblings, 2 replies; 9+ messages in thread
From: Kevin Wolf @ 2011-06-16 10:39 UTC (permalink / raw)
To: Wen Congyang; +Cc: qemu-devel, Aurelien Jarno, Michael S. Tsirkin
Am 16.06.2011 10:23, schrieb Wen Congyang:
> If rtl8139_can_receive() returns 1, it means that the nic can receive packet,
> otherwise, it means the nic can not receive packet.
>
> If !s->clock_enabled or !rtl8139_receiver_enabled(s), it means that the nic
> can not receive packet. So the return value should be 0, not 1.
>
> Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
>
> ---
> hw/rtl8139.c | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/hw/rtl8139.c b/hw/rtl8139.c
> index 2f8db58..9084678 100644
> --- a/hw/rtl8139.c
> +++ b/hw/rtl8139.c
> @@ -810,9 +810,9 @@ static int rtl8139_can_receive(VLANClientState *nc)
>
> /* Receive (drop) packets if card is disabled. */
> if (!s->clock_enabled)
> - return 1;
> + return 0;
> if (!rtl8139_receiver_enabled(s))
> - return 1;
> + return 0;
>
> if (rtl8139_cp_receiver_enabled(s)) {
> /* ??? Flow control not implemented in c+ mode.
NACK.
The old behaviour is clearly intentional. IIRC, can_receive() returning
0 means that the packet is kept in a queue and qemu tries to deliver it
later. For a disabled receiver, what I would expect is that it should
just drop the packets. This is what this code does by returning 1 in
can_receive() and then return -1 without processing the packet in receive().
That said, e1000 has a check for (s->mac_reg[RCTL] & E1000_RCTL_EN) in
can_receive. Should it be changed or is there a reason behind it? If
there is, we may as well change rtl8139, but it definitely needs a
better justification.
Kevin
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH] fix the return value of rtl8139_can_receive()
2011-06-16 10:39 ` Kevin Wolf
@ 2011-06-16 12:46 ` Michael S. Tsirkin
2011-06-17 1:33 ` [Qemu-devel] [PATCH] do not send packet to nic if the packet will be dropped by nic Wen Congyang
2011-06-17 1:49 ` [Qemu-devel] [PATCH] fix the return value of rtl8139_can_receive() Wen Congyang
1 sibling, 1 reply; 9+ messages in thread
From: Michael S. Tsirkin @ 2011-06-16 12:46 UTC (permalink / raw)
To: Kevin Wolf; +Cc: Aurelien Jarno, qemu-devel
On Thu, Jun 16, 2011 at 12:39:51PM +0200, Kevin Wolf wrote:
> Am 16.06.2011 10:23, schrieb Wen Congyang:
> > If rtl8139_can_receive() returns 1, it means that the nic can receive packet,
> > otherwise, it means the nic can not receive packet.
> >
> > If !s->clock_enabled or !rtl8139_receiver_enabled(s), it means that the nic
> > can not receive packet. So the return value should be 0, not 1.
> >
> > Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
> >
> > ---
> > hw/rtl8139.c | 4 ++--
> > 1 files changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/hw/rtl8139.c b/hw/rtl8139.c
> > index 2f8db58..9084678 100644
> > --- a/hw/rtl8139.c
> > +++ b/hw/rtl8139.c
> > @@ -810,9 +810,9 @@ static int rtl8139_can_receive(VLANClientState *nc)
> >
> > /* Receive (drop) packets if card is disabled. */
> > if (!s->clock_enabled)
> > - return 1;
> > + return 0;
> > if (!rtl8139_receiver_enabled(s))
> > - return 1;
> > + return 0;
> >
> > if (rtl8139_cp_receiver_enabled(s)) {
> > /* ??? Flow control not implemented in c+ mode.
>
> NACK.
>
> The old behaviour is clearly intentional. IIRC, can_receive() returning
> 0 means that the packet is kept in a queue and qemu tries to deliver it
> later. For a disabled receiver, what I would expect is that it should
> just drop the packets. This is what this code does by returning 1 in
> can_receive() and then return -1 without processing the packet in receive().
>
> That said, e1000 has a check for (s->mac_reg[RCTL] & E1000_RCTL_EN) in
> can_receive. Should it be changed or is there a reason behind it? If
> there is, we may as well change rtl8139, but it definitely needs a
> better justification.
>
> Kevin
I doubt it matters much. In practice returning 1 has the effect
that qemu will keep getting packets from host and wasting
CPU on dropping packets. This seems worse than packets
that should be dropped but aren't.
You do want to fix the comment above if you tweak this though.`
--
MST
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Qemu-devel] [PATCH] do not send packet to nic if the packet will be dropped by nic
2011-06-16 12:46 ` Michael S. Tsirkin
@ 2011-06-17 1:33 ` Wen Congyang
2011-06-20 9:10 ` Kevin Wolf
0 siblings, 1 reply; 9+ messages in thread
From: Wen Congyang @ 2011-06-17 1:33 UTC (permalink / raw)
To: Michael S. Tsirkin, Kevin Wolf, Aurelien Jarno, qemu-devel
If !s->clock_enabled or !rtl8139_receiver_enabled(s), it means that
the nic will drop all packets from host. So qemu will keep getting
packets from host and wasting CPU on dropping packets. This seems
worse than packets that should be dropped but aren't.
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
hw/rtl8139.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index 2f8db58..9084678 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -810,9 +810,9 @@ static int rtl8139_can_receive(VLANClientState *nc)
/* Receive (drop) packets if card is disabled. */
if (!s->clock_enabled)
- return 1;
+ return 0;
if (!rtl8139_receiver_enabled(s))
- return 1;
+ return 0;
if (rtl8139_cp_receiver_enabled(s)) {
/* ??? Flow control not implemented in c+ mode.
-- 1.7.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH] do not send packet to nic if the packet will be dropped by nic
2011-06-17 1:33 ` [Qemu-devel] [PATCH] do not send packet to nic if the packet will be dropped by nic Wen Congyang
@ 2011-06-20 9:10 ` Kevin Wolf
2011-06-20 9:40 ` Wen Congyang
0 siblings, 1 reply; 9+ messages in thread
From: Kevin Wolf @ 2011-06-20 9:10 UTC (permalink / raw)
To: Wen Congyang; +Cc: qemu-devel, Aurelien Jarno, Michael S. Tsirkin
Am 17.06.2011 03:33, schrieb Wen Congyang:
> If !s->clock_enabled or !rtl8139_receiver_enabled(s), it means that
> the nic will drop all packets from host. So qemu will keep getting
> packets from host and wasting CPU on dropping packets. This seems
> worse than packets that should be dropped but aren't.
>
> Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
Which bug does this change fix? I'm still not convinced that we should
do it.
> ---
> hw/rtl8139.c | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/hw/rtl8139.c b/hw/rtl8139.c
> index 2f8db58..9084678 100644
> --- a/hw/rtl8139.c
> +++ b/hw/rtl8139.c
> @@ -810,9 +810,9 @@ static int rtl8139_can_receive(VLANClientState *nc)
>
> /* Receive (drop) packets if card is disabled. */
This comment isn't accurate any more after applying the patch.
> if (!s->clock_enabled)
> - return 1;
> + return 0;
> if (!rtl8139_receiver_enabled(s))
> - return 1;
> + return 0;
>
> if (rtl8139_cp_receiver_enabled(s)) {
> /* ??? Flow control not implemented in c+ mode.
> -- 1.7.1
Kevin
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH] do not send packet to nic if the packet will be dropped by nic
2011-06-20 9:10 ` Kevin Wolf
@ 2011-06-20 9:40 ` Wen Congyang
2011-06-20 9:52 ` Kevin Wolf
0 siblings, 1 reply; 9+ messages in thread
From: Wen Congyang @ 2011-06-20 9:40 UTC (permalink / raw)
To: Kevin Wolf, Michael S. Tsirkin, Aurelien Jarno, qemu-devel
At 06/20/2011 05:10 PM, Kevin Wolf Write:
> Am 17.06.2011 03:33, schrieb Wen Congyang:
>> If !s->clock_enabled or !rtl8139_receiver_enabled(s), it means that
>> the nic will drop all packets from host. So qemu will keep getting
>> packets from host and wasting CPU on dropping packets. This seems
>> worse than packets that should be dropped but aren't.
>>
>> Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
>
> Which bug does this change fix? I'm still not convinced that we should
> do it.
Maybe not a bug fix now. As Michael S. Tsirkin said, if rtl8139_can_receive()
returns 1, qemu will keep getting packets from host and wasting CPU on
dropping packets. We can save CPU by return 0.
>
>> ---
>> hw/rtl8139.c | 4 ++--
>> 1 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/hw/rtl8139.c b/hw/rtl8139.c
>> index 2f8db58..9084678 100644
>> --- a/hw/rtl8139.c
>> +++ b/hw/rtl8139.c
>> @@ -810,9 +810,9 @@ static int rtl8139_can_receive(VLANClientState *nc)
>>
>> /* Receive (drop) packets if card is disabled. */
>
> This comment isn't accurate any more after applying the patch.
>
>> if (!s->clock_enabled)
>> - return 1;
>> + return 0;
>> if (!rtl8139_receiver_enabled(s))
>> - return 1;
>> + return 0;
>>
>> if (rtl8139_cp_receiver_enabled(s)) {
>> /* ??? Flow control not implemented in c+ mode.
>> -- 1.7.1
>
> Kevin
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH] do not send packet to nic if the packet will be dropped by nic
2011-06-20 9:40 ` Wen Congyang
@ 2011-06-20 9:52 ` Kevin Wolf
2011-06-20 11:13 ` Michael S. Tsirkin
0 siblings, 1 reply; 9+ messages in thread
From: Kevin Wolf @ 2011-06-20 9:52 UTC (permalink / raw)
To: Wen Congyang; +Cc: qemu-devel, Aurelien Jarno, Michael S. Tsirkin
Am 20.06.2011 11:40, schrieb Wen Congyang:
> At 06/20/2011 05:10 PM, Kevin Wolf Write:
>> Am 17.06.2011 03:33, schrieb Wen Congyang:
>>> If !s->clock_enabled or !rtl8139_receiver_enabled(s), it means that
>>> the nic will drop all packets from host. So qemu will keep getting
>>> packets from host and wasting CPU on dropping packets. This seems
>>> worse than packets that should be dropped but aren't.
>>>
>>> Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
>>
>> Which bug does this change fix? I'm still not convinced that we should
>> do it.
>
> Maybe not a bug fix now. As Michael S. Tsirkin said, if rtl8139_can_receive()
> returns 1, qemu will keep getting packets from host and wasting CPU on
> dropping packets. We can save CPU by return 0.
Don't we waste memory instead then because we leave the packets queued
indefinitely?
Kevin
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH] do not send packet to nic if the packet will be dropped by nic
2011-06-20 9:52 ` Kevin Wolf
@ 2011-06-20 11:13 ` Michael S. Tsirkin
0 siblings, 0 replies; 9+ messages in thread
From: Michael S. Tsirkin @ 2011-06-20 11:13 UTC (permalink / raw)
To: Kevin Wolf; +Cc: Aurelien Jarno, qemu-devel
On Mon, Jun 20, 2011 at 11:52:20AM +0200, Kevin Wolf wrote:
> Am 20.06.2011 11:40, schrieb Wen Congyang:
> > At 06/20/2011 05:10 PM, Kevin Wolf Write:
> >> Am 17.06.2011 03:33, schrieb Wen Congyang:
> >>> If !s->clock_enabled or !rtl8139_receiver_enabled(s), it means that
> >>> the nic will drop all packets from host. So qemu will keep getting
> >>> packets from host and wasting CPU on dropping packets. This seems
> >>> worse than packets that should be dropped but aren't.
> >>>
> >>> Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
> >>
> >> Which bug does this change fix? I'm still not convinced that we should
> >> do it.
> >
> > Maybe not a bug fix now. As Michael S. Tsirkin said, if rtl8139_can_receive()
> > returns 1, qemu will keep getting packets from host and wasting CPU on
> > dropping packets. We can save CPU by return 0.
>
> Don't we waste memory instead then because we leave the packets queued
> indefinitely?
>
> Kevin
Yes but the amount of wasted memory is bound from above
so this doesn't seem too bad to me ...
--
MST
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH] fix the return value of rtl8139_can_receive()
2011-06-16 10:39 ` Kevin Wolf
2011-06-16 12:46 ` Michael S. Tsirkin
@ 2011-06-17 1:49 ` Wen Congyang
1 sibling, 0 replies; 9+ messages in thread
From: Wen Congyang @ 2011-06-17 1:49 UTC (permalink / raw)
To: Kevin Wolf, Aurelien Jarno, qemu-devel, Michael S. Tsirkin,
Anthony Liguori
At 06/16/2011 06:39 PM, Kevin Wolf Write:
> Am 16.06.2011 10:23, schrieb Wen Congyang:
>> If rtl8139_can_receive() returns 1, it means that the nic can receive packet,
>> otherwise, it means the nic can not receive packet.
>>
>> If !s->clock_enabled or !rtl8139_receiver_enabled(s), it means that the nic
>> can not receive packet. So the return value should be 0, not 1.
>>
>> Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
>>
>> ---
>> hw/rtl8139.c | 4 ++--
>> 1 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/hw/rtl8139.c b/hw/rtl8139.c
>> index 2f8db58..9084678 100644
>> --- a/hw/rtl8139.c
>> +++ b/hw/rtl8139.c
>> @@ -810,9 +810,9 @@ static int rtl8139_can_receive(VLANClientState *nc)
>>
>> /* Receive (drop) packets if card is disabled. */
>> if (!s->clock_enabled)
>> - return 1;
>> + return 0;
>> if (!rtl8139_receiver_enabled(s))
>> - return 1;
>> + return 0;
>>
>> if (rtl8139_cp_receiver_enabled(s)) {
>> /* ??? Flow control not implemented in c+ mode.
>
> NACK.
>
> The old behaviour is clearly intentional. IIRC, can_receive() returning
> 0 means that the packet is kept in a queue and qemu tries to deliver it
> later. For a disabled receiver, what I would expect is that it should
> just drop the packets. This is what this code does by returning 1 in
> can_receive() and then return -1 without processing the packet in receive().
Thanks for your detailed explanation.
I know why can_receive() returns 1 now.
>
> That said, e1000 has a check for (s->mac_reg[RCTL] & E1000_RCTL_EN) in
> can_receive. Should it be changed or is there a reason behind it? If
This check is introduced in commit 4105de67 by Anthony Liguori.
He may know the reason.
> there is, we may as well change rtl8139, but it definitely needs a
> better justification.
>
> Kevin
>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2011-06-20 11:13 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-16 8:23 [Qemu-devel] [PATCH] fix the return value of rtl8139_can_receive() Wen Congyang
2011-06-16 10:39 ` Kevin Wolf
2011-06-16 12:46 ` Michael S. Tsirkin
2011-06-17 1:33 ` [Qemu-devel] [PATCH] do not send packet to nic if the packet will be dropped by nic Wen Congyang
2011-06-20 9:10 ` Kevin Wolf
2011-06-20 9:40 ` Wen Congyang
2011-06-20 9:52 ` Kevin Wolf
2011-06-20 11:13 ` Michael S. Tsirkin
2011-06-17 1:49 ` [Qemu-devel] [PATCH] fix the return value of rtl8139_can_receive() Wen Congyang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).