Skip to content

Commit

Permalink
[NET]: Store skb->timestamp as offset to a base timestamp
Browse files Browse the repository at this point in the history
Reduces skb size by 8 bytes on 64-bit.

Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
kaber authored and David S. Miller committed Aug 29, 2005
1 parent 25ed891 commit a61bbcf
Show file tree
Hide file tree
Showing 39 changed files with 172 additions and 88 deletions.
2 changes: 1 addition & 1 deletion drivers/atm/ambassador.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {

// VC layer stats
atomic_inc(&atm_vcc->stats->rx);
do_gettimeofday(&skb->stamp);
__net_timestamp(skb);
// end of our responsability
atm_vcc->push (atm_vcc, skb);
return;
Expand Down
2 changes: 1 addition & 1 deletion drivers/atm/atmtcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
result = -ENOBUFS;
goto done;
}
do_gettimeofday(&new_skb->stamp);
__net_timestamp(new_skb);
memcpy(skb_put(new_skb,skb->len),skb->data,skb->len);
out_vcc->push(out_vcc,new_skb);
atomic_inc(&vcc->stats->tx);
Expand Down
2 changes: 1 addition & 1 deletion drivers/atm/eni.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ static int rx_aal0(struct atm_vcc *vcc)
return 0;
}
skb_put(skb,length);
skb->stamp = eni_vcc->timestamp;
skb_set_timestamp(skb, &eni_vcc->timestamp);
DPRINTK("got len %ld\n",length);
if (do_rx_dma(vcc,skb,1,length >> 2,length >> 2)) return 1;
eni_vcc->rxing++;
Expand Down
2 changes: 1 addition & 1 deletion drivers/atm/firestream.c
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
skb_put (skb, qe->p1 & 0xffff);
ATM_SKB(skb)->vcc = atm_vcc;
atomic_inc(&atm_vcc->stats->rx);
do_gettimeofday(&skb->stamp);
__net_timestamp(skb);
fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
atm_vcc->push (atm_vcc, skb);
fs_dprintk (FS_DEBUG_ALLOC, "Free rec-d: %p\n", pe);
Expand Down
2 changes: 1 addition & 1 deletion drivers/atm/fore200e.c
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
return -ENOMEM;
}

do_gettimeofday(&skb->stamp);
__net_timestamp(skb);

#ifdef FORE200E_52BYTE_AAL0_SDU
if (cell_header) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/atm/he.c
Original file line number Diff line number Diff line change
Expand Up @@ -1886,7 +1886,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
if (rx_skb_reserve > 0)
skb_reserve(skb, rx_skb_reserve);

do_gettimeofday(&skb->stamp);
__net_timestamp(skb);

for (iov = he_vcc->iov_head;
iov < he_vcc->iov_tail; ++iov) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/atm/horizon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
// VC layer stats
atomic_inc(&vcc->stats->rx);
do_gettimeofday(&skb->stamp);
__net_timestamp(skb);
// end of our responsability
vcc->push (vcc, skb);
}
Expand Down
8 changes: 4 additions & 4 deletions drivers/atm/idt77252.c
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
cell, ATM_CELL_PAYLOAD);

ATM_SKB(sb)->vcc = vcc;
do_gettimeofday(&sb->stamp);
__net_timestamp(sb);
vcc->push(vcc, sb);
atomic_inc(&vcc->stats->rx);

Expand Down Expand Up @@ -1179,7 +1179,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)

skb_trim(skb, len);
ATM_SKB(skb)->vcc = vcc;
do_gettimeofday(&skb->stamp);
__net_timestamp(skb);

vcc->push(vcc, skb);
atomic_inc(&vcc->stats->rx);
Expand All @@ -1201,7 +1201,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)

skb_trim(skb, len);
ATM_SKB(skb)->vcc = vcc;
do_gettimeofday(&skb->stamp);
__net_timestamp(skb);

vcc->push(vcc, skb);
atomic_inc(&vcc->stats->rx);
Expand Down Expand Up @@ -1340,7 +1340,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
ATM_CELL_PAYLOAD);

ATM_SKB(sb)->vcc = vcc;
do_gettimeofday(&sb->stamp);
__net_timestamp(sb);
vcc->push(vcc, sb);
atomic_inc(&vcc->stats->rx);

Expand Down
2 changes: 1 addition & 1 deletion drivers/atm/lanai.c
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
skb_put(skb, size);
vcc_rx_memcpy(skb->data, lvcc, size);
ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
do_gettimeofday(&skb->stamp);
__net_timestamp(skb);
lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
atomic_inc(&lvcc->rx.atmvcc->stats->rx);
out:
Expand Down
10 changes: 5 additions & 5 deletions drivers/atm/nicstar.c
Original file line number Diff line number Diff line change
Expand Up @@ -2213,7 +2213,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
memcpy(sb->tail, cell, ATM_CELL_PAYLOAD);
skb_put(sb, ATM_CELL_PAYLOAD);
ATM_SKB(sb)->vcc = vcc;
do_gettimeofday(&sb->stamp);
__net_timestamp(sb);
vcc->push(vcc, sb);
atomic_inc(&vcc->stats->rx);
cell += ATM_CELL_PAYLOAD;
Expand Down Expand Up @@ -2346,7 +2346,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
skb->destructor = ns_sb_destructor;
#endif /* NS_USE_DESTRUCTORS */
ATM_SKB(skb)->vcc = vcc;
do_gettimeofday(&skb->stamp);
__net_timestamp(skb);
vcc->push(vcc, skb);
atomic_inc(&vcc->stats->rx);
}
Expand All @@ -2373,7 +2373,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
sb->destructor = ns_sb_destructor;
#endif /* NS_USE_DESTRUCTORS */
ATM_SKB(sb)->vcc = vcc;
do_gettimeofday(&sb->stamp);
__net_timestamp(sb);
vcc->push(vcc, sb);
atomic_inc(&vcc->stats->rx);
}
Expand All @@ -2398,7 +2398,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
memcpy(skb->data, sb->data, NS_SMBUFSIZE);
skb_put(skb, len - NS_SMBUFSIZE);
ATM_SKB(skb)->vcc = vcc;
do_gettimeofday(&skb->stamp);
__net_timestamp(skb);
vcc->push(vcc, skb);
atomic_inc(&vcc->stats->rx);
}
Expand Down Expand Up @@ -2505,7 +2505,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
#ifdef NS_USE_DESTRUCTORS
hb->destructor = ns_hb_destructor;
#endif /* NS_USE_DESTRUCTORS */
do_gettimeofday(&hb->stamp);
__net_timestamp(hb);
vcc->push(vcc, hb);
atomic_inc(&vcc->stats->rx);
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/atm/zatm.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ unsigned long *x;
EVENT("error code 0x%x/0x%x\n",(here[3] & uPD98401_AAL5_ES) >>
uPD98401_AAL5_ES_SHIFT,error);
skb = ((struct rx_buffer_head *) bus_to_virt(here[2]))->skb;
do_gettimeofday(&skb->stamp);
__net_timestamp(skb);
#if 0
printk("[-3..0] 0x%08lx 0x%08lx 0x%08lx 0x%08lx\n",((unsigned *) skb->data)[-3],
((unsigned *) skb->data)[-2],((unsigned *) skb->data)[-1],
Expand Down
47 changes: 45 additions & 2 deletions include/linux/skbuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,20 @@ struct skb_shared_info {
#define SKB_DATAREF_SHIFT 16
#define SKB_DATAREF_MASK ((1 << SKB_DATAREF_SHIFT) - 1)

extern struct timeval skb_tv_base;

struct skb_timeval {
u32 off_sec;
u32 off_usec;
};

/**
* struct sk_buff - socket buffer
* @next: Next buffer in list
* @prev: Previous buffer in list
* @list: List we are on
* @sk: Socket we are owned by
* @stamp: Time we arrived
* @tstamp: Time we arrived stored as offset to skb_tv_base
* @dev: Device we arrived on/are leaving by
* @input_dev: Device we arrived on
* @h: Transport layer header
Expand Down Expand Up @@ -202,7 +209,7 @@ struct sk_buff {
struct sk_buff *prev;

struct sock *sk;
struct timeval stamp;
struct skb_timeval tstamp;
struct net_device *dev;
struct net_device *input_dev;

Expand Down Expand Up @@ -1213,6 +1220,42 @@ static inline void *skb_header_pointer(const struct sk_buff *skb, int offset,
extern void skb_init(void);
extern void skb_add_mtu(int mtu);

/**
* skb_get_timestamp - get timestamp from a skb
* @skb: skb to get stamp from
* @stamp: pointer to struct timeval to store stamp in
*
* Timestamps are stored in the skb as offsets to a base timestamp.
* This function converts the offset back to a struct timeval and stores
* it in stamp.
*/
static inline void skb_get_timestamp(struct sk_buff *skb, struct timeval *stamp)
{
stamp->tv_sec = skb->tstamp.off_sec;
stamp->tv_usec = skb->tstamp.off_usec;
if (skb->tstamp.off_sec) {
stamp->tv_sec += skb_tv_base.tv_sec;
stamp->tv_usec += skb_tv_base.tv_usec;
}
}

/**
* skb_set_timestamp - set timestamp of a skb
* @skb: skb to set stamp of
* @stamp: pointer to struct timeval to get stamp from
*
* Timestamps are stored in the skb as offsets to a base timestamp.
* This function converts a struct timeval to an offset and stores
* it in the skb.
*/
static inline void skb_set_timestamp(struct sk_buff *skb, struct timeval *stamp)
{
skb->tstamp.off_sec = stamp->tv_sec - skb_tv_base.tv_sec;
skb->tstamp.off_usec = stamp->tv_usec - skb_tv_base.tv_usec;
}

extern void __net_timestamp(struct sk_buff *skb);

#ifdef CONFIG_NETFILTER
static inline void nf_conntrack_put(struct nf_conntrack *nfct)
{
Expand Down
2 changes: 1 addition & 1 deletion include/net/bluetooth/hci_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ static inline int hci_recv_frame(struct sk_buff *skb)
bt_cb(skb)->incoming = 1;

/* Time stamp */
do_gettimeofday(&skb->stamp);
__net_timestamp(skb);

/* Queue frame for rx task */
skb_queue_tail(&hdev->rx_q, skb);
Expand Down
9 changes: 8 additions & 1 deletion include/net/neighbour.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,14 @@ __neigh_lookup_errno(struct neigh_table *tbl, const void *pkey,
return neigh_create(tbl, pkey, dev);
}

#define LOCALLY_ENQUEUED -2
struct neighbour_cb {
unsigned long sched_next;
unsigned int flags;
};

#define LOCALLY_ENQUEUED 0x1

#define NEIGH_CB(skb) ((struct neighbour_cb *)(skb)->cb)

#endif
#endif
Expand Down
13 changes: 8 additions & 5 deletions include/net/sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -1282,16 +1282,19 @@ static inline int sock_intr_errno(long timeo)
static __inline__ void
sock_recv_timestamp(struct msghdr *msg, struct sock *sk, struct sk_buff *skb)
{
struct timeval *stamp = &skb->stamp;
struct timeval stamp;

skb_get_timestamp(skb, &stamp);
if (sock_flag(sk, SOCK_RCVTSTAMP)) {
/* Race occurred between timestamp enabling and packet
receiving. Fill in the current time for now. */
if (stamp->tv_sec == 0)
do_gettimeofday(stamp);
if (stamp.tv_sec == 0)
do_gettimeofday(&stamp);
skb_set_timestamp(skb, &stamp);
put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMP, sizeof(struct timeval),
stamp);
&stamp);
} else
sk->sk_stamp = *stamp;
sk->sk_stamp = stamp;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion net/bluetooth/hci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ static int hci_send_frame(struct sk_buff *skb)

if (atomic_read(&hdev->promisc)) {
/* Time stamp */
do_gettimeofday(&skb->stamp);
__net_timestamp(skb);

hci_send_to_sock(hdev, skb);
}
Expand Down
2 changes: 1 addition & 1 deletion net/bluetooth/hci_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ void hci_si_event(struct hci_dev *hdev, int type, int dlen, void *data)
memcpy(ev->data, data, dlen);

bt_cb(skb)->incoming = 1;
do_gettimeofday(&skb->stamp);
__net_timestamp(skb);

bt_cb(skb)->pkt_type = HCI_EVENT_PKT;
skb->dev = (void *) hdev;
Expand Down
8 changes: 6 additions & 2 deletions net/bluetooth/hci_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,12 @@ static inline void hci_sock_cmsg(struct sock *sk, struct msghdr *msg, struct sk_
put_cmsg(msg, SOL_HCI, HCI_CMSG_DIR, sizeof(incoming), &incoming);
}

if (mask & HCI_CMSG_TSTAMP)
put_cmsg(msg, SOL_HCI, HCI_CMSG_TSTAMP, sizeof(skb->stamp), &skb->stamp);
if (mask & HCI_CMSG_TSTAMP) {
struct timeval tv;

skb_get_timestamp(skb, &tv);
put_cmsg(msg, SOL_HCI, HCI_CMSG_TSTAMP, sizeof(tv), &tv);
}
}

static int hci_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
Expand Down
2 changes: 1 addition & 1 deletion net/bridge/netfilter/ebt_ulog.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static void ebt_ulog(const struct sk_buff *skb, unsigned int hooknr,
pm->version = EBT_ULOG_VERSION;
do_gettimeofday(&pm->stamp);
if (ub->qlen == 1)
ub->skb->stamp = pm->stamp;
skb_set_timestamp(ub->skb, &pm->stamp);
pm->data_len = copy_len;
pm->mark = skb->nfmark;
pm->hook = hooknr;
Expand Down
28 changes: 19 additions & 9 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1009,13 +1009,22 @@ void net_disable_timestamp(void)
atomic_dec(&netstamp_needed);
}

static inline void net_timestamp(struct timeval *stamp)
void __net_timestamp(struct sk_buff *skb)
{
struct timeval tv;

do_gettimeofday(&tv);
skb_set_timestamp(skb, &tv);
}
EXPORT_SYMBOL(__net_timestamp);

static inline void net_timestamp(struct sk_buff *skb)
{
if (atomic_read(&netstamp_needed))
do_gettimeofday(stamp);
__net_timestamp(skb);
else {
stamp->tv_sec = 0;
stamp->tv_usec = 0;
skb->tstamp.off_sec = 0;
skb->tstamp.off_usec = 0;
}
}

Expand All @@ -1027,7 +1036,8 @@ static inline void net_timestamp(struct timeval *stamp)
void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev)
{
struct packet_type *ptype;
net_timestamp(&skb->stamp);

net_timestamp(skb);

rcu_read_lock();
list_for_each_entry_rcu(ptype, &ptype_all, list) {
Expand Down Expand Up @@ -1379,8 +1389,8 @@ int netif_rx(struct sk_buff *skb)
if (netpoll_rx(skb))
return NET_RX_DROP;

if (!skb->stamp.tv_sec)
net_timestamp(&skb->stamp);
if (!skb->tstamp.off_sec)
net_timestamp(skb);

/*
* The code is rearranged so that the path is the most
Expand Down Expand Up @@ -1566,8 +1576,8 @@ int netif_receive_skb(struct sk_buff *skb)
if (skb->dev->poll && netpoll_rx(skb))
return NET_RX_DROP;

if (!skb->stamp.tv_sec)
net_timestamp(&skb->stamp);
if (!skb->tstamp.off_sec)
net_timestamp(skb);

if (!skb->input_dev)
skb->input_dev = skb->dev;
Expand Down
Loading

0 comments on commit a61bbcf

Please sign in to comment.