Linux driver example for Per CPU Variable

Per CPU Variables is an interesting feature available from Linux Kernel Version 2.6

When you define a Per CPU Variable, each processor in the system will have its own copy of the variable, hence no locking is required and better performance is achieved.

Header File: <linux/percpu.h>

To create a Per CPU Variable at compile time, use the macro:
DEFINE_PER_CPU(type, name);
E.g. DEFINE_PER_CPU(int, counter);

As linux kernel is preemptible, you must use
get_cpu_var macro to access the current processor's copy of a given variable
And finally call put_cpu_var macro after you have completed using it.

You can access another processor's copy of the variable with:
per_cpu(variable, int cpu_id);

Example:




Output:


Comments

  1. Thanks For Sharing this Interesting Blog. it is really helpful blog. carry on. keep blogging. otherwise anyone wants to learn CREO training Course so, Contact here- +91-9311002620 or visit website- https://www.htsindia.com/Courses/cad-cam-cae/creo-for-industrial-designers-training-course

    ReplyDelete
  2. Thanks for sharing this wonderful information. I too learn something new from your post..
    Primavera Training in Chennai

    ReplyDelete
  3. Thank you for sharing this important conversation with the local and international community, The Electronic Repair Center can use workshop management software free trial to manage its day-to-day transactions and customer management.

    ReplyDelete
  4. Very informative post! There is a lot of information here that can help any business get started with a successful social networking campaign. 加拿大簽證申請

    ReplyDelete
  5. This post is so interactive and informative.keep update more information...
    Tally Course in Tambaram
    Tally course in Chennai

    ReplyDelete
  6. Nice and informative blog! This type of information is a complete business accounting software that can be managed well whether one holds small or medium-sized businesses.
    If you want to know about Tally certification courses in Cochin then you can click here.
    Thanks for sharing.

    ReplyDelete

Post a Comment

Popular posts from this blog

bb.utils.contains yocto

make config vs oldconfig vs defconfig vs menuconfig vs savedefconfig

PR, PN and PV Variable in Yocto