diff --git a/tools/argdist.py b/tools/argdist.py index 88da0d841d49..b810126ec7e5 100755 --- a/tools/argdist.py +++ b/tools/argdist.py @@ -334,10 +334,11 @@ def _generate_key_assignment(self): def _generate_hash_update(self): if self.type == "hist": - return "%s.increment(bpf_log2l(__key));" % \ + return "%s.atomic_increment(bpf_log2l(__key));" % \ self.probe_hash_name else: - return "%s.increment(__key);" % self.probe_hash_name + return "%s.atomic_increment(__key);" % \ + self.probe_hash_name def _generate_pid_filter(self): # Kernel probes need to explicitly filter pid, because the diff --git a/tools/biolatency.py b/tools/biolatency.py index 0599609b8d11..7fb5bd8113be 100755 --- a/tools/biolatency.py +++ b/tools/biolatency.py @@ -132,18 +132,18 @@ disk_key_t key = {.slot = bpf_log2l(delta)}; void *__tmp = (void *)req->rq_disk->disk_name; bpf_probe_read(&key.disk, sizeof(key.disk), __tmp); - dist.increment(key); + dist.atomic_increment(key); """ elif args.flags: storage_str += "BPF_HISTOGRAM(dist, flag_key_t);" store_str += """ flag_key_t key = {.slot = bpf_log2l(delta)}; key.flags = req->cmd_flags; - dist.increment(key); + dist.atomic_increment(key); """ else: storage_str += "BPF_HISTOGRAM(dist);" - store_str += "dist.increment(bpf_log2l(delta));" + store_str += "dist.atomic_increment(bpf_log2l(delta));" if args.extension: storage_str += "BPF_ARRAY(extension, ext_val_t, 1);" @@ -254,7 +254,7 @@ def flags_print(flags): else: if args.timestamp: print("%-8s\n" % strftime("%H:%M:%S"), end="") - + if args.flags: dist.print_log2_hist(label, "flags", flags_print) else: diff --git a/tools/bitesize.py b/tools/bitesize.py index 6ae71dcf8ed4..69e36335ba71 100755 --- a/tools/bitesize.py +++ b/tools/bitesize.py @@ -31,7 +31,7 @@ { struct proc_key_t key = {.slot = bpf_log2l(args->bytes / 1024)}; bpf_probe_read_kernel(&key.name, sizeof(key.name), args->comm); - dist.increment(key); + dist.atomic_increment(key); return 0; } """ diff --git a/tools/btrfsdist.py b/tools/btrfsdist.py index 0aad2d945af9..72ea304a284e 100755 --- a/tools/btrfsdist.py +++ b/tools/btrfsdist.py @@ -144,7 +144,7 @@ // store as histogram dist_key_t key = {.slot = bpf_log2l(delta)}; __builtin_memcpy(&key.op, op, sizeof(key.op)); - dist.increment(key); + dist.atomic_increment(key); start.delete(&tid); return 0; diff --git a/tools/cachestat.py b/tools/cachestat.py index bb949493c779..2c09d14d6b15 100755 --- a/tools/cachestat.py +++ b/tools/cachestat.py @@ -81,7 +81,7 @@ def get_meminfo(): u64 ip; key.ip = PT_REGS_IP(ctx); - counts.increment(key); // update counter + counts.atomic_increment(key); // update counter return 0; } diff --git a/tools/cpudist.py b/tools/cpudist.py index b5a6a9782de2..a4303f85de3b 100755 --- a/tools/cpudist.py +++ b/tools/cpudist.py @@ -144,7 +144,7 @@ section = "" bpf_text = bpf_text.replace('STORAGE', 'BPF_HISTOGRAM(dist);') bpf_text = bpf_text.replace('STORE', - 'dist.increment(bpf_log2l(delta));') + 'dist.atomic_increment(bpf_log2l(delta));') if debug or args.ebpf: print(bpf_text) if args.ebpf: diff --git a/tools/dbstat.py b/tools/dbstat.py index 72af9f8d142f..9e36e632f4d4 100755 --- a/tools/dbstat.py +++ b/tools/dbstat.py @@ -74,7 +74,7 @@ u64 delta = bpf_ktime_get_ns() - *timestampp; FILTER delta /= SCALE; - latency.increment(bpf_log2l(delta)); + latency.atomic_increment(bpf_log2l(delta)); temp.delete(&pid); return 0; } diff --git a/tools/dcstat.py b/tools/dcstat.py index bd0494cd1429..623762883527 100755 --- a/tools/dcstat.py +++ b/tools/dcstat.py @@ -73,18 +73,15 @@ def usage(): */ void count_fast(struct pt_regs *ctx) { int key = S_REFS; - u64 *leaf = stats.lookup(&key); - if (leaf) (*leaf)++; + stats.atomic_increment(key); } void count_lookup(struct pt_regs *ctx) { int key = S_SLOW; - u64 *leaf = stats.lookup(&key); - if (leaf) (*leaf)++; + stats.atomic_increment(key); if (PT_REGS_RC(ctx) == 0) { key = S_MISS; - leaf = stats.lookup(&key); - if (leaf) (*leaf)++; + stats.atomic_increment(key); } } """ @@ -117,7 +114,6 @@ def usage(): try: sleep(interval) except KeyboardInterrupt: - pass exit() print("%-8s: " % strftime("%H:%M:%S"), end="") diff --git a/tools/ext4dist.py b/tools/ext4dist.py index 49139c8197c6..0aab1baa6683 100755 --- a/tools/ext4dist.py +++ b/tools/ext4dist.py @@ -110,7 +110,7 @@ // store as histogram dist_key_t key = {.slot = bpf_log2l(delta)}; __builtin_memcpy(&key.op, op, sizeof(key.op)); - dist.increment(key); + dist.atomic_increment(key); return 0; } diff --git a/tools/funccount.py b/tools/funccount.py index e54ba50a257e..24b293820a84 100755 --- a/tools/funccount.py +++ b/tools/funccount.py @@ -168,11 +168,7 @@ def load(self): FILTERPID FILTERCPU int loc = LOCATION; - u64 *val = counts.lookup(&loc); - if (!val) { - return 0; // Should never happen, # of locations is known - } - (*val)++; + counts.atomic_increment(loc); return 0; } """ diff --git a/tools/funcinterval.py b/tools/funcinterval.py index 097649f44a6e..1840eb54811f 100755 --- a/tools/funcinterval.py +++ b/tools/funcinterval.py @@ -109,7 +109,7 @@ def bail(error): FACTOR // store as histogram - dist.increment(bpf_log2l(delta)); + dist.atomic_increment(bpf_log2l(delta)); out: start.update(&index, &ts); diff --git a/tools/funclatency.py b/tools/funclatency.py index aad879d1b5ba..2ade0695244f 100755 --- a/tools/funclatency.py +++ b/tools/funclatency.py @@ -284,7 +284,7 @@ def bail(error): key.key.ip = ip; key.key.pid = %s; key.slot = bpf_log2l(delta); - dist.increment(key); + dist.atomic_increment(key); if (stack->head == 0) { /* empty */ @@ -309,7 +309,7 @@ def bail(error): key.key.ip = ip; key.key.pid = %s; key.slot = bpf_log2l(delta); - dist.increment(key); + dist.atomic_increment(key); ipaddr.delete(&pid); } """ % pid) @@ -318,7 +318,7 @@ def bail(error): 'BPF_HASH(start, u32);') bpf_text = bpf_text.replace('ENTRYSTORE', 'start.update(&pid, &ts);') bpf_text = bpf_text.replace('STORE', - 'dist.increment(bpf_log2l(delta));') + 'dist.atomic_increment(bpf_log2l(delta));') bpf_text = bpf_text.replace('TYPEDEF', '') bpf_text = bpf_text.replace('FUNCTION', '') diff --git a/tools/hardirqs.py b/tools/hardirqs.py index b60b63ada714..e5924faddfeb 100755 --- a/tools/hardirqs.py +++ b/tools/hardirqs.py @@ -86,7 +86,7 @@ { irq_key_t key = {.slot = 0 /* ignore */}; TP_DATA_LOC_READ_CONST(&key.name, name, sizeof(key.name)); - dist.increment(key); + dist.atomic_increment(key); return 0; } """ @@ -139,12 +139,12 @@ bpf_text = bpf_text.replace('STORE', 'irq_key_t key = {.slot = bpf_log2l(delta / %d)};' % factor + 'bpf_probe_read_kernel(&key.name, sizeof(key.name), name);' + - 'dist.increment(key);') + 'dist.atomic_increment(key);') else: bpf_text = bpf_text.replace('STORE', 'irq_key_t key = {.slot = 0 /* ignore */};' + 'bpf_probe_read_kernel(&key.name, sizeof(key.name), name);' + - 'dist.increment(key, delta);') + 'dist.atomic_increment(key, delta);') if debug or args.ebpf: print(bpf_text) if args.ebpf: diff --git a/tools/inject.py b/tools/inject.py index 9d6b85f8cc16..320b39355f13 100755 --- a/tools/inject.py +++ b/tools/inject.py @@ -225,7 +225,7 @@ def _generate_bottom(self): * If this is the only call in the chain and predicate passes */ if (%s == 1 && %s && overridden < %s) { - count.increment(zero); + count.atomic_increment(zero); bpf_override_return(ctx, %s); return 0; } @@ -240,7 +240,7 @@ def _generate_bottom(self): * If all conds have been met and predicate passes */ if (p->conds_met == %s && %s && overridden < %s) { - count.increment(zero); + count.atomic_increment(zero); bpf_override_return(ctx, %s); } return 0; diff --git a/tools/nfsdist.py b/tools/nfsdist.py index a0841ac1608b..4c1f8e3489b5 100755 --- a/tools/nfsdist.py +++ b/tools/nfsdist.py @@ -96,7 +96,7 @@ // store as histogram dist_key_t key = {.slot = bpf_log2l(delta)}; __builtin_memcpy(&key.op, op, sizeof(key.op)); - dist.increment(key); + dist.atomic_increment(key); start.delete(&tid); return 0; diff --git a/tools/pidpersec.py b/tools/pidpersec.py index c4490043a59d..be72443534bf 100755 --- a/tools/pidpersec.py +++ b/tools/pidpersec.py @@ -29,8 +29,7 @@ BPF_ARRAY(stats, u64, S_MAXSTAT); static void stats_increment(int key) { - u64 *leaf = stats.lookup(&key); - if (leaf) (*leaf)++; + stats.atomic_increment(key); } void do_count(struct pt_regs *ctx) { stats_increment(S_COUNT); } diff --git a/tools/readahead.py b/tools/readahead.py index b338261fc78f..bc8daec23838 100755 --- a/tools/readahead.py +++ b/tools/readahead.py @@ -69,9 +69,7 @@ if (f != NULL && *f == 1) { ts = bpf_ktime_get_ns(); birth.update(&retval, &ts); - - u64 *count = pages.lookup(&zero); - if (count) (*count)++; // increment read ahead pages count + pages.atomic_increment(zero); } return 0; } @@ -83,11 +81,8 @@ u64 *bts = birth.lookup(&arg0); if (bts != NULL) { delta = bpf_ktime_get_ns() - *bts; - dist.increment(bpf_log2l(delta/1000000)); - - u64 *count = pages.lookup(&zero); - if (count) (*count)--; // decrement read ahead pages count - + dist.atomic_increment(bpf_log2l(delta/1000000)); + pages.atomic_increment(zero, -1); birth.delete(&arg0); // remove the entry from hashmap } return 0; diff --git a/tools/runqlat.py b/tools/runqlat.py index b13ff2d1935e..aca0652487b1 100755 --- a/tools/runqlat.py +++ b/tools/runqlat.py @@ -236,12 +236,12 @@ 'BPF_HISTOGRAM(dist, pidns_key_t);') bpf_text = bpf_text.replace('STORE', 'pidns_key_t key = ' + '{.id = prev->nsproxy->pid_ns_for_children->ns.inum, ' + - '.slot = bpf_log2l(delta)}; dist.increment(key);') + '.slot = bpf_log2l(delta)}; dist.atomic_increment(key);') else: section = "" bpf_text = bpf_text.replace('STORAGE', 'BPF_HISTOGRAM(dist);') bpf_text = bpf_text.replace('STORE', - 'dist.increment(bpf_log2l(delta));') + 'dist.atomic_increment(bpf_log2l(delta));') if debug or args.ebpf: print(bpf_text) if args.ebpf: diff --git a/tools/runqlen.py b/tools/runqlen.py index b56a5916a42c..c77947af0f99 100755 --- a/tools/runqlen.py +++ b/tools/runqlen.py @@ -170,7 +170,7 @@ def check_runnable_weight_field(): else: bpf_text = bpf_text.replace('STORAGE', 'BPF_HISTOGRAM(dist, unsigned int);') - bpf_text = bpf_text.replace('STORE', 'dist.increment(len);') + bpf_text = bpf_text.replace('STORE', 'dist.atomic_increment(len);') if check_runnable_weight_field(): bpf_text = bpf_text.replace('RUNNABLE_WEIGHT_FIELD', 'unsigned long runnable_weight;') diff --git a/tools/softirqs.py b/tools/softirqs.py index 32bbef5dec36..ba0dac363c83 100755 --- a/tools/softirqs.py +++ b/tools/softirqs.py @@ -119,11 +119,11 @@ if args.dist: bpf_text = bpf_text.replace('STORE', 'key.vec = vec; key.slot = bpf_log2l(delta / %d); ' % factor + - 'dist.increment(key);') + 'dist.atomic_increment(key);') else: bpf_text = bpf_text.replace('STORE', 'key.vec = valp->vec; ' + - 'dist.increment(key, delta);') + 'dist.atomic_increment(key, delta);') if debug or args.ebpf: print(bpf_text) if args.ebpf: diff --git a/tools/stackcount.py b/tools/stackcount.py index 2afb91ff875a..8b7ca0087838 100755 --- a/tools/stackcount.py +++ b/tools/stackcount.py @@ -129,7 +129,7 @@ def load(self): key.tgid = GET_TGID; STORE_COMM %s - counts.increment(key); + counts.atomic_increment(key); return 0; } """ diff --git a/tools/tcprtt.py b/tools/tcprtt.py index 046e892f6763..ac1b27d470ff 100755 --- a/tools/tcprtt.py +++ b/tools/tcprtt.py @@ -123,7 +123,7 @@ STORE_HIST key.slot = bpf_log2l(srtt); - hist_srtt.increment(key); + hist_srtt.atomic_increment(key); STORE_LATENCY diff --git a/tools/tcpsubnet.py b/tools/tcpsubnet.py index 5f2a8062bdff..77ccc86eece7 100755 --- a/tools/tcpsubnet.py +++ b/tools/tcpsubnet.py @@ -175,7 +175,7 @@ def generate_bpf_subnets(subnets): if (!categorized && (__NET_ADDR__ & __NET_MASK__) == (dst & __NET_MASK__)) { struct index_key_t key = {.index = __POS__}; - ipv4_send_bytes.increment(key, size); + ipv4_send_bytes.atomic_increment(key, size); categorized = 1; } """ diff --git a/tools/tcpsynbl.py b/tools/tcpsynbl.py index c24eb960772a..93cef4b71e69 100755 --- a/tools/tcpsynbl.py +++ b/tools/tcpsynbl.py @@ -33,7 +33,7 @@ backlog_key_t key = {}; key.backlog = sk->sk_max_ack_backlog; key.slot = bpf_log2l(sk->sk_ack_backlog); - dist.increment(key); + dist.atomic_increment(key); return 0; }; diff --git a/tools/vfscount.py b/tools/vfscount.py index 303d3fdea6dc..e58ce68589a0 100755 --- a/tools/vfscount.py +++ b/tools/vfscount.py @@ -40,7 +40,7 @@ def usage(): int do_count(struct pt_regs *ctx) { struct key_t key = {}; key.ip = PT_REGS_IP(ctx); - counts.increment(key); + counts.atomic_increment(key); return 0; } """) diff --git a/tools/vfsstat.py b/tools/vfsstat.py index a3d22db82d4c..9132b95916ba 100755 --- a/tools/vfsstat.py +++ b/tools/vfsstat.py @@ -52,8 +52,7 @@ def usage(): BPF_ARRAY(stats, u64, S_MAXSTAT); static void stats_increment(int key) { - u64 *leaf = stats.lookup(&key); - if (leaf) (*leaf)++; + stats.atomic_increment(key); } """ diff --git a/tools/wakeuptime.py b/tools/wakeuptime.py index 531030bbe3c8..90b114cf93f9 100755 --- a/tools/wakeuptime.py +++ b/tools/wakeuptime.py @@ -142,7 +142,7 @@ def signal_ignore(signal, frame): bpf_probe_read_kernel(&key.target, sizeof(key.target), p->comm); bpf_get_current_comm(&key.waker, sizeof(key.waker)); - counts.increment(key, delta); + counts.atomic_increment(key, delta); return 0; } """ diff --git a/tools/xfsdist.py b/tools/xfsdist.py index 54b1687f5c61..58f73afd6202 100755 --- a/tools/xfsdist.py +++ b/tools/xfsdist.py @@ -98,7 +98,7 @@ // store as histogram dist_key_t key = {.slot = bpf_log2l(delta)}; __builtin_memcpy(&key.op, op, sizeof(key.op)); - dist.increment(key); + dist.atomic_increment(key); start.delete(&tid); return 0; diff --git a/tools/zfsdist.py b/tools/zfsdist.py index 112b10c188bd..a30671daf463 100755 --- a/tools/zfsdist.py +++ b/tools/zfsdist.py @@ -98,7 +98,7 @@ // store as histogram dist_key_t key = {.slot = bpf_log2l(delta)}; __builtin_memcpy(&key.op, op, sizeof(key.op)); - dist.increment(key); + dist.atomic_increment(key); start.delete(&tid); return 0;