1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
|
Network performance regression with vde_switch
I've noticed a significant network performance regression when using vde_switch, starting about one week ago (10/05/2012); before that date, I used to get about 1.5 Gbits host to guest, but now I can only get about 320 Mbits; I didn't find any modification in net/vde.*, just in hw/virtio*.
My command line:
qemu-system-i386 -cdrom /bpd/bpd.iso -m 512 -boot d -enable-kvm \
-localtime -ctrl-grab -usbdevice tablet \
-device virtio-net-pci,mac=52:54:00:18:01:01,netdev=vde0,tx=bh,ioeventfd=on,x-txburst=32 \
-netdev vde,id=vde0 -vga std -tb-size 2M -cpu host -clock unix
My host runs a kernel 3.6.1 and my guest runs a kernel 3.5.4; the same problem happens with other host and guest versions, too.
I know there are better ways of running a guest, but using vde I get a cleaner environment in the host (just one tun/tap interface to manage...), which is quite good when running some accademic experiments.
Interestingly, at the same time I've noticed a performance enhancement of about 25~30 % when using a tun/tap interface, bridged or not.
Thank you, very much.
Edivaldo de Araujo Pereira
On Fri, Oct 12, 2012 at 05:34:23PM -0000, Edivaldo de Araujo Pereira wrote:
> I've noticed a significant network performance regression when using
> vde_switch, starting about one week ago (10/05/2012); before that date,
> I used to get about 1.5 Gbits host to guest, but now I can only get
> about 320 Mbits; I didn't find any modification in net/vde.*, just in
> hw/virtio*.
>
> My command line:
> qemu-system-i386 -cdrom /bpd/bpd.iso -m 512 -boot d -enable-kvm \
> -localtime -ctrl-grab -usbdevice tablet \
> -device virtio-net-pci,mac=52:54:00:18:01:01,netdev=vde0,tx=bh,ioeventfd=on,x-txburst=32 \
> -netdev vde,id=vde0 -vga std -tb-size 2M -cpu host -clock unix
>
> My host runs a kernel 3.6.1 and my guest runs a kernel 3.5.4; the same
> problem happens with other host and guest versions, too.
>
> I know there are better ways of running a guest, but using vde I get a
> cleaner environment in the host (just one tun/tap interface to
> manage...), which is quite good when running some accademic experiments.
>
> Interestingly, at the same time I've noticed a performance enhancement
> of about 25~30 % when using a tun/tap interface, bridged or not.
Hi Edivaldo,
It would be great if you can help find the commit that caused this
regression.
The basic process is:
1. Identify a QEMU release or git tree that gives you 1.5 Gbit/s.
2. Double-check that qemu.git/master suffers reduced performance.
3. git bisect start <bad> <good>
where <bad> and <good> are the git commits that show differing
performance (for example, bad=HEAD good=v1.1.0)
Then git will step through the commit history and ask you to test at
each step. (This is a binary search so even finding regressions that
happened many commits ago requires few steps.)
You can read more about git-bisect(1) here:
http://git-scm.com/book/en/Git-Tools-Debugging-with-Git#Binary-Search
http://www.kernel.org/pub/software/scm/git/docs/git-bisect.html
The end result is the commit introduced the regression. Please post
what you find!
Stefan
Hi Stefan,
Thank you, very much for taking the time to help me, and excuse me for not seeing your answer early...
I've run the procedure you pointed me out, and the result is:
0d8d7690850eb0cf2b2b60933cf47669a6b6f18f is the first bad commit
commit 0d8d7690850eb0cf2b2b60933cf47669a6b6f18f
Author: Amit Shah <email address hidden>
Date: Tue Sep 25 00:05:15 2012 +0530
virtio: Introduce virtqueue_get_avail_bytes()
The current virtqueue_avail_bytes() is oddly named, and checks if a
particular number of bytes are available in a vq. A better API is to
fetch the number of bytes available in the vq, and let the caller do
what's interesting with the numbers.
Introduce virtqueue_get_avail_bytes(), which returns the number of bytes
for buffers marked for both, in as well as out. virtqueue_avail_bytes()
is made a wrapper over this new function.
Signed-off-by: Amit Shah <email address hidden>
Signed-off-by: Michael S. Tsirkin <email address hidden>
:040000 040000 1a58b06a228651cf844621d9ee2f49b525e36c93 e09ea66ce7f6874921670b6aeab5bea921a5227d M hw
I tried to revert that patch in the latest version, but it obviously didnt work; I'm trying to figure out the problem, but I don't know very well the souce code, so I think it's going to take some time. For now, it's all I could do.
Thank you, again.
Edivaldo
On Mon, Oct 15, 2012 at 09:46:06PM -0000, Edivaldo de Araujo Pereira wrote:
> Hi Stefan,
>
> Thank you, very much for taking the time to help me, and excuse me for
> not seeing your answer early...
>
> I've run the procedure you pointed me out, and the result is:
>
> 0d8d7690850eb0cf2b2b60933cf47669a6b6f18f is the first bad commit
> commit 0d8d7690850eb0cf2b2b60933cf47669a6b6f18f
> Author: Amit Shah <email address hidden>
> Date: Tue Sep 25 00:05:15 2012 +0530
>
> virtio: Introduce virtqueue_get_avail_bytes()
>
> The current virtqueue_avail_bytes() is oddly named, and checks if a
> particular number of bytes are available in a vq. A better API is to
> fetch the number of bytes available in the vq, and let the caller do
> what's interesting with the numbers.
>
> Introduce virtqueue_get_avail_bytes(), which returns the number of bytes
> for buffers marked for both, in as well as out. virtqueue_avail_bytes()
> is made a wrapper over this new function.
>
> Signed-off-by: Amit Shah <email address hidden>
> Signed-off-by: Michael S. Tsirkin <email address hidden>
>
> :040000 040000 1a58b06a228651cf844621d9ee2f49b525e36c93
> e09ea66ce7f6874921670b6aeab5bea921a5227d M hw
>
> I tried to revert that patch in the latest version, but it obviously
> didnt work; I'm trying to figure out the problem, but I don't know very
> well the souce code, so I think it's going to take some time. For now,
> it's all I could do.
After git-bisect(1) completes it is good to sanity-check the result by
manually testing 0d8d7690850eb0cf2b2b60933cf47669a6b6f18f^ (the commit
just before the bad commit) and 0d8d7690850eb0cf2b2b60933cf47669a6b6f18f
(the bad commit).
This will verify that the commit indeed introduces the regression. I
suggest doing this just to be sure that you've found the bad commit.
Regarding this commit, I notice two things:
1. We will now loop over all vring descriptors because we calculate the
total in/out length instead of returning early as soon as we see
there is enough space. Maybe this makes a difference, although I'm a
little surprised you see such a huge regression.
2. The comparision semantics have changed from:
(in_total += vring_desc_len(desc_pa, i)) >= in_bytes
to:
(in_bytes && in_bytes < in_total)
Notice that virtqueue_avail_bytes() now returns 0 when in_bytes ==
in_total. Previously, it would return 1. Perhaps we are starving or
delaying I/O due to this comparison change. You can easily change
'<' to '<=' to see if it fixes the issue.
Stefan
Hi Stefan
I finally could revert that commit in the latest snapshot; problem was I needed to revert one later, that modified hw/virtio-serial-bus.c accordingly; after that reversion, the regression in network performance went completely away; this confirms my previous identification of the commit that caused it.
Additionally, I tested your last suggestion, to change '<' to '<=', and that didn't help; the problem was still there.
By the way, the performance gain I observed ,of about 25~30 % when using a tun/tap, was in fact just apparent, because it was result of a greater use of cpu, so it was achieved only when the host was idle; when I stress the host, with a lot of concurrent guests generating traffic, there is no gain at all.
Just for confirmation, this is the performance I get with latest snapshot (8b4a3df8081f3e6f1061ed5cbb303ad623ade66b) running wget in the guest:
$ wget -O /dev/null http://172.18.1.1/bpd.iso
--2012-10-16 09:10:18-- http://172.18.1.1/bpd.iso
Connecting to 172.18.1.1:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 358979584 (342M) [application/x-iso9660-image]
Saving to: `/dev/null'
100%[======================================================>] 358.979.584 29,7M/s in 11s
2012-10-16 09:10:29 (30,3 MB/s) - `/dev/null' saved [358979584/358979584]
The same wget, using the same snapshot, but with that commit reverted is:
$ wget -O /dev/null http://172.18.1.1/bpd.iso
--2012-10-16 09:15:12-- http://172.18.1.1/bpd.iso
Connecting to 172.18.1.1:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 358979584 (342M) [application/x-iso9660-image]
Saving to: `/dev/null'
100%[======================================================>] 358.979.584 180M/s in 1,9s
2012-10-16 09:15:14 (180 MB/s) - `/dev/null' saved [358979584/358979584]
So, as I can see, there is no doubt: that commit is the culprit; as it was intended to be related just to the quality of the source code (at least as I can see), but implied in such a cost in performance, I think it would be better to revert it.
Thank you very much, again.
Edivaldo
On Tue, Oct 16, 2012 at 2:23 PM, Edivaldo de Araujo Pereira
<email address hidden> wrote:
> Hi Stefan
>
> I finally could revert that commit in the latest snapshot; problem was I
> needed to revert one later, that modified hw/virtio-serial-bus.c
> accordingly; after that reversion, the regression in network performance
> went completely away; this confirms my previous identification of the
> commit that caused it.
>
> Additionally, I tested your last suggestion, to change '<' to '<=', and
> that didn't help; the problem was still there.
>
> By the way, the performance gain I observed ,of about 25~30 % when using
> a tun/tap, was in fact just apparent, because it was result of a greater
> use of cpu, so it was achieved only when the host was idle; when I
> stress the host, with a lot of concurrent guests generating traffic,
> there is no gain at all.
>
> Just for confirmation, this is the performance I get with latest
> snapshot (8b4a3df8081f3e6f1061ed5cbb303ad623ade66b) running wget in the
> guest:
>
> $ wget -O /dev/null http://172.18.1.1/bpd.iso
> --2012-10-16 09:10:18-- http://172.18.1.1/bpd.iso
> Connecting to 172.18.1.1:80... connected.
> HTTP request sent, awaiting response... 200 OK
> Length: 358979584 (342M) [application/x-iso9660-image]
> Saving to: `/dev/null'
> 100%[======================================================>] 358.979.584 29,7M/s in 11s
> 2012-10-16 09:10:29 (30,3 MB/s) - `/dev/null' saved [358979584/358979584]
>
> The same wget, using the same snapshot, but with that commit reverted
> is:
>
> $ wget -O /dev/null http://172.18.1.1/bpd.iso
> --2012-10-16 09:15:12-- http://172.18.1.1/bpd.iso
> Connecting to 172.18.1.1:80... connected.
> HTTP request sent, awaiting response... 200 OK
> Length: 358979584 (342M) [application/x-iso9660-image]
> Saving to: `/dev/null'
> 100%[======================================================>] 358.979.584 180M/s in 1,9s
> 2012-10-16 09:15:14 (180 MB/s) - `/dev/null' saved [358979584/358979584]
>
> So, as I can see, there is no doubt: that commit is the culprit; as it
> was intended to be related just to the quality of the source code (at
> least as I can see), but implied in such a cost in performance, I think
> it would be better to revert it.
Hi Amit,
Edivaldo has identified the following commit responsible for a network
performance regression he sees:
commit 0d8d7690850eb0cf2b2b60933cf47669a6b6f18f
Author: Amit Shah <email address hidden>
Date: Tue Sep 25 00:05:15 2012 +0530
virtio: Introduce virtqueue_get_avail_bytes()
I guess this is because we now iterate the entire descriptor chain to
check available space instead of returning early.
Do you want to propose a patch to fix it?
Stefan
Dear Amit,
On a suggestion of Stefan, I've already tested the modification in you patch, and it didn't work; but for confirmation I tested it once again, on the latest snapshot; same result, that is, it didn't work; the problem is still there.
I didn't take enough time to uderstand the code, so unfortunately I fear there is not much I could do to solve the problem, apart from trying your suggestions. But I'll try to spend a little more time on it, until we find a solution.
Thank you very much.
Edivaldo
--- Em seg, 22/10/12, Amit Shah <email address hidden> escreveu:
> De: Amit Shah <email address hidden>
> Assunto: Re: [Qemu-devel] [Bug 1066055] Re: Network performance regression with vde_switch
> Para: "Stefan Hajnoczi" <email address hidden>
> Cc: "Bug 1066055" <email address hidden>, <email address hidden>, <email address hidden>
> Data: Segunda-feira, 22 de Outubro de 2012, 4:18
> On (Tue) 16 Oct 2012 [09:48:09],
> Stefan Hajnoczi wrote:
> > On Mon, Oct 15, 2012 at 09:46:06PM -0000, Edivaldo de
> Araujo Pereira wrote:
> > > Hi Stefan,
> > >
> > > Thank you, very much for taking the time to help
> me, and excuse me for
> > > not seeing your answer early...
> > >
> > > I've run the procedure you pointed me out, and the
> result is:
> > >
> > > 0d8d7690850eb0cf2b2b60933cf47669a6b6f18f is the
> first bad commit
> > > commit 0d8d7690850eb0cf2b2b60933cf47669a6b6f18f
> > > Author: Amit Shah <email address hidden>
> > > Date: Tue Sep 25 00:05:15 2012
> +0530
> > >
> > > virtio: Introduce
> virtqueue_get_avail_bytes()
> > >
> > > The current
> virtqueue_avail_bytes() is oddly named, and checks if a
> > > particular number of bytes
> are available in a vq. A better API is to
> > > fetch the number of bytes
> available in the vq, and let the caller do
> > > what's interesting with
> the numbers.
> > >
> > > Introduce
> virtqueue_get_avail_bytes(), which returns the number of
> bytes
> > > for buffers marked for
> both, in as well as out. virtqueue_avail_bytes()
> > > is made a wrapper over
> this new function.
> > >
> > > Signed-off-by: Amit Shah
> <email address hidden>
> > > Signed-off-by: Michael S.
> Tsirkin <email address hidden>
> > >
> > > :040000 040000
> 1a58b06a228651cf844621d9ee2f49b525e36c93
> > > e09ea66ce7f6874921670b6aeab5bea921a5227d M
> hw
> > >
> > > I tried to revert that patch in the latest
> version, but it obviously
> > > didnt work; I'm trying to figure out the problem,
> but I don't know very
> > > well the souce code, so I think it's going to take
> some time. For now,
> > > it's all I could do.
> >
> > After git-bisect(1) completes it is good to
> sanity-check the result by
> > manually testing
> 0d8d7690850eb0cf2b2b60933cf47669a6b6f18f^ (the commit
> > just before the bad commit) and
> 0d8d7690850eb0cf2b2b60933cf47669a6b6f18f
> > (the bad commit).
> >
> > This will verify that the commit indeed introduces the
> regression. I
> > suggest doing this just to be sure that you've found
> the bad commit.
> >
> > Regarding this commit, I notice two things:
> >
> > 1. We will now loop over all vring descriptors because
> we calculate the
> > total in/out length instead of returning
> early as soon as we see
> > there is enough space. Maybe this
> makes a difference, although I'm a
> > little surprised you see such a huge
> regression.
> >
> > 2. The comparision semantics have changed from:
> >
> > (in_total +=
> vring_desc_len(desc_pa, i)) >= in_bytes
> >
> > to:
> >
> > (in_bytes && in_bytes <
> in_total)
> >
> > Notice that virtqueue_avail_bytes() now
> returns 0 when in_bytes ==
> > in_total. Previously, it would
> return 1. Perhaps we are starving or
> > delaying I/O due to this comparison
> change. You can easily change
> > '<' to '<=' to see if it fixes the
> issue.
>
> Hi Edivaldo,
>
> Can you try the following patch, that will confirm if it's
> the
> descriptor walk or the botched compare that's causing the
> regression.
>
> Thanks,
>
> diff --git a/hw/virtio.c b/hw/virtio.c
> index 6821092..bb08ed8 100644
> --- a/hw/virtio.c
> +++ b/hw/virtio.c
> @@ -406,8 +406,8 @@ int virtqueue_avail_bytes(VirtQueue *vq,
> unsigned int in_bytes,
> unsigned int in_total, out_total;
>
> virtqueue_get_avail_bytes(vq,
> &in_total, &out_total);
> - if ((in_bytes && in_bytes <
> in_total)
> - || (out_bytes &&
> out_bytes < out_total)) {
> + if ((in_bytes && in_bytes <=
> in_total)
> + || (out_bytes &&
> out_bytes <= out_total)) {
> return 1;
> }
> return 0;
>
>
> Amit
>
On Mon, Oct 22, 2012 at 06:50:00AM -0700, Edivaldo de Araujo Pereira wrote:
> I didn't take enough time to uderstand the code, so unfortunately I fear there is not much I could do to solve the problem, apart from trying your suggestions. But I'll try to spend a little more time on it, until we find a solution.
I've thought a little about how to approach this. Amit, here's a brain
dump:
The simplest solution is to make virtqueue_avail_bytes() use the old
behavior of stopping early.
However, I wonder if we can actually *improve* performance of existing
code by changing virtio-net.c:virtio_net_receive(). The intuition is
that calling virtio_net_has_buffers() (internally calls
virtqueue_avail_bytes()) followed by virtqueue_pop() is suboptimal
because we're repeatedly traversing the descriptor chain.
We can get rid of this repetition. A side-effect of this is that we no
longer need to call virtqueue_avail_bytes() from virtio-net.c. Here's
how:
The common case in virtio_net_receive() is that we have buffers and they
are large enough for the received packet. So to optimize for this case:
1. Take the VirtQueueElement off the vring but don't increment
last_avail_idx yet. (This is essentially a "peek" operation.)
2. If there is an error or we drop the packet because the
VirtQueueElement is too small, just bail out and we'll grab the same
VirtQueueElement again next time.
3. When we've committed filling in this VirtQueueElement, increment
last_avail_idx. This is the point of no return.
Essentially we're splitting pop() into peek() and consume(). Peek()
grabs the VirtQueueElement but does not increment last_avail_idx.
Consume() simply increments last_avail_idx and maybe the EVENT_IDX
optimization stuff.
Whether this will improve performance, I'm not sure. Perhaps
virtio_net_has_buffers() pulls most descriptors into the CPU's cache and
following up with virtqueue_pop() is very cheap already. But the idea
here is to avoid the virtio_net_has_buffers() because we'll find out
soon enough when we try to pop :).
Another approach would be to drop virtio_net_has_buffers() but continue
to use virtqueue_pop(). We'd keep the same VirtQueueElem stashed in
VirtIONet across virtio_net_receive() calls in the case where we drop
the packet. I don't like this approach very much though because it gets
tricky when the guest modifies the vring memory, resets the virtio
device, etc across calls.
Stefan
On Thu, Nov 1, 2012 at 5:07 PM, Michael S. Tsirkin <email address hidden> wrote:
> Commit 0d8d7690850eb0cf2b2b60933cf47669a6b6f18f introduced
> a regression in virtio-net performance because it looks
> into the ring aggressively while we really only care
> about a single packet worth of buffers.
> To fix, add parameters limiting lookahead, and
> use in virtqueue_avail_bytes.
>
> Signed-off-by: Michael S. Tsirkin <email address hidden>
> Reported-by: Edivaldo de Araujo Pereira <email address hidden>
Nice, much simpler than the ideas I had.
Reviewed-by: Stefan Hajnoczi <email address hidden>
On Fri, Nov 2, 2012 at 3:48 PM, Michael S. Tsirkin <email address hidden> wrote:
> On Fri, Nov 02, 2012 at 11:18:18AM +0100, Stefan Hajnoczi wrote:
>> On Thu, Nov 1, 2012 at 5:07 PM, Michael S. Tsirkin <email address hidden> wrote:
>> > Commit 0d8d7690850eb0cf2b2b60933cf47669a6b6f18f introduced
>> > a regression in virtio-net performance because it looks
>> > into the ring aggressively while we really only care
>> > about a single packet worth of buffers.
>> > To fix, add parameters limiting lookahead, and
>> > use in virtqueue_avail_bytes.
>> >
>> > Signed-off-by: Michael S. Tsirkin <email address hidden>
>> > Reported-by: Edivaldo de Araujo Pereira <email address hidden>
>>
>> Nice, much simpler than the ideas I had.
>>
>> Reviewed-by: Stefan Hajnoczi <email address hidden>
>
> Anthony could you apply this out of band please so this stops
> biting people?
Especially for the 1.3 release so that we don't have a virtio
performance regression.
Stefan
Dear friends,
Please excuse-me for not reporting earlier... I confirm that the patch by Michael really fixes the problem I've reported. The regression has gone away when I used it, so I think it is good to be applied.
Thanks,
Edivaldo de Araújo Pereira
--- Em ter, 27/11/12, Michael S. Tsirkin <email address hidden> escreveu:
> De: Michael S. Tsirkin <email address hidden>
> Assunto: Re: [PATCH] virtio: limit avail bytes lookahead
> Para: "Amit Shah" <email address hidden>
> Cc: "Stefan Hajnoczi" <email address hidden>, "Edivaldo de Araujo Pereira" <email address hidden>, <email address hidden>, "Anthony Liguori" <email address hidden>, "Bug 1066055" <email address hidden>
> Data: Terça-feira, 27 de Novembro de 2012, 8:25
> On Thu, Nov 01, 2012 at 06:07:21PM
> +0200, Michael S. Tsirkin wrote:
> > Commit 0d8d7690850eb0cf2b2b60933cf47669a6b6f18f
> introduced
> > a regression in virtio-net performance because it
> looks
> > into the ring aggressively while we really only care
> > about a single packet worth of buffers.
> > To fix, add parameters limiting lookahead, and
> > use in virtqueue_avail_bytes.
> >
> > Signed-off-by: Michael S. Tsirkin <email address hidden>
> > Reported-by: Edivaldo de Araujo Pereira <email address hidden>
>
> Ping.
> Anthony - going to apply this?
>
>
> > ---
> >
> > Edivaldo could you please confirm this fixes
> regression?
> >
> > diff --git a/hw/virtio-serial-bus.c
> b/hw/virtio-serial-bus.c
> > index d20bd8b..a761cdc 100644
> > --- a/hw/virtio-serial-bus.c
> > +++ b/hw/virtio-serial-bus.c
> > @@ -297,7 +297,7 @@ size_t
> virtio_serial_guest_ready(VirtIOSerialPort *port)
> > if (use_multiport(port->vser)
> && !port->guest_connected) {
> > return 0;
> > }
> > - virtqueue_get_avail_bytes(vq,
> &bytes, NULL);
> > + virtqueue_get_avail_bytes(vq,
> &bytes, NULL, UINT_MAX, 0);
> > return bytes;
> > }
> >
> > diff --git a/hw/virtio.c b/hw/virtio.c
> > index ec8b7d8..f40a8c5 100644
> > --- a/hw/virtio.c
> > +++ b/hw/virtio.c
> > @@ -336,7 +336,8 @@ static unsigned
> virtqueue_next_desc(hwaddr desc_pa,
> > }
> >
> > void virtqueue_get_avail_bytes(VirtQueue *vq,
> unsigned int *in_bytes,
> > -
>
> unsigned int *out_bytes)
> > +
>
> unsigned int *out_bytes,
> > +
>
> unsigned max_in_bytes, unsigned
> max_out_bytes)
> > {
> > unsigned int idx;
> > unsigned int total_bufs, in_total,
> out_total;
> > @@ -385,6 +386,9 @@ void
> virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int
> *in_bytes,
> > } else
> {
> >
> out_total += vring_desc_len(desc_pa, i);
> > }
> > + if (in_total
> >= max_in_bytes && out_total >= max_out_bytes)
> {
> > +
> goto done;
> > + }
> > } while ((i =
> virtqueue_next_desc(desc_pa, i, max)) != max);
> >
> > if (!indirect)
> > @@ -392,6 +396,7 @@ void
> virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int
> *in_bytes,
> > else
> >
> total_bufs++;
> > }
> > +done:
> > if (in_bytes) {
> > *in_bytes =
> in_total;
> > }
> > @@ -405,12 +410,8 @@ int
> virtqueue_avail_bytes(VirtQueue *vq, unsigned int in_bytes,
> > {
> > unsigned int in_total, out_total;
> >
> > - virtqueue_get_avail_bytes(vq,
> &in_total, &out_total);
> > - if ((in_bytes && in_bytes <
> in_total)
> > - || (out_bytes &&
> out_bytes < out_total)) {
> > - return 1;
> > - }
> > - return 0;
> > + virtqueue_get_avail_bytes(vq,
> &in_total, &out_total, in_bytes, out_bytes);
> > + return in_bytes <= in_total
> && out_bytes <= out_total;
> > }
> >
> > void virtqueue_map_sg(struct iovec *sg, hwaddr
> *addr,
> > diff --git a/hw/virtio.h b/hw/virtio.h
> > index ac482be..1278328 100644
> > --- a/hw/virtio.h
> > +++ b/hw/virtio.h
> > @@ -150,7 +150,8 @@ int virtqueue_pop(VirtQueue *vq,
> VirtQueueElement *elem);
> > int virtqueue_avail_bytes(VirtQueue *vq, unsigned
> int in_bytes,
> >
> unsigned int
> out_bytes);
> > void virtqueue_get_avail_bytes(VirtQueue *vq,
> unsigned int *in_bytes,
> > -
>
> unsigned int *out_bytes);
> > +
>
> unsigned int *out_bytes,
> > +
>
> unsigned max_in_bytes, unsigned
> max_out_bytes);
> >
> > void virtio_notify(VirtIODevice *vdev, VirtQueue
> *vq);
> >
>
"Michael S. Tsirkin" <email address hidden> writes:
> On Thu, Nov 01, 2012 at 06:07:21PM +0200, Michael S. Tsirkin wrote:
>> Commit 0d8d7690850eb0cf2b2b60933cf47669a6b6f18f introduced
>> a regression in virtio-net performance because it looks
>> into the ring aggressively while we really only care
>> about a single packet worth of buffers.
>> To fix, add parameters limiting lookahead, and
>> use in virtqueue_avail_bytes.
>>
>> Signed-off-by: Michael S. Tsirkin <email address hidden>
>> Reported-by: Edivaldo de Araujo Pereira <email address hidden>
>
> Ping.
> Anthony - going to apply this?
Yes, I've got it queued now. In the future, please top post patches.
Regards,
Anthony Liguori
>
>
>> ---
>>
>> Edivaldo could you please confirm this fixes regression?
>>
>> diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
>> index d20bd8b..a761cdc 100644
>> --- a/hw/virtio-serial-bus.c
>> +++ b/hw/virtio-serial-bus.c
>> @@ -297,7 +297,7 @@ size_t virtio_serial_guest_ready(VirtIOSerialPort *port)
>> if (use_multiport(port->vser) && !port->guest_connected) {
>> return 0;
>> }
>> - virtqueue_get_avail_bytes(vq, &bytes, NULL);
>> + virtqueue_get_avail_bytes(vq, &bytes, NULL, UINT_MAX, 0);
>> return bytes;
>> }
>>
>> diff --git a/hw/virtio.c b/hw/virtio.c
>> index ec8b7d8..f40a8c5 100644
>> --- a/hw/virtio.c
>> +++ b/hw/virtio.c
>> @@ -336,7 +336,8 @@ static unsigned virtqueue_next_desc(hwaddr desc_pa,
>> }
>>
>> void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
>> - unsigned int *out_bytes)
>> + unsigned int *out_bytes,
>> + unsigned max_in_bytes, unsigned max_out_bytes)
>> {
>> unsigned int idx;
>> unsigned int total_bufs, in_total, out_total;
>> @@ -385,6 +386,9 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
>> } else {
>> out_total += vring_desc_len(desc_pa, i);
>> }
>> + if (in_total >= max_in_bytes && out_total >= max_out_bytes) {
>> + goto done;
>> + }
>> } while ((i = virtqueue_next_desc(desc_pa, i, max)) != max);
>>
>> if (!indirect)
>> @@ -392,6 +396,7 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
>> else
>> total_bufs++;
>> }
>> +done:
>> if (in_bytes) {
>> *in_bytes = in_total;
>> }
>> @@ -405,12 +410,8 @@ int virtqueue_avail_bytes(VirtQueue *vq, unsigned int in_bytes,
>> {
>> unsigned int in_total, out_total;
>>
>> - virtqueue_get_avail_bytes(vq, &in_total, &out_total);
>> - if ((in_bytes && in_bytes < in_total)
>> - || (out_bytes && out_bytes < out_total)) {
>> - return 1;
>> - }
>> - return 0;
>> + virtqueue_get_avail_bytes(vq, &in_total, &out_total, in_bytes, out_bytes);
>> + return in_bytes <= in_total && out_bytes <= out_total;
>> }
>>
>> void virtqueue_map_sg(struct iovec *sg, hwaddr *addr,
>> diff --git a/hw/virtio.h b/hw/virtio.h
>> index ac482be..1278328 100644
>> --- a/hw/virtio.h
>> +++ b/hw/virtio.h
>> @@ -150,7 +150,8 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem);
>> int virtqueue_avail_bytes(VirtQueue *vq, unsigned int in_bytes,
>> unsigned int out_bytes);
>> void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
>> - unsigned int *out_bytes);
>> + unsigned int *out_bytes,
>> + unsigned max_in_bytes, unsigned max_out_bytes);
>>
>> void virtio_notify(VirtIODevice *vdev, VirtQueue *vq);
>>
"Michael S. Tsirkin" <email address hidden> writes:
> On Thu, Nov 29, 2012 at 06:34:46PM +0530, Amit Shah wrote:
>> On (Wed) 28 Nov 2012 [23:53:08], Michael S. Tsirkin wrote:
>> > On Tue, Nov 27, 2012 at 06:25:04PM +0200, Michael S. Tsirkin wrote:
>> > > On Thu, Nov 01, 2012 at 06:07:21PM +0200, Michael S. Tsirkin wrote:
>> > > > Commit 0d8d7690850eb0cf2b2b60933cf47669a6b6f18f introduced
>> > > > a regression in virtio-net performance because it looks
>> > > > into the ring aggressively while we really only care
>> > > > about a single packet worth of buffers.
>> > > > To fix, add parameters limiting lookahead, and
>> > > > use in virtqueue_avail_bytes.
>> > > >
>> > > > Signed-off-by: Michael S. Tsirkin <email address hidden>
>> > > > Reported-by: Edivaldo de Araujo Pereira <email address hidden>
>> > >
>> > > Ping.
>> > > Anthony - going to apply this?
>> >
>> > virtio rng was added since so naturally build broke.
>> > Here's a patch on top to fix it up. I never used virtio rng before so
>> > could not test at this hour, but it does fix the build.
>> >
>> > I'll take a look at how to test it tomorrow but any
>> > info would be appreciated.
>> > Amit could you pls review?
>>
>> Looks fine, I assume you will send a v2 of the patch to Anthony?
>>
>> Amit
>
>
> Anthony volunteered to test this so there will only be v2 if he sees
> problems.
I need a Signed-off-by so why don't you just go ahead and send a v2 and
I'll test that.
Regards,
Anthony Liguori
The fix had been included here:
https://git.qemu.org/?p=qemu.git;a=commitdiff;h=e1f7b4812eab992de46c98b
... so closing this bug now.
|