<commit_before>// Tests to drive abstract sharing analysis

#include "types.h"
#include "user.h"
#include "fcntl.h"
#include "mtrace.h"
#include "pthread.h"

static int cpu;
static pthread_barrier_t bar;
enum { ncore = 8 };

void
next()
{
  if (setaffinity(cpu) < 0) {
    cpu = 0;
    if (setaffinity(cpu) < 0)
      die("sys_setaffinity(%d) failed", cpu);
  }
  cpu++;
}

void*
vmsharing(void* arg)
{
  u64 i = (u64) arg;

  volatile char *p = (char*)(0x40000UL + i * 4096);
  if (map((void *) p, 4096) < 0)
    die("map failed");

  if (unmap((void *) p, 4096) < 0)
    die("unmap failed");

  return 0;
}

void*
fssharing(void* arg)
{
  u64 i = (u64) arg;

  // Note that we keep these files open; otherwise all of these
  // operations will share the abstract FD object and we won't get any
  // results.

  char filename[32];
  snprintf(filename, sizeof(filename), "f%d", i);

  open(filename, O_CREATE|O_RDWR);

  pthread_barrier_wait(&bar);

  for (u64 j = 0; j < ncore; j++) {
    snprintf(filename, sizeof(filename), "f%d", j);
    open(filename, O_RDWR);
  }
  return 0;
}

int
main(int ac, char **av)
{
  void* (*op)(void*) = 0;
  if (ac == 2 && strcmp(av[1], "vm") == 0)
    op = vmsharing;
  else if (ac == 2 && strcmp(av[1], "fs") == 0)
    op = fssharing;
  else
    fprintf(1, "usage: %s vm|fs\n", av[0]);

  if (op) {
    mtenable_type(mtrace_record_ascope, "xv6-asharing");
    pthread_barrier_init(&bar, 0, ncore);
    for (u64 i = 0; i < ncore; i++) {
      next();
      pthread_t tid;
      pthread_create(&tid, 0, op, (void*) i);
    }
    mtdisable("xv6-asharing");
  }
}<commit_msg>wait for children in asharing; otherwise asharing returns before children are finished, and we can get partial results.<commit_after>// Tests to drive abstract sharing analysis

#include "types.h"
#include "user.h"
#include "fcntl.h"
#include "mtrace.h"
#include "pthread.h"

static int cpu;
static pthread_barrier_t bar;
enum { ncore = 8 };

void
next()
{
  if (setaffinity(cpu) < 0) {
    cpu = 0;
    if (setaffinity(cpu) < 0)
      die("sys_setaffinity(%d) failed", cpu);
  }
  cpu++;
}

void*
vmsharing(void* arg)
{
  u64 i = (u64) arg;

  volatile char *p = (char*)(0x40000UL + i * 4096);
  if (map((void *) p, 4096) < 0)
    die("map failed");

  if (unmap((void *) p, 4096) < 0)
    die("unmap failed");

  return 0;
}

void*
fssharing(void* arg)
{
  u64 i = (u64) arg;

  // Note that we keep these files open; otherwise all of these
  // operations will share the abstract FD object and we won't get any
  // results.

  char filename[32];
  snprintf(filename, sizeof(filename), "f%d", i);

  open(filename, O_CREATE|O_RDWR);

  pthread_barrier_wait(&bar);

  for (u64 j = 0; j < ncore; j++) {
    snprintf(filename, sizeof(filename), "f%d", j);
    open(filename, O_RDWR);
  }
  return 0;
}

int
main(int ac, char **av)
{
  void* (*op)(void*) = 0;
  if (ac == 2 && strcmp(av[1], "vm") == 0)
    op = vmsharing;
  else if (ac == 2 && strcmp(av[1], "fs") == 0)
    op = fssharing;
  else
    fprintf(1, "usage: %s vm|fs\n", av[0]);

  if (op) {
    mtenable_type(mtrace_record_ascope, "xv6-asharing");
    pthread_barrier_init(&bar, 0, ncore);
    for (u64 i = 0; i < ncore; i++) {
      next();
      pthread_t tid;
      pthread_create(&tid, 0, op, (void*) i);
    }

    for (u64 i = 0; i < ncore; i++)
      wait();
    mtdisable("xv6-asharing");
  }
}
{'fraction_non_alphanumeric': 0.17491847020456566, 'fraction_numerical': 0.03350133412392529, 'mean_word_length': 3.1551724137931036, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3986279', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1351, 'n_words': 381}