LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 03-18-2010, 02:04 PM   #1
zman2245
LQ Newbie
 
Registered: Mar 2009
Location: San Francisco, CA
Posts: 26

Rep: Reputation: 15
Network stack behavior handling packets on multiple cores


I am working on a kernel module that sits between a NIC driver and the standard Linux network stack. The module does processing on a per stream (TCP or UDP) basis. My question is:

Is it possible for packets on the same TCP or UDP stream (same IP DA, IP SA, Dst Port, Src Port) to be sent on different CPU cores? I'm trying to decide whether I need to handle/test this case.

If so, how does the kernel ensure that packets do not get out of order?

Thanks,
Zack
 
Old 03-18-2010, 04:08 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Packets on the same stream may come from different cores on Linux. In the case of UDP you have no guarantee, as the protocol itself doesn't guarantee you the order. In the case of TCP, the situation is more complicated and using TCP in that way doesn't make much sense. I don't have a multicore machine now to check out for sure, but you have at least a logical order guarantee after assigning sequence numbers (and that's close to the beginning).
 
Old 03-19-2010, 02:40 PM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,671
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
On a multi-core or multi-CPU system, any of them can potentially access the hardware at any time. Generally speaking, "network packet requests can come from anywhere at any time and in any order."

Having said that... also note that there are software structures (queues, sockets, and so on) which will have various kinds of serialization and mutual-exclusion mechanisms built into them. So, these mechanisms will work as-designed no matter how many cores, CPUs, processes, and threads might be involved.

As long as you're using a multi-engine aware kernel (and a single-engine kernel will detect and shut down all of the engines that it may find except one), Linux will happily and correctly take advantage of whatever hardware capabilities you have. The presence of multiple engines will make the actual behavior much less deterministic, but software is built to have no dependency upon "determinism."

Last edited by sundialsvcs; 03-19-2010 at 02:42 PM.
 
Old 03-22-2010, 01:21 PM   #4
zman2245
LQ Newbie
 
Registered: Mar 2009
Location: San Francisco, CA
Posts: 26

Original Poster
Rep: Reputation: 15
Thank you for the replies. So I went back and looked into the kernel stack code. It looks like HARD_TX_LOCK(dev) is used to synchronize access to network device transmit rings. Is this correct?

Since my module essentially overrides the hard_start_xmit() of the NIC driver it looks like, from an ordering standpoint, I am fine. However, my module does do some queueing and sending packets at a later time, so I will probably need to use HARD_TX_LOCK(dev) from within to make sure I behave and synchronize access to the hardware...
 
Old 03-22-2010, 04:30 PM   #5
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Access to the physical device is synchronized, yes.

From your design it looks that you should check if all entries to your module are in synchronized sections. If not, you may need to synchronize on your own, especially if you have your own queues.
 
Old 03-24-2010, 12:41 PM   #6
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
Ever since NAPI came to Linux kernel 2.6 and 2.4.19, receive has been made more scalable on SMP systems, wherein order in which the packet came in is retained by upper layer software as well. The packet is left on the hardware and is copied into kernel memory when the poll() function is called; thereafter, netif_receive_skb() is called to send the packet up the stack.

Don't think Tx has changed a whole lot, given that that xmit_lock has been around for a long time.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Alias make to automatically use multiple cores? damgar Linux - Software 10 01-28-2010 02:37 PM
How does the kernel handle multiple cpus/cores? riddler313 Linux - General 4 06-18-2009 08:35 AM
configuring MYSQL 5.0.67 to use multiple cores (processors) nino_of_qubic Linux - Server 3 03-31-2009 11:29 PM
linux on multiple cores reslowgr Linux - Server 1 01-20-2007 03:35 PM
handling packets at kernel level using C/C++ valib4u Linux - Networking 3 09-14-2003 02:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 07:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration