From owner-freebsd-hackers@freebsd.org Wed Feb 22 09:21:21 2017 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 57A49CE81DB for ; Wed, 22 Feb 2017 09:21:21 +0000 (UTC) (envelope-from sebastian.huber@embedded-brains.de) Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 146BF1042 for ; Wed, 22 Feb 2017 09:21:20 +0000 (UTC) (envelope-from sebastian.huber@embedded-brains.de) Received: from [88.198.220.131] (helo=sslproxy02.your-server.de) by dedi548.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.85_2) (envelope-from ) id 1cgT6m-00036y-4v for freebsd-hackers@freebsd.org; Wed, 22 Feb 2017 10:21:12 +0100 Received: from [82.135.62.35] (helo=mail.embedded-brains.de) by sslproxy02.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cgT6l-0007Mf-NN for freebsd-hackers@freebsd.org; Wed, 22 Feb 2017 10:21:12 +0100 Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id A154E2A0008 for ; Wed, 22 Feb 2017 10:21:19 +0100 (CET) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id fh-iycHrIbOF for ; Wed, 22 Feb 2017 10:21:16 +0100 (CET) Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id DFA482A1804 for ; Wed, 22 Feb 2017 10:21:16 +0100 (CET) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 7TnDevExwkds for ; Wed, 22 Feb 2017 10:21:16 +0100 (CET) Received: from [192.168.96.129] (unknown [192.168.96.129]) by mail.embedded-brains.de (Postfix) with ESMTPSA id CA85F2A0008 for ; Wed, 22 Feb 2017 10:21:16 +0100 (CET) To: FreeBSD From: Sebastian Huber Subject: Absolute timeouts and clock adjustments Message-ID: <58AD5802.30908@embedded-brains.de> Date: Wed, 22 Feb 2017 10:21:06 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.99.2/23107/Wed Feb 22 05:52:45 2017) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Feb 2017 09:21:21 -0000 Hello, I try to figure out how the timeout mechanisms work in current FreeBSD.=20 My interpretation (which could be completely wrong) of POSIX is=20 something like this should happen: now 2017-02-22 sem_timedwait(s, 2023-12-13) external entity adjusts time to 2050-01-01 timeout of sem_timedwait() occurs due to the time adjustment Inside the kernel all absolute timeouts seem to use the uptime. The=20 sem_timedwait() seems to end up eventually in: /* * Put thread into sleep state, before sleeping, check if * thread was removed from umtx queue. */ static inline int umtxq_sleep(struct umtx_q *uq, const char *wmesg, struct abs_timeout=20 *abstime) { struct umtxq_chain *uc; int error, timo; uc =3D umtxq_getchain(&uq->uq_key); UMTXQ_LOCKED_ASSERT(uc); for (;;) { if (!(uq->uq_flags & UQF_UMTXQ)) return (0); if (abstime !=3D NULL) { timo =3D abs_timeout_gethz(abstime); if (timo < 0) return (ETIMEDOUT); } else timo =3D 0; error =3D msleep(uq, &uc->uc_lock, PCATCH | PDROP, wmesg, timo); if (error !=3D EWOULDBLOCK) { umtxq_lock(&uq->uq_key); break; } if (abstime !=3D NULL) abs_timeout_update(abstime); umtxq_lock(&uq->uq_key); } return (error); } The abs_timeout_gethz() returns the interval length in ticks of=20 [abstime->cur, abstime->end]. Since the msleep() uses the uptime, does=20 this mean that timeouts trigger not immediately due to time adjustments=20 in FreeBSD? --=20 Sebastian Huber, embedded brains GmbH Address : Dornierstr. 4, D-82178 Puchheim, Germany Phone : +49 89 189 47 41-16 Fax : +49 89 189 47 41-09 E-Mail : sebastian.huber@embedded-brains.de PGP : Public key available on request. Diese Nachricht ist keine gesch=C3=A4ftliche Mitteilung im Sinne des EHUG= .