Commit 23fc5890 authored by Brenden Blanco's avatar Brenden Blanco

Update after lookup in map.increment for HASH types

Performing the update before lookup incurs an extra spinlock in the
kernel, which hurts performance. Reorder the code and increment to 1.
The memset is there I believe due to some type mismatch warnings, so I'm
leaving as is rather than doing a direct assign to 1. The resulting code
is optimized away anyway.

Fixes: #1314
Signed-off-by: default avatarBrenden Blanco <bblanco@gmail.com>
parent 917f4c76
...@@ -332,12 +332,14 @@ bool BTypeVisitor::VisitCallExpr(CallExpr *Call) { ...@@ -332,12 +332,14 @@ bool BTypeVisitor::VisitCallExpr(CallExpr *Call) {
string lookup = "bpf_map_lookup_elem_(bpf_pseudo_fd(1, " + fd + ")"; string lookup = "bpf_map_lookup_elem_(bpf_pseudo_fd(1, " + fd + ")";
string update = "bpf_map_update_elem_(bpf_pseudo_fd(1, " + fd + ")"; string update = "bpf_map_update_elem_(bpf_pseudo_fd(1, " + fd + ")";
txt = "({ typeof(" + name + ".key) _key = " + arg0 + "; "; txt = "({ typeof(" + name + ".key) _key = " + arg0 + "; ";
txt += "typeof(" + name + ".leaf) *_leaf = " + lookup + ", &_key); ";
txt += "if (_leaf) (*_leaf)++; ";
if (desc->second.type == BPF_MAP_TYPE_HASH) { if (desc->second.type == BPF_MAP_TYPE_HASH) {
txt += "typeof(" + name + ".leaf) _zleaf; memset(&_zleaf, 0, sizeof(_zleaf)); "; txt += "else { typeof(" + name + ".leaf) _zleaf; memset(&_zleaf, 0, sizeof(_zleaf)); ";
txt += update + ", &_key, &_zleaf, BPF_NOEXIST); "; txt += "_zleaf++; ";
txt += update + ", &_key, &_zleaf, BPF_NOEXIST); } ";
} }
txt += "typeof(" + name + ".leaf) *_leaf = " + lookup + ", &_key); "; txt += "})";
txt += "if (_leaf) (*_leaf)++; })";
} else if (memb_name == "perf_submit") { } else if (memb_name == "perf_submit") {
string name = Ref->getDecl()->getName(); string name = Ref->getDecl()->getName();
string arg0 = rewriter_.getRewrittenText(expansionRange(Call->getArg(0)->getSourceRange())); string arg0 = rewriter_.getRewrittenText(expansionRange(Call->getArg(0)->getSourceRange()));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment