From: Amos Kong <akong@redhat.com>
To: qemu-devel@nongnu.org
Cc: amit.shah@redhat.com, varadgautam@gmail.com, anthony@codemonkey.ws
Subject: [Qemu-devel] [PATCH RFC 2/2] rng-egd: introduce a parameter to set buffer size
Date: Mon, 9 Dec 2013 22:10:13 +0800 [thread overview]
Message-ID: <1386598213-8156-3-git-send-email-akong@redhat.com> (raw)
In-Reply-To: <1386598213-8156-1-git-send-email-akong@redhat.com>
This patch makes the buffer size configurable, the max
buffer size is 65536.
-object rng-egd,chardev=chr0,id=rng0,buf_size=1024
Signed-off-by: Amos Kong <akong@redhat.com>
---
backends/rng-egd.c | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/backends/rng-egd.c b/backends/rng-egd.c
index d317c61..4e5ba18 100644
--- a/backends/rng-egd.c
+++ b/backends/rng-egd.c
@@ -18,7 +18,7 @@
#define TYPE_RNG_EGD "rng-egd"
#define RNG_EGD(obj) OBJECT_CHECK(RngEgd, (obj), TYPE_RNG_EGD)
-#define BUFFER_SIZE 65536
+#define MAX_BUFFER_SIZE 65536
typedef struct RngEgd
{
@@ -31,6 +31,7 @@ typedef struct RngEgd
GSList *requests;
void *opaque;
size_t req_size;
+ uint32_t buf_size;
} RngEgd;
typedef struct RngRequest
@@ -154,9 +155,16 @@ static void rng_egd_request_entropy(RngBackend *b, size_t size,
}
int total_size = get_total_buf_size(s);
+ int buf_size;
- while (total_size < BUFFER_SIZE) {
- int add_size = MIN(BUFFER_SIZE - total_size, 255);
+ if (s->buf_size != 0) {
+ buf_size = MIN(s->buf_size, MAX_BUFFER_SIZE);
+ } else {
+ buf_size = MAX_BUFFER_SIZE;
+ }
+
+ while (total_size < buf_size) {
+ int add_size = MIN(buf_size - total_size, 255);
total_size += add_size;
rng_egd_append_request(b, add_size, receive_entropy, opaque);
}
@@ -253,6 +261,15 @@ static void rng_egd_opened(RngBackend *b, Error **errp)
NULL, s);
}
+static void rng_egd_set_buf_size(Object *obj, const char *value, Error **errp)
+{
+ RngBackend *b = RNG_BACKEND(obj);
+ RngEgd *s = RNG_EGD(b);
+
+ s->buf_size = atoi(value);
+ assert(s->buf_size > 0);
+}
+
static void rng_egd_set_chardev(Object *obj, const char *value, Error **errp)
{
RngBackend *b = RNG_BACKEND(obj);
@@ -281,6 +298,7 @@ static void rng_egd_init(Object *obj)
object_property_add_str(obj, "chardev",
rng_egd_get_chardev, rng_egd_set_chardev,
NULL);
+ object_property_add_str(obj, "buf_size", NULL, rng_egd_set_buf_size, NULL);
}
static void rng_egd_finalize(Object *obj)
--
1.8.3.1
next prev parent reply other threads:[~2013-12-09 14:10 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-09 14:10 [Qemu-devel] [PATCH RFC 0/2] improve rng-egd perf Amos Kong
2013-12-09 14:10 ` [Qemu-devel] [PATCH RFC 1/2] rng-egd: improve egd backend performance Amos Kong
2013-12-16 16:36 ` Amit Shah
2013-12-16 23:19 ` Anthony Liguori
2013-12-17 5:52 ` Amit Shah
2013-12-17 7:03 ` Amos Kong
2013-12-17 7:47 ` Markus Armbruster
2013-12-17 10:32 ` Amit Shah
2013-12-18 10:05 ` Giuseppe Scrivano
2013-12-24 9:58 ` Varad Gautam
2014-01-08 9:14 ` Amos Kong
2014-01-08 16:23 ` Amit Shah
2014-01-10 2:30 ` Amos Kong
2013-12-09 14:10 ` Amos Kong [this message]
2013-12-10 16:58 ` [Qemu-devel] [PATCH RFC 2/2] rng-egd: introduce a parameter to set buffer size Eric Blake
2013-12-12 2:55 ` Amos Kong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1386598213-8156-3-git-send-email-akong@redhat.com \
--to=akong@redhat.com \
--cc=amit.shah@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=qemu-devel@nongnu.org \
--cc=varadgautam@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).