From patchwork Fri May 27 19:50:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 68780 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp272352qge; Fri, 27 May 2016 12:51:27 -0700 (PDT) X-Received: by 10.55.90.130 with SMTP id o124mr15886193qkb.178.1464378687808; Fri, 27 May 2016 12:51:27 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id n125si18931501qkn.142.2016.05.27.12.51.27; Fri, 27 May 2016 12:51:27 -0700 (PDT) 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; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 6341A617B3; Fri, 27 May 2016 19:51:27 +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.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 AE9AA616DC; Fri, 27 May 2016 19:51:22 +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 410E0616E7; Fri, 27 May 2016 19:51:20 +0000 (UTC) Received: from mail-lf0-f54.google.com (mail-lf0-f54.google.com [209.85.215.54]) by lists.linaro.org (Postfix) with ESMTPS id 33EBA61690 for ; Fri, 27 May 2016 19:51:19 +0000 (UTC) Received: by mail-lf0-f54.google.com with SMTP id s64so26177320lfe.0 for ; Fri, 27 May 2016 12:51:19 -0700 (PDT) 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; bh=gkw0qaTJ9bstzvBYLpP94VhHNFF4PwHpKXaKjYjYamk=; b=YkNDE83LKVfhXcPSlecMDAbQSaGzvtY2LJSfddkUOBVBUfB3IDZUJ62DYL04CRuRUx AcOYQ+omfBhFBLiJtk6ypvhqJEhCMKwticeDuXaCHqYSiFyn9YgzscfmO5DkS7dg66qW BScVqRjNnY7jV8FsbyspFWdr6XNmLsuUGbEiwPR7IxDCvADPhMDxGA+vl2kIDFyQPubt 0cTH9XlJzRNCmbSPHow5GjSxnryZlE66+3zV1DOA2tO4Y9D9FV4+v3PSQv0H8Y+5iya0 mUwbU92R6XSJueQOT0Zz4rBqXXQdm80qCC7vXuMj/a3ie9Zv5UT5G9tHT8H9Jk553sOM sG2Q== X-Gm-Message-State: ALyK8tJDrSI7NELke80bhYoOpkp2PMo/FSWUGMZsvR0dUbeJjXNlyRhgxb135ksAt+6DMYSenmw= X-Received: by 10.25.216.36 with SMTP id p36mr4955179lfg.198.1464378677955; Fri, 27 May 2016 12:51:17 -0700 (PDT) Received: from localhost.localdomain (ppp91-77-173-31.pppoe.mtu-net.ru. [91.77.173.31]) by smtp.gmail.com with ESMTPSA id l5sm3119051lbk.1.2016.05.27.12.51.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 May 2016 12:51:17 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Fri, 27 May 2016 22:50:22 +0300 Message-Id: <1464378622-5072-1-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.7.1.250.gff4ea60 X-Topics: patch Subject: [lng-odp] [PATCHv2] validation: sched: fix out of array reference 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" If MAX_CPUS defined to less then current cpus, then odp call calculates current available cpus and references to array on thread creation. Do change to allocate array dynamically. Signed-off-by: Maxim Uvarov --- v2: calculate num_workers first, then calloc needed size. test/performance/odp_scheduling.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/test/performance/odp_scheduling.c b/test/performance/odp_scheduling.c index 1d3bfd1..c575b70 100644 --- a/test/performance/odp_scheduling.c +++ b/test/performance/odp_scheduling.c @@ -27,8 +27,6 @@ /* GNU lib C */ #include - -#define MAX_WORKERS 32 /**< Max worker threads */ #define MSG_POOL_SIZE (4*1024*1024) /**< Message pool size */ #define MAX_ALLOCS 35 /**< Alloc burst size */ #define QUEUES_PER_PRIO 64 /**< Queue per priority */ @@ -775,7 +773,7 @@ static void parse_args(int argc, char *argv[], test_args_t *args) */ int main(int argc, char *argv[]) { - odph_odpthread_t thread_tbl[MAX_WORKERS]; + odph_odpthread_t *thread_tbl; test_args_t args; int num_workers; odp_cpumask_t cpumask; @@ -795,8 +793,6 @@ int main(int argc, char *argv[]) memset(&args, 0, sizeof(args)); parse_args(argc, argv, &args); - memset(thread_tbl, 0, sizeof(thread_tbl)); - /* ODP global init */ if (odp_init_global(&instance, NULL, NULL)) { LOG_ERR("ODP global init failed.\n"); @@ -825,19 +821,20 @@ int main(int argc, char *argv[]) printf("\n"); - /* Default to system CPU count unless user specified */ - num_workers = MAX_WORKERS; - if (args.cpu_count) - num_workers = args.cpu_count; - /* Get default worker cpumask */ - num_workers = odp_cpumask_default_worker(&cpumask, num_workers); + num_workers = odp_cpumask_default_worker(&cpumask, args.cpu_count); (void)odp_cpumask_to_str(&cpumask, cpumaskstr, sizeof(cpumaskstr)); printf("num worker threads: %i\n", num_workers); printf("first CPU: %i\n", odp_cpumask_first(&cpumask)); printf("cpu mask: %s\n", cpumaskstr); + thread_tbl = calloc(sizeof(odph_odpthread_t), num_workers); + if (!thread_tbl) { + LOG_ERR("no memory for thread_tbl\n"); + return -1; + } + /* Test cycle count frequency */ test_cpu_freq(); @@ -947,6 +944,7 @@ int main(int argc, char *argv[]) /* Wait for worker threads to terminate */ odph_odpthreads_join(thread_tbl); + free(thread_tbl); printf("ODP example complete\n\n");