From owner-freebsd-hackers@freebsd.org Wed Sep 19 22:40:38 2018 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7D28F10A9229 for ; Wed, 19 Sep 2018 22:40:38 +0000 (UTC) (envelope-from shrikanth07@gmail.com) Received: from mail-ua1-x92c.google.com (mail-ua1-x92c.google.com [IPv6:2607:f8b0:4864:20::92c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 1C2B195BEC for ; Wed, 19 Sep 2018 22:40:38 +0000 (UTC) (envelope-from shrikanth07@gmail.com) Received: by mail-ua1-x92c.google.com with SMTP id u11-v6so3539540uan.13 for ; Wed, 19 Sep 2018 15:40:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to:cc; bh=rfYclXEABKYoqZFTJ8fREuWv+qttTu4JPo5V5gsVlKw=; b=k7Kj582TIR4YLadyaUuKNDjGe8ITI63Qs5BJS7YWGKUxdcDnB/sDQdVB5qhxx0Qc6W ImNRAZQae9lSWZot3xfrMOGrHSlTfB1Wx62rXy6Cf79eJtpBcDl2OBYGOBfsNZzNeNed uNrIuNorh/ZAIbXcvHLJKfGx2/MlxzLgxm2OyOCd1PLVseCghesCLYYQ15zd5lgQe6oW oHpV/aGWFTclMNCBbwIhgd4WcYQE4HyaiR0nUt4Nw/qvXlzjA905bslEmRqAGktoVAft aj0L2LBw6yErVFNxqnXoAleKvph5xv0ZR97LLAjfzByyceeXktCmpKH1goCsXkq2woKZ NQ7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=rfYclXEABKYoqZFTJ8fREuWv+qttTu4JPo5V5gsVlKw=; b=dcBRbFuzMGYYEwDOFxV6A7HI3qgr9L1XL+myuym5gV1+Mwh0gQTqGJk/KNsanz5hmn d8RBrLv6SF+eOBQUUgrmneTgwpUQ9tIXmMxH0Z1/TMFjrxi+jNV44wID7FwW7IVoBaFi X7GduU9+jQKu/d7tEeyaF8Yis8eDCOiJSVwoqI1marobjP+BGtk3bu8Mh8r+H1NT2O5L C9mLZZvQPQiJm2p4KDIAn98fCjEBzLmPidumXUsWuPU66jr9BHvAkYQQPCJY7scPu7rZ Q6PIzYz+dS4TLjGLNiop7hJDyvk7+2nju7JsPTguDq0P6iWRaGwQq6QAEYeHEdg7coff f+1A== X-Gm-Message-State: APzg51BqgecKzEfbj3k0F45k3wVc884MUDXflRVjKKwkVwDjo5JKRd+H do8OoGC2/ZwdR8E4KG9x+N7SsZVh0wcRwsb7fFRGQrYF X-Google-Smtp-Source: ANB0Vda93Syr8KVHu1PokvvdhTH/tqE3ic6eMXjtdbbCYXbkJhK1WhgADb/q90DDeLEEvfTTBIbO0ET6FnYxav4QTSo= X-Received: by 2002:a9f:3d6f:: with SMTP id m47-v6mr11173546uai.19.1537396837077; Wed, 19 Sep 2018 15:40:37 -0700 (PDT) MIME-Version: 1.0 From: Shrikanth Kamath Date: Wed, 19 Sep 2018 15:40:24 -0700 Message-ID: Subject: Use of msleep after system has reset 'cold' and before SI_SUB_CLOCKS To: freebsd-hackers@freebsd.org Cc: Sreekanth Rupavatharam , hackagadget@gmail.com Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.27 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Sep 2018 22:40:38 -0000 Referring to the following snippet (MFC 309148 in stable/11)in the function callout_when in kern_timeout.c, @@ -981,6 +981,8 @@ callout_when(sbintime_t sbt, sbintime_t precision, int flags, spinlock_exit(); #endif #endif + if (cold && to_sbt == 0) + to_sbt = sbinuptime(); if ((flags & C_HARDCLOCK) == 0) to_sbt += tick_sbt; } else If someone were to use msleep during the window where system has reset "cold" to zero post SI_SUB_CONFIGURE and before clocks are available (after SI_SUB_CLOCKS is processed) then msleep which default has C_HARDCLOCK set would get a wrong timeout set which would lead to erroneous EWOULDBLOCK return from sleepq_check_timeout. In my scenario the value of DPCPU_GET(hardclocktime) which is referenced in callout_when was zero hence to_sbt was zero but the 'adjustment' for that failed because the above check is doing a if(cold && to_sbt) to do that. Should the check be just if (to_sbt == 0) then set to_sbt to sbinuptime? -- Shrikanth R K