Closed cota closed 2 years ago
Thank you for the patch. I modified it to minimize the difference and to avoid increasing the args of CodeGenerator. https://github.com/herumi/xbyak/compare/master...dev
Here is a sample to use it.
>cat t.cpp
#define XBYAK_USE_MEMFD
#include <xbyak/xbyak.h>
class Code : Xbyak::MmapAllocator, public Xbyak::CodeGenerator {
public:
Code(const char *name, int v)
: Xbyak::MmapAllocator(name)
, Xbyak::CodeGenerator(4096, nullptr, this)
{
mov(eax, v);
ret();
}
};
int main()
{
Code c1("abc", 123);
Code c2("xyz", 456);
printf("c1 %d\n", c1.getCode<int (*)()>()());
printf("c2 %d\n", c2.getCode<int (*)()>()());
getchar();
}
xbyak%> g++ t.cpp -I ./ ./a.out
xbyak%> cat /proc/`pidof ./a.out`/maps
7f9b0f763000-7f9b0f764000 rwxs 00000000 00:01 1669965 /memfd:xyz (deleted)
7f9b0f764000-7f9b0f765000 r--p 00000000 08:02 47722023 /usr/lib/x86_64-linux-gnu/ld-2.31.so
7f9b0f765000-7f9b0f788000 r-xp 00001000 08:02 47722023 /usr/lib/x86_64-linux-gnu/ld-2.31.so
7f9b0f788000-7f9b0f790000 r--p 00024000 08:02 47722023 /usr/lib/x86_64-linux-gnu/ld-2.31.so
7f9b0f790000-7f9b0f791000 rwxs 00000000 00:01 1669964 /memfd:abc (deleted)
How about this?
Works for me, thanks! I have squashed your changes onto mine and updated the commit. I've also added your example usage to the commit log, which I like better than mine since it is self-contained.
I made a sample/memfd.cpp.
By initializing an allocator with a specific name, we can allow users to define names of their memfd-allocated memory regions. This can help users obtain more meaningful profiles with tools such as perf(1).
For example, take oneDNN, which instantiates a CodeGenerator for each operation. Before this patch, from perf(1) we cannot discern which oneDNN operations were executed since they are all assigned to "xbyak":
After this patch (and after updating oneDNN to name allocators with the appropriate name, i.e. "/oneDNN:$op"), we can: