|
From: | Avi Kivity |
Subject: | [Qemu-devel] Re: [PATCH 1/4] Add a scatter-gather list type and accessors |
Date: | Wed, 04 Feb 2009 22:30:05 +0200 |
User-agent: | Thunderbird 2.0.0.19 (X11/20090105) |
Anthony Liguori wrote:
Avi Kivity wrote:Scatter-gather lists are used extensively in dma-capable devices; a single data structure allows more code reuse later on. diff --git a/dma-helpers.c b/dma-helpers.c new file mode 100644 index 0000000..315834e --- /dev/null +++ b/dma-helpers.c @@ -0,0 +1,29 @@Needs copyright/license.
Sure.Is it possible to have a blanket license for files which don't have explicit terms? I don't much like boilerplate.
+#include "dma.h" + + +void qemu_sglist_init(QEMUSGList *qsg, int alloc_hint) +{ + qsg->sg = qemu_malloc(alloc_hint * sizeof(ScatterGatherEntry));Would be nice to check for malloc failures and fail gracefully at least.
Do you mean an exit(1)? If so we could just put it in qemu_malloc().Propagation is usually not possible since hardware is not expected to run out of memory. It will also be a never-tested code path.
+void qemu_sglist_add(QEMUSGList *qsg, target_phys_addr_t base, + target_phys_addr_t len) +{ + if (qsg->nsg == qsg->nalloc) { + qsg->nalloc = 2 * qsg->nalloc + 1;Do you really want exponential growth verses linear growth? The sg lists should be relatively small so linear growth should be fine.
I expect this to trigger rarely since the allocation hint should suffice nearly 100% of the time. But in case we miss, it's better to reallocate as little as possible.
(what I really want is std::vector<>) -- I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
[Prev in Thread] | Current Thread | [Next in Thread] |