* [PATCH] x86: refine nr_sockets calculation
@ 2015-12-04 16:29 Jan Beulich
2015-12-04 17:27 ` Andrew Cooper
0 siblings, 1 reply; 2+ messages in thread
From: Jan Beulich @ 2015-12-04 16:29 UTC (permalink / raw)
To: xen-devel; +Cc: Andrew Cooper, Keir Fraser
[-- Attachment #1: Type: text/plain, Size: 2325 bytes --]
The previous variant didn't work for non-contiguous socket numbers.
Reported-by: Ed Swierk <eswierk@skyportsystems.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Tested-by: Ed Swierk <eswierk@skyportsystems.com>
--- a/xen/arch/x86/mpparse.c
+++ b/xen/arch/x86/mpparse.c
@@ -89,19 +89,14 @@ void __init set_nr_cpu_ids(unsigned int
void __init set_nr_sockets(void)
{
- /*
- * Count the actual cpus in the socket 0 and use it to calculate nr_sockets
- * so that the latter will be always >= the actual socket number in the
- * system even when APIC IDs from MP table are too sparse.
- */
- unsigned int cpus = bitmap_weight(phys_cpu_present_map.mask,
- boot_cpu_data.x86_max_cores *
- boot_cpu_data.x86_num_siblings);
-
- if ( cpus == 0 )
- cpus = 1;
-
- nr_sockets = DIV_ROUND_UP(num_processors + disabled_cpus, cpus);
+ nr_sockets = last_physid(phys_cpu_present_map)
+ / boot_cpu_data.x86_max_cores
+ / boot_cpu_data.x86_num_siblings + 1;
+ if (disabled_cpus)
+ nr_sockets += (disabled_cpus - 1)
+ / boot_cpu_data.x86_max_cores
+ / boot_cpu_data.x86_num_siblings + 1;
+ printk(XENLOG_DEBUG "nr_sockets: %u\n", nr_sockets);
}
/*
--- a/xen/include/asm-x86/mpspec.h
+++ b/xen/include/asm-x86/mpspec.h
@@ -43,6 +43,19 @@ typedef struct physid_mask physid_mask_t
#define physid_isset(physid, map) test_bit(physid, (map).mask)
#define physid_test_and_set(physid, map) test_and_set_bit(physid, (map).mask)
+#define first_physid(map) find_first_bit((map).mask, \
+ MAX_APICS)
+#define next_physid(id, map) find_next_bit((map).mask, \
+ MAX_APICS, (id) + 1)
+#define last_physid(map) ({ \
+ const unsigned long *mask = (map).mask; \
+ unsigned int id, last = MAX_APICS; \
+ for (id = find_first_bit(mask, MAX_APICS); id < MAX_APICS; \
+ id = find_next_bit(mask, MAX_APICS, (id) + 1)) \
+ last = id; \
+ last; \
+})
+
#define physids_and(dst, src1, src2) bitmap_and((dst).mask, (src1).mask, (src2).mask, MAX_APICS)
#define physids_or(dst, src1, src2) bitmap_or((dst).mask, (src1).mask, (src2).mask, MAX_APICS)
#define physids_clear(map) bitmap_zero((map).mask, MAX_APICS)
[-- Attachment #2: x86-nr-sockets.patch --]
[-- Type: text/plain, Size: 2357 bytes --]
x86: refine nr_sockets calculation
The previous variant didn't work for non-contiguous socket numbers.
Reported-by: Ed Swierk <eswierk@skyportsystems.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Tested-by: Ed Swierk <eswierk@skyportsystems.com>
--- a/xen/arch/x86/mpparse.c
+++ b/xen/arch/x86/mpparse.c
@@ -89,19 +89,14 @@ void __init set_nr_cpu_ids(unsigned int
void __init set_nr_sockets(void)
{
- /*
- * Count the actual cpus in the socket 0 and use it to calculate nr_sockets
- * so that the latter will be always >= the actual socket number in the
- * system even when APIC IDs from MP table are too sparse.
- */
- unsigned int cpus = bitmap_weight(phys_cpu_present_map.mask,
- boot_cpu_data.x86_max_cores *
- boot_cpu_data.x86_num_siblings);
-
- if ( cpus == 0 )
- cpus = 1;
-
- nr_sockets = DIV_ROUND_UP(num_processors + disabled_cpus, cpus);
+ nr_sockets = last_physid(phys_cpu_present_map)
+ / boot_cpu_data.x86_max_cores
+ / boot_cpu_data.x86_num_siblings + 1;
+ if (disabled_cpus)
+ nr_sockets += (disabled_cpus - 1)
+ / boot_cpu_data.x86_max_cores
+ / boot_cpu_data.x86_num_siblings + 1;
+ printk(XENLOG_DEBUG "nr_sockets: %u\n", nr_sockets);
}
/*
--- a/xen/include/asm-x86/mpspec.h
+++ b/xen/include/asm-x86/mpspec.h
@@ -43,6 +43,19 @@ typedef struct physid_mask physid_mask_t
#define physid_isset(physid, map) test_bit(physid, (map).mask)
#define physid_test_and_set(physid, map) test_and_set_bit(physid, (map).mask)
+#define first_physid(map) find_first_bit((map).mask, \
+ MAX_APICS)
+#define next_physid(id, map) find_next_bit((map).mask, \
+ MAX_APICS, (id) + 1)
+#define last_physid(map) ({ \
+ const unsigned long *mask = (map).mask; \
+ unsigned int id, last = MAX_APICS; \
+ for (id = find_first_bit(mask, MAX_APICS); id < MAX_APICS; \
+ id = find_next_bit(mask, MAX_APICS, (id) + 1)) \
+ last = id; \
+ last; \
+})
+
#define physids_and(dst, src1, src2) bitmap_and((dst).mask, (src1).mask, (src2).mask, MAX_APICS)
#define physids_or(dst, src1, src2) bitmap_or((dst).mask, (src1).mask, (src2).mask, MAX_APICS)
#define physids_clear(map) bitmap_zero((map).mask, MAX_APICS)
[-- Attachment #3: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] x86: refine nr_sockets calculation
2015-12-04 16:29 [PATCH] x86: refine nr_sockets calculation Jan Beulich
@ 2015-12-04 17:27 ` Andrew Cooper
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Cooper @ 2015-12-04 17:27 UTC (permalink / raw)
To: Jan Beulich, xen-devel; +Cc: Keir Fraser
On 04/12/15 16:29, Jan Beulich wrote:
> The previous variant didn't work for non-contiguous socket numbers.
>
> Reported-by: Ed Swierk <eswierk@skyportsystems.com>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> Tested-by: Ed Swierk <eswierk@skyportsystems.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-12-04 17:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-04 16:29 [PATCH] x86: refine nr_sockets calculation Jan Beulich
2015-12-04 17:27 ` Andrew Cooper
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.