From patchwork Fri Oct 26 11:42:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Borkmann X-Patchwork-Id: 194445 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id ADFC52C0095 for ; Fri, 26 Oct 2012 22:42:59 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932397Ab2JZLm5 (ORCPT ); Fri, 26 Oct 2012 07:42:57 -0400 Received: from mail-ee0-f46.google.com ([74.125.83.46]:37074 "EHLO mail-ee0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932362Ab2JZLm4 (ORCPT ); Fri, 26 Oct 2012 07:42:56 -0400 Received: by mail-ee0-f46.google.com with SMTP id b15so982539eek.19 for ; Fri, 26 Oct 2012 04:42:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=MZrPr1BzfhkPcMf9zow0BK8c7qLYLMBsIMjGFgqO0XE=; b=HEeNQu04XKEaU1a5nj0N9QNZ5GbVf1Y3KZmT21Wp7VRUddfQ6KII27MRLxHfUA1RAA SZ+NDRgVHCooYohzRGHNNUNImyJUrytO3d/5bamqwNtsN75z52ns1jOtmm26gbXx9mqE w+SpL740hx9+YNrLGN3FJ5MuYcua3IDiFE73ZfigM2I1b9AKWnOVWo0pv49JVktHqRuN 9fPZg3Y2LuyLeAYY5VOE9SI7VApkqouI0u1iyQTkXBSN+gOGczxJlzPgUa5nRZ9d7sbE jU2w3aEbSpts8Zf5cHKN2dJCFPudQBq/xK42nm9cgroCs+JRfG6Zty0AVDe9IhCGxegh bHMg== Received: by 10.14.223.4 with SMTP id u4mr31218814eep.19.1351251775404; Fri, 26 Oct 2012 04:42:55 -0700 (PDT) Received: from thinkbox ([2001:620:8:2a49:f2de:f1ff:fe3a:137]) by mx.google.com with ESMTPS id e1sm2156407eem.3.2012.10.26.04.42.54 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 26 Oct 2012 04:42:54 -0700 (PDT) Date: Fri, 26 Oct 2012 13:42:51 +0200 From: Daniel Borkmann To: shemminger@vyatta.com Cc: davem@davemloft.net, tglx@linutronix.de, netdev@vger.kernel.org Subject: [RFC PATCH net-next] pktgen: clean up ktime_t helpers Message-ID: <20121026114250.GA13378@thinkbox> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Some years ago, the ktime_t helper functions ktime_now() and ktime_lt() have been introduced. Instead of defining them inside pktgen.c, they should either use ktime_t library functions or, if not available, they should be defined in ktime.h, so that also others can benefit from them. ktime_compare() is introduced with a similar notion as in timespec_compare(). Signed-off-by: Daniel Borkmann --- include/linux/ktime.h | 19 +++++++++++++++++++ net/core/pktgen.c | 41 +++++++++++++---------------------------- 2 files changed, 32 insertions(+), 28 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/include/linux/ktime.h b/include/linux/ktime.h index 06177ba10..e83512f 100644 --- a/include/linux/ktime.h +++ b/include/linux/ktime.h @@ -282,6 +282,25 @@ static inline int ktime_equal(const ktime_t cmp1, const ktime_t cmp2) return cmp1.tv64 == cmp2.tv64; } +/** + * ktime_compare - Compares two ktime_t variables for less, greater or equal + * @cmp1: comparable1 + * @cmp2: comparable2 + * + * Returns ... + * cmp1 < cmp2: return <0 + * cmp1 == cmp2: return 0 + * cmp1 > cmp2: return >0 + */ +static inline int ktime_compare(const ktime_t cmp1, const ktime_t cmp2) +{ + if (cmp1.tv64 < cmp2.tv64) + return -1; + if (cmp1.tv64 > cmp2.tv64) + return 1; + return 0; +} + static inline s64 ktime_to_us(const ktime_t kt) { struct timeval tv = ktime_to_timeval(kt); diff --git a/net/core/pktgen.c b/net/core/pktgen.c index 1d1c216..b29dacf 100644 --- a/net/core/pktgen.c +++ b/net/core/pktgen.c @@ -419,20 +419,6 @@ struct pktgen_thread { #define REMOVE 1 #define FIND 0 -static inline ktime_t ktime_now(void) -{ - struct timespec ts; - ktime_get_ts(&ts); - - return timespec_to_ktime(ts); -} - -/* This works even if 32 bit because of careful byte order choice */ -static inline int ktime_lt(const ktime_t cmp1, const ktime_t cmp2) -{ - return cmp1.tv64 < cmp2.tv64; -} - static const char version[] = "Packet Generator for packet performance testing. " "Version: " VERSION "\n"; @@ -675,7 +661,7 @@ static int pktgen_if_show(struct seq_file *seq, void *v) seq_puts(seq, "\n"); /* not really stopped, more like last-running-at */ - stopped = pkt_dev->running ? ktime_now() : pkt_dev->stopped_at; + stopped = pkt_dev->running ? ktime_get() : pkt_dev->stopped_at; idle = pkt_dev->idle_acc; do_div(idle, NSEC_PER_USEC); @@ -2141,12 +2127,12 @@ static void spin(struct pktgen_dev *pkt_dev, ktime_t spin_until) return; } - start_time = ktime_now(); + start_time = ktime_get(); if (remaining < 100000) { /* for small delays (<100us), just loop until limit is reached */ do { - end_time = ktime_now(); - } while (ktime_lt(end_time, spin_until)); + end_time = ktime_get(); + } while (ktime_compare(end_time, spin_until) < 0); } else { /* see do_nanosleep */ hrtimer_init_sleeper(&t, current); @@ -2162,7 +2148,7 @@ static void spin(struct pktgen_dev *pkt_dev, ktime_t spin_until) hrtimer_cancel(&t.timer); } while (t.task && pkt_dev->running && !signal_pending(current)); __set_current_state(TASK_RUNNING); - end_time = ktime_now(); + end_time = ktime_get(); } pkt_dev->idle_acc += ktime_to_ns(ktime_sub(end_time, start_time)); @@ -2912,8 +2898,7 @@ static void pktgen_run(struct pktgen_thread *t) pktgen_clear_counters(pkt_dev); pkt_dev->running = 1; /* Cranke yeself! */ pkt_dev->skb = NULL; - pkt_dev->started_at = - pkt_dev->next_tx = ktime_now(); + pkt_dev->started_at = pkt_dev->next_tx = ktime_get(); set_pkt_overhead(pkt_dev); @@ -3072,7 +3057,7 @@ static int pktgen_stop_device(struct pktgen_dev *pkt_dev) kfree_skb(pkt_dev->skb); pkt_dev->skb = NULL; - pkt_dev->stopped_at = ktime_now(); + pkt_dev->stopped_at = ktime_get(); pkt_dev->running = 0; show_results(pkt_dev, nr_frags); @@ -3091,7 +3076,7 @@ static struct pktgen_dev *next_to_run(struct pktgen_thread *t) continue; if (best == NULL) best = pkt_dev; - else if (ktime_lt(pkt_dev->next_tx, best->next_tx)) + else if (ktime_compare(pkt_dev->next_tx, best->next_tx) < 0) best = pkt_dev; } if_unlock(t); @@ -3176,14 +3161,14 @@ static void pktgen_rem_thread(struct pktgen_thread *t) static void pktgen_resched(struct pktgen_dev *pkt_dev) { - ktime_t idle_start = ktime_now(); + ktime_t idle_start = ktime_get(); schedule(); - pkt_dev->idle_acc += ktime_to_ns(ktime_sub(ktime_now(), idle_start)); + pkt_dev->idle_acc += ktime_to_ns(ktime_sub(ktime_get(), idle_start)); } static void pktgen_wait_for_skb(struct pktgen_dev *pkt_dev) { - ktime_t idle_start = ktime_now(); + ktime_t idle_start = ktime_get(); while (atomic_read(&(pkt_dev->skb->users)) != 1) { if (signal_pending(current)) @@ -3194,7 +3179,7 @@ static void pktgen_wait_for_skb(struct pktgen_dev *pkt_dev) else cpu_relax(); } - pkt_dev->idle_acc += ktime_to_ns(ktime_sub(ktime_now(), idle_start)); + pkt_dev->idle_acc += ktime_to_ns(ktime_sub(ktime_get(), idle_start)); } static void pktgen_xmit(struct pktgen_dev *pkt_dev) @@ -3216,7 +3201,7 @@ static void pktgen_xmit(struct pktgen_dev *pkt_dev) * "never transmit" */ if (unlikely(pkt_dev->delay == ULLONG_MAX)) { - pkt_dev->next_tx = ktime_add_ns(ktime_now(), ULONG_MAX); + pkt_dev->next_tx = ktime_add_ns(ktime_get(), ULONG_MAX); return; }