debuggers.hg

annotate tools/remus/kmod/sch_queue.c @ 20950:989014ce7b4a

Remus: fix ia64 build

This patch fixes the following error:
/xen-unstable.hg/tools/remus/kmod/sch_queue.c: In function
`is_foreign':
/xen-unstable.hg/tools/remus/kmod/sch_queue.c:51: error:
`phys_to_machine_mapping' undeclared (first use in this function)

Signed-off-by: KUWAMURA Shin'ya <kuwa@jp.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Feb 05 10:37:24 2010 +0000 (2010-02-05)
parents 1c8c18ae1d3b
children 373daaeb636e
rev   line source
keir@20486 1 /*
keir@20486 2 * sch_queue.c Queue traffic until an explicit release command
keir@20486 3 *
keir@20486 4 * This program is free software; you can redistribute it and/or
keir@20486 5 * modify it under the terms of the GNU General Public License
keir@20486 6 * as published by the Free Software Foundation; either version
keir@20486 7 * 2 of the License, or (at your option) any later version.
keir@20486 8 *
keir@20486 9 * The operation of the buffer is as follows:
keir@20486 10 * When a checkpoint begins, a barrier is inserted into the
keir@20486 11 * network queue by a netlink request (it operates by storing
keir@20486 12 * a pointer to the next packet which arrives and blocking dequeue
keir@20486 13 * when that packet is at the head of the queue).
keir@20486 14 * When a checkpoint completes (the backup acknowledges receipt),
keir@20486 15 * currently-queued packets are released.
keir@20486 16 * So it supports two operations, barrier and release.
keir@20486 17 */
keir@20486 18
keir@20486 19 #include <linux/config.h>
keir@20486 20 #include <linux/module.h>
keir@20486 21 #include <linux/types.h>
keir@20486 22 #include <linux/kernel.h>
keir@20486 23 #include <linux/errno.h>
keir@20486 24 #include <linux/netdevice.h>
keir@20486 25 #include <linux/skbuff.h>
keir@20486 26 #include <net/pkt_sched.h>
keir@20486 27
keir@20486 28 /* xenbus directory */
keir@20486 29 #define FIFO_BUF (10*1024*1024)
keir@20486 30
keir@20486 31 #define TCQ_CHECKPOINT 0
keir@20486 32 #define TCQ_DEQUEUE 1
keir@20486 33
keir@20486 34 struct queue_sched_data {
keir@20486 35 /* this packet is the first packet which should not be delivered.
keir@20486 36 * If it is NULL, queue_enqueue will set it to the next packet it sees. */
keir@20486 37 struct sk_buff *stop;
keir@20486 38 };
keir@20486 39
keir@20486 40 struct tc_queue_qopt {
keir@20486 41 /* 0: reset stop packet pointer
keir@20486 42 * 1: dequeue to stop pointer */
keir@20486 43 int action;
keir@20486 44 };
keir@20486 45
keir@20486 46 /* borrowed from drivers/xen/netback/loopback.c */
keir@20950 47 #ifdef CONFIG_X86
keir@20486 48 static int is_foreign(unsigned long pfn)
keir@20486 49 {
keir@20486 50 /* NB. Play it safe for auto-translation mode. */
keir@20486 51 return (xen_feature(XENFEAT_auto_translated_physmap) ||
keir@20486 52 (phys_to_machine_mapping[pfn] & FOREIGN_FRAME_BIT));
keir@20486 53 }
keir@20950 54 #else
keir@20950 55 /* How to detect a foreign mapping? Play it safe. */
keir@20950 56 #define is_foreign(pfn) (1)
keir@20950 57 #endif
keir@20486 58
keir@20486 59 static int skb_remove_foreign_references(struct sk_buff *skb)
keir@20486 60 {
keir@20486 61 struct page *page;
keir@20486 62 unsigned long pfn;
keir@20486 63 int i, off;
keir@20486 64 char *vaddr;
keir@20486 65
keir@20486 66 BUG_ON(skb_shinfo(skb)->frag_list);
keir@20486 67
keir@20486 68 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
keir@20486 69 pfn = page_to_pfn(skb_shinfo(skb)->frags[i].page);
keir@20486 70 if (!is_foreign(pfn))
keir@20486 71 continue;
keir@20486 72 /*
keir@20486 73 printk("foreign ref found\n");
keir@20486 74 */
keir@20486 75 page = alloc_page(GFP_ATOMIC | __GFP_NOWARN);
keir@20486 76 if (unlikely(!page))
keir@20486 77 return 0;
keir@20486 78
keir@20486 79 vaddr = kmap_skb_frag(&skb_shinfo(skb)->frags[i]);
keir@20486 80 off = skb_shinfo(skb)->frags[i].page_offset;
keir@20486 81 memcpy(page_address(page) + off, vaddr + off,
keir@20486 82 skb_shinfo(skb)->frags[i].size);
keir@20486 83 kunmap_skb_frag(vaddr);
keir@20486 84
keir@20486 85 put_page(skb_shinfo(skb)->frags[i].page);
keir@20486 86 skb_shinfo(skb)->frags[i].page = page;
keir@20486 87 }
keir@20486 88
keir@20486 89 return 1;
keir@20486 90 }
keir@20486 91
keir@20486 92 static int queue_enqueue(struct sk_buff *skb, struct Qdisc* sch)
keir@20486 93 {
keir@20486 94 struct queue_sched_data *q = qdisc_priv(sch);
keir@20486 95
keir@20486 96 if (likely(sch->qstats.backlog + skb->len <= FIFO_BUF))
keir@20486 97 {
keir@20486 98 if (!q->stop)
keir@20486 99 q->stop = skb;
keir@20486 100
keir@20486 101 if (!skb_remove_foreign_references(skb)) {
keir@20486 102 printk("error removing foreign ref\n");
keir@20486 103 return qdisc_reshape_fail(skb, sch);
keir@20486 104 }
keir@20486 105
keir@20486 106 return qdisc_enqueue_tail(skb, sch);
keir@20486 107 }
keir@20486 108 printk("queue reported full: %d,%d\n", sch->qstats.backlog, skb->len);
keir@20486 109
keir@20486 110 return qdisc_reshape_fail(skb, sch);
keir@20486 111 }
keir@20486 112
keir@20486 113 /* dequeue doesn't actually dequeue until the release command is
keir@20486 114 * received. */
keir@20486 115 static inline struct sk_buff *queue_dequeue(struct Qdisc* sch)
keir@20486 116 {
keir@20486 117 struct queue_sched_data *q = qdisc_priv(sch);
keir@20486 118 struct sk_buff* peek;
keir@20486 119 /*
keir@20486 120 struct timeval tv;
keir@20486 121
keir@20486 122 if (!q->stop) {
keir@20486 123 do_gettimeofday(&tv);
keir@20486 124 printk("packet dequeued at %lu.%06lu\n", tv.tv_sec, tv.tv_usec);
keir@20486 125 }
keir@20486 126 */
keir@20486 127
keir@20486 128 if (sch->flags & TCQ_F_THROTTLED)
keir@20486 129 return NULL;
keir@20486 130
keir@20486 131 peek = (struct sk_buff *)((sch->q).next);
keir@20486 132
keir@20486 133 /* this pointer comparison may be shady */
keir@20486 134 if (peek == q->stop) {
keir@20486 135 /*
keir@20486 136 do_gettimeofday(&tv);
keir@20486 137 printk("stop packet at %lu.%06lu\n", tv.tv_sec, tv.tv_usec);
keir@20486 138 */
keir@20486 139
keir@20486 140 /* this is the tail of the last round. Release it and block the queue */
keir@20486 141 sch->flags |= TCQ_F_THROTTLED;
keir@20486 142 return NULL;
keir@20486 143 }
keir@20486 144
keir@20486 145 return qdisc_dequeue_head(sch);
keir@20486 146 }
keir@20486 147
keir@20486 148 static int queue_init(struct Qdisc *sch, struct rtattr *opt)
keir@20486 149 {
keir@20486 150 sch->flags |= TCQ_F_THROTTLED;
keir@20486 151
keir@20486 152 return 0;
keir@20486 153 }
keir@20486 154
keir@20486 155 /* receives two messages:
keir@20486 156 * 0: checkpoint queue (set stop to next packet)
keir@20486 157 * 1: dequeue until stop */
keir@20486 158 static int queue_change(struct Qdisc* sch, struct rtattr* opt)
keir@20486 159 {
keir@20486 160 struct queue_sched_data *q = qdisc_priv(sch);
keir@20486 161 struct tc_queue_qopt* msg;
keir@20486 162 /*
keir@20486 163 struct timeval tv;
keir@20486 164 */
keir@20486 165
keir@20486 166 if (!opt || RTA_PAYLOAD(opt) < sizeof(*msg))
keir@20486 167 return -EINVAL;
keir@20486 168
keir@20486 169 msg = RTA_DATA(opt);
keir@20486 170
keir@20486 171 if (msg->action == TCQ_CHECKPOINT) {
keir@20486 172 /* reset stop */
keir@20486 173 q->stop = NULL;
keir@20486 174 } else if (msg->action == TCQ_DEQUEUE) {
keir@20486 175 /* dequeue */
keir@20486 176 sch->flags &= ~TCQ_F_THROTTLED;
keir@20486 177 netif_schedule(sch->dev);
keir@20486 178 /*
keir@20486 179 do_gettimeofday(&tv);
keir@20486 180 printk("queue release at %lu.%06lu (%d bytes)\n", tv.tv_sec, tv.tv_usec,
keir@20486 181 sch->qstats.backlog);
keir@20486 182 */
keir@20486 183 } else {
keir@20486 184 return -EINVAL;
keir@20486 185 }
keir@20486 186
keir@20486 187 return 0;
keir@20486 188 }
keir@20486 189
keir@20486 190 struct Qdisc_ops queue_qdisc_ops = {
keir@20486 191 .id = "queue",
keir@20486 192 .priv_size = sizeof(struct queue_sched_data),
keir@20486 193 .enqueue = queue_enqueue,
keir@20486 194 .dequeue = queue_dequeue,
keir@20486 195 .init = queue_init,
keir@20486 196 .change = queue_change,
keir@20486 197 .owner = THIS_MODULE,
keir@20486 198 };
keir@20486 199
keir@20486 200 static int __init queue_module_init(void)
keir@20486 201 {
keir@20486 202 printk("loading queue\n");
keir@20486 203 return register_qdisc(&queue_qdisc_ops);
keir@20486 204 }
keir@20486 205
keir@20486 206 static void __exit queue_module_exit(void)
keir@20486 207 {
keir@20486 208 printk("queue unloaded\n");
keir@20486 209 unregister_qdisc(&queue_qdisc_ops);
keir@20486 210 }
keir@20486 211 module_init(queue_module_init)
keir@20486 212 module_exit(queue_module_exit)
keir@20486 213 MODULE_LICENSE("GPL");