[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v4 07/11] libqos: Added basic virtqueue support
From: |
Stefan Hajnoczi |
Subject: |
Re: [Qemu-devel] [PATCH v4 07/11] libqos: Added basic virtqueue support to virtio implementation |
Date: |
Wed, 13 Aug 2014 18:27:40 +0100 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
On Tue, Aug 12, 2014 at 01:41:52PM +0200, Marc Marí wrote:
> + /* Check power of 2 */
> + aux = vq->size;
> + while ((aux & 1) != 0) {
> + aux = aux >> 1;
> + }
> + g_assert_cmpint(aux, !=, 1);
Power of 2 can be tested like this without a while loop:
g_assert_cmpint(vq->size & (vq->size - 1), ==, 0)
> +void qvring_init(const QGuestAllocator *alloc, QVirtQueue *vq, uint64_t addr)
> +{
> + int i;
> +
> + vq->desc = addr;
> + vq->avail = vq->desc + vq->size*sizeof(QVRingDesc);
> + vq->used = (uint64_t)((vq->avail + sizeof(uint16_t) * (3 + vq->size)
> + +vq->align-1) & ~(vq->align - 1));
> +
> + for (i = 0; i < vq->size-1; i++) {
> + /* vq->desc[i].addr */
> + writew(vq->desc+(16*i), 0);
> + /* vq->desc[i].next */
> + writew(vq->desc+(16*i)+14, i+1);
> + }
Please use space between operators:
writew(vq->desc + (16 * i) + 14, i + 1)
This applies to all patches.
> +void qvirtqueue_kick(const QVirtioBus *bus, QVirtioDevice *d, QVirtQueue *vq,
> + uint32_t
> free_head)
> +{
> + /* vq->avail->idx */
> + uint16_t idx = readl(vq->avail+2);
> +
> + /* vq->avail->ring[idx % vq->size] */
> + writel(vq->avail+4+(2*(idx % vq->size)), free_head);
If you want to use typed pointers you can. It will make the code nicer
to read, just be careful never to dereference them and only to access
through writel()/readl():
typedef struct {
uint16_t foo; /* Forgot what these fields are called and didn't check */
uint16_t bar;
uint16_t ring[];
} VirtioAvail;
writel(&vq->avail.ring[idx % vq->size], free_head);
Now it looks more like normal C and the compiler is doing the address
calculations for us.
pgpq1gDU5HrUR.pgp
Description: PGP signature
- [Qemu-devel] [PATCH v4 03/11] libqtest: add QTEST_LOG for debugging qtest testcases, (continued)
- [Qemu-devel] [PATCH v4 03/11] libqtest: add QTEST_LOG for debugging qtest testcases, Marc Marí, 2014/08/12
- [Qemu-devel] [PATCH v4 04/11] libqos: Correct mask to align size to PAGE_SIZE in malloc-pc, Marc Marí, 2014/08/12
- [Qemu-devel] [PATCH v4 05/11] libqos: Change free function called in malloc, Marc Marí, 2014/08/12
- [Qemu-devel] [PATCH v4 06/11] virtio-blk: Correct bug in support for flexible descriptor layout, Marc Marí, 2014/08/12
- [Qemu-devel] [PATCH v4 07/11] libqos: Added basic virtqueue support to virtio implementation, Marc Marí, 2014/08/12
- Re: [Qemu-devel] [PATCH v4 07/11] libqos: Added basic virtqueue support to virtio implementation,
Stefan Hajnoczi <=
- [Qemu-devel] [PATCH v4 08/11] libqos: Added indirect descriptor support to virtio implementation, Marc Marí, 2014/08/12
- [Qemu-devel] [PATCH v4 09/11] libqos: Added test case for configuration changes in virtio-blk test, Marc Marí, 2014/08/12
- [Qemu-devel] [PATCH v4 10/11] libqos: Added MSI-X support, Marc Marí, 2014/08/12
- [Qemu-devel] [PATCH v4 11/11] libqos: Added EVENT_IDX support, Marc Marí, 2014/08/12