Skip to content

Commit

Permalink
Rename node to numaid, example:
Browse files Browse the repository at this point in the history
NUMA node information:

  $ numactl --hardware
  available: 2 nodes (0-1)
  node 0 cpus: 0 1 2 3 4 5 6 7 ...
  [...]
  node 1 cpus: 20 21 22 23 24 25 ...
  [...]
  node distances:
  node   0   1
    0:  10  21
    1:  21  10

bpftrace script code net_action.bt:
  kprobe:net_tx_action,
  kprobe:net_rx_action
  {
      @[numaid, comm] = count();
  }

Example1:
  ------------------------------------------------------------
  iperf3 server:
  $ taskset -c 1 iperf3 -s
  [...]
  [  5]   0.00-1.00   sec  6.04 GBytes  51.9 Gbits/sec
  [...]

  iperf3 client:
  $ taskset -c 2 iperf3 -c 0
  [...]
  [  5]   0.00-1.00   sec  6.04 GBytes  51.9 Gbits/sec    0   1.19 MBytes
  [...]

  net_action.bt output:
  @[0, iperf3]: 2430857

  Because both cpu1 and cpu2 are on the numa node 0.

Example2:
  ------------------------------------------------------------
  iperf3 server:
  $ taskset -c 1 iperf3 -s
  [...]
  [  5]   0.00-1.00   sec  2.79 GBytes  24.0 Gbits/sec
  [...]

  iperf3 client:
  $ taskset -c 21 iperf3 -c 0
  [...]
  [  5]   0.00-1.00   sec  2.79 GBytes  24.0 Gbits/sec    0   1023 KBytes
  [...]

  net_action.bt output:
  @[0, iperf3]: 456193
  @[1, iperf3]: 684853

Because cpu1 on numa node0, cpu21 on numa node1, Processes that
need to communicate running on different nodes cause poor performance,
It is very easy to get numa with `numaid`.
  • Loading branch information
Rtoax committed Mar 30, 2022
1 parent e88eb2f commit f605119
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to
## Unreleased

#### Added
- Add builtin: `node`
- Add builtin: `numaid`
- [#2177](https://github.com/iovisor/bpftrace/pull/2177)
- Add builtin function: `cgroup_path`
- [#2055](https://github.com/iovisor/bpftrace/pull/2055)
Expand Down
2 changes: 1 addition & 1 deletion docs/reference_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1831,7 +1831,7 @@ NetworkManager:1155 /var/lib/sss/mc/passwd (deleted)
- `gid` - Group ID
- `nsecs` - Nanosecond timestamp
- `elapsed` - Nanoseconds since bpftrace initialization
- `node` - NUMA Node ID
- `numaid` - NUMA Node ID
- `cpu` - Processor ID
- `comm` - Process name
- `kstack` - Kernel stack trace
Expand Down
2 changes: 1 addition & 1 deletion man/adoc/bpftrace.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ For string arguments use the `str()` call to retrieve the value.
| n/a
| PID of the child process

| node
| numaid
| uint32
| 5.8
| numa_node_id
Expand Down
12 changes: 6 additions & 6 deletions src/ast/irbuilderbpf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,17 +906,17 @@ CallInst *IRBuilderBPF::CreateGetUidGid()
return createCall(getuidgid_func, {}, "get_uid_gid");
}

CallInst *IRBuilderBPF::CreateGetNodeId()
CallInst *IRBuilderBPF::CreateGetNumaId()
{
// u32 bpf_get_numa_node_id(void)
// Return: NUMA Node ID
FunctionType *getnodeid_func_type = FunctionType::get(getInt64Ty(), false);
PointerType *getnodeid_func_ptr_type = PointerType::get(getnodeid_func_type, 0);
Constant *getnodeid_func = ConstantExpr::getCast(
FunctionType *getnumaid_func_type = FunctionType::get(getInt64Ty(), false);
PointerType *getnumaid_func_ptr_type = PointerType::get(getnumaid_func_type, 0);
Constant *getnumaid_func = ConstantExpr::getCast(
Instruction::IntToPtr,
getInt64(libbpf::BPF_FUNC_get_numa_node_id),
getnodeid_func_ptr_type);
return createCall(getnodeid_func, {}, "get_node_id");
getnumaid_func_ptr_type);
return createCall(getnumaid_func, {}, "get_numa_id");
}

CallInst *IRBuilderBPF::CreateGetCpuId()
Expand Down
2 changes: 1 addition & 1 deletion src/ast/irbuilderbpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class IRBuilderBPF : public IRBuilder<>
CallInst *CreateGetPidTgid();
CallInst *CreateGetCurrentCgroupId();
CallInst *CreateGetUidGid();
CallInst *CreateGetNodeId();
CallInst *CreateGetNumaId();
CallInst *CreateGetCpuId();
CallInst *CreateGetCurrentTask();
CallInst *CreateGetRandom();
Expand Down
4 changes: 2 additions & 2 deletions src/ast/passes/codegen_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ void CodegenLLVM::visit(Builtin &builtin)
expr_ = b_.CreateLShr(uidgid, 32);
}
}
else if (builtin.ident == "node")
else if (builtin.ident == "numaid")
{
expr_ = b_.CreateGetNodeId();
expr_ = b_.CreateGetNumaId();
}
else if (builtin.ident == "cpu")
{
Expand Down
2 changes: 1 addition & 1 deletion src/ast/passes/semantic_analyser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ void SemanticAnalyser::visit(Builtin &builtin)
builtin.ident == "pid" || builtin.ident == "tid" ||
builtin.ident == "cgroup" || builtin.ident == "uid" ||
builtin.ident == "gid" || builtin.ident == "cpu" ||
builtin.ident == "rand" || builtin.ident == "node")
builtin.ident == "rand" || builtin.ident == "numaid")
{
builtin.type = CreateUInt64();
if (builtin.ident == "cgroup" &&
Expand Down
2 changes: 1 addition & 1 deletion src/lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ hspace [ \t]
vspace [\n\r]
space {hspace}|{vspace}
path :(\\.|[_\-\./a-zA-Z0-9#\*])+
builtin arg[0-9]|args|cgroup|comm|cpid|node|cpu|ctx|curtask|elapsed|func|gid|nsecs|pid|probe|rand|retval|sarg[0-9]|tid|uid|username
builtin arg[0-9]|args|cgroup|comm|cpid|numaid|cpu|ctx|curtask|elapsed|func|gid|nsecs|pid|probe|rand|retval|sarg[0-9]|tid|uid|username
call avg|buf|cat|cgroupid|clear|count|delete|exit|hist|join|kaddr|kptr|ksym|lhist|macaddr|max|min|ntop|override|print|printf|cgroup_path|reg|signal|sizeof|stats|str|strftime|strncmp|sum|system|time|uaddr|uptr|usym|zero|path|unwatch

/* Don't add to this! Use builtin OR call not both */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace bpftrace {
namespace test {
namespace codegen {

TEST(codegen, builtin_node)
TEST(codegen, builtin_numaid)
{
test("kprobe:f { @x = node }",
test("kprobe:f { @x = numaid }",

NAME);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ TEST(Parser, builtin_variables)
test("kprobe:f { gid }", "Program\n kprobe:f\n builtin: gid\n");
test("kprobe:f { nsecs }", "Program\n kprobe:f\n builtin: nsecs\n");
test("kprobe:f { elapsed }", "Program\n kprobe:f\n builtin: elapsed\n");
test("kprobe:f { node }", "Program\n kprobe:f\n builtin: node\n");
test("kprobe:f { numaid }", "Program\n kprobe:f\n builtin: numaid\n");
test("kprobe:f { cpu }", "Program\n kprobe:f\n builtin: cpu\n");
test("kprobe:f { curtask }", "Program\n kprobe:f\n builtin: curtask\n");
test("kprobe:f { rand }", "Program\n kprobe:f\n builtin: rand\n");
Expand Down
2 changes: 1 addition & 1 deletion tests/semantic_analyser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ TEST(semantic_analyser, builtin_variables)
test("kprobe:f { gid }", 0);
test("kprobe:f { nsecs }", 0);
test("kprobe:f { elapsed }", 0);
test("kprobe:f { node }", 0);
test("kprobe:f { numaid }", 0);
test("kprobe:f { cpu }", 0);
test("kprobe:f { curtask }", 0);
test("kprobe:f { rand }", 0);
Expand Down

0 comments on commit f605119

Please sign in to comment.