Skip to content

Commit

Permalink
tools: replace add with xadd (iovisor#3518)
Browse files Browse the repository at this point in the history
resolve iovisor#3481
replace add with xadd for more tools.
  • Loading branch information
chenyuezhou committed Jul 1, 2021
1 parent 7191918 commit 80242fb
Show file tree
Hide file tree
Showing 29 changed files with 45 additions and 59 deletions.
5 changes: 3 additions & 2 deletions tools/argdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tools/biolatency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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);"
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tools/bitesize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
"""
Expand Down
2 changes: 1 addition & 1 deletion tools/btrfsdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tools/cachestat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tools/cpudist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tools/dbstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 3 additions & 7 deletions tools/dcstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
"""
Expand Down Expand Up @@ -117,7 +114,6 @@ def usage():
try:
sleep(interval)
except KeyboardInterrupt:
pass
exit()

print("%-8s: " % strftime("%H:%M:%S"), end="")
Expand Down
2 changes: 1 addition & 1 deletion tools/ext4dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 1 addition & 5 deletions tools/funccount.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
"""
Expand Down
2 changes: 1 addition & 1 deletion tools/funcinterval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions tools/funclatency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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)
Expand All @@ -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', '')
Expand Down
6 changes: 3 additions & 3 deletions tools/hardirqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
"""
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions tools/inject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tools/nfsdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions tools/pidpersec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down
11 changes: 3 additions & 8 deletions tools/readahead.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tools/runqlat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tools/runqlen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;')
Expand Down
4 changes: 2 additions & 2 deletions tools/softirqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tools/stackcount.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def load(self):
key.tgid = GET_TGID;
STORE_COMM
%s
counts.increment(key);
counts.atomic_increment(key);
return 0;
}
"""
Expand Down
2 changes: 1 addition & 1 deletion tools/tcprtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
STORE_HIST
key.slot = bpf_log2l(srtt);
hist_srtt.increment(key);
hist_srtt.atomic_increment(key);
STORE_LATENCY
Expand Down
2 changes: 1 addition & 1 deletion tools/tcpsubnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
"""
Expand Down
2 changes: 1 addition & 1 deletion tools/tcpsynbl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion tools/vfscount.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
""")
Expand Down
3 changes: 1 addition & 2 deletions tools/vfsstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
"""

Expand Down
2 changes: 1 addition & 1 deletion tools/wakeuptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
"""
Expand Down
2 changes: 1 addition & 1 deletion tools/xfsdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tools/zfsdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 80242fb

Please sign in to comment.