From patchwork Thu Dec 3 08:17:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balasubramanian Manoharan X-Patchwork-Id: 57620 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp3357277lbb; Thu, 3 Dec 2015 00:18:08 -0800 (PST) X-Received: by 10.140.92.16 with SMTP id a16mr9659155qge.54.1449130688486; Thu, 03 Dec 2015 00:18:08 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id q62si7675360qgd.98.2015.12.03.00.18.05; Thu, 03 Dec 2015 00:18:08 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro-org.20150623.gappssmtp.com Received: by lists.linaro.org (Postfix, from userid 109) id 9BAAE62C73; Thu, 3 Dec 2015 08:18:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,T_DKIM_INVALID,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id ABB2862BF8; Thu, 3 Dec 2015 08:17:54 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id DE63E62C0E; Thu, 3 Dec 2015 08:17:50 +0000 (UTC) Received: from mail-pa0-f43.google.com (mail-pa0-f43.google.com [209.85.220.43]) by lists.linaro.org (Postfix) with ESMTPS id 3E19A62C6B for ; Thu, 3 Dec 2015 08:17:25 +0000 (UTC) Received: by pabfh17 with SMTP id fh17so66332584pab.0 for ; Thu, 03 Dec 2015 00:17:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cRFHUbg4dZNkPat7Bb9E8pjb/rxftE0Rt8U7E19fKek=; b=bNZhyomZ7ied+2rvlhEolrR5mK7HgeRPcE9u97wy7u7OMJeT2+brc174d3eO0yYVuQ aBxQ61eGlnDB/13oCqc4BlAiwZ4TRPTwplTORItK+FREAhz2nA245R4sPGoEay9WZa72 unIsuejZDtKYjH3vHkgN82lOyf5RJ6EdetkzhzMGLuGo7kQ1prxTKh0AW8+2eG28Tt6A q9a8YiLHcH8+2fI+1RxsdoOR1eOb3euZigvVWaZeUoJwJQCKnvJO3P5Ed+Cye8rkRPHh POKlbNDNm4rNiE/aAc/Rjko9NdVAv5cSUAIL6WqrLXl7zet8p6FjvKaDy3lhznm32KI4 xeuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cRFHUbg4dZNkPat7Bb9E8pjb/rxftE0Rt8U7E19fKek=; b=By5pWiWkgJQHES7pVRQCefP0wzulbATT1ZAWlhxcbu1YbeRJOEEcn08tg/pJOW1eCx vm7VdspvgH5+2hnCDhgGzoCicMrsQ9nH2C8buWPyhAQSjfywhaNuJi2HvB3UzoyQCQ+X 5mt7q/inVb6cpGP9LHGsd70CiQsly0HdlvW4HcXXM70ohgQlaHWRMKbx1vYpSi2EXrto OFTKgCOtNiUwIvilCTq9PukspNOWS1/w4Ycv5slT2o7ol23j21VLGxePinirew82TIO9 WpewHVeSi9LObwZqm8Y0OwHjd5PQvd7G3bmS6jBW1czpAeEmcfzI0z3IBJvt+NSFEcJc tegA== X-Gm-Message-State: ALoCoQmSqPuOhQMfkTwAw9P28q9ivm+snJQrTQJQ50Drb5V71ObaYIpOl9edliGlHPcn+3mHY+gp X-Received: by 10.66.154.129 with SMTP id vo1mr11285593pab.152.1449130644593; Thu, 03 Dec 2015 00:17:24 -0800 (PST) Received: from bala-Vostro-2520.caveonetworks.com ([111.93.218.67]) by smtp.gmail.com with ESMTPSA id ry1sm8880683pab.30.2015.12.03.00.17.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 Dec 2015 00:17:24 -0800 (PST) From: Balasubramanian Manoharan To: lng-odp@lists.linaro.org Date: Thu, 3 Dec 2015 13:47:07 +0530 Message-Id: <1449130627-1234-4-git-send-email-bala.manoharan@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1449130627-1234-1-git-send-email-bala.manoharan@linaro.org> References: <1449130627-1234-1-git-send-email-bala.manoharan@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT/PATCHv3 4/4] example: classifier: add odp_cls_cos_pool_set() api X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Adds packet pool to CoS using odp_cls_cos_pool_set() api. Signed-off-by: Balasubramanian Manoharan --- example/classifier/odp_classifier.c | 125 +++++++++++++++++++++++++++--------- 1 file changed, 96 insertions(+), 29 deletions(-) diff --git a/example/classifier/odp_classifier.c b/example/classifier/odp_classifier.c index 365c748..2ecf733 100644 --- a/example/classifier/odp_classifier.c +++ b/example/classifier/odp_classifier.c @@ -49,10 +49,12 @@ typedef struct { odp_queue_t queue; /**< Associated queue handle */ + odp_pool_t pool; /**< Associated pool handle */ odp_cos_t cos; /**< Associated cos handle */ odp_pmr_t pmr; /**< Associated pmr handle */ - odp_atomic_u64_t packet_count; /**< count of received packets */ - char queue_name[ODP_QUEUE_NAME_LEN]; /**< queue name */ + odp_atomic_u64_t queue_pkt_count; /**< count of received packets */ + odp_atomic_u64_t pool_pkt_count; /**< count of received packets */ + char cos_name[ODP_COS_NAME_LEN]; /**< cos name */ struct { odp_pmr_term_e term; /**< odp pmr term value */ uint64_t val; /**< pmr term value */ @@ -85,8 +87,8 @@ static void swap_pkt_addrs(odp_packet_t pkt_tbl[], unsigned len); static void parse_args(int argc, char *argv[], appl_args_t *appl_args); static void print_info(char *progname, appl_args_t *appl_args); static void usage(char *progname); -static void configure_cos_queue(odp_pktio_t pktio, appl_args_t *args); -static void configure_default_queue(odp_pktio_t pktio, appl_args_t *args); +static void configure_cos(odp_pktio_t pktio, appl_args_t *args); +static void configure_default_cos(odp_pktio_t pktio, appl_args_t *args); static int convert_str_to_pmr_enum(char *token, odp_pmr_term_e *term, uint32_t *offset); static int parse_pmr_policy(appl_args_t *appl_args, char *argv[], char *optarg); @@ -109,12 +111,12 @@ void print_cls_statistics(appl_args_t *args) printf("\n"); printf("CONFIGURATION\n"); printf("\n"); - printf("QUEUE\tVALUE\t\tMASK\n"); + printf("COS\tVALUE\t\tMASK\n"); for (i = 0; i < 40; i++) printf("-"); printf("\n"); for (i = 0; i < args->policy_count - 1; i++) { - printf("%s\t", args->stats[i].queue_name); + printf("%s\t", args->stats[i].cos_name); printf("%s\t", args->stats[i].value); printf("%s\n", args->stats[i].mask); } @@ -124,9 +126,12 @@ void print_cls_statistics(appl_args_t *args) printf("-"); printf("\n"); for (i = 0; i < args->policy_count; i++) - printf("%-12s ", args->stats[i].queue_name); + printf("%-12s |", args->stats[i].cos_name); printf("Total Packets"); printf("\n"); + for (i = 0; i < args->policy_count; i++) + printf("%-6s %-6s|", "queue", "pool"); + printf("\n"); timeout = args->time; @@ -136,10 +141,14 @@ void print_cls_statistics(appl_args_t *args) infinite = 1; for (; timeout > 0 || infinite; timeout--) { - for (i = 0; i < args->policy_count; i++) - printf("%-12" PRIu64 " ", + for (i = 0; i < args->policy_count; i++) { + printf("%-6" PRIu64 " ", + odp_atomic_load_u64(&args->stats[i] + .queue_pkt_count)); + printf("%-6" PRIu64 "|", odp_atomic_load_u64(&args->stats[i] - .packet_count)); + .pool_pkt_count)); + } printf("%-" PRIu64, odp_atomic_load_u64(&args-> total_packets)); @@ -279,6 +288,7 @@ static void *pktio_receive_thread(void *arg) int thr; odp_queue_t outq_def; odp_packet_t pkt; + odp_pool_t pool; odp_event_t ev; unsigned long err_cnt = 0; odp_queue_t queue; @@ -318,13 +328,16 @@ static void *pktio_receive_thread(void *arg) return NULL; } + pool = odp_packet_pool(pkt); + /* Swap Eth MACs and possibly IP-addrs before sending back */ swap_pkt_addrs(&pkt, 1); - for (i = 0; i < MAX_PMR_COUNT; i++) { stats = &appl->stats[i]; if (queue == stats->queue) - odp_atomic_inc_u64(&stats->packet_count); + odp_atomic_inc_u64(&stats->queue_pkt_count); + if (pool == stats->pool) + odp_atomic_inc_u64(&stats->pool_pkt_count); } if (appl->appl_mode == APPL_MODE_DROP) @@ -341,16 +354,18 @@ static void *pktio_receive_thread(void *arg) return NULL; } -static void configure_default_queue(odp_pktio_t pktio, appl_args_t *args) +static void configure_default_cos(odp_pktio_t pktio, appl_args_t *args) { odp_queue_param_t qparam; odp_cos_t cos_default; - char cos_name[ODP_COS_NAME_LEN]; const char *queue_name = "DefaultQueue"; + const char *pool_name = "DefaultPool"; + const char *cos_name = "DefaultCos"; odp_queue_t queue_default; + odp_pool_t pool_default; + odp_pool_param_t pool_params; global_statistics *stats = args->stats; - snprintf(cos_name, sizeof(cos_name), "Default%s", args->if_name); cos_default = odp_cos_create(cos_name); odp_queue_param_init(&qparam); @@ -365,6 +380,24 @@ static void configure_default_queue(odp_pktio_t pktio, appl_args_t *args) exit(EXIT_FAILURE); } + odp_pool_param_init(&pool_params); + pool_params.pkt.seg_len = SHM_PKT_POOL_BUF_SIZE; + pool_params.pkt.len = SHM_PKT_POOL_BUF_SIZE; + pool_params.pkt.num = SHM_PKT_POOL_SIZE / SHM_PKT_POOL_BUF_SIZE; + pool_params.type = ODP_POOL_PACKET; + + pool_default = odp_pool_create(pool_name, &pool_params); + + if (pool_default == ODP_POOL_INVALID) { + EXAMPLE_ERR("Error: default pool create failed.\n"); + exit(EXIT_FAILURE); + } + + if (0 > odp_cls_cos_pool_set(cos_default, pool_default)) { + EXAMPLE_ERR("odp_cls_cos_pool_set failed"); + exit(EXIT_FAILURE); + } + if (0 > odp_pktio_default_cos_set(pktio, cos_default)) { EXAMPLE_ERR("odp_pktio_default_cos_set failed"); exit(EXIT_FAILURE); @@ -372,17 +405,21 @@ static void configure_default_queue(odp_pktio_t pktio, appl_args_t *args) stats[args->policy_count].cos = cos_default; /* add default queue to global stats */ stats[args->policy_count].queue = queue_default; - snprintf(stats[args->policy_count].queue_name, - sizeof(stats[args->policy_count].queue_name), - "%s", queue_name); - odp_atomic_init_u64(&stats[args->policy_count].packet_count, 0); + stats[args->policy_count].pool = pool_default; + snprintf(stats[args->policy_count].cos_name, + sizeof(stats[args->policy_count].cos_name), + "%s", cos_name); + odp_atomic_init_u64(&stats[args->policy_count].queue_pkt_count, 0); + odp_atomic_init_u64(&stats[args->policy_count].pool_pkt_count, 0); args->policy_count++; } -static void configure_cos_queue(odp_pktio_t pktio, appl_args_t *args) +static void configure_cos(odp_pktio_t pktio, appl_args_t *args) { char cos_name[ODP_COS_NAME_LEN]; char queue_name[ODP_QUEUE_NAME_LEN]; + char pool_name[ODP_POOL_NAME_LEN]; + odp_pool_param_t pool_params; int i; global_statistics *stats; odp_queue_param_t qparam; @@ -390,7 +427,7 @@ static void configure_cos_queue(odp_pktio_t pktio, appl_args_t *args) for (i = 0; i < args->policy_count; i++) { stats = &args->stats[i]; snprintf(cos_name, sizeof(cos_name), "CoS%s", - stats->queue_name); + stats->cos_name); stats->cos = odp_cos_create(cos_name); const odp_pmr_match_t match = { @@ -402,26 +439,49 @@ static void configure_cos_queue(odp_pktio_t pktio, appl_args_t *args) }; stats->pmr = odp_pmr_create(&match); + odp_queue_param_init(&qparam); qparam.sched.prio = i % odp_schedule_num_prio(); qparam.sched.sync = ODP_SCHED_SYNC_NONE; qparam.sched.group = ODP_SCHED_GROUP_ALL; - snprintf(queue_name, sizeof(queue_name), "%s%d", - args->stats[i].queue_name, i); + snprintf(queue_name, sizeof(queue_name), "%sQueue%d", + args->stats[i].cos_name, i); stats->queue = odp_queue_create(queue_name, ODP_QUEUE_TYPE_SCHED, &qparam); + if (ODP_QUEUE_INVALID == stats->queue) { + EXAMPLE_ERR("odp_queue_create failed"); + exit(EXIT_FAILURE); + } + if (0 > odp_cos_queue_set(stats->cos, stats->queue)) { EXAMPLE_ERR("odp_cos_queue_set failed"); exit(EXIT_FAILURE); } + odp_pool_param_init(&pool_params); + pool_params.pkt.seg_len = SHM_PKT_POOL_BUF_SIZE; + pool_params.pkt.len = SHM_PKT_POOL_BUF_SIZE; + pool_params.pkt.num = SHM_PKT_POOL_SIZE / + SHM_PKT_POOL_BUF_SIZE; + pool_params.type = ODP_POOL_PACKET; + + snprintf(pool_name, sizeof(pool_name), "%sPool%d", + args->stats[i].cos_name, i); + stats->pool = odp_pool_create(pool_name, &pool_params); + + if (0 > odp_cls_cos_pool_set(stats->cos, stats->pool)) { + EXAMPLE_ERR("odp_cls_cos_pool_set failed"); + exit(EXIT_FAILURE); + } + if (0 > odp_pktio_pmr_cos(stats->pmr, pktio, stats->cos)) { EXAMPLE_ERR("odp_pktio_pmr_cos failed"); exit(EXIT_FAILURE); } - odp_atomic_init_u64(&stats->packet_count, 0); + odp_atomic_init_u64(&stats->queue_pkt_count, 0); + odp_atomic_init_u64(&stats->pool_pkt_count, 0); } } @@ -440,6 +500,7 @@ int main(int argc, char *argv[]) odp_pool_param_t params; odp_pktio_t pktio; appl_args_t *args; + odp_queue_t inq; odp_shm_t shm; /* Init ODP before calling anything else */ @@ -494,7 +555,7 @@ int main(int argc, char *argv[]) odp_pool_param_init(¶ms); params.pkt.seg_len = SHM_PKT_POOL_BUF_SIZE; params.pkt.len = SHM_PKT_POOL_BUF_SIZE; - params.pkt.num = SHM_PKT_POOL_SIZE/SHM_PKT_POOL_BUF_SIZE; + params.pkt.num = SHM_PKT_POOL_SIZE / SHM_PKT_POOL_BUF_SIZE; params.type = ODP_POOL_PACKET; pool = odp_pool_create("packet_pool", ¶ms); @@ -510,10 +571,10 @@ int main(int argc, char *argv[]) /* create pktio per interface */ pktio = create_pktio(args->if_name, pool); - configure_cos_queue(pktio, args); + configure_cos(pktio, args); - /* configure default Cos and default queue */ - configure_default_queue(pktio, args); + /* configure default Cos */ + configure_default_cos(pktio, args); if (odp_pktio_start(pktio)) { EXAMPLE_ERR("Error: unable to start pktio.\n"); @@ -542,10 +603,16 @@ int main(int argc, char *argv[]) for (i = 0; i < args->policy_count; i++) { odp_cos_destroy(args->stats[i].cos); odp_queue_destroy(args->stats[i].queue); + odp_pool_destroy(args->stats[i].pool); } free(args->if_name); odp_shm_free(shm); + odp_pool_destroy(pool); + inq = odp_pktio_inq_getdef(pktio); + odp_pktio_inq_remdef(pktio); + odp_queue_destroy(inq); + odp_pktio_close(pktio); printf("Exit\n\n"); return 0; @@ -706,7 +773,7 @@ static int parse_pmr_policy(appl_args_t *appl_args, char *argv[], char *optarg) /* Queue Name */ token = strtok(NULL, ":"); - strncpy(stats[policy_count].queue_name, token, ODP_QUEUE_NAME_LEN - 1); + strncpy(stats[policy_count].cos_name, token, ODP_QUEUE_NAME_LEN - 1); appl_args->policy_count++; free(pmr_str); return 0;