From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 61960A04FE; Tue, 9 Jun 2020 21:44:10 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4512A322C; Tue, 9 Jun 2020 21:44:10 +0200 (CEST) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by dpdk.org (Postfix) with ESMTP id A5E401DB9 for ; Tue, 9 Jun 2020 21:44:08 +0200 (CEST) Received: by mail-pg1-f193.google.com with SMTP id d10so10757207pgn.4 for ; Tue, 09 Jun 2020 12:44:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0376gIzWJ4nLuuTAjMjhmXdPAPZoS4RtRqgKnIoRi3I=; b=n69iRr9Ts/r4bC4j0HTwPjPqkSV3O+U/UmaBlZ/U925LZ7JzPfKGDtFD6h7U9aKKeq IPUJQiEpNftAsBx+tNbKU8f3u2C7CGaI4iatw4oDZ3SwLiF9MJmZO+KaJWVB50YiUarq XUj6kMVyVN27mv4F6RmsDlCeZEV4TllDVx1IjdsYwGunDDhCt+uDk16kwqL8xAmrxZEf 1IsfgdphSqSXdXjvfAv9+sLZPpJTxvS27gUkqjTEmvKYvXixA6BghbYk5vGFnRHhpWVq hWzxoIKKSxpjpHolEOqp8HfCJiYcNBYJTMp8VBaetknjy6i535SzJ2HpcM86c4Dp2/bO Loaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0376gIzWJ4nLuuTAjMjhmXdPAPZoS4RtRqgKnIoRi3I=; b=J2V/do+bd1B2b1P/mLnaR1mrS8ajP6zFEWujC4BysXcBssMebaj1UXm9VHq8EK9k7v 885CK2fUZoIcvbnd6G95Rtr8qHoWtcwM3+LdufTJK9JkowD6M/ZvU1GvCFusinY3GeQB tVa8xmy9LGeIoLp8+n6p11ZH4fyNiF2ZX2WSP5MEWGat0AvKVigrasWUaTNh05SkAV/K wufSuqzw8ssmUmgjA7E1sYVuliAZraYEiB03J94bKR4AFmVQOXqFuK/aPEdJhcnXKAeU LgNtR8TKWL3Lxx4z1wtlEEeh4SGgGjqRCisxYHSHGZmcaL2x9/n8gXoWZFJ062vGAegi RWOQ== X-Gm-Message-State: AOAM530Jx1rZocc8a9lRH+JfoNZqujIPGpO2Z21YBuAKPJ1JaXWTyPPs jtO6+LGTaHD+53ncQck22v/otg== X-Google-Smtp-Source: ABdhPJwaJHFMLWISGz0FYjTtb4gegSeCNrgLm7n1atylo5fUnGYK2rplEU4E77/tIe1pgwlg0zp2VQ== X-Received: by 2002:aa7:96b3:: with SMTP id g19mr16948595pfk.64.1591731847798; Tue, 09 Jun 2020 12:44:07 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id f136sm10465834pfa.59.2020.06.09.12.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 12:44:07 -0700 (PDT) Date: Tue, 9 Jun 2020 12:43:57 -0700 From: Stephen Hemminger To: Vivien Didelot Cc: dev@dpdk.org, Ferruh Yigit , patrick.keroulas@radio-canada.ca, thomas@monjalon.net Message-ID: <20200609124357.20e7b4ea@hermes.lan> In-Reply-To: <20200609190719.105323-1-vivien.didelot@gmail.com> References: <20200609190719.105323-1-vivien.didelot@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v2] net/pcap: support software Tx nanosecond timestamps X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Tue, 9 Jun 2020 15:07:19 -0400 Vivien Didelot wrote: > > +#define NSEC_PER_SEC 1000000000L > + > static inline void > calculate_timestamp(struct timeval *ts) { > uint64_t cycles; > @@ -294,8 +296,14 @@ calculate_timestamp(struct timeval *ts) { > > cycles = rte_get_timer_cycles() - start_cycles; > cur_time.tv_sec = cycles / hz; > - cur_time.tv_usec = (cycles % hz) * 1e6 / hz; > - timeradd(&start_time, &cur_time, ts); > + cur_time.tv_usec = (cycles % hz) * NSEC_PER_SEC / hz; > + > + ts->tv_sec = start_time.tv_sec + cur_time.tv_sec; > + ts->tv_usec = start_time.tv_usec + cur_time.tv_usec; > + if (ts->tv_usec >= NSEC_PER_SEC) { > + ts->tv_usec -= NSEC_PER_SEC; > + ts->tv_sec += 1; > + } > } > You may want to pre-compute the reciprocal here to save the expensive cost of divide in the fast path. See rte_reciprocal.