A brief analysis of multi-core multithreading mechanism in DPDK

Source: Internet
Author: User

DPDK improves performance by creating multiple threads on a multi-core device, each bound to a separate core, and reducing the overhead of thread scheduling.

DPDK threads are divided into control threads and data threads, and the control threads are generally bound to the master kernel, mainly accepting user configuration, passing configuration parameters to data threads, etc., and the data threads are mainly processing packets.

First, initialize

1, Rte_eal_cpu_init () function, by reading the relevant information under the/sys/devices/system/cpu/cpux/, determine what the current system CPU cores, each core is a CPU Socket.

2, Eal_parse_args () function, resolve the-c parameter, confirm which CPU cores are available, and set the first kernel to master.

3. Create a thread for each slave core and call eal_thread_set_affinity () to bind the CPU. The execution body of the thread is Eal_thread_loop (). The body of Eal_thread_loop () is a while dead loop that invokes a callback function that registers to LCORE_CONFIG[LCORE_ID].F with different modules.

1 Rte_lcore_foreach_slave (i) {2 3     /*4 * Create communication pipes between master thread5 * and children6      */7     if(Pipe (Lcore_config[i].pipe_master2slave) <0)8Rte_panic ("Cannot create pipe\n");9     if(Pipe (Lcore_config[i].pipe_slave2master) <0)TenRte_panic ("Cannot create pipe\n"); One  ALcore_config[i].state =WAIT; -  -     /*Create a thread for each Lcore*/ theret = Pthread_create (&lcore_config[i].thread_id, NULL, - Eal_thread_loop, NULL); -     if(Ret! =0) -Rte_panic ("Cannot create thread\n"); +}

Second, registration

Different modules need to call Rte_eal_mp_remote_launch () and register their callback handlers in LCORE_CONFIG[].F. Take L2FWD as an example, the registered callback handler is L2fwd_launch_on_lcore ().

1 rte_eal_mp_remote_launch (L2fwd_launch_one_lcore, NULL, Call_master);

DPDK the thread on each core will eventually call Eal_thread_loop ()--->l2fwd_launch_on_lcore (), calling to its own implementation of the handler function.

Mistakes, please note.

Reprint please indicate transfer from http://www.cnblogs.com/MerlinJ/p/4103790.html

A brief analysis of multi-core multithreading mechanism in DPDK

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.