slirp: replace qemu_notify_event() with a callback

Introduce a SlirpCb callback to kick the main io-thread.

Add an intermediary sodrop() function that will call SlirpCb.notify
callback when sbdrop() returns true.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
This commit is contained in:
Marc-André Lureau 2019-01-17 15:43:43 +04:00 committed by Samuel Thibault
parent f6e5aa366f
commit c21d959440
7 changed files with 19 additions and 6 deletions

View File

@ -205,6 +205,7 @@ static const SlirpCb slirp_cb = {
.timer_mod = net_slirp_timer_mod, .timer_mod = net_slirp_timer_mod,
.register_poll_fd = net_slirp_register_poll_fd, .register_poll_fd = net_slirp_register_poll_fd,
.unregister_poll_fd = net_slirp_unregister_poll_fd, .unregister_poll_fd = net_slirp_unregister_poll_fd,
.notify = qemu_notify_event,
}; };
static int net_slirp_init(NetClientState *peer, const char *model, static int net_slirp_init(NetClientState *peer, const char *model,

View File

@ -31,6 +31,8 @@ typedef struct SlirpCb {
void (*register_poll_fd)(int fd); void (*register_poll_fd)(int fd);
/* Unregister a fd */ /* Unregister a fd */
void (*unregister_poll_fd)(int fd); void (*unregister_poll_fd)(int fd);
/* Kick the io-thread, to signal that new events may be processed */
void (*notify)(void);
} SlirpCb; } SlirpCb;

View File

@ -17,7 +17,7 @@ sbfree(struct sbuf *sb)
free(sb->sb_data); free(sb->sb_data);
} }
void bool
sbdrop(struct sbuf *sb, int num) sbdrop(struct sbuf *sb, int num)
{ {
int limit = sb->sb_datalen / 2; int limit = sb->sb_datalen / 2;
@ -34,8 +34,10 @@ sbdrop(struct sbuf *sb, int num)
sb->sb_rptr -= sb->sb_datalen; sb->sb_rptr -= sb->sb_datalen;
if (sb->sb_cc < limit && sb->sb_cc + num >= limit) { if (sb->sb_cc < limit && sb->sb_cc + num >= limit) {
qemu_notify_event(); return true;
} }
return false;
} }
void void

View File

@ -21,7 +21,7 @@ struct sbuf {
}; };
void sbfree(struct sbuf *); void sbfree(struct sbuf *);
void sbdrop(struct sbuf *, int); bool sbdrop(struct sbuf *, int);
void sbreserve(struct sbuf *, int); void sbreserve(struct sbuf *, int);
void sbappend(struct socket *, struct mbuf *); void sbappend(struct socket *, struct mbuf *);
void sbcopy(struct sbuf *, int, int, char *); void sbcopy(struct sbuf *, int, int, char *);

View File

@ -928,3 +928,10 @@ void sotranslate_accept(struct socket *so)
break; break;
} }
} }
void sodrop(struct socket *s, int num)
{
if (sbdrop(&s->so_snd, num)) {
s->slirp->cb->notify();
}
}

View File

@ -156,6 +156,7 @@ int soreadbuf(struct socket *so, const char *buf, int size);
void sotranslate_out(struct socket *, struct sockaddr_storage *); void sotranslate_out(struct socket *, struct sockaddr_storage *);
void sotranslate_in(struct socket *, struct sockaddr_storage *); void sotranslate_in(struct socket *, struct sockaddr_storage *);
void sotranslate_accept(struct socket *); void sotranslate_accept(struct socket *);
void sodrop(struct socket *, int num);
#endif /* SLIRP_SOCKET_H */ #endif /* SLIRP_SOCKET_H */

View File

@ -506,7 +506,7 @@ findso:
SEQ_GT(ti->ti_ack, tp->t_rtseq)) SEQ_GT(ti->ti_ack, tp->t_rtseq))
tcp_xmit_timer(tp, tp->t_rtt); tcp_xmit_timer(tp, tp->t_rtt);
acked = ti->ti_ack - tp->snd_una; acked = ti->ti_ack - tp->snd_una;
sbdrop(&so->so_snd, acked); sodrop(so, acked);
tp->snd_una = ti->ti_ack; tp->snd_una = ti->ti_ack;
m_free(m); m_free(m);
@ -1118,10 +1118,10 @@ trimthenstep6:
} }
if (acked > so->so_snd.sb_cc) { if (acked > so->so_snd.sb_cc) {
tp->snd_wnd -= so->so_snd.sb_cc; tp->snd_wnd -= so->so_snd.sb_cc;
sbdrop(&so->so_snd, (int )so->so_snd.sb_cc); sodrop(so, (int)so->so_snd.sb_cc);
ourfinisacked = 1; ourfinisacked = 1;
} else { } else {
sbdrop(&so->so_snd, acked); sodrop(so, acked);
tp->snd_wnd -= acked; tp->snd_wnd -= acked;
ourfinisacked = 0; ourfinisacked = 0;
} }