Skip to content

Commit

Permalink
lib/dev: add lock for vf command (#144)
Browse files Browse the repository at this point in the history
Always get below log if app are running from multi thread with vf.
  _atomic_set_cmd(): There is incomplete cmd 112
  iavf_fdir_add(): fail to execute command OP_ADD_FDIR_FILTER
  iavf_flow_create(): Failed to create flow

Signed-off-by: Frank Du <frank.du@intel.com>
(cherry picked from commit 26c103a)
  • Loading branch information
frankdjx committed Jan 16, 2023
1 parent 6cd5715 commit e2f6d18
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/src/mt_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,9 @@ static int dev_tx_queue_set_rl_rate(struct mtl_main_impl* impl, enum mtl_port po
shaper->shaper_profile_id);
}

mt_pthread_mutex_lock(&inf->vf_cmd_mutex);
ret = rte_tm_hierarchy_commit(port_id, 1, &error);
mt_pthread_mutex_unlock(&inf->vf_cmd_mutex);
if (ret < 0) {
err("%s(%d), commit error (%d)%s\n", __func__, port, ret, error.message);
return ret;
Expand Down Expand Up @@ -579,7 +581,9 @@ static struct rte_flow* dev_rx_queue_create_flow_raw(struct mt_interface* inf, u
action[0].conf = &to_queue;
action[1].type = RTE_FLOW_ACTION_TYPE_END;

mt_pthread_mutex_lock(&inf->vf_cmd_mutex);
r_flow = rte_flow_create(port_id, &attr, pattern, action, &error);
mt_pthread_mutex_unlock(&inf->vf_cmd_mutex);
if (!r_flow) {
err("%s(%d), rte_flow_create fail for queue %d, %s\n", __func__, port_id, q,
error.message);
Expand Down Expand Up @@ -676,7 +680,9 @@ static struct rte_flow* dev_rx_queue_create_flow(struct mt_interface* inf, uint1
return NULL;
}

mt_pthread_mutex_lock(&inf->vf_cmd_mutex);
r_flow = rte_flow_create(port_id, &attr, pattern, action, &error);
mt_pthread_mutex_unlock(&inf->vf_cmd_mutex);
if (!r_flow) {
err("%s(%d), rte_flow_create fail for queue %d, %s\n", __func__, port_id, q,
error.message);
Expand Down Expand Up @@ -1992,6 +1998,7 @@ int mt_dev_if_uinit(struct mtl_main_impl* impl) {
mt_pthread_mutex_destroy(&inf->tx_queues_mutex);
mt_pthread_mutex_destroy(&inf->rx_queues_mutex);
mt_pthread_mutex_destroy(&inf->tx_sys_queue_mutex);
mt_pthread_mutex_destroy(&inf->vf_cmd_mutex);

dev_close_port(impl, i);
}
Expand Down Expand Up @@ -2040,6 +2047,7 @@ int mt_dev_if_init(struct mtl_main_impl* impl) {
mt_pthread_mutex_init(&inf->tx_queues_mutex, NULL);
mt_pthread_mutex_init(&inf->rx_queues_mutex, NULL);
mt_pthread_mutex_init(&inf->tx_sys_queue_mutex, NULL);
mt_pthread_mutex_init(&inf->vf_cmd_mutex, NULL);

if (mt_has_user_ptp(impl)) /* user provide the ptp source */
inf->ptp_get_time_fn = ptp_from_user;
Expand Down
5 changes: 5 additions & 0 deletions lib/src/mt_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,11 @@ struct mt_interface {
uint16_t nb_rx_desc;

struct rte_mbuf* pad;
/*
* protect rl and fdir for vf.
* _atomic_set_cmd(): There is incomplete cmd 112
*/
pthread_mutex_t vf_cmd_mutex;

/* tx queue resources */
int max_tx_queues;
Expand Down

0 comments on commit e2f6d18

Please sign in to comment.