Page MenuHomePhabricator

Add some minimal portability code paths for PS4.
ClosedPublic

Authored by silvas on Feb 26 2016, 11:53 PM.

Details

Summary

Hi David, SCE folks,

What is implemented in this patch is enough for the upstream libprofile to
work for PGO with the PS4 game codebase I tested ("game7" for you SCE
folks; this is with a standalone build of compiler-rt).

The first change, which is simple, is to stub out gethostname. PS4
doesn't have a simple analog for this that doesn't bring in extra
OS libraries, so for now we do not support %h expansion.
This is consistent with internal B#136272.

The second change implies future work, but is a simple change at present.
PS4 does not have getenv, so for now we will introduce a shim.
This obviously makes it impossible for many of the tests to be run since
they require setting LLVM_PROFILE_FILE=.

I see two paths forward:

  1. In the tests we are already wrapping execution with %run and so by setting a PS4-specific expansion for %run we can pass the information in another way We can adapt the getenv shim as appropriate. We will need to experiment with this internally. Maggie, Phillip, Filipe? Any ideas? Maybe ping me internally since we may need to get into some PS4 vagaries. I'm thinking a fake getenv library that uses some side channel for communication.
  1. Another possibility which is more verbose is to use a separate clang invocation with -profile-generate=<filename> to set the filename in each test. This might require redundant clang invocations though which may be undesirable for upstream. David, thoughts? Also, this is a fairly libprofile-specific workaround, so it e.g. doesn't help Filipe's ASan work. Overall, this approach sounds like a bit of a hack to me.

Small detail:
InstrProfilingPort.h seems like the natural place for the getenv shim,
but GCDAProfiling.c needs it as well. InstrProfilingUtil.h is currently
the only header common between InstrProfilingFile.c and GCDAProfiling.c.
I can move the shim to InstrProfilingPort.h and add an include to
GCDAProfiling.c as per your preference David.

Diff Detail

Event Timeline

silvas updated this revision to Diff 49288.Feb 26 2016, 11:53 PM
silvas retitled this revision from to Add some minimal portability code paths for PS4..
silvas updated this object.
filcab edited edge metadata.Feb 27 2016, 12:07 PM

Thanks for working on this. I'll ping you to talk about the %run.

lib/profile/InstrProfilingPort.h
29

Should we do something about COMPILER_RT_HAS_UNAME? (Both here and on the Windows case)
Or simply get rid of it, it it's there just for one case...

lib/profile/InstrProfilingUtil.h
18

Use NULL?

davidxl added inline comments.Feb 27 2016, 2:05 PM
lib/profile/InstrProfilingPort.h
29

The macro is needed to enable definition of the GetHostName wrapper (to uname). For PS4 there is no need to define it.

silvas updated this revision to Diff 49402.Feb 29 2016, 11:37 AM
silvas edited edge metadata.
  • Update for filcab's comments.
silvas marked an inline comment as done.Feb 29 2016, 11:37 AM

Updated for filcab's comments.

Quick update: I talked with Filipe and I think that we will be using a custom %run (but not in this patch, obviously). He as a mechanism for doing this that he has already established with his ASan testing internally.

MaggieYi edited edge metadata.Mar 2 2016, 5:22 AM

Thanks Sean, the patch looks good to me.

This revision was automatically updated to reflect the committed changes.