This is an archive of the discontinued LLVM Phabricator instance.

[flang][driver] Randomise the names of the temporary unparsed files
ClosedPublic

Authored by awarzynski on Jul 15 2021, 3:44 AM.

Details

Summary

This patch makes sure that the base name of the temporary unparsed files
(generated by the flang bash script) are randomised. This is required
to make the name of these temporary files unique to a particular
invocation of the script. Otherwise, we cannot reliably run it in
parallel.

Diff Detail

Event Timeline

awarzynski created this revision.Jul 15 2021, 3:44 AM
awarzynski requested review of this revision.Jul 15 2021, 3:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 15 2021, 3:44 AM
awarzynski added a project: Restricted Project.
DavidSpickett added inline comments.Jul 15 2021, 4:20 AM
flang/tools/f18/flang.in
331

Wouldn't date/time have a small chance to collide?

Would something like /proc/sys/kernel/random/uuid be better to guarantee that each one is unique?

awarzynski added inline comments.Jul 15 2021, 5:12 AM
flang/tools/f18/flang.in
331

Wouldn't date/time have a small chance to collide?

I'm also slightly concerned, but %N gives you nanoseconds and I'd hope that that's enough to get rando results.

Would something like /proc/sys/kernel/random/uuid be better to guarantee that each one is unique?

I like your suggestion! Are we confident that it's going to be present on every system that this script might be run on? I think that it would be OK to limit it to Linux, but I would need to check with @sscalpone (he is likely to use this script a lot).

tschuett added inline comments.
flang/tools/f18/flang.in
331

How about mktemp? At least on Apple proc does not exists. I doubt Windows will have a proc dir.

awarzynski added inline comments.Jul 15 2021, 6:06 AM
flang/tools/f18/flang.in
331

This one is also nice @tschuett , thanks! However, the version that I have on Darwin only allows me to specify the prefix. I need to be able to specify the suffix though:

mktemp XXXXXX.f90

I can do this with mktemp on Linux.

Perhaps it's worth adding a bit of context here. This script is only a temporary workaround and hence there is no need to support every possible system or to make it future-proof. It is fine to use something that's OS specific, as long as we support all our users that rely on this script. AFAIK, the list is not long. And I assume that all of Linaro's BuildBots are running Linux.

As for /proc/sys/kernel/random/uuid, I just want to make sure that it's available on all Linux systems. Given the location, it's seems safe to assume that that's the case, right?

DavidSpickett added inline comments.Jul 15 2021, 6:24 AM
flang/tools/f18/flang.in
331

I see some isolated comments that it's not present on some Linux, but it's listed on the man page:
https://man7.org/linux/man-pages/man4/random.4.html
(maybe they were talking about older kernels)

I have uuidgen on Ubuntu, maybe that's a better way to go if Macs also have that. (since they and the BSDs won't have /proc)

DavidSpickett added inline comments.Jul 15 2021, 6:30 AM
flang/tools/f18/flang.in
331

And I assume that all of Linaro's BuildBots are running Linux.

All recent Ubuntu yes.

awarzynski added inline comments.Jul 15 2021, 7:31 AM
flang/tools/f18/flang.in
331

I have uuidgen on Ubuntu, maybe that's a better way to go if Macs also have that. (since they and the BSDs won't have /proc)

Yes, it's available on Mac OS and it looks like the most adequate solution here. Thanks for the suggestion!

Switch from using $RANDOM to uuidgen.

This revision is now accepted and ready to land.Jul 15 2021, 7:48 AM