Skip to content

Commit 4da14f9

Browse files
committed
support dpdk-17.11.4; support vhost/virtio; enhance anscli; update doc.
1 parent 1feab3c commit 4da14f9

23 files changed

+155
-12
lines changed

ans/ans_main.c

Lines changed: 89 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <errno.h>
4545
#include <getopt.h>
4646
#include <sched.h>
47+
#include <signal.h>
4748

4849
#include <rte_common.h>
4950
#include <rte_vect.h>
@@ -89,6 +90,7 @@
8990
static struct ans_user_config ans_user_conf;
9091
static struct ans_lcore_queue g_lcore_queue[RTE_MAX_LCORE];
9192
static struct rte_mempool *ans_pktmbuf_pool[MAX_NB_SOCKETS];
93+
static uint8_t ans_stopped = 0;
9294

9395
static struct ans_lcore_params ans_lcore_params_default[] =
9496
{
@@ -214,9 +216,15 @@ static void ans_check_ports_link_status(uint8_t port_num, uint32_t port_mask)
214216

215217
for (count = 0; count <= max_check_time; count++)
216218
{
219+
if (ans_stopped)
220+
return;
221+
217222
all_ports_up = 1;
218223
for (portid = 0; portid < port_num; portid++)
219224
{
225+
if (ans_stopped)
226+
return;
227+
220228
if ((port_mask & (1 << portid)) == 0)
221229
continue;
222230

@@ -563,8 +571,6 @@ static int ans_init_ports(unsigned short nb_ports, struct ans_user_config *user
563571
return 0;
564572
}
565573

566-
567-
568574
/**********************************************************************
569575
*@description:
570576
*
@@ -607,6 +613,35 @@ static int ans_start_ports(unsigned short nb_ports, struct ans_user_config *use
607613

608614
return 0;
609615
}
616+
617+
/**********************************************************************
618+
*@description:
619+
*
620+
*
621+
*@parameters:
622+
* [in]:
623+
* [in]:
624+
*
625+
*@return values:
626+
*
627+
**********************************************************************/
628+
static int ans_stop_ports(unsigned short nb_ports, struct ans_user_config *user_conf)
629+
{
630+
int portid;
631+
/* stop ports */
632+
for (portid = 0; portid < nb_ports; portid++) {
633+
if ((user_conf->port_mask & (1 << portid)) == 0)
634+
continue;
635+
636+
printf("Closing port %d...", portid);
637+
rte_eth_dev_stop(portid);
638+
rte_eth_dev_close(portid);
639+
printf(" Done\n");
640+
}
641+
printf("Bye...\n");
642+
643+
return 0;
644+
}
610645
/**********************************************************************
611646
*@description:
612647
* Send burst of packets on an output interface
@@ -765,7 +800,7 @@ static int ans_main_loop(__attribute__((unused)) void *dummy)
765800

766801
timer_10ms_tsc = rte_get_tsc_hz() / 100;
767802

768-
while (1)
803+
while (!ans_stopped)
769804
{
770805

771806
cur_tsc = rte_rdtsc();
@@ -834,6 +869,30 @@ static int ans_main_loop(__attribute__((unused)) void *dummy)
834869
}
835870
}
836871

872+
/**********************************************************************
873+
*@description:
874+
*
875+
*
876+
*@parameters:
877+
* [in]:
878+
* [in]:
879+
*
880+
*@return values:
881+
*
882+
**********************************************************************/
883+
static void ans_signal_handler(int signum)
884+
{
885+
int nb_ports;
886+
if (signum == SIGINT || signum == SIGTERM)
887+
{
888+
printf("\nSignal %d received, preparing to exit...\n", signum);
889+
890+
printf("Telling cores to stop...\n");
891+
ans_stopped = 1;
892+
}
893+
894+
return;
895+
}
837896

838897
/**********************************************************************
839898
*@description:
@@ -877,6 +936,9 @@ int main(int argc, char **argv)
877936
if (ret < 0)
878937
rte_exit(EXIT_FAILURE, "Invalid EAL parameters\n");
879938

939+
signal(SIGINT, ans_signal_handler);
940+
signal(SIGTERM, ans_signal_handler);
941+
880942
argc -= ret;
881943
argv += ret;
882944

@@ -945,7 +1007,7 @@ int main(int argc, char **argv)
9451007

9461008
ret = ans_initialize(&init_conf);
9471009
if (ret != 0)
948-
rte_exit(EXIT_FAILURE, "Init ans failed \n");
1010+
rte_exit(EXIT_FAILURE, "Init ans failed \n");
9491011

9501012
/* add by ans_team ---end */
9511013

@@ -956,6 +1018,7 @@ int main(int argc, char **argv)
9561018
struct ether_addr eth_addr;
9571019
uint16_t qmapping_nb;
9581020
struct ans_port_qmapping qmapping[32];
1021+
struct rte_eth_dev_info dev_info;
9591022

9601023
for(portid= 0; portid < nb_ports; portid++)
9611024
{
@@ -965,10 +1028,23 @@ int main(int argc, char **argv)
9651028
printf("\nSkipping disabled port %d\n", portid);
9661029
continue;
9671030
}
968-
1031+
1032+
rte_eth_dev_info_get(portid, &dev_info);
1033+
9691034
memset(ifname, 0, sizeof(ifname));
970-
971-
sprintf(ifname, "veth%d", portid);
1035+
if(strcmp(dev_info.driver_name, "net_vhost") == 0)
1036+
{
1037+
sprintf(ifname, "vhost%d", portid);
1038+
}
1039+
else if(strcmp(dev_info.driver_name, "net_virtio_user") == 0)
1040+
{
1041+
sprintf(ifname, "virtio%d", portid);
1042+
}
1043+
else
1044+
{
1045+
sprintf(ifname, "veth%d", portid);
1046+
}
1047+
9721048
kni_id = ans_kni_id_get(portid);
9731049

9741050
printf("add %s device, kni id %d \n", ifname, kni_id);
@@ -1013,6 +1089,11 @@ int main(int argc, char **argv)
10131089
rte_eal_mp_remote_launch(ans_main_loop, NULL, CALL_MASTER);
10141090
RTE_LCORE_FOREACH_SLAVE(lcore_id){
10151091
if (rte_eal_wait_lcore(lcore_id) < 0)
1016-
return -1;
1092+
ret = -1;
1093+
break;
10171094
}
1095+
1096+
ans_stop_ports(nb_ports, &ans_user_conf);
1097+
1098+
return ret;
10181099
}

ans/ans_param.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ int ans_check_port_config(const unsigned nb_ports, struct ans_user_config *user_
9393
for (i = 0; i < user_conf->lcore_param_nb; i++)
9494
{
9595
portid = user_conf->lcore_param[i].port_id;
96-
printf("port id %d \n ", portid);
9796

9897
if ((user_conf->port_mask & (1 << portid)) == 0)
9998
{

cli/anscli_main.c

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,37 @@
5959
#include "anscli_intf.h"
6060

6161

62+
/**********************************************************************
63+
*@description:
64+
* display usage
65+
*
66+
*
67+
**********************************************************************/
68+
static void anscli_print_usage(void)
69+
{
70+
printf ("anscli has four input format: \n"
71+
" ./anscli - enter cli window with default file-prefix \n"
72+
" ./anscli --file-prefix=NAME - enter cli window with specified file-prefix, eg: ./anscli --file-prefix=testprefix \n"
73+
" ./anscli \"CMD\" - enter CMD with default file-prefix, eg: ./anscli \"help\" \n"
74+
" ./anscli --file-prefix=NAME \"CMD\" - enter CMD with specified file-prefix, eg: ./anscli --file-prefix=testprefix \"help\" \n"
75+
" Notes: the file-prefix shall same as ans's file-prefix \n");
76+
77+
return;
78+
}
79+
80+
/**********************************************************************
81+
*@description:
82+
* anscli main
83+
*
84+
*
85+
**********************************************************************/
6286
int main(int argc, char **argv)
6387
{
6488
int ret;
89+
char *cmd;
90+
short has_cmd = 0;
6591
int param_num = 8;
66-
char *param[] = {"anscli",
92+
char *param[9] = {"anscli",
6793
"-c",
6894
"1",
6995
"-n",
@@ -73,17 +99,54 @@ int main(int argc, char **argv)
7399
"--proc-type=secondary",
74100
NULL};
75101

102+
if(argc >= 2)
103+
{
104+
if(strcmp(argv[1], "help") == 0 || strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)
105+
{
106+
anscli_print_usage();
107+
return 0;
108+
}
109+
110+
if(strncmp(argv[1], "--file-prefix", strlen("--file-prefix")) == 0)
111+
{
112+
param[8] = argv[1];
113+
param_num++;
114+
115+
if(argc > 2)
116+
{
117+
has_cmd = 1;
118+
cmd = argv[2];
119+
}
120+
else
121+
{
122+
has_cmd = 0;
123+
}
124+
}
125+
else
126+
{
127+
has_cmd = 1;
128+
cmd = argv[1];
129+
}
130+
131+
}
132+
else
133+
{
134+
has_cmd = 0;
135+
}
136+
76137
rte_log_set_global_level(RTE_LOG_ERR);
77138
ret = rte_eal_init(param_num, param);
78139
if (ret < 0)
79140
rte_panic("Cannot init EAL\n");
80-
if(argc > 1)
141+
142+
if(has_cmd)
81143
{
82-
anscli_start(argv[1]);
144+
anscli_start(cmd);
83145
}
84146
else
85147
{
86148
anscli_start(NULL);
87149
}
150+
88151
return 0;
89152
}
19.8 KB
Binary file not shown.

doc/guides/ans_user_guide.pdf

-148 KB
Binary file not shown.

librte_ans/librte_ans_broadwell.a

94 Bytes
Binary file not shown.

librte_ans/librte_ans_haswell.a

94 Bytes
Binary file not shown.

librte_ans/librte_ans_ivybridge.a

78 Bytes
Binary file not shown.

librte_ans/librte_ans_knl.a

110 Bytes
Binary file not shown.
78 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)