ssrg-vt / popcorn-kernel

Popcorn Linux kernel for distributed thread execution
Other
156 stars 23 forks source link

[Merge] pthreads early exit #100

Open cesarjp opened 4 years ago

cesarjp commented 4 years ago

The following pthread test exits early. It should print out the number '10'. Based on the output, the process never migrates back to node 0.

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include "migrate.h"

#define NUM_THREADS 2

int data[NUM_THREADS];

void *do_it(void *t)
{
  int ret = 0;
  int i = (int)t;

  data[i] = 10;

  pthread_exit (&ret);
}

int
main (int argc, char *argv[])
{
  int i;
  pthread_t threads[NUM_THREADS];

  migrate(0, NULL, NULL);

  for (i = 0; i < NUM_THREADS; i++)
    {
      pthread_create(&threads[i], NULL, do_it, (void *)i);
    }

  for (i = 0; i < NUM_THREADS; i++)
    {
      int status = 0;
      pthread_join (threads[i], &status);
    }

  migrate(1, NULL, NULL);

  printf ("%d\n", data[0]);

  return data[0];
}

Here is the output:

popcorn@x86:~$ ./pthread_test [ 28.879191] ####### MIGRATE [633] to 1 [ 29.019960] EXITED [633] local / 0xa00 [ 29.023048] TERMINATE [238/1] with 0x2560

bxatnarf commented 4 years ago

@cesarjp Is the output you posted based on starting execution on node 0 or node 1?
I see that your example first calls migrate(0, NULL, NULL) which sort of implies it shouldn't begin on node 0. But if I start from node 1, I am seeing a whole different set of issues, so I just want to double check.

cesarjp commented 4 years ago

@bxatnarf, I should have been more clear. I was testing multiple combinations of the test. One version launched from the x86 host (which is node 0) and another version that launched from the arm node (node 1).

Here's the code that corresponds to this output:

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include "migrate.h"

#define N 50
#define NUM_THREADS 2

int data[NUM_THREADS];

void *do_it(void *t)
{
  int ret = 0;
  int i = (int)t;

  data[i] = 10;

  pthread_exit (&ret);
}

int
main (int argc, char *argv[])
{
  int i;
  pthread_t threads[NUM_THREADS];

  migrate(1, NULL, NULL);
  for (i = 0; i < NUM_THREADS; i++)
    {
      pthread_create(&threads[i], NULL, do_it, (void *)i);
    }

  for (i = 0; i < NUM_THREADS; i++)
    {
      int status = 0;
      pthread_join (threads[i], &status);
    }

  migrate(0, NULL, NULL);

  printf ("%d\n", data[0]);

  return data[0];
}
bxatnarf commented 4 years ago

If the first example starts execution from host 0, then we should not expect to see it to printf anything since printf is called after it migrates to host 1. If we execute the code in https://github.com/ssrg-vt/popcorn-kernel/issues/100#issuecomment-606104337 from host 0 then we should see the printf since it migrates to 0 before the printf. @cesarjp on which host do you execute this second example? to get the output you pasted in the original question?