From patchwork Thu Dec 3 10:46:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balasubramanian Manoharan X-Patchwork-Id: 57634 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp3417752lbb; Thu, 3 Dec 2015 02:51:29 -0800 (PST) X-Received: by 10.140.163.198 with SMTP id j189mr10806658qhj.36.1449139889851; Thu, 03 Dec 2015 02:51:29 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id l62si8088570qge.34.2015.12.03.02.51.29; Thu, 03 Dec 2015 02:51:29 -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 507E062BF3; Thu, 3 Dec 2015 10:51:29 +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_H3, RCVD_IN_MSPIKE_WL, 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 5D4EB62C74; Thu, 3 Dec 2015 10:47:05 +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 9449B62C48; Thu, 3 Dec 2015 10:46:54 +0000 (UTC) Received: from mail-pa0-f54.google.com (mail-pa0-f54.google.com [209.85.220.54]) by lists.linaro.org (Postfix) with ESMTPS id 1E81262C6A for ; Thu, 3 Dec 2015 10:46:25 +0000 (UTC) Received: by pabfh17 with SMTP id fh17so69118340pab.0 for ; Thu, 03 Dec 2015 02:46: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=UgNMI90fypMBHxEXrO5YooueOId3+egGegdJbHQToamFhpiI1BhugWF6pTqlTnxSAz SpNDgmRcAIuPNn9JwIRk3bY7cUlHLx6yB6kdr2QTkgwWB5YDVLcib5qC806JD5iHBKAM n6wScf+boBcTIK8aaYvPP0jxOKKlnt8MEGYcmIkCFeugq0uZ9+tzGZ6z3swOFg5RCQBy Q/pmNr7x+AQ4vzwHceynZ/OGCxsB2cWf7cUvlkfvm/Myq5/RvxcrdadjIDsMEdiy/mRy gSTqQ5F9rOxrIHAcUevqMHHu1IACiUMGZ9YZ3jzv25gNxIxypumBV2vIOnQfV0sfUctH cG+g== 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=IuMPJY/GJPRUjqc8XRgJ/OeOH2vzmN+8AonLQgoHusNhdi35SIBpsUXwxyLmXtT1ko z5fy0eXLnnpknXIG/jkEDsGCLmI+cVm3oTEJrZmBneNX88yeiDuv3990//a/cwuBJ33O QWheiaRZ+PXqf76FSpQghusYqhBeF2/d6Iu63OEJo9invHLPDbFwhyRVoDOEFHeLfNwF vO5l3X0NG/tOxjKkvDzznXfzw/1WGichoTfla6S/CUlpIPR9t+z9Qriv55Yh+1o/LICU 7JTSljCWVX9tOpO9U3zSPIamRBMgx9VG1u+fTH7prkdfzvejmTSIO60slbJoiYmdgJNW LuUg== X-Gm-Message-State: ALoCoQkKWORpI3Izl/DSy5tEYtbzZlQ6+sJ+gKobr56Pr3ivEOSCvxwy62riWa8Up7cgwTTnWnBX X-Received: by 10.66.192.193 with SMTP id hi1mr11973827pac.110.1449139584445; Thu, 03 Dec 2015 02:46:24 -0800 (PST) Received: from bala-Vostro-2520.caveonetworks.com ([111.93.218.67]) by smtp.gmail.com with ESMTPSA id 68sm9908068pfq.37.2015.12.03.02.46.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 Dec 2015 02:46:23 -0800 (PST) From: Balasubramanian Manoharan To: lng-odp@lists.linaro.org Date: Thu, 3 Dec 2015 16:16:06 +0530 Message-Id: <1449139566-1196-4-git-send-email-bala.manoharan@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1449139566-1196-1-git-send-email-bala.manoharan@linaro.org> References: <1449139566-1196-1-git-send-email-bala.manoharan@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT/PATCHv4 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;