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 C6885A04FE; Tue, 9 Jun 2020 16:18:11 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 61D2B1BED0; Tue, 9 Jun 2020 16:17:58 +0200 (CEST) Received: from mail-qk1-f194.google.com (mail-qk1-f194.google.com [209.85.222.194]) by dpdk.org (Postfix) with ESMTP id 33A701BEC3 for ; Tue, 9 Jun 2020 16:17:57 +0200 (CEST) Received: by mail-qk1-f194.google.com with SMTP id v79so20857465qkb.10 for ; Tue, 09 Jun 2020 07:17:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=radio-canada-ca.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bbumoIL1GQDHiCjr2O5eAilHqbnCE0Ruv4WLPro2G3o=; b=zN4HyzOYQS/LrzRdC256gxgLYSluP+GbLp6VkQQaV1Wn4pTvckQPJsHy2oUzSx5y0W YPwMNnr94vjccTHNQ0GEjRcdAwXB8SwaNwaaNTgFYZFhgQH9Zy51SYsDbHZRUiajfu4n KnduSu7+pBaTJdrlYs84ek6h+VpFg+I3Du9VXrF0m2T61hpBJRYSaIxwrjuX3xke90hi MxwGGW65bjMVWyBOiRK45cdWMBvE3fwClwOIw/cMsVbjxyGhsWXecz+01+iHM4b81Aln 4H4l3KO36mdrynr7Fzc6lw3MsTB+kNsICnrV0zOtOZxKE9d3/8nlurge4dOM+o0/6ShN SliQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bbumoIL1GQDHiCjr2O5eAilHqbnCE0Ruv4WLPro2G3o=; b=YyCnDAJwbzodZoyeiLIRCsEH1ZhB9wItx0CVvilEvBJ13BFNmHuDIFa5CTX/2vvtl2 elE/KzTSdr1p/QJW09EhJvm55D1c6DbhK0v6KZHav6q8lZ9J67PKoD54Z9Sar0PRNNhJ KmIoh3hb5KAa4j2BRWUDFmgtvmJybZEPxKL7oVVdLkage3C4OVgFpwEcPhju+bMTPpmS bLYkC+t8oUEoaIOIGj1oufpIti/wlBJPiIxWL6UyDXofEz2vAx6aYdHSbeEFsjSKd9FA NorNAbQDo5GFkJtclks1tF+dkogGSh/FPj1Gk9e2EstTRrqq1tS4UzuLYl3j9nxp18Fr c2rw== X-Gm-Message-State: AOAM532lVnpqBtQp9SM/6I9VjyDm5hnMshCoSC2pb/L5OQvaT78gTFzg hfk3pJgMNjqjzpkUTZmc1WopxJtM70nU6w== X-Google-Smtp-Source: ABdhPJz7djA/CYd0MkNN0+XTTmSD0zB18nVvZIWJdTxymviQdcGbnbvuyRqsIsJteQRBQOrSz/3QbA== X-Received: by 2002:a37:b883:: with SMTP id i125mr27762400qkf.392.1591712276220; Tue, 09 Jun 2020 07:17:56 -0700 (PDT) Received: from localhost.localdomain (104-163-142-249.qc.dsl.ebox.net. [104.163.142.249]) by smtp.gmail.com with ESMTPSA id a82sm10287148qkb.29.2020.06.09.07.17.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 07:17:55 -0700 (PDT) From: Patrick Keroulas To: dev@dpdk.org Cc: Patrick Keroulas , Vivien Didelot Date: Tue, 9 Jun 2020 10:17:13 -0400 Message-Id: <20200609141713.11614-4-patrick.keroulas@radio-canada.ca> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609141713.11614-1-patrick.keroulas@radio-canada.ca> References: <20200609141713.11614-1-patrick.keroulas@radio-canada.ca> Subject: [dpdk-dev] [RFC] [PATCH v1 3/3] net/pcap: dump hardware 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" When hardware timestamping is activated, system time should no longer be used to timestamp dumped the packets. Instead, use value held by forwarded and assume they were converted to nanoseconds. Signed-off-by: Patrick Keroulas Signed-off-by: Vivien Didelot --- drivers/net/pcap/rte_eth_pcap.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c index b4c79d174..1303e3338 100644 --- a/drivers/net/pcap/rte_eth_pcap.c +++ b/drivers/net/pcap/rte_eth_pcap.c @@ -45,6 +45,8 @@ #define RTE_PMD_PCAP_MAX_QUEUES 16 +#define NSEC_PER_SEC 1000000000L + static char errbuf[PCAP_ERRBUF_SIZE]; static struct timeval start_time; static uint64_t start_cycles; @@ -288,14 +290,24 @@ eth_null_rx(void *queue __rte_unused, } static inline void -calculate_timestamp(struct timeval *ts) { - uint64_t cycles; - struct timeval cur_time; - - 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); +calculate_timestamp(const struct rte_mbuf *mbuf, struct timeval *ts) { + if (mbuf->ol_flags & PKT_RX_TIMESTAMP) { + /* timestamp unit is nanoseconds but must fit in timeval */ + ts->tv_sec = mbuf->timestamp / NSEC_PER_SEC; + ts->tv_usec = mbuf->timestamp % NSEC_PER_SEC; + } + else { + uint64_t cycles = rte_get_timer_cycles() - start_cycles; + struct timeval cur_time; + cur_time.tv_sec = cycles / hz; + 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; + } + } } /* @@ -331,7 +343,7 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) caplen = sizeof(temp_data); } - calculate_timestamp(&header.ts); + calculate_timestamp(mbuf, &header.ts); header.len = len; header.caplen = caplen; /* rte_pktmbuf_read() returns a pointer to the data directly @@ -475,7 +487,7 @@ open_single_tx_pcap(const char *pcap_filename, pcap_dumper_t **dumper) * with pcap_dump_open(). We create big enough an Ethernet * pcap holder. */ - tx_pcap = pcap_open_dead(DLT_EN10MB, RTE_ETH_PCAP_SNAPSHOT_LEN); + tx_pcap = pcap_open_dead_with_tstamp_precision(DLT_EN10MB, RTE_ETH_PCAP_SNAPSHOT_LEN, PCAP_TSTAMP_PRECISION_NANO); if (tx_pcap == NULL) { PMD_LOG(ERR, "Couldn't create dead pcap"); return -1; -- 2.17.1