From: Wei Liu <Wei.Liu2@citrix.com>
To: Ian Campbell <Ian.Campbell@citrix.com>
Cc: wei.liu2@citrix.com, "xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Subject: Re: [PATCH V2] Switch from select() to poll() in xenconsoled's IO loop.
Date: Fri, 4 Jan 2013 16:38:35 +0000 [thread overview]
Message-ID: <1357317515.18503.38.camel@iceland> (raw)
In-Reply-To: <1357315716.14291.65.camel@zakaz.uk.xensource.com>
On Fri, 2013-01-04 at 16:08 +0000, Ian Campbell wrote:
> > +static int initialize_pollfd_arrays(void)
> > +{
> > + fds = (struct pollfd *)
> > + malloc(sizeof(struct pollfd) * DEFAULT_ARRAY_SIZE);
> > + if (!fds)
> > + goto fail;
> > + fd_to_pollfd = (struct pollfd **)
> > + malloc(sizeof(struct pollfd *) * DEFAULT_ARRAY_SIZE);
> > + if (!fd_to_pollfd)
> > + goto fail;
> > + memset(fds, 0, sizeof(struct pollfd) * DEFAULT_ARRAY_SIZE);
> > + memset(fd_to_pollfd, 0, sizeof(struct pollfd *) * DEFAULT_ARRAY_SIZE);
> > + current_array_size = DEFAULT_ARRAY_SIZE;
> > + return 0;
> > +fail:
> > + free(fds);
> > + free(fd_to_pollfd);
> > + return -ENOMEM;
> > +}
> > +
> > +static void destroy_pollfd_arrays(void)
> > +{
> > + free(fds);
> > + free(fd_to_pollfd);
> > + current_array_size = 0;
> > +}
> > +
> > +static void set_fds(int fd, short events)
> > +{
> > + if (current_array_size < fd+1) {
> > + struct pollfd *p1 = NULL;
> > + struct pollfd **p2 = NULL;
> > + unsigned int newsize = current_array_size;
> > +
> > + do { newsize += GROWTH_LENGTH; } while (newsize < fd+1);
>
> Steal #define ROUNDUP from tools/libxc/xc_linux_osdep.c.
> > +
> > + p1 = realloc(fds, sizeof(struct pollfd)*newsize);
> > + if (!p1)
> > + goto fail;
> > + fds = p1;
> > +
> > + p2 = realloc(fd_to_pollfd, sizeof(struct pollfd *)*newsize);
>
> realloc(NULL, ...) is the same as malloc() so I think you can initialise
> current_array_size to 0 and the various pointers to NULL and avoid the
> need for initialize_pollfd_arrays -- i.e. it will just grow from 0 on
> the first use here.
>
Huh, good idea.
> > for (;;) {
> > struct domain *d, *n;
> > - int max_fd = -1;
> > - struct timeval timeout;
> > + int poll_timeout; /* timeout in milliseconds */
> > struct timespec ts;
> > long long now, next_timeout = 0;
> >
> > - FD_ZERO(&readfds);
> > - FD_ZERO(&writefds);
> > + reset_fds();
> >
> > - FD_SET(xs_fileno(xs), &readfds);
> > - max_fd = MAX(xs_fileno(xs), max_fd);
> > + set_fds(xs_fileno(xs), POLLIN);
>
> Do you know, or can you track, the maximum fd over time?
> If you can then you could likely make use of automatic stack allocations
> (struct pollfd fds[max_fd]) and therefore avoid the pain of manual
> memory management.
Stack size is subject to system setting. Typically it is limited to 8MB
in Linux as shown by `ulimit -s`. This is actually very small compared
to heap space.
Of course we can make xenconsoled special among all the processes... But
that's not ideal.
Wei.
> Not sure what the semantics of those are inside a for loop where max_fd
> can change but worst case you could put the content of the loop into a
> function.
>
> Ian.
>
next prev parent reply other threads:[~2013-01-04 16:38 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-03 17:14 [PATCH] Switch to poll in xenconsoled's io loop Wei Liu
2013-01-03 18:22 ` Mats Petersson
2013-01-04 12:30 ` Wei Liu
2013-01-04 15:58 ` [PATCH V2] Switch from select() to poll() in xenconsoled's IO loop Wei Liu
2013-01-04 16:08 ` Ian Campbell
2013-01-04 16:38 ` Wei Liu [this message]
2013-01-04 16:51 ` Mats Petersson
2013-01-04 17:17 ` [PATCH V3] " Wei Liu
2013-01-07 10:20 ` Ian Campbell
2013-01-07 12:12 ` Wei Liu
2013-01-07 12:16 ` Ian Campbell
2013-01-07 14:28 ` [PATCH V4] " Wei Liu
2013-01-07 14:39 ` Ian Campbell
2013-01-07 14:44 ` Wei Liu
2013-01-07 14:52 ` Ian Jackson
2013-01-07 14:41 ` Mats Petersson
2013-01-07 15:01 ` Wei Liu
2013-01-07 15:06 ` Mats Petersson
2013-01-07 15:17 ` Ian Campbell
2013-01-07 15:16 ` Ian Campbell
2013-01-07 15:24 ` Wei Liu
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=1357317515.18503.38.camel@iceland \
--to=wei.liu2@citrix.com \
--cc=Ian.Campbell@citrix.com \
--cc=xen-devel@lists.xen.org \
/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).