From patchwork Wed Jul 30 12:16:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Santosh Shukla X-Patchwork-Id: 34515 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f71.google.com (mail-yh0-f71.google.com [209.85.213.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 791CA20792 for ; Wed, 30 Jul 2014 12:17:23 +0000 (UTC) Received: by mail-yh0-f71.google.com with SMTP id 29sf3769477yhl.10 for ; Wed, 30 Jul 2014 05:17:23 -0700 (PDT) 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:subject :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=dOquxgpBz2555zQbfD4//QytA3COcx8L3iDJr4TqHHA=; b=K5NrtC6yEHCCAgF1NVZ7UwzlQ+lLR1G91Sk0x0iNrx1YZuqiKFBRgfLjpHOIRdJdMo kCz6OVmk++dNRx2NfMjUrGj0E+GcPeCemUF+qCfpzo5kDB8uUgU/61nFXGcR4jxmUUqK nxH9pyI5c3Tad6cOPLA+dzJiToNJeI9ujZIfFvE5wkFTElknQKOQi+jhsGv0+cOVJ5iX kNMI3cxETQNabhHjxThdUm42kM4Ft9EcO0cJIhyQ8Lvue6TnfQ5apic4/QjYgGATEBun YcMZ8BWhupqrc1DN6fI/CJa2iuTSjJlYUwFZq/ujRbQq5prpvBVb9enAsH+RCK+kcRX+ xi2A== X-Gm-Message-State: ALoCoQl09IbOtaEEire4gcNhlGOrEM7GE12clFEyVdOstipH4rbJBbr62vynFle6ltFrujMsc6iF X-Received: by 10.224.171.130 with SMTP id h2mr1528055qaz.7.1406722643310; Wed, 30 Jul 2014 05:17:23 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.87.37 with SMTP id q34ls551586qgd.5.gmail; Wed, 30 Jul 2014 05:17:23 -0700 (PDT) X-Received: by 10.220.131.207 with SMTP id y15mr660403vcs.71.1406722643218; Wed, 30 Jul 2014 05:17:23 -0700 (PDT) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by mx.google.com with ESMTPS id da3si1394478vcb.102.2014.07.30.05.17.23 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Jul 2014 05:17:23 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.179 as permitted sender) client-ip=209.85.220.179; Received: by mail-vc0-f179.google.com with SMTP id hq11so1566365vcb.24 for ; Wed, 30 Jul 2014 05:17:23 -0700 (PDT) X-Received: by 10.52.244.138 with SMTP id xg10mr7265225vdc.40.1406722643115; Wed, 30 Jul 2014 05:17:23 -0700 (PDT) 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.221.37.5 with SMTP id tc5csp22710vcb; Wed, 30 Jul 2014 05:17:22 -0700 (PDT) X-Received: by 10.140.108.68 with SMTP id i62mr5877435qgf.56.1406722632888; Wed, 30 Jul 2014 05:17:12 -0700 (PDT) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id q6si3554279qah.75.2014.07.30.05.16.42 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 30 Jul 2014 05:17:12 -0700 (PDT) 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-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XCSoE-0005eB-MC; Wed, 30 Jul 2014 12:16:42 +0000 Received: from mail-pa0-f41.google.com ([209.85.220.41]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XCSo8-0005e1-5h for lng-odp@lists.linaro.org; Wed, 30 Jul 2014 12:16:36 +0000 Received: by mail-pa0-f41.google.com with SMTP id rd3so1422616pab.14 for ; Wed, 30 Jul 2014 05:16:30 -0700 (PDT) X-Received: by 10.69.26.134 with SMTP id iy6mr4084914pbd.115.1406722590615; Wed, 30 Jul 2014 05:16:30 -0700 (PDT) Received: from santosh-Latitude-E5530-non-vPro.10.0.0.5 ([111.93.218.67]) by mx.google.com with ESMTPSA id ln10sm2164524pbc.96.2014.07.30.05.16.27 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Jul 2014 05:16:29 -0700 (PDT) From: Santosh Shukla To: lng-odp@lists.linaro.org Date: Wed, 30 Jul 2014 17:46:10 +0530 Message-Id: <1406722571-23556-1-git-send-email-santosh.shukla@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Topics: patch Subject: [lng-odp] [PATCH 1/2] linux-generic: add pthread_create_single api 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: santosh.shukla@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.220.179 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 odp_linux_pthread_create_single api stripped down version of existing odp_linux_pthread_create api, It avoid complete thread_tbl flushing, only specific thread_tbl index get flushed. pthread_create_single api will - only create one thread, - thread can pin to core_num - thread can update to any thread_tbl[] index. Signed-off-by: santosh shukla --- include/helper/odp_linux.h | 16 ++++++++++++ platform/linux-generic/odp_linux.c | 48 ++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/include/helper/odp_linux.h b/include/helper/odp_linux.h index 3076c22..834e553 100644 --- a/include/helper/odp_linux.h +++ b/include/helper/odp_linux.h @@ -48,6 +48,22 @@ void odp_linux_pthread_create(odp_linux_pthread_t *thread_tbl, int num, int first_core, void *(*start_routine) (void *), void *arg); +/** + * Create and launch a single pthread + * + * Create, pin and launch thread to specific core_number + * + * @param thread_tbl Thread table + * @param thd_tbl_idx Thread table index to update thread info + * @param core_num Core number to pin thread with + * @param start_routine Thread start function + * @param arg Thread argument + */ +void odp_linux_pthread_create_single(odp_linux_pthread_t *thread_tbl, + int thd_tbl_idx, + int first_core, + void *(*start_routine) (void *), + void *arg); /** * Waits pthreads to exit diff --git a/platform/linux-generic/odp_linux.c b/platform/linux-generic/odp_linux.c index 6e2b448..bebff51 100644 --- a/platform/linux-generic/odp_linux.c +++ b/platform/linux-generic/odp_linux.c @@ -85,6 +85,54 @@ void odp_linux_pthread_create(odp_linux_pthread_t *thread_tbl, int num, } +void odp_linux_pthread_create_single(odp_linux_pthread_t *thread_tbl, + int thd_tbl_idx, + int first_core, + void *(*start_routine) (void *), void *arg) +{ + cpu_set_t cpu_set; + odp_start_args_t *start_args; + int core_count; + int cpu; + + core_count = odp_sys_core_count(); + + assert((first_core >= 0) && (first_core < core_count)); + assert((thd_tbl_idx >= 0) && (thd_tbl_idx <= core_count)); + + /* check thread_tbl idx is free for use? */ + if (thread_tbl[thd_tbl_idx].thread != 0) { + ODP_ERR("thread_tbl idx[%d] used\n", thd_tbl_idx); + return; + } + + /* flush that tbl_idx only */ + memset(thread_tbl+thd_tbl_idx, 0, sizeof(odp_linux_pthread_t)); + + /* now create a thread, affine to first_core */ + pthread_attr_init(&thread_tbl[thd_tbl_idx].attr); + + CPU_ZERO(&cpu_set); + + cpu = first_core % core_count; + CPU_SET(cpu, &cpu_set); + + pthread_attr_setaffinity_np(&thread_tbl[thd_tbl_idx].attr, + sizeof(cpu_set_t), &cpu_set); + + start_args = malloc(sizeof(odp_start_args_t)); + memset(start_args, 0, sizeof(odp_start_args_t)); + start_args->start_routine = start_routine; + start_args->arg = arg; + + start_args->thr_id = odp_thread_create(cpu); + + pthread_create(&thread_tbl[thd_tbl_idx].thread, + &thread_tbl[thd_tbl_idx].attr, + odp_run_start_routine, start_args); +} + + void odp_linux_pthread_join(odp_linux_pthread_t *thread_tbl, int num) { int i;