[systemd-commits] 4 commits - .gitignore src/libsystemd src/shared src/test
David Herrmann
dvdhrm at kemper.freedesktop.org
Fri Jul 11 07:44:01 PDT 2014
.gitignore | 1 +
src/libsystemd/sd-event/sd-event.c | 3 ++-
src/shared/macro.h | 6 ++++++
src/shared/ring.c | 18 ++++++++++--------
src/shared/ring.h | 18 ++++++++++--------
src/test/test-ring.c | 2 +-
6 files changed, 30 insertions(+), 18 deletions(-)
New commits:
commit eea1aadb5bb3fc121e8f66332249d05e5437debc
Author: David Herrmann <dh.herrmann at gmail.com>
Date: Fri Jul 11 16:35:37 2014 +0200
gitignore: ignore .swp files
vim places them in the source-tree while editing files. Ignore them.
diff --git a/.gitignore b/.gitignore
index 3cf7006..31cd8f8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,6 +8,7 @@
*.plist
*.pyc
*.stamp
+*.swp
*.trs
*~
.deps/
commit b63c8d4f0364457b0ead8793504012bb7113974f
Author: David Herrmann <dh.herrmann at gmail.com>
Date: Thu Jul 10 00:47:23 2014 +0200
sd-event: always call epoll_ctl() on mask-updates if edge-triggered
A call to sd_event_source_set_io_events() skipps calling into the kernel
if the new event-mask matches the old one. This is safe for
level-triggered sources as the kernel moves them onto the ready-list
automatically if events change. However, edge-triggered sources might not
be on the ready-list even though events are present.
A call to sd_event_source_set_io_events() with EPOLLET set might thus be
used to just move the io-source onto the ready-list so the next poll
will return it again. This is very useful to avoid starvation in
priority-based event queues.
Imagine a read() loop on an edge-triggered fd. If we cannot read data fast
enough to drain the receive queue, we might decide to skip reading for now
and schedule it for later. On edge-triggered io-sources we have to make
sure it's put on the ready-list so the next dispatch-round will return it
again if it's still the highest priority task. We could make sd-event
handle edge-triggered sources directly and allow marking them ready again.
However, it's much simpler to let the kernel do that for now via
EPOLL_CTL_MOD.
diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
index 53f1904..a21f7db 100644
--- a/src/libsystemd/sd-event/sd-event.c
+++ b/src/libsystemd/sd-event/sd-event.c
@@ -1282,7 +1282,8 @@ _public_ int sd_event_source_set_io_events(sd_event_source *s, uint32_t events)
assert_return(s->event->state != SD_EVENT_FINISHED, -ESTALE);
assert_return(!event_pid_changed(s->event), -ECHILD);
- if (s->io.events == events)
+ /* edge-triggered updates are never skipped, so we can reset edges */
+ if (s->io.events == events && !(events & EPOLLET))
return 0;
if (s->enabled != SD_EVENT_OFF) {
commit 1ca5fd003f5d3ffb32db581cb8d82d0721b5b12d
Author: David Herrmann <dh.herrmann at gmail.com>
Date: Wed Jul 9 20:20:46 2014 +0200
shared: fix coding-style for ring-buffer implementation
We use "typedef struct Ring Ring" with camel-case for internal objects.
So rename "struct ring" to "Ring".
diff --git a/src/shared/ring.c b/src/shared/ring.c
index 8ae6123..309075e 100644
--- a/src/shared/ring.c
+++ b/src/shared/ring.c
@@ -29,14 +29,16 @@
#define RING_MASK(_r, _v) ((_v) & ((_r)->size - 1))
-void ring_flush(struct ring *r) {
+void ring_flush(Ring *r) {
assert(r);
r->start = 0;
r->used = 0;
}
-void ring_clear(struct ring *r) {
+void ring_clear(Ring *r) {
+ assert(r);
+
free(r->buf);
zero(*r);
}
@@ -53,7 +55,7 @@ void ring_clear(struct ring *r) {
* size_t iov_len;
* };
*/
-size_t ring_peek(struct ring *r, struct iovec *vec) {
+size_t ring_peek(Ring *r, struct iovec *vec) {
assert(r);
if (r->used == 0) {
@@ -80,7 +82,7 @@ size_t ring_peek(struct ring *r, struct iovec *vec) {
* at most @size bytes. If the ring buffer size is smaller, copy less bytes and
* return the number of bytes copied.
*/
-size_t ring_copy(struct ring *r, void *buf, size_t size) {
+size_t ring_copy(Ring *r, void *buf, size_t size) {
size_t l;
assert(r);
@@ -106,7 +108,7 @@ size_t ring_copy(struct ring *r, void *buf, size_t size) {
* Resize ring-buffer to size @nsize. @nsize must be a power-of-2, otherwise
* ring operations will behave incorrectly.
*/
-static int ring_resize(struct ring *r, size_t nsize) {
+static int ring_resize(Ring *r, size_t nsize) {
uint8_t *buf;
size_t l;
@@ -140,7 +142,7 @@ static int ring_resize(struct ring *r, size_t nsize) {
* resizes the buffer if it is too small. It returns -ENOMEM on OOM and 0 on
* success.
*/
-static int ring_grow(struct ring *r, size_t add) {
+static int ring_grow(Ring *r, size_t add) {
size_t need;
assert(r);
@@ -165,7 +167,7 @@ static int ring_grow(struct ring *r, size_t add) {
* Push @len bytes from @u8 into the ring buffer. The buffer is resized if it
* is too small. -ENOMEM is returned on OOM, 0 on success.
*/
-int ring_push(struct ring *r, const void *u8, size_t size) {
+int ring_push(Ring *r, const void *u8, size_t size) {
int err;
size_t pos, l;
@@ -197,7 +199,7 @@ int ring_push(struct ring *r, const void *u8, size_t size) {
* Remove @len bytes from the start of the ring-buffer. Note that we protect
* against overflows so removing more bytes than available is safe.
*/
-void ring_pull(struct ring *r, size_t size) {
+void ring_pull(Ring *r, size_t size) {
assert(r);
if (size > r->used)
diff --git a/src/shared/ring.h b/src/shared/ring.h
index 6b12530..1210aab 100644
--- a/src/shared/ring.h
+++ b/src/shared/ring.h
@@ -27,7 +27,9 @@
#include <string.h>
#include <sys/uio.h>
-struct ring {
+typedef struct Ring Ring;
+
+struct Ring {
uint8_t *buf; /* buffer or NULL */
size_t size; /* actual size of @buf */
size_t start; /* start position of ring */
@@ -35,25 +37,25 @@ struct ring {
};
/* flush buffer so it is empty again */
-void ring_flush(struct ring *r);
+void ring_flush(Ring *r);
/* flush buffer, free allocated data and reset to initial state */
-void ring_clear(struct ring *r);
+void ring_clear(Ring *r);
/* get pointers to buffer data and their length */
-size_t ring_peek(struct ring *r, struct iovec *vec);
+size_t ring_peek(Ring *r, struct iovec *vec);
/* copy data into external linear buffer */
-size_t ring_copy(struct ring *r, void *buf, size_t size);
+size_t ring_copy(Ring *r, void *buf, size_t size);
/* push data to the end of the buffer */
-int ring_push(struct ring *r, const void *u8, size_t size);
+int ring_push(Ring *r, const void *u8, size_t size);
/* pull data from the front of the buffer */
-void ring_pull(struct ring *r, size_t size);
+void ring_pull(Ring *r, size_t size);
/* return size of occupied buffer in bytes */
-static inline size_t ring_get_size(struct ring *r)
+static inline size_t ring_get_size(Ring *r)
{
return r->used;
}
diff --git a/src/test/test-ring.c b/src/test/test-ring.c
index 8808158..5e4efdb 100644
--- a/src/test/test-ring.c
+++ b/src/test/test-ring.c
@@ -31,7 +31,7 @@
static void test_ring(void) {
static const char buf[8192];
- struct ring r;
+ Ring r;
size_t l;
struct iovec vec[2];
int s;
commit 7df23077e45e55a6fc15eb99fe2ae439678e37e0
Author: David Herrmann <dh.herrmann at gmail.com>
Date: Mon Jun 30 15:43:40 2014 +0200
shared: add MIN3 macro
This is like MIN but evaluates 3 arguments. We already have MAX3, so add
the equivalent for MIN.
diff --git a/src/shared/macro.h b/src/shared/macro.h
index 32cf714..70c5fb5 100644
--- a/src/shared/macro.h
+++ b/src/shared/macro.h
@@ -154,6 +154,12 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) {
_a < _b ? _a : _b; \
})
+#define MIN3(x,y,z) \
+ __extension__ ({ \
+ typeof(x) _c = MIN(x,y); \
+ MIN(_c, z); \
+ })
+
#define LESS_BY(A,B) \
__extension__ ({ \
typeof(A) _A = (A); \
More information about the systemd-commits
mailing list