static void perfmon_counters_env_init(void) { for (int i = 0; i < num_cores; i++) { struct perfmon_cpu_context *cctx = _PERCPU_VARPTR(counters_env, i); spinlock_init_irqsave(&cctx->lock); } }
void percpu_counter_set(struct percpu_counter *fbc, int64_t amount) { int cpu; unsigned long flags; spin_lock_irqsave(&fbc->lock); for_each_possible_cpu(cpu) { int32_t *pcount = _PERCPU_VARPTR(*fbc->counters, cpu); *pcount = 0; } fbc->count = amount; spin_unlock_irqsave(&fbc->lock); }
/* * Add up all the per-cpu counts, return the result. This is a more accurate * but much slower version of percpu_counter_read_positive() */ int64_t __percpu_counter_sum(struct percpu_counter *fbc) { int64_t ret; int cpu; unsigned long flags; spin_lock_irqsave(&fbc->lock); ret = fbc->count; for_each_online_cpu(cpu) { int32_t *pcount = _PERCPU_VARPTR(*fbc->counters, cpu); ret += *pcount; } spin_unlock_irqsave(&fbc->lock); return ret; }