* [LTP] [PATCH v2 1/2] tst_is_virt(): Allow checking for any hypervisor
@ 2020-04-28 15:47 Martin Doucha
2020-04-28 15:47 ` [LTP] [PATCH v2 2/2] Skip oversleep checks in timer tests under VM Martin Doucha
0 siblings, 1 reply; 4+ messages in thread
From: Martin Doucha @ 2020-04-28 15:47 UTC (permalink / raw)
To: ltp
Add two more valid arguments for tst_is_virt():
- VIRT_ANY: return 1 if any hypervisor is detected
- VIRT_OTHER: return 1 if an unrecognized hypervisor is detected
Also fix bugs in try_systemd_detect_virt() and return -1 on error.
Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
Changes since v1: New patch
The is_kvm() fallback test pretty much doesn't work anywhere except in our
OpenQA setup. But looking at SystemD sources (yuck), detecting KVM properly
will be a major pain in the ass, never mind any other hypervisor. So I'll
leave any further improvements as an exercise for the reader.
BTW, systemd-detect-virt can't detect the PowerPC LPAR hypervisor.
include/tst_cpu.h | 2 ++
lib/tst_virt.c | 23 +++++++++++++++++------
2 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/include/tst_cpu.h b/include/tst_cpu.h
index db6138f43..c83a58260 100644
--- a/include/tst_cpu.h
+++ b/include/tst_cpu.h
@@ -9,8 +9,10 @@ long tst_ncpus(void);
long tst_ncpus_conf(void);
long tst_ncpus_max(void);
+#define VIRT_ANY 0 /* catch-all argument for tst_is_virt() */
#define VIRT_XEN 1 /* xen dom0/domU */
#define VIRT_KVM 2 /* only default virtual CPU */
+#define VIRT_OTHER 0xffff /* unrecognized hypervisor */
int tst_is_virt(int virt_type);
diff --git a/lib/tst_virt.c b/lib/tst_virt.c
index 090e6334c..53d33e69c 100644
--- a/lib/tst_virt.c
+++ b/lib/tst_virt.c
@@ -49,7 +49,7 @@ static int is_kvm(void)
static int is_xen(void)
{
- char hypervisor_type[3];
+ char hypervisor_type[4];
if (access("/proc/xen", F_OK) == 0)
return 1;
@@ -90,30 +90,41 @@ static int try_systemd_detect_virt(void)
* systemd-detect-virt not found by shell or no virtualization detected
* (systemd-detect-virt returns non-zero)
*/
+ if (ret < 0 || (WIFEXITED(ret) && WEXITSTATUS(ret) == 127))
+ return -1;
+
if (ret)
return 0;
- if (strncmp("kvm", virt_type, 3))
+ if (!strncmp("kvm", virt_type, 3))
return VIRT_KVM;
- if (strncmp("xen", virt_type, 3))
+ if (!strncmp("xen", virt_type, 3))
return VIRT_XEN;
- return 0;
+ return VIRT_OTHER;
}
int tst_is_virt(int virt_type)
{
int ret = try_systemd_detect_virt();
- if (ret)
- return ret == virt_type;
+ if (ret >= 0) {
+ if (virt_type == VIRT_ANY)
+ return ret != 0;
+ else
+ return ret == virt_type;
+ }
switch (virt_type) {
+ case VIRT_ANY:
+ return is_xen() || is_kvm();
case VIRT_XEN:
return is_xen();
case VIRT_KVM:
return is_kvm();
+ case VIRT_OTHER:
+ return 0;
}
tst_brkm(TBROK, NULL, "invalid virt_type flag: %d", virt_type);
--
2.26.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [LTP] [PATCH v2 2/2] Skip oversleep checks in timer tests under VM
2020-04-28 15:47 [LTP] [PATCH v2 1/2] tst_is_virt(): Allow checking for any hypervisor Martin Doucha
@ 2020-04-28 15:47 ` Martin Doucha
2020-04-29 6:54 ` Jan Stancek
0 siblings, 1 reply; 4+ messages in thread
From: Martin Doucha @ 2020-04-28 15:47 UTC (permalink / raw)
To: ltp
Timer tests often fail on sleep overrun when LTP is running inside a VM.
The main cause is usually that the VM doesn't get enough CPU time to wake up
the test process in time. Disable oversleep tests if tst_is_virt() detects
any hypervisor.
Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
Changes since v1: Use tst_is_virt() instead of env variable.
lib/tst_timer_test.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/lib/tst_timer_test.c b/lib/tst_timer_test.c
index 13e9deff2..a9693a5a1 100644
--- a/lib/tst_timer_test.c
+++ b/lib/tst_timer_test.c
@@ -26,6 +26,7 @@ static long long *samples;
static unsigned int cur_sample;
static unsigned int monotonic_resolution;
static unsigned int timerslack;
+static int virt_env;
static char *print_frequency_plot;
static char *file_name;
@@ -306,7 +307,10 @@ void do_timer_test(long long usec, unsigned int nsamples)
samples[nsamples-1], samples[0], median,
1.00 * trunc_mean / keep_samples, discard);
- if (trunc_mean > (nsamples - discard) * usec + threshold) {
+ if (virt_env) {
+ tst_res(TINFO,
+ "Virtualisation detected, skipping oversleep checks");
+ } else if (trunc_mean > (nsamples - discard) * usec + threshold) {
tst_res(TFAIL, "%s slept for too long", scall);
if (!print_frequency_plot)
@@ -343,6 +347,11 @@ static void timer_setup(void)
if (setup)
setup();
+ /*
+ * Running tests in VM may cause timing issues, disable upper bound
+ * checks if LTP_VM_ENV is set to non-zero.
+ */
+ virt_env = tst_is_virt(VIRT_ANY);
tst_clock_getres(CLOCK_MONOTONIC, &t);
tst_res(TINFO, "CLOCK_MONOTONIC resolution %lins", (long)t.tv_nsec);
--
2.26.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [LTP] [PATCH v2 2/2] Skip oversleep checks in timer tests under VM
2020-04-28 15:47 ` [LTP] [PATCH v2 2/2] Skip oversleep checks in timer tests under VM Martin Doucha
@ 2020-04-29 6:54 ` Jan Stancek
2020-04-29 13:23 ` Li Wang
0 siblings, 1 reply; 4+ messages in thread
From: Jan Stancek @ 2020-04-29 6:54 UTC (permalink / raw)
To: ltp
----- Original Message -----
> Timer tests often fail on sleep overrun when LTP is running inside a VM.
> The main cause is usually that the VM doesn't get enough CPU time to wake up
> the test process in time. Disable oversleep tests if tst_is_virt() detects
> any hypervisor.
> BTW, systemd-detect-virt can't detect the PowerPC LPAR hypervisor.
Same with virt-what. We could (in separate patch) add check for
'pseries_platform' (powerpc-utils) output:
# pseries_platform
PowerVM pSeries LPAR
# pseries_platform
PowerNV Host
# pseries_platform
Power KVM pSeries Guest
>
> + /*
> + * Running tests in VM may cause timing issues, disable upper bound
> + * checks if LTP_VM_ENV is set to non-zero.
> + */
> + virt_env = tst_is_virt(VIRT_ANY);
The comment still mentions LTP_VM_ENV. Other than that, I don't have major
objections. Maybe somebody would like to run strict checks on VMs too, but
that's something we could add later with an env. variable.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [LTP] [PATCH v2 2/2] Skip oversleep checks in timer tests under VM
2020-04-29 6:54 ` Jan Stancek
@ 2020-04-29 13:23 ` Li Wang
0 siblings, 0 replies; 4+ messages in thread
From: Li Wang @ 2020-04-29 13:23 UTC (permalink / raw)
To: ltp
On Wed, Apr 29, 2020 at 2:55 PM Jan Stancek <jstancek@redhat.com> wrote:
>
>
> ----- Original Message -----
> > Timer tests often fail on sleep overrun when LTP is running inside a VM.
> > The main cause is usually that the VM doesn't get enough CPU time to
> wake up
> > the test process in time. Disable oversleep tests if tst_is_virt()
> detects
> > any hypervisor.
>
> > BTW, systemd-detect-virt can't detect the PowerPC LPAR hypervisor.
>
> Same with virt-what. We could (in separate patch) add check for
> 'pseries_platform' (powerpc-utils) output:
>
+1 that makes sense to me.
>
> # pseries_platform
> PowerVM pSeries LPAR
>
> # pseries_platform
> PowerNV Host
>
> # pseries_platform
> Power KVM pSeries Guest
>
> >
> > + /*
> > + * Running tests in VM may cause timing issues, disable upper bound
> > + * checks if LTP_VM_ENV is set to non-zero.
> > + */
> > + virt_env = tst_is_virt(VIRT_ANY);
>
> The comment still mentions LTP_VM_ENV. Other than that, I don't have major
> objections. Maybe somebody would like to run strict checks on VMs too, but
> that's something we could add later with an env. variable.
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
>
--
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20200429/758bab33/attachment.htm>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-04-29 13:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-28 15:47 [LTP] [PATCH v2 1/2] tst_is_virt(): Allow checking for any hypervisor Martin Doucha
2020-04-28 15:47 ` [LTP] [PATCH v2 2/2] Skip oversleep checks in timer tests under VM Martin Doucha
2020-04-29 6:54 ` Jan Stancek
2020-04-29 13:23 ` Li Wang
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.