From: Dario Faggioli <dario.faggioli@citrix.com>
To: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: Marcus Granado <Marcus.Granado@eu.citrix.com>,
Keir Fraser <keir@xen.org>,
Ian Campbell <Ian.Campbell@citrix.com>,
Li Yechen <lccycc123@gmail.com>,
George Dunlap <george.dunlap@eu.citrix.com>,
Andrew Cooper <Andrew.Cooper3@citrix.com>,
Juergen Gross <juergen.gross@ts.fujitsu.com>,
xen-devel@lists.xen.org, Jan Beulich <JBeulich@suse.com>,
Justin Weaver <jtweaver@hawaii.edu>, Matt Wilson <msw@amazon.com>,
Elena Ufimtseva <ufimtseva@gmail.com>
Subject: Re: [PATCH v2 12/16] libxl: get and set soft affinity
Date: Fri, 15 Nov 2013 04:45:38 +0100 [thread overview]
Message-ID: <1384487138.16918.110.camel@Solace> (raw)
In-Reply-To: <21124.59400.960708.501641@mariner.uk.xensource.com>
[-- Attachment #1.1: Type: text/plain, Size: 7871 bytes --]
On gio, 2013-11-14 at 15:11 +0000, Ian Jackson wrote:
> > + if (libxl_cpu_bitmap_alloc(ctx, &ptr->cpumap_soft, 0)) {
> > + LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "allocating cpumap_soft");
> > + return NULL;
> > + }
>
> I went and looked at the error handling. Normally in libxl allocators
> can't fail but this one wants to do a hypercall to look up the max
> cpus.
>
Yep.
> But, pulling on the thread, I wonder if it would be better to do this
> error logging in libxl_cpu_bitmap_alloc rather than all the call
> sites.
>
Indeed. And the main problem I see here is that the logging mostly says
(and mine above is no exception, shame on me! :-P) "failed
allocating ...", which is not true. If something failed, it was the
retrieval of max cpus/nodes!
> (If we did that in principle we should introduce a new #define
> which allows applications to #ifdef out their own logging for this,
> but in practice the double-logging isn't likely to be a problem.)
>
Do we? Right now we don't have anything like that... Looks to me that
logging inside rather than outside the function is going to result in
the same amount of logging we have already, with the notable difference
that the "new" logging will be much more accurate.
> And looking at libxl_cpu_bitmap_alloc, it calls libxl_get_max_cpus and
> does something very odd with the return value: libxl_get_max_nodes
> ought to return a positive number or a libxl error code.
>
> So I went to look at libxl_get_max_nodes and it just returns whatever
> it got from libxc, which is definitely wrong!
>
I think I see what you mean. It's a weird path, since those xc calls
(xc_get_max_cpus() and xc_get_max_nodes()) either return a positive
number (if successful) or zero (if failing).
That's why, I think, libxl ended up checking for zero, as an indication
of failure, rather than "< 0" / libxl error code.
> Would you mind fixing this as part of this series ?
>
I don't, but I'm not sure I'm 100% getting how you think this should be
fixed. What about the following (compile tested only) patch?
Basically, I tried to modify libxl_get_max_{cpus,nodes} as you suggeste
above (making them return either a positive number or a libxl error
code). At the same time, I made them a bit more "robust" against what
could come from xc_get_max_{cpus,nodes}() (by checking for <= 0).
I also added the proper logging --stating correctly what is it that is
failing-- inside libxl_get_max_{cpus,nodes}() and removed it from the
callsites that had it (wrong).
If you're fine with that, I've got no problem in folding it in the
series.
Thanks and Regards,
Dario
---
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 0de1112..d3ab65e 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -616,10 +616,8 @@ static int cpupool_info(libxl__gc *gc,
info->n_dom = xcinfo->n_dom;
rc = libxl_cpu_bitmap_alloc(CTX, &info->cpumap, 0);
if (rc)
- {
- LOG(ERROR, "unable to allocate cpumap %d\n", rc);
goto out;
- }
+
memcpy(info->cpumap.map, xcinfo->cpumap, info->cpumap.size);
rc = 0;
@@ -4204,10 +4202,8 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t domid,
}
for (*nb_vcpu = 0; *nb_vcpu <= domaininfo.max_vcpu_id; ++*nb_vcpu, ++ptr) {
- if (libxl_cpu_bitmap_alloc(ctx, &ptr->cpumap, 0)) {
- LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "allocating cpumap");
+ if (libxl_cpu_bitmap_alloc(ctx, &ptr->cpumap, 0))
return NULL;
- }
if (xc_vcpu_getinfo(ctx->xch, domid, *nb_vcpu, &vcpuinfo) == -1) {
LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting vcpu info");
return NULL;
diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index 682f874..28e5b91 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -645,6 +645,47 @@ char *libxl_bitmap_to_hex_string(libxl_ctx *ctx, const libxl_bitmap *bitmap)
return q;
}
+inline int libxl_cpu_bitmap_alloc(libxl_ctx *ctx,
+ libxl_bitmap *cpumap,
+ int max_cpus)
+{
+ if (max_cpus < 0)
+ return ERROR_INVAL;
+
+ if (max_cpus == 0)
+ max_cpus = libxl_get_max_cpus(ctx);
+
+ if (max_cpus <= 0) {
+ LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
+ "failed to retrieve the maximum number of cpus");
+ return ERROR_FAIL;
+ }
+
+
+ /* This can't fail: no need to check and log */
+ return libxl_bitmap_alloc(ctx, cpumap, max_cpus);
+}
+
+int libxl_node_bitmap_alloc(libxl_ctx *ctx,
+ libxl_bitmap *nodemap,
+ int max_nodes)
+{
+ if (max_nodes < 0)
+ return ERROR_INVAL;
+
+ if (max_nodes == 0)
+ max_nodes = libxl_get_max_nodes(ctx);
+
+ if (max_nodes <= 0) {
+ LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
+ "failed to retrieve the maximum number of nodes");
+ return ERROR_FAIL;
+ }
+
+ /* This can't fail: no need to check and log */
+ return libxl_bitmap_alloc(ctx, nodemap, max_nodes);
+}
+
int libxl_nodemap_to_cpumap(libxl_ctx *ctx,
const libxl_bitmap *nodemap,
libxl_bitmap *cpumap)
@@ -713,12 +754,16 @@ int libxl_cpumap_to_nodemap(libxl_ctx *ctx,
int libxl_get_max_cpus(libxl_ctx *ctx)
{
- return xc_get_max_cpus(ctx->xch);
+ int max_cpus = xc_get_max_cpus(ctx->xch);
+
+ return max_cpus <= 0 ? ERROR_FAIL : max_cpus;
}
int libxl_get_max_nodes(libxl_ctx *ctx)
{
- return xc_get_max_nodes(ctx->xch);
+ int max_nodes = xc_get_max_nodes(ctx->xch);
+
+ return max_nodes <= 0 ? ERROR_FAIL : max_nodes;
}
int libxl__enum_from_string(const libxl_enum_string_table *t,
diff --git a/tools/libxl/libxl_utils.h b/tools/libxl/libxl_utils.h
index 7b84e6a..b11cf28 100644
--- a/tools/libxl/libxl_utils.h
+++ b/tools/libxl/libxl_utils.h
@@ -98,32 +98,12 @@ static inline int libxl_bitmap_cpu_valid(libxl_bitmap *bitmap, int bit)
#define libxl_for_each_set_bit(v, m) for (v = 0; v < (m).size * 8; v++) \
if (libxl_bitmap_test(&(m), v))
-static inline int libxl_cpu_bitmap_alloc(libxl_ctx *ctx, libxl_bitmap *cpumap,
- int max_cpus)
-{
- if (max_cpus < 0)
- return ERROR_INVAL;
- if (max_cpus == 0)
- max_cpus = libxl_get_max_cpus(ctx);
- if (max_cpus == 0)
- return ERROR_FAIL;
-
- return libxl_bitmap_alloc(ctx, cpumap, max_cpus);
-}
-
-static inline int libxl_node_bitmap_alloc(libxl_ctx *ctx,
- libxl_bitmap *nodemap,
- int max_nodes)
-{
- if (max_nodes < 0)
- return ERROR_INVAL;
- if (max_nodes == 0)
- max_nodes = libxl_get_max_nodes(ctx);
- if (max_nodes == 0)
- return ERROR_FAIL;
-
- return libxl_bitmap_alloc(ctx, nodemap, max_nodes);
-}
+int libxl_cpu_bitmap_alloc(libxl_ctx *ctx,
+ libxl_bitmap *cpumap,
+ int max_cpus);
+int libxl_node_bitmap_alloc(libxl_ctx *ctx,
+ libxl_bitmap *nodemap,
+ int max_nodes);
/* Populate cpumap with the cpus spanned by the nodes in nodemap */
int libxl_nodemap_to_cpumap(libxl_ctx *ctx,
--
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
[-- Attachment #2: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2013-11-15 3:45 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-13 19:10 [PATCH v2 00/16] Implement vcpu soft affinity for credit1 Dario Faggioli
2013-11-13 19:11 ` [PATCH v2 01/16] xl: match output of vcpu-list with pinning syntax Dario Faggioli
2013-11-14 10:50 ` George Dunlap
2013-11-14 11:11 ` Dario Faggioli
2013-11-14 11:14 ` George Dunlap
2013-11-14 11:13 ` Dario Faggioli
2013-11-14 12:44 ` Ian Jackson
2013-11-14 14:19 ` Ian Jackson
2013-11-13 19:11 ` [PATCH v2 02/16] xl: allow for node-wise specification of vcpu pinning Dario Faggioli
2013-11-14 11:02 ` George Dunlap
2013-11-14 14:24 ` Ian Jackson
2013-11-14 14:37 ` Dario Faggioli
2013-11-13 19:11 ` [PATCH v2 03/16] xl: implement and enable dryrun mode for `xl vcpu-pin' Dario Faggioli
2013-11-13 19:11 ` [PATCH v2 04/16] xl: test script for the cpumap parser (for vCPU pinning) Dario Faggioli
2013-11-13 19:11 ` [PATCH v2 05/16] xen: fix leaking of v->cpu_affinity_saved Dario Faggioli
2013-11-14 11:11 ` George Dunlap
2013-11-14 11:58 ` Dario Faggioli
2013-11-14 14:25 ` Ian Jackson
2013-11-13 19:11 ` [PATCH v2 06/16] xen: sched: make space for cpu_soft_affinity Dario Faggioli
2013-11-14 15:03 ` George Dunlap
2013-11-14 16:14 ` Dario Faggioli
2013-11-15 10:07 ` George Dunlap
2013-11-13 19:12 ` [PATCH v2 07/16] xen: sched: rename v->cpu_affinity into v->cpu_hard_affinity Dario Faggioli
2013-11-14 14:17 ` George Dunlap
2013-11-13 19:12 ` [PATCH v2 08/16] xen: derive NUMA node affinity from hard and soft CPU affinity Dario Faggioli
2013-11-14 15:21 ` George Dunlap
2013-11-14 16:30 ` Dario Faggioli
2013-11-15 10:52 ` George Dunlap
2013-11-15 14:17 ` Dario Faggioli
2013-11-13 19:12 ` [PATCH v2 09/16] xen: sched: DOMCTL_*vcpuaffinity works with hard and soft affinity Dario Faggioli
2013-11-14 14:42 ` George Dunlap
2013-11-14 16:21 ` Dario Faggioli
2013-11-13 19:12 ` [PATCH v2 10/16] xen: sched: use soft-affinity instead of domain's node-affinity Dario Faggioli
2013-11-14 15:30 ` George Dunlap
2013-11-15 0:39 ` Dario Faggioli
2013-11-15 11:23 ` George Dunlap
2013-11-13 19:12 ` [PATCH v2 11/16] libxc: get and set soft and hard affinity Dario Faggioli
2013-11-14 14:58 ` Ian Jackson
2013-11-14 16:18 ` Dario Faggioli
2013-11-14 15:38 ` George Dunlap
2013-11-14 16:41 ` Dario Faggioli
2013-11-13 19:12 ` [PATCH v2 12/16] libxl: get and set soft affinity Dario Faggioli
2013-11-13 19:16 ` Dario Faggioli
2013-11-14 15:11 ` Ian Jackson
2013-11-14 15:55 ` George Dunlap
2013-11-14 16:25 ` Ian Jackson
2013-11-15 5:13 ` Dario Faggioli
2013-11-15 12:02 ` George Dunlap
2013-11-15 17:29 ` Dario Faggioli
2013-11-15 3:45 ` Dario Faggioli [this message]
2013-11-13 19:12 ` [PATCH v2 13/16] xl: show soft affinity in `xl vcpu-list' Dario Faggioli
2013-11-14 15:12 ` Ian Jackson
2013-11-13 19:13 ` [PATCH v2 14/16] xl: enable setting soft affinity Dario Faggioli
2013-11-13 19:13 ` [PATCH v2 15/16] xl: enable for specifying node-affinity in the config file Dario Faggioli
2013-11-14 15:14 ` Ian Jackson
2013-11-14 16:12 ` Dario Faggioli
2013-11-13 19:13 ` [PATCH v2 16/16] libxl: automatic NUMA placement affects soft affinity Dario Faggioli
2013-11-14 15:17 ` Ian Jackson
2013-11-14 16:11 ` Dario Faggioli
2013-11-14 16:03 ` George Dunlap
2013-11-14 16:48 ` Dario Faggioli
2013-11-14 17:49 ` George Dunlap
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=1384487138.16918.110.camel@Solace \
--to=dario.faggioli@citrix.com \
--cc=Andrew.Cooper3@citrix.com \
--cc=Ian.Campbell@citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=JBeulich@suse.com \
--cc=Marcus.Granado@eu.citrix.com \
--cc=george.dunlap@eu.citrix.com \
--cc=jtweaver@hawaii.edu \
--cc=juergen.gross@ts.fujitsu.com \
--cc=keir@xen.org \
--cc=lccycc123@gmail.com \
--cc=msw@amazon.com \
--cc=ufimtseva@gmail.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).