Find the answer to your Linux question:
Results 1 to 3 of 3
When I want to execute a little code snippet absolute atomically on it's current CPU, which instructions do I have to call before? Do I need local_irq_disable() *and* preempt_disable() or ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2009
    Posts
    3

    atomicity


    When I want to execute a little code snippet absolute atomically on it's current CPU, which instructions do I have to call before? Do I need local_irq_disable() *and* preempt_disable() or is one of them sufficient? I.e. is one a subset of the other or where is the difference between these calls?

  2. #2
    Just Joined!
    Join Date
    Jul 2009
    Posts
    49

    Have a look a the kernel API documentation

    You will find some API functions called: atomic_read(), atomic_set(), atomic_add() and so forth. You may find that these functions will cover your "code snippet" and do the job.

    As a developer's note, I usually have the source code of the kernel all indexed through some IDE (in my case cscope, I guess I'm showing my age.) available to me so that I can check out the code of the API that I'm using. It comes in handy for questions like what you have asked. When I looked at "preempt_disable()" I got the following:

    #define preempt_disable() \
    do { \
    inc_preempt_count(); \
    barrier(); \
    } while (0)

    When I searched for "local_irq_disable()", they did not seem to be related at all.

    Hope this helps.

    Cheers!!

  3. #3
    Just Joined!
    Join Date
    Oct 2009
    Posts
    3
    Hmm, atomic_read/set/add are just usable to make very small pieces of code atomically - like reading, setting or adding variables. But what I have to do is to make a code snippet of say 10 or 20 lines atomically.

    Thanks for the hint with cscope. Usually I use online source browsers like lxr for that. Anyhow, I looked at the functions, but I still wonder, if I need one or both of them. To be save I am just using both of them in the moment

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •