[PATCHES] messaging iov / recvfrom
Michael Adam
obnox at samba.org
Tue May 27 02:50:12 MDT 2014
On 2014-05-27 at 10:27 +0200, Volker Lendecke wrote:
> On Tue, May 27, 2014 at 09:51:10AM +0200, Andreas Schneider wrote:
> > On Monday 26 May 2014 17:07:44 Michael Adam wrote:
> > > Oops, there was a bug in the first patch.
> > > Sorry for posting prematurely...
> > > Attaching a fixed version.
> >
> > > diff --git a/source3/lib/unix_msg/unix_msg.c
> > > b/source3/lib/unix_msg/unix_msg.c index 956e3a3..bcabd28 100644
> > > --- a/source3/lib/unix_msg/unix_msg.c
> > > +++ b/source3/lib/unix_msg/unix_msg.c
> > > @@ -233,8 +233,22 @@ static void unix_dgram_recv_handler(struct poll_watch
> > > *w, int fd, short events,>
> > > {
> > >
> > > struct unix_dgram_ctx *ctx = (struct unix_dgram_ctx *)private_data;
> > > ssize_t received;
> > >
> > > + struct msghdr msg;
> > > + struct iovec iov;
> > > +
> > > + iov = (struct iovec) {
> > > + .iov_base = (void *)ctx->recv_buf,
> > > + .iov_len = ctx->max_msg,
> > > + };
> > > +
> >
> > Please use ZERO_STRUCT(msg) here!
>
> Why? This adds an additional call to memset. This construct
> zeros out everything that is not explicitly initialized
> anyway. So it is equivalent to a ZERO_STRUCT(msg) and two
> explicit assignments and gives the compiler the chance to
> use more efficient instructions.
I have to add that I had ZERO_STRUCT in the first
incarnation of the patch, and Volker pointed out
to me that this can be spared by using the new
struct initializers. I guess this is a good optimization
for a potentially hot code path, and we should make
it common practice in samba code (where appropriate).
Equivalently, we can initialize to zero in the
definition "struct iovec iov = {};" and later on
use only the isolated assignments "iov.iov_base = ...",
but I think the above variant has the advantage
of having it all in one place and more visbly
separated.
Cheers - Michael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20140527/6767646b/attachment.pgp>
More information about the samba-technical
mailing list