Exemplo n.º 1
0
static int allocate_transition_tls(int id)
{
    /* Libc function to initialize TLS-based locale info for ctype functions. */
    extern void __ctype_init(void);

    /* We want to free and then reallocate the tls rather than simply
     * reinitializing it because its size may have changed.  TODO: not sure if
     * this is right.  0-ing is one thing, but freeing and reallocating can be
     * expensive, esp if syscalls are involved.  Check out glibc's
     * allocatestack.c for what might work. */
    free_transition_tls(id);

    void *tcb = allocate_tls();
    if (!tcb) {
        errno = ENOMEM;
        return -1;
    }

    /* Setup some intitial TLS data for the newly allocated transition tls. */
    void *temp_tcb = get_tls_desc();
    set_tls_desc(tcb);
    begin_safe_access_tls_vars();
    __vcoreid = id;
    __vcore_context = TRUE;
    __ctype_init();
    end_safe_access_tls_vars();
    set_tls_desc(temp_tcb);

    /* Install the new tls into the vcpd. */
    set_vcpd_tls_desc(id, tcb);
    return 0;
}
Exemplo n.º 2
0
int main(int argc, char** argv)
{
	uint32_t vcoreid = vcore_id();
	int retval = 0;

	mcs_barrier_init(&b, max_vcores());

/* begin: stuff userspace needs to do before switching to multi-mode */
	vcore_lib_init();
	#if 0
	/* tell the kernel where and how we want to receive notifications */
	struct notif_method *nm;
	for (int i = 0; i < MAX_NR_NOTIF; i++) {
		nm = &__procdata.notif_methods[i];
		nm->flags |= NOTIF_WANTED | NOTIF_MSG | NOTIF_IPI;
		nm->vcoreid = i % 2; // vcore0 or 1, keepin' it fresh.
	}
	#endif
	/* Need to save this somewhere that you can find it again when restarting
	 * core0 */
	core0_tls = get_tls_desc(0);
	/* Need to save our floating point state somewhere (like in the
	 * user_thread_tcb so it can be restarted too */
/* end: stuff userspace needs to do before switching to multi-mode */

	/* get into multi mode */
	retval = vcore_request(1);
	if (retval)
		printf("F****d!\n");

	printf("Proc %d requesting another vcore\n", getpid());
	begin = read_tsc();
	retval = vcore_request(1);
	if (retval)
		printf("F****d!\n");
	while (!core1_up)
		cpu_relax;
	end = read_tsc();
	printf("Took %llu usec (%llu nsec) to receive 1 core (cold).\n",
	       udiff(begin, end), ndiff(begin, end));
	printf("[T]:002:%llu:%llu:1:C.\n",
	       udiff(begin, end), ndiff(begin, end));
	core1_up = FALSE;
	udelay(2000000);
	printf("Proc %d requesting the vcore again\n", getpid());
	begin = read_tsc();
	retval = vcore_request(1);
	if (retval)
		printf("F****d!\n");
	while (!core1_up)
		cpu_relax();
	end = read_tsc();
	printf("Took %llu usec (%llu nsec) to receive 1 core (warm).\n",
	       udiff(begin, end), ndiff(begin, end));
	printf("[T]:002:%llu:%llu:1:W.\n",
	       udiff(begin, end), ndiff(begin, end));
	return 0;
}
Exemplo n.º 3
0
/* Test program for the audio device.  mmap()s the stuff, sets up a notif
 * handler, and switches to multi_mode.
 *
 * Note: this has a lot of mhello-like MCP infrastructure.  When Lithe is
 * working, you won't need any of this.  Just the mmap stuff and the notif
 * handler.  Stuff specific to the ethernet audio device is marked ETH_AUD. */
int main() 
{ 
	int retval;
	int in_fd, out_fd;
	/* ETHAUD mmap the input and output buffers */
	in_fd = open("/dev/eth_audio_in", O_RDONLY);
	out_fd = open("/dev/eth_audio_out", O_RDWR);
	assert(in_fd != -1);
	assert(out_fd != -1);
	in_buf = mmap(0, PGSIZE, PROT_READ, 0, in_fd, 0);
	if (in_buf == MAP_FAILED) {
		int err = errno;
		perror("Can't mmap the input buf:");
	}
	out_buf = mmap(0, PGSIZE, PROT_READ | PROT_WRITE, MAP_POPULATE, out_fd, 0);
	if (out_buf == MAP_FAILED) {
		int err = errno;
		perror("Can't mmap the output buf:");
	}
	//strncpy(out_buf, "Nanwan loves you!\n", 19);

/* begin: stuff userspace needs to do before switching to multi-mode */
	vcore_init();

	/* ETHAUD Turn on Free apple pie (which is the network packet) */
	enable_kevent(EV_FREE_APPLE_PIE, 0, EVENT_IPI);

	/* Need to save this somewhere that you can find it again when restarting
	 * core0 */
	core0_tls = get_tls_desc(0);
	/* Need to save our floating point state somewhere (like in the
	 * user_thread_tcb so it can be restarted too */

/* end: stuff userspace needs to do before switching to multi-mode */
	/* ETHAUD */
	/* Switch into _M mode */
	retval = vcore_request(1);

	/* Stay alive for a minute (will take interrupts) */
	udelay(60000000);

	printf("Eth aud, finishing up!\n");
	/* Need to do unmap it, due to some limitations in the kernel */
	munmap(in_buf, PGSIZE);
	munmap(out_buf, PGSIZE);
	close(in_fd);
	close(out_fd);
}
Exemplo n.º 4
0
/* Helper, initializes a fresh uthread to be thread0. */
static void uthread_init_thread0(struct uthread *uthread)
{
	assert(uthread);
	/* Save a pointer to thread0's tls region (the glibc one) into its tcb */
	uthread->tls_desc = get_tls_desc();
	/* Save a pointer to the uthread in its own TLS */
	current_uthread = uthread;
	/* Thread is currently running (it is 'us') */
	uthread->state = UT_RUNNING;
	/* utf/as doesn't represent the state of the uthread (we are running) */
	uthread->flags &= ~(UTHREAD_SAVED | UTHREAD_FPSAVED);
	/* need to track thread0 for TLS deallocation */
	uthread->flags |= UTHREAD_IS_THREAD0;
	uthread->notif_disabled_depth = 0;
	/* setting the uthread's TLS var.  this is idempotent for SCPs (us) */
	__vcoreid = 0;
}