From: Miao Xie <miaox@cn.fujitsu.com>
To: Subrata Modak <subrata@linux.vnet.ibm.com>
Cc: LTP-ML <ltp-list@lists.sourceforge.net>
Subject: [LTP] [PATCH] fix the bug of the smaller cpu_set_t's length in getcpu01
Date: Wed, 06 Jan 2010 11:30:50 +0800 [thread overview]
Message-ID: <4B4403EA.7020600@cn.fujitsu.com> (raw)
getcpu01 test failed because the len of cpu_set_t in the glibc is smaller than
the length of the cpumask in the kernel. So we must use the dynamically sized CPU sets instead
of the standard cpu_set_t.
This patch fix this problem.
Before using this patch, the test result is following:
getcpu01 1 TFAIL : sched_getaffinity:errno:22
After using this patch, the test result is following:
getcpu01 1 TPASS : getcpu() returned proper cpuid:3, node id:0
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
---
testcases/kernel/syscalls/getcpu/getcpu01.c | 66 +++++++++++++++++++++++----
1 files changed, 56 insertions(+), 10 deletions(-)
diff --git a/testcases/kernel/syscalls/getcpu/getcpu01.c b/testcases/kernel/syscalls/getcpu/getcpu01.c
index 9b4e52e..c13e0e7 100644
--- a/testcases/kernel/syscalls/getcpu/getcpu01.c
+++ b/testcases/kernel/syscalls/getcpu/getcpu01.c
@@ -77,12 +77,16 @@ int sys_support = 0;
int sys_support = 0;
#endif
+#if !(__GLIBC_PREREQ(2, 7))
+#define CPU_FREE(ptr) free(ptr)
+#endif
+
void cleanup(void);
void setup(void);
static inline int getcpu(unsigned int *, unsigned int *, void *);
unsigned int set_cpu_affinity();
unsigned int get_nodeid(unsigned int);
-unsigned int max_cpuid(cpu_set_t *);
+unsigned int max_cpuid(size_t, cpu_set_t *);
char *TCID = "getcpu01";
int TST_TOTAL = 1;
@@ -189,18 +193,56 @@ void setup(void)
unsigned int set_cpu_affinity()
{
unsigned cpu_max;
- cpu_set_t set;
- if (sched_getaffinity(0, sizeof(cpu_set_t), &set) < 0) {
- tst_resm(TFAIL, "sched_getaffinity:errno:%d", errno);
+ cpu_set_t *set;
+ size_t size;
+ int nrcpus = 1024;
+#if __GLIBC_PREREQ(2, 7)
+realloc:
+ set = CPU_ALLOC(nrcpus);
+#else
+ set = malloc(sizeof(cpu_set_t));
+#endif
+ if (set == NULL) {
+ tst_resm(TFAIL, "CPU_ALLOC:errno:%d", errno);
+ tst_exit();
+ }
+
+#if __GLIBC_PREREQ(2, 7)
+ size = CPU_ALLOC_SIZE(nrcpus);
+ CPU_ZERO_S(size, set);
+#else
+ size = sizeof(cpu_set_t);
+ CPU_ZERO(set);
+#endif
+ if (sched_getaffinity(0, size, set) < 0) {
+ CPU_FREE(set);
+#if __GLIBC_PREREQ(2, 7)
+ if (errno == EINVAL && nrcpus < (1024 << 8)) {
+ nrcpus = nrcpus << 2;
+ goto realloc;
+ }
+#else
+ if (errno == EINVAL)
+ tst_resm(TFAIL, "NR_CPUS of the kernel is more than 1024, so we'd better use a newer glibc(>= 2.7)");
+ else
+#endif
+ tst_resm(TFAIL, "sched_getaffinity:errno:%d", errno);
tst_exit();
}
- cpu_max = max_cpuid(&set);
- CPU_ZERO(&set);
- CPU_SET(cpu_max, &set);
- if (sched_setaffinity(0, sizeof(cpu_set_t), &set) < 0) {
+ cpu_max = max_cpuid(size, set);
+#if __GLIBC_PREREQ(2, 7)
+ CPU_ZERO_S(size, set);
+ CPU_SET_S(cpu_max, size, set);
+#else
+ CPU_ZERO(set);
+ CPU_SET(cpu_max, set);
+#endif
+ if (sched_setaffinity(0, size, set) < 0) {
+ CPU_FREE(set);
tst_resm(TFAIL, "sched_setaffinity:errno:%d", errno);
tst_exit();
}
+ CPU_FREE(set);
return cpu_max;
}
@@ -208,11 +250,15 @@ unsigned int set_cpu_affinity()
* Return the maximum cpu id
*/
#define BITS_PER_BYTE 8
-unsigned int max_cpuid(cpu_set_t * set)
+unsigned int max_cpuid(size_t size, cpu_set_t * set)
{
unsigned int index, max = 0;
- for (index = 0; index < sizeof(cpu_set_t) * BITS_PER_BYTE; index++)
+ for (index = 0; index < size * BITS_PER_BYTE; index++)
+#if __GLIBC_PREREQ(2, 7)
+ if (CPU_ISSET_S(index, size, set))
+#else
if (CPU_ISSET(index, set))
+#endif
max = index;
return max;
}
--
1.6.5.2
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
next reply other threads:[~2010-01-06 3:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-06 3:30 Miao Xie [this message]
2010-01-06 5:11 ` [LTP] [PATCH] fix the bug of the smaller cpu_set_t's length in getcpu01 Garrett Cooper
2010-01-07 11:06 ` Subrata Modak
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=4B4403EA.7020600@cn.fujitsu.com \
--to=miaox@cn.fujitsu.com \
--cc=ltp-list@lists.sourceforge.net \
--cc=subrata@linux.vnet.ibm.com \
/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