From patchwork Tue Dec 16 09:54:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciprian Barbu X-Patchwork-Id: 42312 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 982FD2456A for ; Tue, 16 Dec 2014 09:55:25 +0000 (UTC) Received: by mail-la0-f71.google.com with SMTP id q1sf8433359lam.10 for ; Tue, 16 Dec 2014 01:55:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=fj1bp9vcXWepZDkMaUV4hBt/bCJpkod1uevS73Ph6Ag=; b=jXaniyHTdzqotCeWNu8InVkmTEukM1qq2Mb6+hlLrKCKPeOoGClhNGTiVgir0Fz50c lbOP+nBMauMaItoiVnjPf428dIdhHyK83DdCz6am1f3gPMDwvNluVwzGxO4hWNCi7SXn Pp+cb3Z2CFS6DVeWJfKcg0ErJvYbwayT+TT5DUvNJK7I0SbZNL9dhGbY/ybnUidnTn8q mdDapsgDYmYq9lqTPfnbEwFd+zonL3b1DILAhoFo2qkTCqu0eLJSqwCzg8oijw+pTP6d fSp5xnPVrgbvHnzUpiJJ6TNUEgx79hNAwMGBRXkmxhbzs+B6B/Vfu3JYWVa7FjAaOi7r oiIA== X-Gm-Message-State: ALoCoQkH/Hqt/eXWoRzFXP0rw38vC7TxRuSy9dXp+kJUyts8RyfZXcV8aJ/BWOHK3ak4csaaTa2W X-Received: by 10.112.162.199 with SMTP id yc7mr2670lbb.23.1418723724530; Tue, 16 Dec 2014 01:55:24 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.170.227 with SMTP id ap3ls856879lac.60.gmail; Tue, 16 Dec 2014 01:55:24 -0800 (PST) X-Received: by 10.152.43.103 with SMTP id v7mr34932201lal.29.1418723724375; Tue, 16 Dec 2014 01:55:24 -0800 (PST) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id ay3si346454lbc.17.2014.12.16.01.55.24 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 16 Dec 2014 01:55:24 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by mail-la0-f42.google.com with SMTP id gd6so11072649lab.29 for ; Tue, 16 Dec 2014 01:55:24 -0800 (PST) X-Received: by 10.152.23.38 with SMTP id j6mr27144280laf.81.1418723724262; Tue, 16 Dec 2014 01:55:24 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.142.69 with SMTP id ru5csp982770lbb; Tue, 16 Dec 2014 01:55:23 -0800 (PST) X-Received: by 10.140.95.52 with SMTP id h49mr59346271qge.97.1418723722685; Tue, 16 Dec 2014 01:55:22 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id a2si308754qam.24.2014.12.16.01.55.21 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 16 Dec 2014 01:55:22 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Y0oqe-0006w9-6D; Tue, 16 Dec 2014 09:55:20 +0000 Received: from mail-la0-f43.google.com ([209.85.215.43]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Y0oqO-0006sB-Bh for lng-odp@lists.linaro.org; Tue, 16 Dec 2014 09:55:04 +0000 Received: by mail-la0-f43.google.com with SMTP id s18so11074774lam.16 for ; Tue, 16 Dec 2014 01:54:58 -0800 (PST) X-Received: by 10.112.142.201 with SMTP id ry9mr11670306lbb.4.1418723698804; Tue, 16 Dec 2014 01:54:58 -0800 (PST) Received: from cipriantemp.enea.se (sestofw01.enea.se. [192.36.1.252]) by mx.google.com with ESMTPSA id l9sm92457lae.0.2014.12.16.01.54.57 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 16 Dec 2014 01:54:57 -0800 (PST) From: Ciprian Barbu To: lng-odp@lists.linaro.org, petri.savolainen@nsn.com, ola.liljedahl@linaro.org Date: Tue, 16 Dec 2014 11:54:28 +0200 Message-Id: <1418723669-10161-4-git-send-email-ciprian.barbu@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1418723669-10161-1-git-send-email-ciprian.barbu@linaro.org> References: <1418723669-10161-1-git-send-email-ciprian.barbu@linaro.org> Subject: [lng-odp] [RFC 3/4] example showing scheduler bug X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: 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-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ciprian.barbu@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Signed-off-by: Ciprian Barbu --- configure.ac | 1 + example/Makefile.am | 2 +- example/sched_bug/Makefile.am | 7 ++ example/sched_bug/sched_bug.c | 189 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 example/sched_bug/Makefile.am create mode 100644 example/sched_bug/sched_bug.c diff --git a/configure.ac b/configure.ac index bc97f1a..2dd1c33 100644 --- a/configure.ac +++ b/configure.ac @@ -199,6 +199,7 @@ AC_CONFIG_FILES([Makefile example/odp_example/Makefile example/packet/Makefile example/timer/Makefile + example/sched_bug/Makefile test/Makefile test/api_test/Makefile test/validation/Makefile diff --git a/example/Makefile.am b/example/Makefile.am index b2a22a3..d3d7cb9 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -1 +1 @@ -SUBDIRS = generator ipsec l2fwd odp_example packet timer +SUBDIRS = generator ipsec l2fwd odp_example packet timer sched_bug diff --git a/example/sched_bug/Makefile.am b/example/sched_bug/Makefile.am new file mode 100644 index 0000000..3e9caa3 --- /dev/null +++ b/example/sched_bug/Makefile.am @@ -0,0 +1,7 @@ +include $(top_srcdir)/example/Makefile.inc + +bin_PROGRAMS = sched_bug +sched_bug_LDFLAGS = $(AM_LDFLAGS) -static +sched_bug_CFLAGS = $(AM_CFLAGS) -I../ + +dist_sched_bug_SOURCES = sched_bug.c diff --git a/example/sched_bug/sched_bug.c b/example/sched_bug/sched_bug.c new file mode 100644 index 0000000..37e60eb --- /dev/null +++ b/example/sched_bug/sched_bug.c @@ -0,0 +1,189 @@ +#include +#include +#include +#include + +#define QUEUES_PER_PRIO 4 /* Must match the value in + platform/linux-generic/odp_schedule.c */ + +#define MAX_DEQ 4 /* Must match the value in + platform/linux-generic/odp_schedule.c */ + +#define MSG_POOL_SIZE (4*1024*1024) /**< Message pool size */ +#define NUM_QUEUES (2 * QUEUES_PER_PRIO) + +/** Dummy message */ +typedef struct { + int msg_id; /**< Message ID */ + int seq; /**< Sequence number */ +} test_message_t; + +#define MSG_HELLO 1 /**< Hello */ +#define MSG_ACK 2 /**< Ack */ + +odp_buffer_pool_t pool; + +static odp_queue_t create_prio_queue(odp_schedule_prio_t prio, int num) +{ + odp_queue_param_t param; + odp_queue_t queue; + char name[64]; + + snprintf(name, sizeof(name), "sched_%d_%d", prio, num); + param.sched.prio = prio; + param.sched.sync = ODP_SCHED_SYNC_NONE; + param.sched.group = ODP_SCHED_GROUP_DEFAULT; + queue = odp_queue_create(name, ODP_QUEUE_TYPE_SCHED, ¶m); + + printf("Created q=0x%x prio=%d name=%s\n", + queue, odp_queue_sched_prio(queue), name); + + return queue; +} + +static int create_queues(void) +{ + int i; + odp_queue_t queue; + + for (i = 0; i < NUM_QUEUES; i++) { + + queue = create_prio_queue(0, i); + if (queue == ODP_QUEUE_INVALID) + return -1; + } + + for (i = 0; i < NUM_QUEUES; i++) { + queue = create_prio_queue(1, i); + if (queue == ODP_QUEUE_INVALID) + return -1; + } + + return 0; +} + +static void fill_queue_prio(odp_schedule_prio_t prio, int qnum, int buf_num) +{ + odp_queue_t queue; + char name[64]; + int i; + + snprintf(name, sizeof(name), "sched_%d_%d", prio, qnum); + queue = odp_queue_lookup(name); + + for (i = 0; i < buf_num; i++) { + odp_buffer_t buf; + buf = odp_buffer_alloc(pool); + odp_queue_enq(queue, buf); + } +} + +static void fill_queues(void) +{ + int i; + + for (i = 0; i < NUM_QUEUES; i++) { + fill_queue_prio(0, i, MAX_DEQ); + fill_queue_prio(1, i, MAX_DEQ); + } +} + +static void fill_queues_error_case(void) +{ + int i; + + for (i = 0; i < NUM_QUEUES; i++) { + fill_queue_prio(1, i, MAX_DEQ); + } + + fill_queue_prio(0, 0, MAX_DEQ); + fill_queue_prio(0, QUEUES_PER_PRIO, 2 * MAX_DEQ); +} + +static void test_prio(int num) +{ + int i; + + for (i = 0; i < num; i++) { + odp_buffer_t buf; + odp_queue_t from; + odp_schedule_prio_t prio; + + buf = odp_schedule(&from, ODP_SCHED_WAIT); + + if (buf == ODP_BUFFER_INVALID) + return; + + odp_buffer_free(buf); + + prio = odp_queue_sched_prio(from); + + printf("Got buffer q=0x%x prio=%d\n", from, prio); + } +} + +int main(int argc, char *argv[]) +{ + odp_shm_t shm; + void *pool_base; + odp_buffer_pool_param_t params; + + (void)argc; + (void)argv; + + /* ODP global init */ + if (odp_init_global(NULL, NULL)) { + EXAMPLE_ERR("ODP global init failed.\n"); + return -1; + } + + /* + * Init this thread. It makes also ODP calls when + * setting up resources for worker threads. + */ + if (odp_init_local()) { + EXAMPLE_ERR("ODP global init failed.\n"); + return -1; + } + + shm = odp_shm_reserve("msg_pool", + MSG_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0); + + pool_base = odp_shm_addr(shm); + + if (pool_base == NULL) { + EXAMPLE_ERR("Shared memory reserve failed.\n"); + return -1; + } + + /* + * Create message pool + */ + + params.buf_size = sizeof(test_message_t); + params.buf_align = 0; + params.num_bufs = MSG_POOL_SIZE/sizeof(test_message_t); + params.buf_type = ODP_BUFFER_TYPE_RAW; + + pool = odp_buffer_pool_create("msg_pool_", ODP_SHM_NULL, ¶ms); + + if (pool == ODP_BUFFER_POOL_INVALID) { + EXAMPLE_ERR("Pool create failed.\n"); + return -1; + } + + if (create_queues()) + return -1; + + printf("\nRound 1\n"); + + fill_queues(); + test_prio(2 * NUM_QUEUES * MAX_DEQ); + + printf("\nRound 2\n"); + + fill_queues_error_case(); + test_prio(2 * NUM_QUEUES + 3 * MAX_DEQ); + + return 0; +}