NetBSD Problem Report #57273

From www@netbsd.org  Thu Mar 16 16:52:07 2023
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 19D931A9239
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 16 Mar 2023 16:52:07 +0000 (UTC)
Message-Id: <20230316165205.983C91A923A@mollari.NetBSD.org>
Date: Thu, 16 Mar 2023 16:52:05 +0000 (UTC)
From: roy@marples.name
Reply-To: roy@marples.name
To: gnats-bugs@NetBSD.org
Subject: poll timeout is doubled when NetBSD is run inside QEMU
X-Send-Pr-Version: www-1.0

>Number:         57273
>Category:       kern
>Synopsis:       poll timeout is doubled when NetBSD is run inside QEMU
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Mar 16 16:55:00 +0000 2023
>Last-Modified:  Thu Mar 16 17:15:02 +0000 2023
>Originator:     Roy Marples
>Release:        NetBSD-9.3
>Organization:
>Environment:
NetBSD netbsd9 9.3_STABLE NetBSD 9.3_STABLE (GENERIC) #0: Mon Mar 13 21:38:46 UTC 2023  mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/amd64/compile/GENERIC amd64
>Description:
Testing dhcpcd timings in a NetBSD vm is impossible because the time to sleep with any polling mechanism (poll, pollts, kqueue) is doubled.
Outside the vm, on bare metal, it works fine.
>How-To-Repeat:
Install NetBSD to a qemu VM hosted on NetBSD.

Reproducer:

#include <poll.h>
#include <stdio.h>
#include <time.h>

int
main(void)
{
        struct timespec ts = { .tv_sec = 10 };
        struct timespec start, end;

        fprintf(stderr, "ppoll timeout %ld secs\n", ts.tv_sec);
        clock_gettime(CLOCK_MONOTONIC, &start);
        fprintf(stderr, "poll start is %ld, timeout is %ld, end should be %ld\n",
            start.tv_sec, ts.tv_sec, start.tv_sec + ts.tv_sec);
        pollts(NULL, 0, &ts, NULL);
        clock_gettime(CLOCK_MONOTONIC, &end);
        fprintf(stderr, "poll end is %ld, off by %ld secs\n",
            end.tv_sec, end.tv_sec - (start.tv_sec + ts.tv_sec));
        return 0;
}
>Fix:

>Audit-Trail:
From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/57273: poll timeout is doubled when NetBSD is run inside
 QEMU
Date: Thu, 16 Mar 2023 18:08:45 +0100

 On Thu, Mar 16, 2023 at 04:55:01PM +0000, roy@marples.name wrote:
 > Install NetBSD to a qemu VM hosted on NetBSD.

 This is most likely a well known issue caused by small delay values being
 rounded up to HZ-of-the-host granularity on non-tickless kernels.

 Workaround is to build a host kernel with options HZ=1000 or similar.

 Martin

From: Paul Goyette <paul@whooppee.com>
To: gnats-bugs@netbsd.org
Cc: kern-bug-people@netbsd.org, gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: kern/57273: poll timeout is doubled when NetBSD is run inside
 QEMU
Date: Thu, 16 Mar 2023 10:10:50 -0700 (PDT)

 See kern/43997

 On Thu, 16 Mar 2023, roy@marples.name wrote:

 >> Number:         57273
 >> Category:       kern
 >> Synopsis:       poll timeout is doubled when NetBSD is run inside QEMU
 >> Confidential:   no
 >> Severity:       serious
 >> Priority:       medium
 >> Responsible:    kern-bug-people
 >> State:          open
 >> Class:          sw-bug
 >> Submitter-Id:   net
 >> Arrival-Date:   Thu Mar 16 16:55:00 +0000 2023
 >> Originator:     Roy Marples
 >> Release:        NetBSD-9.3
 >> Organization:
 >> Environment:
 > NetBSD netbsd9 9.3_STABLE NetBSD 9.3_STABLE (GENERIC) #0: Mon Mar 13 21:38:46 UTC 2023  mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/amd64/compile/GENERIC amd64
 >> Description:
 > Testing dhcpcd timings in a NetBSD vm is impossible because the time to sleep with any polling mechanism (poll, pollts, kqueue) is doubled.
 > Outside the vm, on bare metal, it works fine.
 >> How-To-Repeat:
 > Install NetBSD to a qemu VM hosted on NetBSD.
 >
 > Reproducer:
 >
 > #include <poll.h>
 > #include <stdio.h>
 > #include <time.h>
 >
 > int
 > main(void)
 > {
 >        struct timespec ts = { .tv_sec = 10 };
 >        struct timespec start, end;
 >
 >        fprintf(stderr, "ppoll timeout %ld secs\n", ts.tv_sec);
 >        clock_gettime(CLOCK_MONOTONIC, &start);
 >        fprintf(stderr, "poll start is %ld, timeout is %ld, end should be %ld\n",
 >            start.tv_sec, ts.tv_sec, start.tv_sec + ts.tv_sec);
 >        pollts(NULL, 0, &ts, NULL);
 >        clock_gettime(CLOCK_MONOTONIC, &end);
 >        fprintf(stderr, "poll end is %ld, off by %ld secs\n",
 >            end.tv_sec, end.tv_sec - (start.tv_sec + ts.tv_sec));
 >        return 0;
 > }
 >> Fix:
 >
 >
 > !DSPAM:641349ef114062545387549!
 >
 >

 +--------------------+--------------------------+----------------------+
 | Paul Goyette       | PGP Key fingerprint:     | E-mail addresses:    |
 | (Retired)          | FA29 0E3B 35AF E8AE 6651 | paul@whooppee.com    |
 | Software Developer | 0786 F758 55DE 53BA 7731 | pgoyette@netbsd.org  |
 | & Network Engineer |                          | pgoyette99@gmail.com |
 +--------------------+--------------------------+----------------------+

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2023 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.