Skip to content

Commit cda9de0

Browse files
YajunDengdavem330
authored andcommitted
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: Yejune Deng <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 85eb138 commit cda9de0

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed

net/core/pktgen.c

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t,
467467
static int pktgen_device_event(struct notifier_block *, unsigned long, void *);
468468
static void pktgen_run_all_threads(struct pktgen_net *pn);
469469
static void pktgen_reset_all_threads(struct pktgen_net *pn);
470-
static void pktgen_stop_all_threads_ifs(struct pktgen_net *pn);
470+
static void pktgen_stop_all_threads(struct pktgen_net *pn);
471471

472472
static void pktgen_stop(struct pktgen_thread *t);
473473
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,
516516
data[count - 1] = 0; /* Strip trailing '\n' and terminate string */
517517

518518
if (!strcmp(data, "stop"))
519-
pktgen_stop_all_threads_ifs(pn);
520-
519+
pktgen_stop_all_threads(pn);
521520
else if (!strcmp(data, "start"))
522521
pktgen_run_all_threads(pn);
523-
524522
else if (!strcmp(data, "reset"))
525523
pktgen_reset_all_threads(pn);
526-
527524
else
528525
return -EINVAL;
529526

@@ -3027,20 +3024,25 @@ static void pktgen_run(struct pktgen_thread *t)
30273024
t->control &= ~(T_STOP);
30283025
}
30293026

3030-
static void pktgen_stop_all_threads_ifs(struct pktgen_net *pn)
3027+
static void pktgen_handle_all_threads(struct pktgen_net *pn, u32 flags)
30313028
{
30323029
struct pktgen_thread *t;
30333030

3034-
func_enter();
3035-
30363031
mutex_lock(&pktgen_thread_lock);
30373032

30383033
list_for_each_entry(t, &pn->pktgen_threads, th_list)
3039-
t->control |= T_STOP;
3034+
t->control |= (flags);
30403035

30413036
mutex_unlock(&pktgen_thread_lock);
30423037
}
30433038

3039+
static void pktgen_stop_all_threads(struct pktgen_net *pn)
3040+
{
3041+
func_enter();
3042+
3043+
pktgen_handle_all_threads(pn, T_STOP);
3044+
}
3045+
30443046
static int thread_is_running(const struct pktgen_thread *t)
30453047
{
30463048
const struct pktgen_dev *pkt_dev;
@@ -3103,16 +3105,9 @@ static int pktgen_wait_all_threads_run(struct pktgen_net *pn)
31033105

31043106
static void pktgen_run_all_threads(struct pktgen_net *pn)
31053107
{
3106-
struct pktgen_thread *t;
3107-
31083108
func_enter();
31093109

3110-
mutex_lock(&pktgen_thread_lock);
3111-
3112-
list_for_each_entry(t, &pn->pktgen_threads, th_list)
3113-
t->control |= (T_RUN);
3114-
3115-
mutex_unlock(&pktgen_thread_lock);
3110+
pktgen_handle_all_threads(pn, T_RUN);
31163111

31173112
/* Propagate thread->control */
31183113
schedule_timeout_interruptible(msecs_to_jiffies(125));
@@ -3122,16 +3117,9 @@ static void pktgen_run_all_threads(struct pktgen_net *pn)
31223117

31233118
static void pktgen_reset_all_threads(struct pktgen_net *pn)
31243119
{
3125-
struct pktgen_thread *t;
3126-
31273120
func_enter();
31283121

3129-
mutex_lock(&pktgen_thread_lock);
3130-
3131-
list_for_each_entry(t, &pn->pktgen_threads, th_list)
3132-
t->control |= (T_REMDEVALL);
3133-
3134-
mutex_unlock(&pktgen_thread_lock);
3122+
pktgen_handle_all_threads(pn, T_REMDEVALL);
31353123

31363124
/* Propagate thread->control */
31373125
schedule_timeout_interruptible(msecs_to_jiffies(125));

0 commit comments

Comments
 (0)