From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 2E89C6A95 for ; Thu, 11 Dec 2014 03:05:15 +0100 (CET) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP; 10 Dec 2014 18:03:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,691,1406617200"; d="scan'208";a="496997342" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by orsmga003.jf.intel.com with ESMTP; 10 Dec 2014 18:01:25 -0800 Received: from shecgisg004.sh.intel.com (shecgisg004.sh.intel.com [10.239.29.89]) by shvmail01.sh.intel.com with ESMTP id sBB25CAD011470; Thu, 11 Dec 2014 10:05:12 +0800 Received: from shecgisg004.sh.intel.com (localhost [127.0.0.1]) by shecgisg004.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id sBB259cX021338; Thu, 11 Dec 2014 10:05:12 +0800 Received: (from cliang18@localhost) by shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id sBB25945021334; Thu, 11 Dec 2014 10:05:09 +0800 From: Cunming Liang To: dev@dpdk.org Date: Thu, 11 Dec 2014 10:04:48 +0800 Message-Id: <1418263490-21088-6-git-send-email-cunming.liang@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1418263490-21088-1-git-send-email-cunming.liang@intel.com> References: <1418263490-21088-1-git-send-email-cunming.liang@intel.com> Subject: [dpdk-dev] [RFC PATCH 5/7] testpmd: support multi-pthread mode X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Dec 2014 02:05:16 -0000 Signed-off-by: Cunming Liang --- app/test-pmd/cmdline.c | 41 ++++++++++++++++++++++++ app/test-pmd/testpmd.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++- app/test-pmd/testpmd.h | 1 + 3 files changed, 125 insertions(+), 1 deletion(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 882a5a2..9c2322c 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -8697,6 +8697,45 @@ cmdline_parse_inst_t cmd_set_flow_director_flex_payload = { }, }; +/* *** SET SP/MP *** */ +struct cmd_set_mp_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t mp; + cmdline_fixed_string_t mode; +}; + +static void cmd_set_mp_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_set_mp_result *res = parsed_result; + + if (!strcmp(res->mode, "on")) + set_multi_thread(1); + else + set_multi_thread(0); +} + +cmdline_parse_token_string_t cmd_setmp_set = + TOKEN_STRING_INITIALIZER(struct cmd_set_mp_result, set, "set"); +cmdline_parse_token_string_t cmd_setmp_mp = + TOKEN_STRING_INITIALIZER(struct cmd_set_mp_result, mp, "mp"); +cmdline_parse_token_string_t cmd_setmp_mode = + TOKEN_STRING_INITIALIZER(struct cmd_set_mp_result, mode, + "on#off"); + +cmdline_parse_inst_t cmd_set_mp = { + .f = cmd_set_mp_parsed, + .data = (void *)1, + .help_str = "set mp on|off: turn on/off multi-thread per lcore", + .tokens = { + (void *)&cmd_setmp_set, + (void *)&cmd_setmp_mp, + (void *)&cmd_setmp_mode, + NULL, + }, +}; + /* ******************************************************************************** */ /* list of instructions */ @@ -8836,6 +8875,7 @@ cmdline_parse_ctx_t main_ctx[] = { (cmdline_parse_inst_t *)&cmd_flush_flow_director, (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask, (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload, + (cmdline_parse_inst_t *)&cmd_set_mp, NULL, }; @@ -8906,3 +8946,4 @@ bypass_is_supported(portid_t port_id) } } #endif + diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 8c69756..7ff9d0c 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -943,7 +943,7 @@ flush_fwd_rx_queues(void) } static void -run_pkt_fwd_on_lcore(struct fwd_lcore *fc, packet_fwd_t pkt_fwd) +run_pkt_fwd_on_lcore_sp(struct fwd_lcore *fc, packet_fwd_t pkt_fwd) { struct fwd_stream **fsm; streamid_t nb_fs; @@ -957,6 +957,70 @@ run_pkt_fwd_on_lcore(struct fwd_lcore *fc, packet_fwd_t pkt_fwd) } while (! fc->stopped); } +struct work_arg { + struct fwd_lcore *fc; + struct fwd_stream *fs; + packet_fwd_t pkt_fwd; +}; + +static void* work(void *arg) +{ + struct work_arg *warg = (struct work_arg *)arg; + struct fwd_stream *fs = warg->fs; + struct fwd_lcore *fc = warg->fc; + packet_fwd_t pkt_fwd = warg->pkt_fwd; + + do { + (*pkt_fwd)(fs); + } while (! fc->stopped); + + return NULL; +} + +static void +run_pkt_fwd_on_lcore_mp(struct fwd_lcore *fc, packet_fwd_t pkt_fwd) +{ + struct fwd_stream **fsm; + streamid_t nb_fs; + streamid_t sm_id; + streamid_t i; + struct work_arg *work_arg = NULL; + pthread_t *tids = NULL; + + fsm = &fwd_streams[fc->stream_idx]; + nb_fs = fc->stream_nb; + tids = calloc(nb_fs, nb_fs * sizeof(*tids)); + if (!tids) + goto exit; + + work_arg = calloc(nb_fs, nb_fs * sizeof(*work_arg)); + if (!work_arg) + goto exit; + + for (sm_id = 0; sm_id < nb_fs; sm_id++) { + work_arg[sm_id].pkt_fwd = pkt_fwd; + work_arg[sm_id].fc = fc; + work_arg[sm_id].fs = fsm[sm_id]; + if (rte_pthread_create(&tids[sm_id], work, + &work_arg[sm_id]) < 0) { + printf("create pthread fail on stream %u\n", + sm_id); + break; + } + } + + for (i = 0; i < sm_id; i++) + (void)pthread_join(tids[i], NULL); + +exit: + free(tids); + free(work_arg); +} + +void +(*run_pkt_fwd_on_lcore)(struct fwd_lcore *fc, packet_fwd_t pkt_fwd) = + run_pkt_fwd_on_lcore_sp; + static int start_pkt_forward_on_core(void *fwd_arg) { @@ -965,6 +1029,24 @@ start_pkt_forward_on_core(void *fwd_arg) return 0; } +int set_multi_thread(int on) +{ + unsigned int lc_id; + + for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) + if (fwd_lcores[lc_id]->stopped != 1) { + printf("Make sure stop forwarding first\n"); + return -1; + } + + if (on) + run_pkt_fwd_on_lcore = run_pkt_fwd_on_lcore_mp; + else + run_pkt_fwd_on_lcore = run_pkt_fwd_on_lcore_sp; + + return 0; +} + /* * Run the TXONLY packet forwarding engine to send a single burst of packets. * Used to start communication flows in network loopback test configurations. diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index f8b0740..3658e0f 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -558,6 +558,7 @@ void get_flex_filter(uint8_t port_id, uint16_t index); int port_id_is_invalid(portid_t port_id); int rx_queue_id_is_invalid(queueid_t rxq_id); int tx_queue_id_is_invalid(queueid_t txq_id); +int set_multi_thread(int on); /* * Work-around of a compilation error with ICC on invocations of the -- 1.8.1.4