Subject: Re: [PATCH net-next 1/2] mlx4_en: Add PTP hardware clock

From: Richard Cochran <[email-masked]>
Date: Thu, 26 Dec 2013 15:49:08 +0100

On Thu, Dec 26, 2013 at 04:41:11PM +0200, Hadar Hen-Zion wrote:

> +u64 mlx4_en_timecounter_read(struct mlx4_en_dev *mdev)
> +{
> +	struct timecounter *new_tc, *old_tc;
> +	unsigned long flags;
> +	s64 now;
> +
> +	new_tc = kmalloc(sizeof(*new_tc), GFP_KERNEL);

So you want to call malloc/free on every clock read?
That is crazy.

> +	spin_lock_irqsave(&mdev->clock_lock, flags);
> +	old_tc = mdev->clock;
> +	*new_tc = *old_tc;
> +	now = timecounter_read(new_tc);
> +	rcu_assign_pointer(mdev->clock, new_tc);
> +	spin_unlock_irqrestore(&mdev->clock_lock, flags);
> +	synchronize_rcu();
> +	kfree(old_tc);
> +
> +	return now;
> +}

Thanks,
Richard