Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752035AbdI1RDd (ORCPT ); Thu, 28 Sep 2017 13:03:33 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:60140 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751154AbdI1RDc (ORCPT ); Thu, 28 Sep 2017 13:03:32 -0400 Date: Thu, 28 Sep 2017 19:03:29 +0200 From: Andrew Lunn To: Brandon Streiff Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "David S. Miller" , Florian Fainelli , Vivien Didelot , Richard Cochran , Erik Hons Subject: Re: [PATCH net-next RFC 2/9] net: dsa: mv88e6xxx: expose switch time as a PTP hardware clock Message-ID: <20170928170329.GC14940@lunn.ch> References: <1506612341-18061-1-git-send-email-brandon.streiff@ni.com> <1506612341-18061-3-git-send-email-brandon.streiff@ni.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1506612341-18061-3-git-send-email-brandon.streiff@ni.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1084 Lines: 33 > +/* The 32-bit timestamp counter overflows every ~34.3 seconds; this task > + * forces periodic reads so that we don't miss any wraparounds. > + */ > +#define MV88E6XXX_TAI_OVERFLOW_PERIOD (34 * HZ / 2) > +static void mv88e6xxx_ptp_overflow_check(struct work_struct *work) > +{ > + struct delayed_work *dw = to_delayed_work(work); > + struct mv88e6xxx_chip *chip = > + container_of(dw, struct mv88e6xxx_chip, overflow_work); > + bool timeout = time_is_before_jiffies(chip->last_overflow_check + > + MV88E6XXX_TAI_OVERFLOW_PERIOD); > + > + if (timeout) { Why do you need this timeout? Do you think the kernel will call this more often than required? Also, if it did call this function early, you skip the read, and reschedule. There is then a danger the next read is after the wraparound..... > + mutex_lock(&chip->reg_lock); > + timecounter_read(&chip->tstamp_tc); > + chip->last_overflow_check = jiffies; > + mutex_unlock(&chip->reg_lock); > + } > + > + schedule_delayed_work(&chip->overflow_work, > + MV88E6XXX_TAI_OVERFLOW_PERIOD); > +} Thanks Andrew