Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Make Hostx64/arm crossgen /CreatePerfMap behave the same as Hostarm/arm crossgen #20035

Merged
merged 3 commits into from
Sep 20, 2018
Merged

Make Hostx64/arm crossgen /CreatePerfMap behave the same as Hostarm/arm crossgen #20035

merged 3 commits into from
Sep 20, 2018

Conversation

echesakov
Copy link

This PR addresses couple issues with /CreatePerfMap with Hostx64/arm32 crossgen:

  1. line.Printf uses host-specific "%p" -> change to target-specific format string FMT_TARGET_ADDR in src/vm/perfmap.cpp
  2. AcquireImage uses sizeof(PVOID) -> replace with TARGET_POINTER_SIZE in src/vm/readytoruninfo.cpp
  3. Nit: replace pModule->HasNativeImage() || pModule->IsReadyToRun() with pModule->HasNativeOrReadyToRunImage() in src/vm/compile.cpp

@echesakov
Copy link
Author

@jkotas Can you please review this?
/cc @RussKeldorph

@@ -173,7 +179,7 @@ void PerfMap::LogMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize)
// Build the map file line.
StackScratchBuffer scratch;
SString line;
line.Printf("%p %x %s\n", pCode, codeSize, fullMethodSignature.GetANSI(scratch));
line.Printf(FMT_TARGET_ADDR " %x %s\n", pCode, codeSize, fullMethodSignature.GetANSI(scratch));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are 32-bit offsets in crossgen generated map files, not actual addresses. It took me a while to figure this out.

@brianrob Would it make sense to always print these as 32-bit numbers in crossgen generated map files?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pCode can either be an offset in the case where a native image perfmap is being built or an actual address in the case where we're building a perfmap for a live process. In the latter, case PerfMap::LogMethod is called by PerfMap::LogJITCompiledMethod which takes the actual code address via pCode. So, this does need to support writing the full width of a pointer.

Copy link
Member

@jkotas jkotas Sep 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, this needs to be a full pointer for the JITed case. My question is whether it needs to be full 64-bit pointer in the native image case as well. We seem to be just wasting space on zeros.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. As long as we can guarantee that the value will fit into 32-bits then it should be fine. I'm not 100% sure about this as the values that we calculate this from are of type TADDR. If you know it to be true that the values fit into 32-bits then that should be fine for the crossgen case. I could also imagine us changing the format string (if possible) to just not write the full width of the value with prepended zeros and instead just write the minimal number of characters. Then we get the savings on the JITed case too.

Copy link
Author

@echesakov echesakov Sep 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://github.com/torvalds/linux/blob/master/tools/perf/Documentation/jit-interface.txt

perf supports a simple JIT interface to resolve symbols for dynamic code generated
by a JIT.

The JIT has to write a /tmp/perf-%d.map (%d = pid of process) file

This is a text file.

Each line has the following format, fields separated with spaces:

START SIZE symbolname

START and SIZE are hex numbers without 0x.
symbolname is the rest of the line, so it could contain special characters.

The ownership of the file has to match the process.

it should be safe to remove leading zeros from format string

@@ -12,6 +12,12 @@
#include "perfinfo.h"
#include "pal.h"

#ifdef _TARGET_64BIT_
Copy link
Member

@jkotas jkotas Sep 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but it will make them file less readable. I would keep the crossgen addresses/offsets padded to 32-bit. Something like:

#ifdef CROSSGEN_COMPILE
// The code addresses are actually native image offsets during crossgen. Print them as 32-bit numbers for consistent output when cross-targeting and to make the output more compact.
#define FMT_TARGET_ADDR "%08x"
#else
#define FMT_TARGET_ADDR "%p"
#endif

@echesakov
Copy link
Author

Rebased/squashed into three separate commits

@echesakov echesakov merged commit 3d2e9cc into dotnet:master Sep 20, 2018
@echesakov echesakov deleted the CrossBitnessLinuxPerfMap branch September 20, 2018 16:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants