Skip to content

Commit

Permalink
net: hns3: schedule hclgevf_service by using delayed workqueue
Browse files Browse the repository at this point in the history
Currently, a timer is defined to schedule hclgevf_service per
second. To simplify the code, this patch uses the delayed work
instead of timer to schedule hclgevf_serive.

Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
Signed-off-by: Huazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Yunsheng Lin authored and David S. Miller committed Dec 17, 2019
1 parent 54e1f08 commit b3c3fe8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
39 changes: 14 additions & 25 deletions drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1786,8 +1786,11 @@ void hclgevf_mbx_task_schedule(struct hclgevf_dev *hdev)
static void hclgevf_task_schedule(struct hclgevf_dev *hdev)
{
if (!test_bit(HCLGEVF_STATE_DOWN, &hdev->state) &&
!test_and_set_bit(HCLGEVF_STATE_SERVICE_SCHED, &hdev->state))
schedule_work(&hdev->service_task);
!test_and_set_bit(HCLGEVF_STATE_SERVICE_SCHED, &hdev->state)) {
mod_delayed_work(system_wq, &hdev->service_task,
round_jiffies_relative(HZ));
hdev->stats_timer++;
}
}

static void hclgevf_deferred_task_schedule(struct hclgevf_dev *hdev)
Expand All @@ -1800,17 +1803,6 @@ static void hclgevf_deferred_task_schedule(struct hclgevf_dev *hdev)
hclgevf_reset_task_schedule(hdev);
}

static void hclgevf_service_timer(struct timer_list *t)
{
struct hclgevf_dev *hdev = from_timer(hdev, t, service_timer);

mod_timer(&hdev->service_timer, jiffies +
HCLGEVF_GENERAL_TASK_INTERVAL * HZ);

hdev->stats_timer++;
hclgevf_task_schedule(hdev);
}

static void hclgevf_reset_service_task(struct work_struct *work)
{
#define HCLGEVF_MAX_RESET_ATTEMPTS_CNT 3
Expand Down Expand Up @@ -1933,7 +1925,7 @@ static void hclgevf_service_task(struct work_struct *work)
struct hnae3_handle *handle;
struct hclgevf_dev *hdev;

hdev = container_of(work, struct hclgevf_dev, service_task);
hdev = container_of(work, struct hclgevf_dev, service_task.work);
handle = &hdev->nic;

if (hdev->stats_timer >= HCLGEVF_STATS_TIMER_INTERVAL) {
Expand All @@ -1953,6 +1945,8 @@ static void hclgevf_service_task(struct work_struct *work)
hclgevf_deferred_task_schedule(hdev);

clear_bit(HCLGEVF_STATE_SERVICE_SCHED, &hdev->state);

hclgevf_task_schedule(hdev);
}

static void hclgevf_clear_event_cause(struct hclgevf_dev *hdev, u32 regclr)
Expand Down Expand Up @@ -2194,10 +2188,10 @@ static void hclgevf_set_timer_task(struct hnae3_handle *handle, bool enable)
struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);

if (enable) {
mod_timer(&hdev->service_timer, jiffies + HZ);
hclgevf_task_schedule(hdev);
} else {
del_timer_sync(&hdev->service_timer);
cancel_work_sync(&hdev->service_task);
set_bit(HCLGEVF_STATE_DOWN, &hdev->state);
cancel_delayed_work_sync(&hdev->service_task);
clear_bit(HCLGEVF_STATE_SERVICE_SCHED, &hdev->state);
}
}
Expand Down Expand Up @@ -2279,10 +2273,7 @@ static void hclgevf_state_init(struct hclgevf_dev *hdev)
clear_bit(HCLGEVF_STATE_MBX_SERVICE_SCHED, &hdev->state);
clear_bit(HCLGEVF_STATE_MBX_HANDLING, &hdev->state);

/* setup tasks for service timer */
timer_setup(&hdev->service_timer, hclgevf_service_timer, 0);

INIT_WORK(&hdev->service_task, hclgevf_service_task);
INIT_DELAYED_WORK(&hdev->service_task, hclgevf_service_task);
clear_bit(HCLGEVF_STATE_SERVICE_SCHED, &hdev->state);

INIT_WORK(&hdev->rst_service_task, hclgevf_reset_service_task);
Expand All @@ -2302,10 +2293,8 @@ static void hclgevf_state_uninit(struct hclgevf_dev *hdev)
del_timer_sync(&hdev->keep_alive_timer);
if (hdev->keep_alive_task.func)
cancel_work_sync(&hdev->keep_alive_task);
if (hdev->service_timer.function)
del_timer_sync(&hdev->service_timer);
if (hdev->service_task.func)
cancel_work_sync(&hdev->service_task);
if (hdev->service_task.work.func)
cancel_delayed_work_sync(&hdev->service_task);
if (hdev->mbx_service_task.func)
cancel_work_sync(&hdev->mbx_service_task);
if (hdev->rst_service_task.func)
Expand Down
3 changes: 1 addition & 2 deletions drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,8 @@ struct hclgevf_dev {
struct hclgevf_mbx_resp_status mbx_resp; /* mailbox response */
struct hclgevf_mbx_arq_ring arq; /* mailbox async rx queue */

struct timer_list service_timer;
struct timer_list keep_alive_timer;
struct work_struct service_task;
struct delayed_work service_task;
struct work_struct keep_alive_task;
struct work_struct rst_service_task;
struct work_struct mbx_service_task;
Expand Down

0 comments on commit b3c3fe8

Please sign in to comment.