Re: [lng-odp] [ARCH PATCHv2] ipc design and usage modes
On Tue, Oct 28, 2014 at 10:43:54PM +0300, Maxim Uvarov wrote: Signed-off-by: Maxim Uvarov maxim.uva...@linaro.org --- v2: fixed according to Mikes comments. ipc.dox | 228 1 file changed, 228 insertions(+) create mode 100644 ipc.dox diff --git a/ipc.dox b/ipc.dox new file mode 100644 index 000..fd8e71d --- /dev/null +++ b/ipc.dox @@ -0,0 +1,228 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** +@page ipc_design Inter Process Communication (IPC) API + +@tableofcontents + +@section ipc_intro Introduction + This document defines the two different ODP application modes + multithreading and multiprocessing with respect to their impact on IPC + +@subsection odp_modes Application Thread/Process modes: + ODP applications can use following programming models for multi core support: + -# Single application with ODP worker Threads. + -# Multi process application with single packet I/O pool and common initialization. + -# Different processed communicated thought IPC API. + +@todo - add diagram about IPC modes. + +@subsubsection odp_mode_threads Thread mode + The initialization sequence for thread mode is following: + +@verbatim + main() { + /* Init ODP before calling anything else. */ + odp_init_global(NULL, NULL); + + /* Init this thread. */ + odp_init_local(); + + /* Allocate memory for packets pool. That memory will be visible for all threads.*/ + shm = odp_shm_reserve(shm_packet_pool, + SHM_PKT_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0); + pool_base = odp_shm_addr(shm); + + /* Create pool instance with reserved shm. */ + pool = odp_buffer_pool_create(packet_pool, pool_base, + SHM_PKT_POOL_SIZE, + SHM_PKT_POOL_BUF_SIZE, + ODP_CACHE_LINE_SIZE, + ODP_BUFFER_TYPE_PACKET); + + /* Create worker threads. */ + odph_linux_pthread_create(thread_tbl[i], 1, core, thr_run_func, + args); + } + + /* thread function */ + thr_run_func () { + /* Lookup the packet pool */ + pkt_pool = odp_buffer_pool_lookup(packet_pool); + + /* Open a packet IO instance for this thread */ + pktio = odp_pktio_open(eth0, pkt_pool); + + for (;;) { + /* read buffer */ + buf = odp_schedule(NULL, ODP_SCHED_WAIT); + ... do something ... + } + } +@endverbatim + +@subsubsection odp_mode_processes Processes mode with shared memory + Initialization sequence in processes mode with shared memory is following: + +@verbatim + main() { + /* Init ODP before calling anything else. In process mode odp_init_global + * function called only once in main run process. + */ + odp_init_global(NULL, NULL); + + /* Init this thread. */ + odp_init_local(); + + /* Allocate memory for packets pool. That memory will be visible for all threads.*/ + shm = odp_shm_reserve(shm_packet_pool, + SHM_PKT_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0); + pool_base = odp_shm_addr(shm); + + /* Create pool instance with reserved shm. */ + pool = odp_buffer_pool_create(packet_pool, pool_base, + SHM_PKT_POOL_SIZE, + SHM_PKT_POOL_BUF_SIZE, + ODP_CACHE_LINE_SIZE, + ODP_BUFFER_TYPE_PACKET); + + /* Call odph_linux_process_fork_n which will fork() current process to + * different processes. + */ + odph_linux_process_fork_n(proc, num_workers, first_core); + + /* Run same function as thread uses */ + thr_run_func(); + } + + /* thread function */ + thr_run_func () { + /* Lookup the packet pool */ + pkt_pool = odp_buffer_pool_lookup(packet_pool); + + /* Open a packet IO instance for this thread */ + pktio = odp_pktio_open(eth0, pkt_pool); + + for (;;) { + /* read buffer */ + buf = odp_schedule(NULL, ODP_SCHED_WAIT); + ... do something ... + } + } +@endverbatim + +@subsubsection odp_mode_sep_processes Separate Processes mode + This mode differs from mode with common shared memory.
Re: [lng-odp] [ARCH PATCHv2] ipc design and usage modes
On 10/30/2014 12:30 PM, Jerin Jacob wrote: On Thu, Oct 30, 2014 at 12:02:17PM +0530, Jerin Jacob wrote: On Tue, Oct 28, 2014 at 10:43:54PM +0300, Maxim Uvarov wrote: Signed-off-by: Maxim Uvarov maxim.uva...@linaro.org --- v2: fixed according to Mikes comments. ipc.dox | 228 1 file changed, 228 insertions(+) create mode 100644 ipc.dox diff --git a/ipc.dox b/ipc.dox new file mode 100644 index 000..fd8e71d --- /dev/null +++ b/ipc.dox @@ -0,0 +1,228 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** +@page ipc_design Inter Process Communication (IPC) API + +@tableofcontents + +@section ipc_intro Introduction + This document defines the two different ODP application modes + multithreading and multiprocessing with respect to their impact on IPC + +@subsection odp_modes Application Thread/Process modes: + ODP applications can use following programming models for multi core support: + -# Single application with ODP worker Threads. + -# Multi process application with single packet I/O pool and common initialization. + -# Different processed communicated thought IPC API. + +@todo - add diagram about IPC modes. + +@subsubsection odp_mode_threads Thread mode + The initialization sequence for thread mode is following: + +@verbatim +main() { + /* Init ODP before calling anything else. */ + odp_init_global(NULL, NULL); + + /* Init this thread. */ + odp_init_local(); + + /* Allocate memory for packets pool. That memory will be visible for all threads.*/ + shm = odp_shm_reserve(shm_packet_pool, + SHM_PKT_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0); + pool_base = odp_shm_addr(shm); + + /* Create pool instance with reserved shm. */ + pool = odp_buffer_pool_create(packet_pool, pool_base, + SHM_PKT_POOL_SIZE, + SHM_PKT_POOL_BUF_SIZE, + ODP_CACHE_LINE_SIZE, + ODP_BUFFER_TYPE_PACKET); + + /* Create worker threads. */ + odph_linux_pthread_create(thread_tbl[i], 1, core, thr_run_func, + args); + } + + /* thread function */ + thr_run_func () { + /* Lookup the packet pool */ + pkt_pool = odp_buffer_pool_lookup(packet_pool); + + /* Open a packet IO instance for this thread */ + pktio = odp_pktio_open(eth0, pkt_pool); + + for (;;) { + /* read buffer */ + buf = odp_schedule(NULL, ODP_SCHED_WAIT); + ... do something ... + } + } +@endverbatim + +@subsubsection odp_mode_processes Processes mode with shared memory + Initialization sequence in processes mode with shared memory is following: + +@verbatim +main() { +/* Init ODP before calling anything else. In process mode odp_init_global + * function called only once in main run process. + */ +odp_init_global(NULL, NULL); + +/* Init this thread. */ +odp_init_local(); + +/* Allocate memory for packets pool. That memory will be visible for all threads.*/ +shm = odp_shm_reserve(shm_packet_pool, +SHM_PKT_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0); +pool_base = odp_shm_addr(shm); + +/* Create pool instance with reserved shm. */ +pool = odp_buffer_pool_create(packet_pool, pool_base, +SHM_PKT_POOL_SIZE, +SHM_PKT_POOL_BUF_SIZE, +ODP_CACHE_LINE_SIZE, +ODP_BUFFER_TYPE_PACKET); + +/* Call odph_linux_process_fork_n which will fork() current process to + * different processes. + */ +odph_linux_process_fork_n(proc, num_workers, first_core); + +/* Run same function as thread uses */ +thr_run_func(); + } + + /* thread function */ + thr_run_func () { + /* Lookup the packet pool */ + pkt_pool = odp_buffer_pool_lookup(packet_pool); + + /* Open a packet IO instance for this thread */ + pktio = odp_pktio_open(eth0, pkt_pool); + + for (;;) { + /* read buffer */ + buf = odp_schedule(NULL, ODP_SCHED_WAIT); + ... do something ... + } + } +@endverbatim +
[lng-odp] [ARCH PATCHv2] ipc design and usage modes
Signed-off-by: Maxim Uvarov maxim.uva...@linaro.org --- v2: fixed according to Mikes comments. ipc.dox | 228 1 file changed, 228 insertions(+) create mode 100644 ipc.dox diff --git a/ipc.dox b/ipc.dox new file mode 100644 index 000..fd8e71d --- /dev/null +++ b/ipc.dox @@ -0,0 +1,228 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** +@page ipc_design Inter Process Communication (IPC) API + +@tableofcontents + +@section ipc_intro Introduction + This document defines the two different ODP application modes + multithreading and multiprocessing with respect to their impact on IPC + +@subsection odp_modes Application Thread/Process modes: + ODP applications can use following programming models for multi core support: + -# Single application with ODP worker Threads. + -# Multi process application with single packet I/O pool and common initialization. + -# Different processed communicated thought IPC API. + +@todo - add diagram about IPC modes. + +@subsubsection odp_mode_threads Thread mode + The initialization sequence for thread mode is following: + +@verbatim +main() { + /* Init ODP before calling anything else. */ + odp_init_global(NULL, NULL); + + /* Init this thread. */ + odp_init_local(); + + /* Allocate memory for packets pool. That memory will be visible for all threads.*/ + shm = odp_shm_reserve(shm_packet_pool, + SHM_PKT_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0); + pool_base = odp_shm_addr(shm); + + /* Create pool instance with reserved shm. */ + pool = odp_buffer_pool_create(packet_pool, pool_base, + SHM_PKT_POOL_SIZE, + SHM_PKT_POOL_BUF_SIZE, + ODP_CACHE_LINE_SIZE, + ODP_BUFFER_TYPE_PACKET); + + /* Create worker threads. */ + odph_linux_pthread_create(thread_tbl[i], 1, core, thr_run_func, + args); + } + + /* thread function */ + thr_run_func () { + /* Lookup the packet pool */ + pkt_pool = odp_buffer_pool_lookup(packet_pool); + + /* Open a packet IO instance for this thread */ + pktio = odp_pktio_open(eth0, pkt_pool); + + for (;;) { + /* read buffer */ + buf = odp_schedule(NULL, ODP_SCHED_WAIT); + ... do something ... + } + } +@endverbatim + +@subsubsection odp_mode_processes Processes mode with shared memory + Initialization sequence in processes mode with shared memory is following: + +@verbatim +main() { +/* Init ODP before calling anything else. In process mode odp_init_global + * function called only once in main run process. + */ +odp_init_global(NULL, NULL); + +/* Init this thread. */ +odp_init_local(); + +/* Allocate memory for packets pool. That memory will be visible for all threads.*/ +shm = odp_shm_reserve(shm_packet_pool, +SHM_PKT_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0); +pool_base = odp_shm_addr(shm); + +/* Create pool instance with reserved shm. */ +pool = odp_buffer_pool_create(packet_pool, pool_base, +SHM_PKT_POOL_SIZE, +SHM_PKT_POOL_BUF_SIZE, +ODP_CACHE_LINE_SIZE, +ODP_BUFFER_TYPE_PACKET); + +/* Call odph_linux_process_fork_n which will fork() current process to + * different processes. + */ +odph_linux_process_fork_n(proc, num_workers, first_core); + +/* Run same function as thread uses */ +thr_run_func(); + } + + /* thread function */ + thr_run_func () { + /* Lookup the packet pool */ + pkt_pool = odp_buffer_pool_lookup(packet_pool); + + /* Open a packet IO instance for this thread */ + pktio = odp_pktio_open(eth0, pkt_pool); + + for (;;) { + /* read buffer */ + buf = odp_schedule(NULL, ODP_SCHED_WAIT); + ... do something ... + } + } +@endverbatim + +@subsubsection odp_mode_sep_processes Separate Processes mode + This mode differs from mode with common shared memory. Each execution thread is completely independent