Commit cda9de0b authored by Yejune Deng's avatar Yejune Deng Committed by David S. Miller

pktgen: add pktgen_handle_all_threads() for the same code

The pktgen_{run, reset, stop}_all_threads() has the same code,
so add pktgen_handle_all_threads() for it.
Signed-off-by: default avatarYejune Deng <yejune.deng@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 85eb1389
...@@ -467,7 +467,7 @@ static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t, ...@@ -467,7 +467,7 @@ static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t,
static int pktgen_device_event(struct notifier_block *, unsigned long, void *); static int pktgen_device_event(struct notifier_block *, unsigned long, void *);
static void pktgen_run_all_threads(struct pktgen_net *pn); static void pktgen_run_all_threads(struct pktgen_net *pn);
static void pktgen_reset_all_threads(struct pktgen_net *pn); static void pktgen_reset_all_threads(struct pktgen_net *pn);
static void pktgen_stop_all_threads_ifs(struct pktgen_net *pn); static void pktgen_stop_all_threads(struct pktgen_net *pn);
static void pktgen_stop(struct pktgen_thread *t); static void pktgen_stop(struct pktgen_thread *t);
static void pktgen_clear_counters(struct pktgen_dev *pkt_dev); static void pktgen_clear_counters(struct pktgen_dev *pkt_dev);
...@@ -516,14 +516,11 @@ static ssize_t pgctrl_write(struct file *file, const char __user *buf, ...@@ -516,14 +516,11 @@ static ssize_t pgctrl_write(struct file *file, const char __user *buf,
data[count - 1] = 0; /* Strip trailing '\n' and terminate string */ data[count - 1] = 0; /* Strip trailing '\n' and terminate string */
if (!strcmp(data, "stop")) if (!strcmp(data, "stop"))
pktgen_stop_all_threads_ifs(pn); pktgen_stop_all_threads(pn);
else if (!strcmp(data, "start")) else if (!strcmp(data, "start"))
pktgen_run_all_threads(pn); pktgen_run_all_threads(pn);
else if (!strcmp(data, "reset")) else if (!strcmp(data, "reset"))
pktgen_reset_all_threads(pn); pktgen_reset_all_threads(pn);
else else
return -EINVAL; return -EINVAL;
...@@ -3027,20 +3024,25 @@ static void pktgen_run(struct pktgen_thread *t) ...@@ -3027,20 +3024,25 @@ static void pktgen_run(struct pktgen_thread *t)
t->control &= ~(T_STOP); t->control &= ~(T_STOP);
} }
static void pktgen_stop_all_threads_ifs(struct pktgen_net *pn) static void pktgen_handle_all_threads(struct pktgen_net *pn, u32 flags)
{ {
struct pktgen_thread *t; struct pktgen_thread *t;
func_enter();
mutex_lock(&pktgen_thread_lock); mutex_lock(&pktgen_thread_lock);
list_for_each_entry(t, &pn->pktgen_threads, th_list) list_for_each_entry(t, &pn->pktgen_threads, th_list)
t->control |= T_STOP; t->control |= (flags);
mutex_unlock(&pktgen_thread_lock); mutex_unlock(&pktgen_thread_lock);
} }
static void pktgen_stop_all_threads(struct pktgen_net *pn)
{
func_enter();
pktgen_handle_all_threads(pn, T_STOP);
}
static int thread_is_running(const struct pktgen_thread *t) static int thread_is_running(const struct pktgen_thread *t)
{ {
const struct pktgen_dev *pkt_dev; const struct pktgen_dev *pkt_dev;
...@@ -3103,16 +3105,9 @@ static int pktgen_wait_all_threads_run(struct pktgen_net *pn) ...@@ -3103,16 +3105,9 @@ static int pktgen_wait_all_threads_run(struct pktgen_net *pn)
static void pktgen_run_all_threads(struct pktgen_net *pn) static void pktgen_run_all_threads(struct pktgen_net *pn)
{ {
struct pktgen_thread *t;
func_enter(); func_enter();
mutex_lock(&pktgen_thread_lock); pktgen_handle_all_threads(pn, T_RUN);
list_for_each_entry(t, &pn->pktgen_threads, th_list)
t->control |= (T_RUN);
mutex_unlock(&pktgen_thread_lock);
/* Propagate thread->control */ /* Propagate thread->control */
schedule_timeout_interruptible(msecs_to_jiffies(125)); schedule_timeout_interruptible(msecs_to_jiffies(125));
...@@ -3122,16 +3117,9 @@ static void pktgen_run_all_threads(struct pktgen_net *pn) ...@@ -3122,16 +3117,9 @@ static void pktgen_run_all_threads(struct pktgen_net *pn)
static void pktgen_reset_all_threads(struct pktgen_net *pn) static void pktgen_reset_all_threads(struct pktgen_net *pn)
{ {
struct pktgen_thread *t;
func_enter(); func_enter();
mutex_lock(&pktgen_thread_lock); pktgen_handle_all_threads(pn, T_REMDEVALL);
list_for_each_entry(t, &pn->pktgen_threads, th_list)
t->control |= (T_REMDEVALL);
mutex_unlock(&pktgen_thread_lock);
/* Propagate thread->control */ /* Propagate thread->control */
schedule_timeout_interruptible(msecs_to_jiffies(125)); schedule_timeout_interruptible(msecs_to_jiffies(125));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment