taprio: make clock reference conversions easier
authorVedang Patel <vedang.patel@intel.com>
Tue, 25 Jun 2019 22:07:18 +0000 (15:07 -0700)
committerDavid S. Miller <davem@davemloft.net>
Fri, 28 Jun 2019 21:45:34 +0000 (14:45 -0700)
Later in this series we will need to transform from
CLOCK_MONOTONIC (used in TCP) to the clock reference used in TAPRIO.

Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
Signed-off-by: Vedang Patel <vedang.patel@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/sched/sch_taprio.c

index 078230e44471a1be170bfbd904cb80ea16e611d3..5c5e7db520dccb5ddca06cf2e2a528ccb32180e6 100644 (file)
@@ -61,6 +61,7 @@ struct taprio_sched {
        struct Qdisc **qdiscs;
        struct Qdisc *root;
        u32 flags;
+       enum tk_offsets tk_offset;
        int clockid;
        atomic64_t picos_per_byte; /* Using picoseconds because for 10Gbps+
                                    * speeds it's sub-nanoseconds per byte
@@ -71,7 +72,6 @@ struct taprio_sched {
        struct sched_entry __rcu *current_entry;
        struct sched_gate_list __rcu *oper_sched;
        struct sched_gate_list __rcu *admin_sched;
-       ktime_t (*get_time)(void);
        struct hrtimer advance_timer;
        struct list_head taprio_list;
        int txtime_delay;
@@ -85,6 +85,20 @@ static ktime_t sched_base_time(const struct sched_gate_list *sched)
        return ns_to_ktime(sched->base_time);
 }
 
+static ktime_t taprio_get_time(struct taprio_sched *q)
+{
+       ktime_t mono = ktime_get();
+
+       switch (q->tk_offset) {
+       case TK_OFFS_MAX:
+               return mono;
+       default:
+               return ktime_mono_to_any(mono, q->tk_offset);
+       }
+
+       return KTIME_MAX;
+}
+
 static void taprio_free_sched_cb(struct rcu_head *head)
 {
        struct sched_gate_list *sched = container_of(head, struct sched_gate_list, rcu);
@@ -278,7 +292,7 @@ static long get_packet_txtime(struct sk_buff *skb, struct Qdisc *sch)
        struct sched_entry *entry;
        bool sched_changed;
 
-       now = q->get_time();
+       now = taprio_get_time(q);
        minimum_time = ktime_add_ns(now, q->txtime_delay);
 
        rcu_read_lock();
@@ -469,7 +483,7 @@ static struct sk_buff *taprio_dequeue(struct Qdisc *sch)
                        continue;
 
                len = qdisc_pkt_len(skb);
-               guard = ktime_add_ns(q->get_time(),
+               guard = ktime_add_ns(taprio_get_time(q),
                                     length_to_duration(q, len));
 
                /* In the case that there's no gate entry, there's no
@@ -838,7 +852,7 @@ static int taprio_get_start_time(struct Qdisc *sch,
        s64 n;
 
        base = sched_base_time(sched);
-       now = q->get_time();
+       now = taprio_get_time(q);
 
        if (ktime_after(base, now)) {
                *start = base;
@@ -1084,16 +1098,16 @@ static int taprio_change(struct Qdisc *sch, struct nlattr *opt,
 
        switch (q->clockid) {
        case CLOCK_REALTIME:
-               q->get_time = ktime_get_real;
+               q->tk_offset = TK_OFFS_REAL;
                break;
        case CLOCK_MONOTONIC:
-               q->get_time = ktime_get;
+               q->tk_offset = TK_OFFS_MAX;
                break;
        case CLOCK_BOOTTIME:
-               q->get_time = ktime_get_boottime;
+               q->tk_offset = TK_OFFS_BOOT;
                break;
        case CLOCK_TAI:
-               q->get_time = ktime_get_clocktai;
+               q->tk_offset = TK_OFFS_TAI;
                break;
        default:
                NL_SET_ERR_MSG(extack, "Invalid 'clockid'");