kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: dave.jing.tian@gmail.com (Dave Tian)
To: kernelnewbies@lists.kernelnewbies.org
Subject: doubt about interrupts and spinlocks
Date: Sat, 25 Oct 2014 00:00:12 +0800	[thread overview]
Message-ID: <DFB62688-DBDC-4CC7-88B6-15036F5F005F@gmail.com> (raw)
In-Reply-To: <CAOXBz7iYtoupvxGvVzdcFKFv-9WvES192Bv1rES5YB=zrWZowg@mail.gmail.com>

If you are talking about the same spin_lock, once it is locked, it is locked. Others (even from other CPUs) have to ?spin' util the lock is freed.

-daveti


> On Oct 24, 2014, at 11:04 PM, Oscar Salvador <osalvador.vilardaga@gmail.com> wrote:
> 
> Hi!
> 
> I have a doubt about interrupts and spin locks.
> I'm not sure if I'm in the good way:
> 
> When an interrupt is raised, the kernel (through do_IRQ and etc) acknowledges the interrupt and locks this IRQ taking a spin lock, so any other cpu can not handle this interrupt, and then the kernel executes the handler, if there is a handler available for that interrupt.
> 
> When we are on the handler interrupt , maybe we need to lock the cpu till we finish( if we are in a network driver, may we need to process some TX/RX packets ), 
> so if we have to lock the code we can do a spin_lock().
> But with a spin_lock, even other CPU's can execute part of your code(code that is not part of the handler interrupt). 
> For example:
> 
> (this is an example in a network device driver)
> The system has to transmit a packet, so network subsystem calls ndo_start_xmit. Inside this function we take a lock disabling the interrupts(spin_lock_irqsave) because we have to do some private things, but suddenly an interrupt is raised and we go to the interrupt handler, we take a spin_lock, we do some work (processing some RX/TX packets), and exites from the interrupt handler, and then we come back to the ndo_start_xmit when we were.
> 
> As far I could understand( I have read http://www.makelinux.net/ldd3/chp-5-sect-5 <http://www.makelinux.net/ldd3/chp-5-sect-5> ), spin_lock_irqsave only disables the interrupts for the local cpu(where the code is executed), 
> so I think that another cpu took the handler interrupt.
> The problem is if I'm working with irq disabled, because I have to handle a private structure and suddenly interrupts is taking place, the interrupt can manipulate the code that I'm trying to keep safe.
> Is there any advice? Maybe that is happened because the code within my critical section on ndo_start_xmit has to be atomic? Otherwise it can go to sleep and I can lose my lock?
> 
> Thank you very much
> Oscar Salvador
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20141025/0d8ee412/attachment.html 

  reply	other threads:[~2014-10-24 16:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-24 15:04 doubt about interrupts and spinlocks Oscar Salvador
2014-10-24 16:00 ` Dave Tian [this message]
2014-10-24 19:16 ` anish singh
2014-10-27 10:58   ` Oscar Salvador

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DFB62688-DBDC-4CC7-88B6-15036F5F005F@gmail.com \
    --to=dave.jing.tian@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).