From patchwork Thu Jan 27 11:45:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miroslav Lichvar X-Patchwork-Id: 12726648 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E560C433EF for ; Thu, 27 Jan 2022 11:45:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240774AbiA0Lpn (ORCPT ); Thu, 27 Jan 2022 06:45:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:29332 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240729AbiA0Lpn (ORCPT ); Thu, 27 Jan 2022 06:45:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643283942; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AD61UJefV4ldqNZTeQa0Q6Eqd5G/BKYwphalJ1/v8lg=; b=EBAKaANeACV+8EOEF0kf9fR+r5mEbqwc8vdI0FKhDxPr0/FkAQonxbWXGpg5lzwlLuX6k+ 6t+8KffZ6CxZCA47X43oQL5Sqrwz8Xr+yWa/ds6TK+3t6Db1WNf1YfkWrGzszSluiBFjjK a9Qj4NURhOod31gfylOyg074q/oyxvc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-538-v1UNgN-FNFqF5haCXOjLLQ-1; Thu, 27 Jan 2022 06:45:41 -0500 X-MC-Unique: v1UNgN-FNFqF5haCXOjLLQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3EEFE180E48E; Thu, 27 Jan 2022 11:45:40 +0000 (UTC) Received: from queeg.tpb.lab.eng.brq.redhat.com (unknown [10.43.135.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id C6A9D6E4AC; Thu, 27 Jan 2022 11:45:38 +0000 (UTC) From: Miroslav Lichvar To: netdev@vger.kernel.org Cc: Miroslav Lichvar , Yangbo Lu , Yang Yingliang , Richard Cochran Subject: [PATCH net-next 1/5] ptp: unregister virtual clocks when unregistering physical clock. Date: Thu, 27 Jan 2022 12:45:32 +0100 Message-Id: <20220127114536.1121765-2-mlichvar@redhat.com> In-Reply-To: <20220127114536.1121765-1-mlichvar@redhat.com> References: <20220127114536.1121765-1-mlichvar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org When unregistering a physical clock which has some virtual clocks, unregister the virtual clocks with it. This fixes the following oops, which can be triggered by unloading a driver providing a PTP clock when it has enabled virtual clocks: BUG: unable to handle page fault for address: ffffffffc04fc4d8 Oops: 0000 [#1] PREEMPT SMP NOPTI RIP: 0010:ptp_vclock_read+0x31/0xb0 Call Trace: timecounter_read+0xf/0x50 ptp_vclock_refresh+0x2c/0x50 ? ptp_clock_release+0x40/0x40 ptp_aux_kworker+0x17/0x30 kthread_worker_fn+0x9b/0x240 ? kthread_should_park+0x30/0x30 kthread+0xe2/0x110 ? kthread_complete_and_exit+0x20/0x20 ret_from_fork+0x22/0x30 Fixes: 73f37068d540 ("ptp: support ptp physical/virtual clocks conversion") Signed-off-by: Miroslav Lichvar Cc: Yangbo Lu Cc: Yang Yingliang Cc: Richard Cochran --- drivers/ptp/ptp_clock.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c index 0e4bc8b9329d..b6f2cfd15dd2 100644 --- a/drivers/ptp/ptp_clock.c +++ b/drivers/ptp/ptp_clock.c @@ -317,11 +317,18 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info, } EXPORT_SYMBOL(ptp_clock_register); +static int unregister_vclock(struct device *dev, void *data) +{ + struct ptp_clock *ptp = dev_get_drvdata(dev); + + ptp_vclock_unregister(info_to_vclock(ptp->info)); + return 0; +} + int ptp_clock_unregister(struct ptp_clock *ptp) { if (ptp_vclock_in_use(ptp)) { - pr_err("ptp: virtual clock in use\n"); - return -EBUSY; + device_for_each_child(&ptp->dev, NULL, unregister_vclock); } ptp->defunct = 1; From patchwork Thu Jan 27 11:45:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miroslav Lichvar X-Patchwork-Id: 12726649 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 372C9C433F5 for ; Thu, 27 Jan 2022 11:45:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240781AbiA0Lpx (ORCPT ); Thu, 27 Jan 2022 06:45:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:50394 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240776AbiA0Lpx (ORCPT ); Thu, 27 Jan 2022 06:45:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643283952; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P1x/bsWZnepqjTHWiF0eiQUP2G8wsP+Rexb59jZRYaY=; b=a1v9p+ONVzdtsJXoxdgNnp467JsNp55BYklueEeI479SofAbaM5/n/k5iVKpYrgCZ1asG3 Vj0n+84/20HyGFOmzblYBIj3kC4y5D7GvgRxLRoqDay6dGXV+T5O7TZ5GE8XyT+QQWbM0H pnH/JYgpm2gYs2C8Bjj9VD8DSmC7Imo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-287-npvD7r0ROie9C7n0iOtwvg-1; Thu, 27 Jan 2022 06:45:51 -0500 X-MC-Unique: npvD7r0ROie9C7n0iOtwvg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 584D01091DA0; Thu, 27 Jan 2022 11:45:50 +0000 (UTC) Received: from queeg.tpb.lab.eng.brq.redhat.com (unknown [10.43.135.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 960636E4B7; Thu, 27 Jan 2022 11:45:40 +0000 (UTC) From: Miroslav Lichvar To: netdev@vger.kernel.org Cc: Miroslav Lichvar , Yangbo Lu , Richard Cochran Subject: [PATCH net-next 2/5] ptp: increase maximum adjustment of virtual clocks. Date: Thu, 27 Jan 2022 12:45:33 +0100 Message-Id: <20220127114536.1121765-3-mlichvar@redhat.com> In-Reply-To: <20220127114536.1121765-1-mlichvar@redhat.com> References: <20220127114536.1121765-1-mlichvar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Increase the maximum frequency offset of virtual clocks to 50% to enable faster slewing corrections. This value cannot be represented as scaled ppm when long has 32 bits, but that is already the case for other drivers, even those that provide the adjfine() function, i.e. 32-bit applications are expected to check for the limit. Signed-off-by: Miroslav Lichvar Cc: Yangbo Lu Cc: Richard Cochran --- drivers/ptp/ptp_vclock.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/ptp/ptp_vclock.c b/drivers/ptp/ptp_vclock.c index ab1d233173e1..5aa2b32d9dc7 100644 --- a/drivers/ptp/ptp_vclock.c +++ b/drivers/ptp/ptp_vclock.c @@ -84,8 +84,7 @@ static long ptp_vclock_refresh(struct ptp_clock_info *ptp) static const struct ptp_clock_info ptp_vclock_info = { .owner = THIS_MODULE, .name = "ptp virtual clock", - /* The maximum ppb value that long scaled_ppm can support */ - .max_adj = 32767999, + .max_adj = 500000000, .adjfine = ptp_vclock_adjfine, .adjtime = ptp_vclock_adjtime, .gettime64 = ptp_vclock_gettime, From patchwork Thu Jan 27 11:45:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miroslav Lichvar X-Patchwork-Id: 12726651 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C823C433F5 for ; Thu, 27 Jan 2022 11:46:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240785AbiA0LqB (ORCPT ); Thu, 27 Jan 2022 06:46:01 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:24418 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240786AbiA0LqA (ORCPT ); Thu, 27 Jan 2022 06:46:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643283960; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sG7YUXpPRl6RONBOQknLLzz4wjgiShFuatkXsXcovdo=; b=Cyjzqwg6BidsudegKkxH2Np7XBlFMiFsQ4Fj3HpoXamFEQoe38pBwjdrWN/ZFSmdcB1NvY +DPJlC9KbmXB9M0X+1KdELuPqR9H40jQpC447kTWFKPeV0ApocKeJeN1gqgtw43LYMWIIh 6Q3KOj+SJ3ipwj/JcHo6VPwj0puZGjc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-132-6ltsihxdOMS0rX6DSaat_A-1; Thu, 27 Jan 2022 06:45:54 -0500 X-MC-Unique: 6ltsihxdOMS0rX6DSaat_A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DA22A1091DA1; Thu, 27 Jan 2022 11:45:53 +0000 (UTC) Received: from queeg.tpb.lab.eng.brq.redhat.com (unknown [10.43.135.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id B2E0B6E4A9; Thu, 27 Jan 2022 11:45:50 +0000 (UTC) From: Miroslav Lichvar To: netdev@vger.kernel.org Cc: Miroslav Lichvar , Yangbo Lu , Richard Cochran Subject: [PATCH net-next 3/5] ptp: add gettimex64() to virtual clocks. Date: Thu, 27 Jan 2022 12:45:34 +0100 Message-Id: <20220127114536.1121765-4-mlichvar@redhat.com> In-Reply-To: <20220127114536.1121765-1-mlichvar@redhat.com> References: <20220127114536.1121765-1-mlichvar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org If the physical clock has the gettimex64() function, provide a gettimex64() wrapper in the virtual clock to enable more accurate and stable synchronization. This adds support for the PTP_SYS_OFFSET_EXTENDED ioctl. Signed-off-by: Miroslav Lichvar Cc: Yangbo Lu Cc: Richard Cochran --- drivers/ptp/ptp_vclock.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/ptp/ptp_vclock.c b/drivers/ptp/ptp_vclock.c index 5aa2b32d9dc7..2f0b46386176 100644 --- a/drivers/ptp/ptp_vclock.c +++ b/drivers/ptp/ptp_vclock.c @@ -57,6 +57,30 @@ static int ptp_vclock_gettime(struct ptp_clock_info *ptp, return 0; } +static int ptp_vclock_gettimex(struct ptp_clock_info *ptp, + struct timespec64 *ts, + struct ptp_system_timestamp *sts) +{ + struct ptp_vclock *vclock = info_to_vclock(ptp); + struct ptp_clock *pptp = vclock->pclock; + struct timespec64 pts; + unsigned long flags; + int err; + u64 ns; + + err = pptp->info->gettimex64(pptp->info, &pts, sts); + if (err) + return err; + + spin_lock_irqsave(&vclock->lock, flags); + ns = timecounter_cyc2time(&vclock->tc, timespec64_to_ns(&pts)); + spin_unlock_irqrestore(&vclock->lock, flags); + + *ts = ns_to_timespec64(ns); + + return 0; +} + static int ptp_vclock_settime(struct ptp_clock_info *ptp, const struct timespec64 *ts) { @@ -87,7 +111,6 @@ static const struct ptp_clock_info ptp_vclock_info = { .max_adj = 500000000, .adjfine = ptp_vclock_adjfine, .adjtime = ptp_vclock_adjtime, - .gettime64 = ptp_vclock_gettime, .settime64 = ptp_vclock_settime, .do_aux_work = ptp_vclock_refresh, }; @@ -123,6 +146,10 @@ struct ptp_vclock *ptp_vclock_register(struct ptp_clock *pclock) vclock->pclock = pclock; vclock->info = ptp_vclock_info; + if (pclock->info->gettimex64) + vclock->info.gettimex64 = ptp_vclock_gettimex; + else + vclock->info.gettime64 = ptp_vclock_gettime; vclock->cc = ptp_vclock_cc; snprintf(vclock->info.name, PTP_CLOCK_NAME_LEN, "ptp%d_virt", From patchwork Thu Jan 27 11:45:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miroslav Lichvar X-Patchwork-Id: 12726650 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9FC72C433F5 for ; Thu, 27 Jan 2022 11:45:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240783AbiA0Lp7 (ORCPT ); Thu, 27 Jan 2022 06:45:59 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:35693 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240785AbiA0Lp6 (ORCPT ); Thu, 27 Jan 2022 06:45:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643283957; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3U3lZnv2taoPJ7iI5c30DVn9gDpy+KRd+ExrBb4Jie4=; b=OYKMn2lNzrOTyu6Z7O4/0aaFzzdWAFvrKT2cd5dieoZdUyjlV3hPPqjTPLFmEDWFfp3vmb 5SGU9+IDivd01qqiRpanM9i6llMO7Kby41Nxav00eh1bef6ijzTyeQDfOV/gt9rxCEbElw bKgQk++xml3eQ95l96gzSdfH0BORno4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-184-TL-7Yak9NzmaUy7whLulVg-1; Thu, 27 Jan 2022 06:45:56 -0500 X-MC-Unique: TL-7Yak9NzmaUy7whLulVg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4F07D84DA40; Thu, 27 Jan 2022 11:45:55 +0000 (UTC) Received: from queeg.tpb.lab.eng.brq.redhat.com (unknown [10.43.135.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C1776E4A9; Thu, 27 Jan 2022 11:45:54 +0000 (UTC) From: Miroslav Lichvar To: netdev@vger.kernel.org Cc: Miroslav Lichvar , Yangbo Lu , Richard Cochran Subject: [PATCH net-next 4/5] ptp: add getcrosststamp() to virtual clocks. Date: Thu, 27 Jan 2022 12:45:35 +0100 Message-Id: <20220127114536.1121765-5-mlichvar@redhat.com> In-Reply-To: <20220127114536.1121765-1-mlichvar@redhat.com> References: <20220127114536.1121765-1-mlichvar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org If the physical clock supports cross timestamping (it has the getcrosststamp() function), provide a wrapper in the virtual clock to enable cross timestamping. This adds support for the PTP_SYS_OFFSET_PRECISE ioctl. Signed-off-by: Miroslav Lichvar Cc: Yangbo Lu Cc: Richard Cochran --- drivers/ptp/ptp_vclock.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/ptp/ptp_vclock.c b/drivers/ptp/ptp_vclock.c index 2f0b46386176..cb179a3ea508 100644 --- a/drivers/ptp/ptp_vclock.c +++ b/drivers/ptp/ptp_vclock.c @@ -95,6 +95,28 @@ static int ptp_vclock_settime(struct ptp_clock_info *ptp, return 0; } +static int ptp_vclock_getcrosststamp(struct ptp_clock_info *ptp, + struct system_device_crosststamp *xtstamp) +{ + struct ptp_vclock *vclock = info_to_vclock(ptp); + struct ptp_clock *pptp = vclock->pclock; + unsigned long flags; + int err; + u64 ns; + + err = pptp->info->getcrosststamp(pptp->info, xtstamp); + if (err) + return err; + + spin_lock_irqsave(&vclock->lock, flags); + ns = timecounter_cyc2time(&vclock->tc, ktime_to_ns(xtstamp->device)); + spin_unlock_irqrestore(&vclock->lock, flags); + + xtstamp->device = ns_to_ktime(ns); + + return 0; +} + static long ptp_vclock_refresh(struct ptp_clock_info *ptp) { struct ptp_vclock *vclock = info_to_vclock(ptp); @@ -150,6 +172,8 @@ struct ptp_vclock *ptp_vclock_register(struct ptp_clock *pclock) vclock->info.gettimex64 = ptp_vclock_gettimex; else vclock->info.gettime64 = ptp_vclock_gettime; + if (pclock->info->getcrosststamp) + vclock->info.getcrosststamp = ptp_vclock_getcrosststamp; vclock->cc = ptp_vclock_cc; snprintf(vclock->info.name, PTP_CLOCK_NAME_LEN, "ptp%d_virt", From patchwork Thu Jan 27 11:45:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miroslav Lichvar X-Patchwork-Id: 12726652 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6829CC433F5 for ; Thu, 27 Jan 2022 11:46:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240788AbiA0LqH (ORCPT ); Thu, 27 Jan 2022 06:46:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:59095 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240786AbiA0LqH (ORCPT ); Thu, 27 Jan 2022 06:46:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643283966; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UDbTLHNTV72OAYvNxfm6AHdNXZ6OKHdc08mMN+K/M2g=; b=FMeXdiZzEGz39bdh7t6RphM/Db5rLKYyxFuSd4bHWyC32QL79M3FFiATZk1FFOCJldFKS1 7DAJrfq9itw2HHOEvNBY5WZMW+U89WOOnZ0ChIxlHkQkQszsySMF8UnFIVvehKn8kfUp6O KUFZF3wJ9eJpurs4mEniZpRkt9rmIBY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-315-BqH0NZfsPBeiSYBtx-DMWA-1; Thu, 27 Jan 2022 06:46:03 -0500 X-MC-Unique: BqH0NZfsPBeiSYBtx-DMWA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 37E1B839A42; Thu, 27 Jan 2022 11:46:02 +0000 (UTC) Received: from queeg.tpb.lab.eng.brq.redhat.com (unknown [10.43.135.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E89D6E4A9; Thu, 27 Jan 2022 11:45:55 +0000 (UTC) From: Miroslav Lichvar To: netdev@vger.kernel.org Cc: Miroslav Lichvar , Yangbo Lu , Richard Cochran Subject: [PATCH net-next 5/5] ptp: start virtual clocks at current system time. Date: Thu, 27 Jan 2022 12:45:36 +0100 Message-Id: <20220127114536.1121765-6-mlichvar@redhat.com> In-Reply-To: <20220127114536.1121765-1-mlichvar@redhat.com> References: <20220127114536.1121765-1-mlichvar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org When a virtual clock is being created, initialize the timecounter to the current system time instead of the Unix epoch to avoid very large steps when the clock will be synchronized. Signed-off-by: Miroslav Lichvar Cc: Yangbo Lu Cc: Richard Cochran --- drivers/ptp/ptp_vclock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/ptp/ptp_vclock.c b/drivers/ptp/ptp_vclock.c index cb179a3ea508..5a24a5128013 100644 --- a/drivers/ptp/ptp_vclock.c +++ b/drivers/ptp/ptp_vclock.c @@ -187,7 +187,8 @@ struct ptp_vclock *ptp_vclock_register(struct ptp_clock *pclock) return NULL; } - timecounter_init(&vclock->tc, &vclock->cc, 0); + timecounter_init(&vclock->tc, &vclock->cc, + ktime_to_ns(ktime_get_real())); ptp_schedule_worker(vclock->clock, PTP_VCLOCK_REFRESH_INTERVAL); return vclock;