From patchwork Mon Aug 6 17:09:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yousuk Seung X-Patchwork-Id: 954004 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="R8qmGl45"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41kkfk21G6z9ryt for ; Tue, 7 Aug 2018 03:10:06 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732553AbeHFTUF (ORCPT ); Mon, 6 Aug 2018 15:20:05 -0400 Received: from mail-ua0-f202.google.com ([209.85.217.202]:45291 "EHLO mail-ua0-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728349AbeHFTUF (ORCPT ); Mon, 6 Aug 2018 15:20:05 -0400 Received: by mail-ua0-f202.google.com with SMTP id x17-v6so9201974uap.12 for ; Mon, 06 Aug 2018 10:10:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=3dvuBKCwolYtzLpEHBd6XN8+I6HNrqKzCn6wk4RtUgM=; b=R8qmGl457TT5OI6Uxp5Mhk3nai2rQ/T3fxuYFsPbTXca+E741q55g+8L2w8Kr4CjZq xO8qlp3XMKBSgmd+QNeqcJx4hidfllEyQ+/36sC5qgn0e7EafZYFZWkpk2ggs3tuK7qd vqD+7GhAhYJV85uFqDu8eSgEL5sT5B7Nw7lih95Ks9GKOiO+PDTXdwdLlMBJPT2uBO9C RpdPlaIm8T3565qiOX4JZ1UzTlwWc3wp38bn7vYaDf9gN9lo3E29OPAaEzchDqTfChGp JEUX1EmxDwU0MW3osZIFgBJtA7IaaJ+zEkitGCcLE7E452xRIgGplUG73NlMNJX40Td6 WmRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=3dvuBKCwolYtzLpEHBd6XN8+I6HNrqKzCn6wk4RtUgM=; b=iiOOCuaq2YxyrSUZbi7UOdSmNzA1avGcRCUc96AsHm1zOAy8UzC0iH/5LTsB+EnZmR /VNs8EbFH2ET1fm4D98fk5lFKcjLMQVQMBgaSWmP0GIqH7vzr0tPX398FE4pcwDJJ2Ep E3X+257xAmUe8qsTFD+csAXhR2f18gCMkwL+qoi/bhUIuTj7RVyYOGi6fl/pO7+6G9Z8 Kt69xSuxMgBdIWScAYoti3RziMTUBojpnR0vK3bJFOTCdSLYm+NFHMNvRq6G6Dq6uIP3 EU3Jfz1UtbCU4t/+ZDZjG69c3yPjVp0D56A7JVjBdLmcBMDPOqEBSk/UhFQwQpovqpmZ N8IQ== X-Gm-Message-State: AOUpUlHA2u4RAd607pgf1qU6pEmr0FvWbyr4Ffrx5MrKFjntefQ+7O+W p38GbbNfweqgB4fcN+6VF1BFzSFNqy3bUD8xotiIn63IydmoN4HsutqyujAkQzMBTvLUPlHrAzQ ZSzyr5mFhHbaJoWUrsReszKz8ePpArC6ZeVfMIztbk3Qa7pUaUEzxbYe2TZjdMVwN X-Google-Smtp-Source: AAOMgpcFwvc0jujNdRskgUppUxat5MZsxcDogbExRQLStu05vB8/rEUyQFtTSr2tRRjwJZmRJ16VDGlEcEhf X-Received: by 2002:a1f:5647:: with SMTP id k68-v6mr9932633vkb.75.1533575403107; Mon, 06 Aug 2018 10:10:03 -0700 (PDT) Date: Mon, 6 Aug 2018 10:09:51 -0700 In-Reply-To: <20180806170953.164776-1-ysseung@google.com> Message-Id: <20180806170953.164776-2-ysseung@google.com> Mime-Version: 1.0 References: <20180806170953.164776-1-ysseung@google.com> X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog Subject: [PATCH iproute2-next 1/3] tc: support conversions to or from 64 bit nanosecond-based time From: Yousuk Seung To: netdev@vger.kernel.org Cc: Stephen Hemminger , David Ahern , Michael McLennan , Priyaranjan Jha , Dave Taht , Yousuk Seung , Neal Cardwell Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Dave Taht Using a 32 bit field to represent time in nanoseconds results in a maximum value of about 4.3 seconds, which is well below many observed delays in WiFi and LTE, and barely in the ballpark for a trip past the Earth's moon, Luna. Using 64 bit time fields in nanoseconds allows us to simulate network diameters of several hundred light-years. However, only conversions to and from ns, us, ms, and seconds are provided. Signed-off-by: Yousuk Seung Signed-off-by: Dave Taht Signed-off-by: Neal Cardwell --- tc/tc_core.h | 4 ++++ tc/tc_util.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tc/tc_util.h | 3 +++ 3 files changed, 62 insertions(+) diff --git a/tc/tc_core.h b/tc/tc_core.h index 1dfa9a4f773b..a0fe0923d171 100644 --- a/tc/tc_core.h +++ b/tc/tc_core.h @@ -7,6 +7,10 @@ #define TIME_UNITS_PER_SEC 1000000 +#define NSEC_PER_USEC 1000 +#define NSEC_PER_MSEC 1000000 +#define NSEC_PER_SEC 1000000000LL + enum link_layer { LINKLAYER_UNSPEC, LINKLAYER_ETHERNET, diff --git a/tc/tc_util.c b/tc/tc_util.c index d7578528a31b..c39c9046dcae 100644 --- a/tc/tc_util.c +++ b/tc/tc_util.c @@ -385,6 +385,61 @@ char *sprint_ticks(__u32 ticks, char *buf) return sprint_time(tc_core_tick2time(ticks), buf); } +/* 64 bit times are represented internally in nanoseconds */ +int get_time64(__s64 *time, const char *str) +{ + double nsec; + char *p; + + nsec = strtod(str, &p); + if (p == str) + return -1; + + if (*p) { + if (strcasecmp(p, "s") == 0 || + strcasecmp(p, "sec") == 0 || + strcasecmp(p, "secs") == 0) + nsec *= NSEC_PER_SEC; + else if (strcasecmp(p, "ms") == 0 || + strcasecmp(p, "msec") == 0 || + strcasecmp(p, "msecs") == 0) + nsec *= NSEC_PER_MSEC; + else if (strcasecmp(p, "us") == 0 || + strcasecmp(p, "usec") == 0 || + strcasecmp(p, "usecs") == 0) + nsec *= NSEC_PER_USEC; + else if (strcasecmp(p, "ns") == 0 || + strcasecmp(p, "nsec") == 0 || + strcasecmp(p, "nsecs") == 0) + nsec *= 1; + else + return -1; + } + + *time = nsec; + return 0; +} + +void print_time64(char *buf, int len, __s64 time) +{ + double nsec = time; + + if (time >= NSEC_PER_SEC) + snprintf(buf, len, "%.3fs", nsec/NSEC_PER_SEC); + else if (time >= NSEC_PER_MSEC) + snprintf(buf, len, "%.3fms", nsec/NSEC_PER_MSEC); + else if (time >= NSEC_PER_USEC) + snprintf(buf, len, "%.3fus", nsec/NSEC_PER_USEC); + else + snprintf(buf, len, "%lldns", time); +} + +char *sprint_time64(__s64 time, char *buf) +{ + print_time64(buf, SPRINT_BSIZE-1, time); + return buf; +} + int get_size(unsigned int *size, const char *str) { double sz; diff --git a/tc/tc_util.h b/tc/tc_util.h index 6632c4f9c528..87be951c622d 100644 --- a/tc/tc_util.h +++ b/tc/tc_util.h @@ -82,12 +82,14 @@ int get_percent_rate64(__u64 *rate, const char *str, const char *dev); int get_size(unsigned int *size, const char *str); int get_size_and_cell(unsigned int *size, int *cell_log, char *str); int get_time(unsigned int *time, const char *str); +int get_time64(__s64 *time, const char *str); int get_linklayer(unsigned int *val, const char *arg); void print_rate(char *buf, int len, __u64 rate); void print_size(char *buf, int len, __u32 size); void print_qdisc_handle(char *buf, int len, __u32 h); void print_time(char *buf, int len, __u32 time); +void print_time64(char *buf, int len, __s64 time); void print_linklayer(char *buf, int len, unsigned int linklayer); void print_devname(enum output_type type, int ifindex); @@ -96,6 +98,7 @@ char *sprint_size(__u32 size, char *buf); char *sprint_qdisc_handle(__u32 h, char *buf); char *sprint_tc_classid(__u32 h, char *buf); char *sprint_time(__u32 time, char *buf); +char *sprint_time64(__s64 time, char *buf); char *sprint_ticks(__u32 ticks, char *buf); char *sprint_linklayer(unsigned int linklayer, char *buf);