Skip to content

Commit

Permalink
time64.h: consolidate uses of PSEC_PER_NSEC
Browse files Browse the repository at this point in the history
[ Upstream commit 837ced3 ]

Time-sensitive networking code needs to work with PTP times expressed in
nanoseconds, and with packet transmission times expressed in
picoseconds, since those would be fractional at higher than gigabit
speed when expressed in nanoseconds.

Convert the existing uses in tc-taprio and the ocelot/felix DSA driver
to a PSEC_PER_NSEC macro. This macro is placed in include/linux/time64.h
as opposed to its relatives (PSEC_PER_SEC etc) from include/vdso/time64.h
because the vDSO library does not (yet) need/use it.

Cc: Andy Lutomirski <luto@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Vincenzo Frascino <vincenzo.frascino@arm.com> # for the vDSO parts
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Stable-dep-of: 11afdc6 ("net: dsa: felix: tc-taprio intervals smaller than MTU should send at least one packet")
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
vladimiroltean authored and gregkh committed Sep 15, 2022
1 parent 1ceb383 commit c078abe
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions drivers/net/dsa/ocelot/felix_vsc9959.c
Expand Up @@ -16,6 +16,7 @@
#include <linux/iopoll.h>
#include <linux/mdio.h>
#include <linux/pci.h>
#include <linux/time.h>
#include "felix.h"

#define VSC9959_NUM_PORTS 6
Expand Down Expand Up @@ -1592,7 +1593,7 @@ static void vsc9959_tas_guard_bands_update(struct ocelot *ocelot, int port)
u32 max_sdu;

if (min_gate_len[tc] == U64_MAX /* Gate always open */ ||
min_gate_len[tc] * 1000 > needed_bit_time_ps) {
min_gate_len[tc] * PSEC_PER_NSEC > needed_bit_time_ps) {
/* Setting QMAXSDU_CFG to 0 disables oversized frame
* dropping.
*/
Expand All @@ -1606,7 +1607,7 @@ static void vsc9959_tas_guard_bands_update(struct ocelot *ocelot, int port)
* frame, make sure to enable oversize frame dropping
* for frames larger than the smallest that would fit.
*/
max_sdu = div_u64(min_gate_len[tc] * 1000,
max_sdu = div_u64(min_gate_len[tc] * PSEC_PER_NSEC,
picos_per_byte);
/* A TC gate may be completely closed, which is a
* special case where all packets are oversized.
Expand Down
3 changes: 3 additions & 0 deletions include/linux/time64.h
Expand Up @@ -20,6 +20,9 @@ struct itimerspec64 {
struct timespec64 it_value;
};

/* Parameters used to convert the timespec values: */
#define PSEC_PER_NSEC 1000L

/* Located here for timespec[64]_valid_strict */
#define TIME64_MAX ((s64)~((u64)1 << 63))
#define TIME64_MIN (-TIME64_MAX - 1)
Expand Down
5 changes: 3 additions & 2 deletions net/sched/sch_taprio.c
Expand Up @@ -18,6 +18,7 @@
#include <linux/module.h>
#include <linux/spinlock.h>
#include <linux/rcupdate.h>
#include <linux/time.h>
#include <net/netlink.h>
#include <net/pkt_sched.h>
#include <net/pkt_cls.h>
Expand Down Expand Up @@ -176,7 +177,7 @@ static ktime_t get_interval_end_time(struct sched_gate_list *sched,

static int length_to_duration(struct taprio_sched *q, int len)
{
return div_u64(len * atomic64_read(&q->picos_per_byte), 1000);
return div_u64(len * atomic64_read(&q->picos_per_byte), PSEC_PER_NSEC);
}

/* Returns the entry corresponding to next available interval. If
Expand Down Expand Up @@ -551,7 +552,7 @@ static struct sk_buff *taprio_peek(struct Qdisc *sch)
static void taprio_set_budget(struct taprio_sched *q, struct sched_entry *entry)
{
atomic_set(&entry->budget,
div64_u64((u64)entry->interval * 1000,
div64_u64((u64)entry->interval * PSEC_PER_NSEC,
atomic64_read(&q->picos_per_byte)));
}

Expand Down

0 comments on commit c078abe

Please sign in to comment.