-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle thread escaping via global and after thread creation #686
Conversation
Nice, looks good! What I started wondering about is whether the collecting of things potentially escaped into globals already needs to be done during single-threaded mode as we currently do it here? Intuitively, it would suffice to treat those things as escaped, that are still reachable from globals when we go multi-threaded, right? It has the effect of making #include <pthread.h>
#include <assert.h>
int* gptr;
void *foo(void* p){
*gptr = 17;
return NULL;
}
int main(){
int x = 0;
int y = 0;
gptr = &y;
gptr = &x;
assert(x==0);
pthread_t thread;
pthread_create(&thread, NULL, foo, NULL);
sleep(3);
assert(x == 0); // UNKNOWN!
assert(y == 0);
y = 5;
assert(y == 5);
pthread_join(thread, NULL);
return 0;
} But on the other hand, I'm not sure if this does not just make it more complicated than it needs to be without much of a benefit, as we would still need all the things you have in place now to account for things escaping via globals after we went multi-threaded. |
That sounds right, but it's not so easy for the escape analysis to know, what exactly all those things are. It's the base privatizations that know and publish those in I agree, it'd be possible to be a bit more precise, but I suspect then essentially all the escape logic would have to be baked into base analysis itself. Unless there's particular need for that precision, we shouldn't unnecessarily overthink it for now. |
This seems to have caused non-termination/extreme slowdown on zstd. I'll see tomorrow if I can find out why. Otherwise we'll have to have an option to disable these indirect escapes for zstd benchmarking, unless zstd actually does these weird things. |
Turns out without this our zstd analysis is also unsound exactly due to this pattern here: https://github.com/facebook/zstd/blob/7543085013db1a20a848d166e5931edc49e3cc2f/lib/dictBuilder/cover.c#L1207. I found this because |
Is this also unsound without your malloc freshness analysis? Maybe we can turn that off to salvage our benchmarks? |
I have a fix for the extreme slowdown of threadEscape: it should only consider local variables for possible escaping! The analysis, even before this PR, didn't have that filtering. Yes, it's also unsound without symb_locks, var_eq and mallocFresh, so it's been unsound all along. And it's suspicious indeed that the basic analysis before all my precision attempts had a few thousand lines of dead code. |
So the problem clearly is that this These seem to be two different issues at least to me? |
Without this PR, But even then we're unsound and it seems to be because the function pointer gets lost somewhere. So indeed that's the new issue I'm looking into, but that only showed after fixing the termination of this PR. |
Closes #246.
Lots of tests fail and the new ones don't even pass. Coincidentally, #687 fixes many of the failures: from 41 down to 9. And avoiding escapes in singlethreaded mode gets from 9 down to just the new 2 tests. All passing now!
Changes
TODO