mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-04-02 04:24:05 +00:00
pktgen: spin using hrtimer
This changes how the pktgen thread spins/waits between packets if delay is configured. It uses a high res timer to wait for time to arrive. Signed-off-by: Stephen Hemminger <shemminger@vyatta.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
fd29cf7262
commit
2bc481cf43
2 changed files with 30 additions and 21 deletions
|
@ -485,6 +485,7 @@ void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t clock_id,
|
||||||
debug_object_init_on_stack(timer, &hrtimer_debug_descr);
|
debug_object_init_on_stack(timer, &hrtimer_debug_descr);
|
||||||
__hrtimer_init(timer, clock_id, mode);
|
__hrtimer_init(timer, clock_id, mode);
|
||||||
}
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(hrtimer_init_on_stack);
|
||||||
|
|
||||||
void destroy_hrtimer_on_stack(struct hrtimer *timer)
|
void destroy_hrtimer_on_stack(struct hrtimer *timer)
|
||||||
{
|
{
|
||||||
|
@ -1477,6 +1478,7 @@ void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, struct task_struct *task)
|
||||||
sl->timer.function = hrtimer_wakeup;
|
sl->timer.function = hrtimer_wakeup;
|
||||||
sl->task = task;
|
sl->task = task;
|
||||||
}
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(hrtimer_init_sleeper);
|
||||||
|
|
||||||
static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mode)
|
static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mode)
|
||||||
{
|
{
|
||||||
|
|
|
@ -131,6 +131,7 @@
|
||||||
#include <linux/ioport.h>
|
#include <linux/ioport.h>
|
||||||
#include <linux/interrupt.h>
|
#include <linux/interrupt.h>
|
||||||
#include <linux/capability.h>
|
#include <linux/capability.h>
|
||||||
|
#include <linux/hrtimer.h>
|
||||||
#include <linux/freezer.h>
|
#include <linux/freezer.h>
|
||||||
#include <linux/delay.h>
|
#include <linux/delay.h>
|
||||||
#include <linux/timer.h>
|
#include <linux/timer.h>
|
||||||
|
@ -2086,33 +2087,40 @@ static void pktgen_setup_inject(struct pktgen_dev *pkt_dev)
|
||||||
pkt_dev->nflows = 0;
|
pkt_dev->nflows = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline s64 delta_ns(ktime_t a, ktime_t b)
|
|
||||||
{
|
|
||||||
return ktime_to_ns(ktime_sub(a, b));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void spin(struct pktgen_dev *pkt_dev, ktime_t spin_until)
|
static void spin(struct pktgen_dev *pkt_dev, ktime_t spin_until)
|
||||||
{
|
{
|
||||||
ktime_t start, now;
|
ktime_t start;
|
||||||
s64 dt;
|
s32 remaining;
|
||||||
|
struct hrtimer_sleeper t;
|
||||||
|
|
||||||
start = now = ktime_now();
|
hrtimer_init_on_stack(&t.timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
|
||||||
|
hrtimer_set_expires(&t.timer, spin_until);
|
||||||
|
|
||||||
while ((dt = delta_ns(spin_until, now)) > 0) {
|
remaining = ktime_to_us(hrtimer_expires_remaining(&t.timer));
|
||||||
/* TODO: optimize sleeping behavior */
|
if (remaining <= 0)
|
||||||
if (dt > TICK_NSEC)
|
return;
|
||||||
schedule_timeout_interruptible(1);
|
|
||||||
else if (dt > 100*NSEC_PER_USEC) {
|
start = ktime_now();
|
||||||
if (!pkt_dev->running)
|
if (remaining < 100)
|
||||||
return;
|
udelay(remaining); /* really small just spin */
|
||||||
if (need_resched())
|
else {
|
||||||
|
/* see do_nanosleep */
|
||||||
|
hrtimer_init_sleeper(&t, current);
|
||||||
|
do {
|
||||||
|
set_current_state(TASK_INTERRUPTIBLE);
|
||||||
|
hrtimer_start_expires(&t.timer, HRTIMER_MODE_ABS);
|
||||||
|
if (!hrtimer_active(&t.timer))
|
||||||
|
t.task = NULL;
|
||||||
|
|
||||||
|
if (likely(t.task))
|
||||||
schedule();
|
schedule();
|
||||||
}
|
|
||||||
|
|
||||||
now = ktime_now();
|
hrtimer_cancel(&t.timer);
|
||||||
|
} while (t.task && pkt_dev->running && !signal_pending(current));
|
||||||
|
__set_current_state(TASK_RUNNING);
|
||||||
}
|
}
|
||||||
|
pkt_dev->idle_acc += ktime_to_ns(ktime_sub(ktime_now(), start));
|
||||||
pkt_dev->idle_acc += ktime_to_ns(ktime_sub(now, start));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void set_pkt_overhead(struct pktgen_dev *pkt_dev)
|
static inline void set_pkt_overhead(struct pktgen_dev *pkt_dev)
|
||||||
|
@ -3360,8 +3368,7 @@ static void pktgen_xmit(struct pktgen_dev *pkt_dev)
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (pkt_dev->delay) {
|
if (pkt_dev->delay) {
|
||||||
if (ktime_lt(ktime_now(), pkt_dev->next_tx))
|
spin(pkt_dev, pkt_dev->next_tx);
|
||||||
spin(pkt_dev, pkt_dev->next_tx);
|
|
||||||
|
|
||||||
/* This is max DELAY, this has special meaning of
|
/* This is max DELAY, this has special meaning of
|
||||||
* "never transmit"
|
* "never transmit"
|
||||||
|
|
Loading…
Add table
Reference in a new issue