pcounter.c 624 B

1234567891011121314151617181920212223242526
  1. /*
  2. * Define default pcounter functions
  3. * Note that often used pcounters use dedicated functions to get a speed increase.
  4. * (see DEFINE_PCOUNTER/REF_PCOUNTER_MEMBER)
  5. */
  6. #include <linux/module.h>
  7. #include <linux/pcounter.h>
  8. #include <linux/smp.h>
  9. void pcounter_def_add(struct pcounter *self, int inc)
  10. {
  11. per_cpu_ptr(self->per_cpu_values, smp_processor_id())[0] += inc;
  12. }
  13. EXPORT_SYMBOL_GPL(pcounter_def_add);
  14. int pcounter_def_getval(const struct pcounter *self)
  15. {
  16. int res = 0, cpu;
  17. for_each_possible_cpu(cpu)
  18. res += per_cpu_ptr(self->per_cpu_values, cpu)[0];
  19. return res;
  20. }
  21. EXPORT_SYMBOL_GPL(pcounter_def_getval);