From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 448C4318EDF for ; Thu, 21 May 2026 06:30:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.98 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779345008; cv=none; b=rxCbWCMuLrg9IzwNh+TEe142JkjPqOLrjuPlVDGVieohhlmuD/TrAB8detcbKqTy7s1qW/VkzhBERgJr4A6D3NaE4rr6nX5SdWfluqlT6WiSgjz535H2VkgJHnTHfc+skxSKKKn2xClXUIQ9KVuwVUuAkNWhUFhJQ+I+uPTSOVk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779345008; c=relaxed/simple; bh=CivL2RG7PdsPZZSPMsomtbLIZE7zk1nVNElZ7Dbq6HA=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:References: In-Reply-To:Content-Type; b=QFgnb2sSGL27B1xShIIuZ7g65rdzc5Yp0jJHRU6amcptsYJspj4xS2dMs4zDajsHoYaQvYSTjUrePWiYya3o9pHh8h1b5vRDfFMNQMr5ulPaHsxNHHIRcg8H4CaqRjFqdsnuazpSTy4z5aHS8kHDTlpWKfwpNduoqEaWSWqhBDQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=WKGVh21v; arc=none smtp.client-ip=115.124.30.98 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="WKGVh21v" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1779344996; h=Message-ID:Date:MIME-Version:From:Subject:To:Content-Type; bh=oesQOmPGE4yHUiaMwiKGABn7f9AlPRnc23n1dLbyepI=; b=WKGVh21v/q7uoXD9ppu3Qs2HvI9Y28Fiatd/q99WedIjZ+hSRMKzuAp0O1+5pIn96j0WWVFl4wk2P9zwgD2G9Tl+NVcIjdKMKNkieGGloEnDRw1Yr7VZcPIgvtzooaoUgaFzIanwmPNv6tQm0rCuyVIJoZgKmYIaZmX04BxF1U0= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R261e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033032089153;MF=guwen@linux.alibaba.com;NM=1;PH=DS;RN=21;SR=0;TI=SMTPD_---0X3Kyw3w_1779344987; Received: from 30.221.129.160(mailfrom:guwen@linux.alibaba.com fp:SMTPD_---0X3Kyw3w_1779344987 cluster:ay36) by smtp.aliyun-inc.com; Thu, 21 May 2026 14:29:55 +0800 Message-ID: Date: Thu, 21 May 2026 14:29:46 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Wen Gu Subject: Re: [RFC PATCH v3 10/10] kernel/time: Add /dev/vmclock_host miscdev To: David Woodhouse , Richard Cochran , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , John Stultz , Thomas Gleixner , Stephen Boyd , Anna-Maria Behnsen , Frederic Weisbecker , Shuah Khan , Peter Zijlstra , =?UTF-8?Q?Thomas_Wei=C3=9Fschuh?= , Arnd Bergmann , Miroslav Lichvar , Julien Ridoux , Ryan Luu , linux-kernel@vger.kernel.org Cc: David Woodhouse References: <20260520135207.37826-1-dwmw2@infradead.org> <20260520135207.37826-11-dwmw2@infradead.org> In-Reply-To: <20260520135207.37826-11-dwmw2@infradead.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2026/5/20 21:33, David Woodhouse wrote: > +/* > + * Called from pvclock_gtod_notify on every timekeeping update. > + * Only does real work when ntp_tick or skew_delta changes. > + */ > +static int vmclock_host_notify(struct notifier_block *nb, > + unsigned long was_set, void *data) > +{ <...> > + > + /* Compute time tuple: C = A + ntp_error + time_offset */ > + ns = tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift; > + sec = tk->xtime_sec + tk->tai_offset; > + ns += tk->ntp_error >> (tk->tkr_mono.shift + tk->ntp_error_shift); > + ns += ntp_get_time_offset_ns(tk->id); > + > + while (ns < 0) { > + ns += NSEC_PER_SEC; > + sec--; > + } > + while (ns >= NSEC_PER_SEC) { > + ns -= NSEC_PER_SEC; > + sec++; > + } > + > + counter_value = tk->tkr_mono.cycle_last; > + hi = div64_u64_rem((u64)ns << 32, 1000000000ULL, &rem); > + time_frac = (hi << 32) | div64_u64(rem << 32, 1000000000ULL); > + > + clock_status = !(ntp_get_status() & STA_UNSYNC) ? > + VMCLOCK_STATUS_SYNCHRONIZED : VMCLOCK_STATUS_FREERUNNING; > + > + /* Prepare le values */ > + le_counter_value = cpu_to_le64(counter_value); > + le_time_sec = cpu_to_le64(sec); > + le_time_frac = cpu_to_le64(time_frac); > + le_period_frac = cpu_to_le64(cached_period_frac); > + period_shift = cached_period_shift; > + > + /* Update page under seqcount */ > + WRITE_ONCE(clk->seq_count, cpu_to_le32( > + le32_to_cpu(READ_ONCE(clk->seq_count)) + 1)); > + smp_wmb(); > + > + clk->counter_id = counter_id; > + clk->counter_value = le_counter_value; > + clk->time_sec = le_time_sec; > + clk->time_frac_sec = le_time_frac; > + if (period_changed) { > + clk->counter_period_frac_sec = le_period_frac; > + clk->counter_period_shift = period_shift; > + } > + clk->clock_status = clock_status; > + > + /* Set leap second indicator from NTP time_state */ > + switch (ntp_get_time_state()) { > + case TIME_INS: > + clk->leap_indicator = VMCLOCK_LEAP_PRE_POS; > + break; > + case TIME_DEL: > + clk->leap_indicator = VMCLOCK_LEAP_PRE_NEG; > + break; > + case TIME_OOP: > + clk->leap_indicator = VMCLOCK_LEAP_POS; > + break; > + case TIME_WAIT: > + clk->leap_indicator = (ntp_get_status() & STA_DEL) ? > + VMCLOCK_LEAP_POST_NEG : VMCLOCK_LEAP_POST_POS; > + break; > + default: > + clk->leap_indicator = VMCLOCK_LEAP_NONE; > + break; > + } > + > + /* Export as TAI if tai_offset is known, otherwise UTC */ > + if (tk->tai_offset) { > + clk->time_type = VMCLOCK_TIME_TAI; > + clk->tai_offset_sec = cpu_to_le16((s16)tk->tai_offset); I think this should be cpu_to_le16(-(s16)tk->tai_offset)? vmclock_set_tk_reference() in Patch 9 treats clk->tai_offset_sec as a (UTC - TAI) offset, so the sign here probably needs to be inverted. > + clk->flags = cpu_to_le64(VMCLOCK_FLAG_TAI_OFFSET_VALID | > + VMCLOCK_FLAG_TIME_MONOTONIC | > + VMCLOCK_FLAG_NOTIFICATION_PRESENT); > + } else { > + clk->time_type = VMCLOCK_TIME_UTC; > + clk->tai_offset_sec = 0; > + clk->flags = cpu_to_le64(VMCLOCK_FLAG_TIME_MONOTONIC | > + VMCLOCK_FLAG_NOTIFICATION_PRESENT); > + } > + > + smp_wmb(); > + WRITE_ONCE(clk->seq_count, cpu_to_le32( > + le32_to_cpu(READ_ONCE(clk->seq_count)) + 1)); > + > + wake_up_interruptible(&vmclock_wait); > + return NOTIFY_DONE; > +}