static void cpuManager_join(ObjectDesc * self, CPUStateProxy * cpuStateProxy)
{
    ThreadDesc *cpuState = cpuState2thread((ObjectDesc *) cpuStateProxy);
    while (cpuState->state != STATE_ZOMBIE) {
        rt_task_yield();
    }
}
static jint cpuManager_waitUntilBlocked(ObjectDesc * self, CPUStateProxy * cpuStateProxy)
{
    ThreadDesc *cpuState = cpuState2thread((ObjectDesc *) cpuStateProxy);

    while (cpuState->state != STATE_BLOCKEDUSER) {
        rt_task_yield();
    }
    return 0;
}
        INTERNAL_QUAL void rtos_task_yield(RTOS_TASK* mytask) {
            if (mytask->rtaitask == 0)
                return;

            rt_task_yield();
        }
Beispiel #4
0
 INTERNAL_QUAL void rtos_task_yield(RTOS_TASK*) {
     rt_task_yield();
 }
Beispiel #5
0
        INTERNAL_QUAL int rtos_task_create(RTOS_TASK* task,
                                           int priority,
                                           unsigned cpu_affinity,
                                           const char* name,
                                           int sched_type,
                                           size_t stack_size,
                                           void * (*start_routine)(void *),
                                           ThreadInterface* obj)
        {
            rtos_task_check_priority(&sched_type, &priority);
            XenoCookie* xcookie = (XenoCookie*)malloc( sizeof(XenoCookie) );
            xcookie->data = obj;
            xcookie->wrapper = start_routine;
            if ( name == 0 || strlen(name) == 0)
                name = "XenoThread";
            task->name = strncpy( (char*)malloc( (strlen(name)+1)*sizeof(char) ), name, strlen(name)+1 );
            task->sched_type = sched_type; // User requested scheduler.
            int rv;

            unsigned int aff = 0;
            if ( cpu_affinity != 0 ) {
                // calculate affinity:
                for(unsigned i = 0; i < 8*sizeof(cpu_affinity); i++) {
                    if(cpu_affinity & (1 << i)) { 
                        // RTHAL_NR_CPUS is defined in the kernel, not in user space. So we just limit up to 7, until Xenomai allows us to get the maximum.
                        if ( i > 7 ) {
                            const unsigned int all_cpus = ~0;
                            if ( cpu_affinity != all_cpus ) // suppress this warning when ~0 is provided
                                log(Warning) << "rtos_task_create: ignoring cpu_affinity for "<< name << " on CPU " << i << " since it's larger than RTHAL_NR_CPUS - 1 (="<< 7 <<")"<<endlog();
                        } else {
                            aff |= T_CPU(i); 
                        }
                    }
                }
            }
            
            if (stack_size == 0) {
                log(Debug) << "Raizing default stack size to 128kb for Xenomai threads in Orocos." <<endlog();
                stack_size = 128000;
            }

            // task, name, stack, priority, mode, fun, arg
            // UGLY, how can I check in Xenomai that a name is in use before calling rt_task_spawn ???
            rv = rt_task_spawn(&(task->xenotask), name, stack_size, priority, T_JOINABLE | (aff & T_CPUMASK), rtos_xeno_thread_wrapper, xcookie);
            if ( rv == -EEXIST ) {
                free( task->name );
                task->name = strncpy( (char*)malloc( (strlen(name)+2)*sizeof(char) ), name, strlen(name)+1 );
                task->name[ strlen(name) ] = '0';
                task->name[ strlen(name)+1 ] = 0;
                while ( rv == -EEXIST &&  task->name[ strlen(name) ] != '9') {
                    task->name[ strlen(name) ] += 1;
                    rv = rt_task_spawn(&(task->xenotask), task->name, stack_size, priority, T_JOINABLE | (aff & T_CPUMASK), rtos_xeno_thread_wrapper, xcookie);
                }
            }
            if ( rv == -EEXIST ) {
                log(Warning) << name << ": an object with that name is already existing in Xenomai." << endlog();
                rv = rt_task_spawn(&(task->xenotask), 0, stack_size, priority, T_JOINABLE | (aff & T_CPUMASK), rtos_xeno_thread_wrapper, xcookie);
            }
            if ( rv != 0) {
                log(Error) << name << " : CANNOT INIT Xeno TASK " << task->name <<" error code: "<< rv << endlog();
                return rv;
            }

            rt_task_yield();
            return 0;
        }
Beispiel #6
0
int main(int argc, char* argv[])
{
	unsigned long mtsk_name = nam2num("MTSK");
	unsigned long btsk_name = nam2num("BTSK");
	unsigned long sem_name  = nam2num("SEM");
	unsigned long smbx_name  = nam2num("SMBX");
	unsigned long rmbx_name  = nam2num("RMBX");
	unsigned long msg;

	long long mbx_msg;
	long long llmsg = 0xaaaaaaaaaaaaaaaaLL;

	RT_TASK *mtsk, *rcvd_from;
	SEM *sem;
	MBX *smbx, *rmbx;
	int pid, count;

 	if (!(mtsk = rt_task_init_schmod(mtsk_name, 0, 0, 0, SCHED_FIFO, 0x1))) {
		printf("CANNOT INIT MASTER TASK\n");
		exit(1);
	}
	printf("MASTER TASK INIT: name = %lx, address = %p.\n", mtsk_name, mtsk);

	printf("MASTER TASK STARTS THE ONESHOT TIMER\n");
	rt_set_oneshot_mode();
	start_rt_timer(nano2count(10000000));
	mlockall(MCL_CURRENT | MCL_FUTURE);
	rt_make_hard_real_time();
	rt_sleep(1000000);


	printf("MASTER TASK MAKES ITSELF PERIODIC WITH A PERIOD OF 1 ms\n");
	rt_task_make_periodic(mtsk, rt_get_time(), nano2count(PERIOD));
	rt_sleep(nano2count(1000000000));

	count = PERIODIC_LOOPS;
	printf("MASTER TASK LOOPS ON WAIT_PERIOD FOR %d PERIODS\n", count);
	while(count--) {
		printf("PERIOD %d\n", count);
		rt_task_wait_period();
	}

	count = SLEEP_LOOPS;
	printf("MASTER TASK LOOPS ON SLEEP 0.1 s FOR %d PERIODS\n", count);
	while(count--) {
		printf("SLEEPING %d\n", count);
		rt_sleep(nano2count(DELAY));
	}
	printf("MASTER TASK YIELDS ITSELF\n");
	rt_task_yield();

	printf("MASTER TASK CREATES BUDDY TASK\n");
	pid = fork();
	if (!pid) {
		execl("./slave", "./slave", NULL);
	}

	printf("MASTER TASK SUSPENDS ITSELF, TO BE RESUMED BY BUDDY TASK\n");
	rt_task_suspend(mtsk);
	printf("MASTER TASK RESUMED BY BUDDY TASK\n");

 	if (!(sem = rt_sem_init(sem_name, 0))) {
		printf("CANNOT CREATE SEMAPHORE %lx\n", sem_name);
		exit(1);
	}
	printf("MASTER TASK CREATES SEM: name = %lx, address = %p.\n", sem_name, sem);

	printf("MASTER TASK WAIT_IF ON SEM\n");
	rt_sem_wait_if(sem);

	printf("MASTER STEP BLOCKS WAITING ON SEM\n");
	rt_sem_wait(sem);

	printf("MASTER TASK SIGNALLED BY BUDDY TASK WAKES UP AND BLOCKS WAIT TIMED 1 s ON SEM\n");
	rt_sem_wait_timed(sem, nano2count(1000000000));

	printf("MASTER TASK DELETES SEM\n");
	rt_sem_delete(sem);

	printf("MASTER TASK BLOCKS RECEIVING FROM ANY\n");
	rcvd_from = rt_receive(0, (void *)&msg);
	printf("MASTER TASK RECEIVED MESSAGE %lx FROM BUDDY TASK\n", msg);

	printf("MASTER TASK RPCS TO BUDDY TASK THE MESSAGE %lx\n", 0xabcdefL);
	rcvd_from = rt_rpc(rcvd_from, 0xabcdef, (void *)&msg);
	printf("MASTER TASK RECEIVED THE MESSAGE %lx RETURNED BY BUDDY TASK\n", msg);
//exit(1);
 	if (!(smbx = rt_mbx_init(smbx_name, 1))) {
		printf("CANNOT CREATE MAILBOX %lx\n", smbx_name);
		exit(1);
	}
 	if (!(rmbx = rt_mbx_init(rmbx_name, 1))) {
		printf("CANNOT CREATE MAILBOX %lx\n", rmbx_name);
		exit(1);
	}
	printf("MASTER TASK CREATED TWO MAILBOXES %p %p %p %p \n", smbx, rmbx, &mtsk_name, &msg);

	count = MBX_LOOPS;
	while(count--) {
		rt_mbx_send(smbx, &llmsg, sizeof(llmsg));
		printf("%d MASTER TASK SENDS THE MESSAGE %llx MBX\n", count, llmsg);
		mbx_msg = 0;
		rt_mbx_receive_timed(rmbx, &mbx_msg, sizeof(mbx_msg), nano2count(MSG_DELAY));
		printf("%d MASTER TASK RECEIVED THE MESSAGE %llx FROM MBX\n", count, mbx_msg);
		rt_sleep(nano2count(DELAY));
	}

	printf("MASTER TASK SENDS THE MESSAGE %lx TO BUDDY TO ALLOW ITS END\n", 0xeeeeeeeeL);
	rt_send(rcvd_from, 0xeeeeeeee);

	printf("MASTER TASK WAITS FOR BUDDY TASK END\n");
	while (rt_get_adr(btsk_name)) {
		rt_sleep(nano2count(1000000000));
	}
	printf("MASTER TASK STOPS THE PERIODIC TIMER\n");
	stop_rt_timer();

	printf("MASTER TASK DELETES MAILBOX %p\n", smbx);
	rt_mbx_delete(smbx);
	printf("MASTER TASK DELETES MAILBOX %p\n", rmbx);
	rt_mbx_delete(rmbx);

	printf("MASTER TASK DELETES ITSELF\n");
	rt_task_delete(mtsk);

	printf("END MASTER TASK\n");

	return 0;
}
Beispiel #7
0
void start_domain_zero(void *arg)
{
    DomainDesc      *domainInit;
    DomainProxy     *domainProxy;
    LibDesc         *lib;
    ObjectDesc      *dm;
    ArrayDesc       *arr;

    printk(KERN_INFO "Starting DomainZero.\n");

    /* load zero lib and create portals */
    lib = load(domainZero, "zero.jll");
    if (lib == NULL) {
        printk(KERN_ERR "Cannot load lib %s\n", "zero.jll");
        return;
    }

    /*
     * Create virtual method tables for interaction between
     * Java code and C-code that implements DomainZero.
     */
    zeroLib = lib->sharedLib;

    init_zero_from_lib(domainZero, lib->sharedLib);

    /* Domainzero's naming does now exist.
     * Make it available.
     */
    domainZero->initialNamingProxy = initialNamingProxy;

    callClassConstructors(domainZero, lib);

    lib = load(domainZero, "jdk0.jll");
    if (lib == NULL) {
        printk(KERN_ERR "Cannot load lib %s\n", "jdk0.jll");
        return;
    }
    callClassConstructors(domainZero, lib);

  /*********************************
   * Create and start initial Java domain
   *********************************/
    dm = (ObjectDesc *) lookupPortal("DomainManager");
    arr = (ArrayDesc *) newStringArray(domainZero, sizeof(start_libs) / sizeof(char *), start_libs);

    thread_prepare_to_copy();

    domainProxy =
        domainManager_createDomain(dm, newString(domainZero, "Init"), NULL, NULL, newString(domainZero, "init.jll"), arr,
                       newString(domainZero, "jx/init/Main"), getJVMConfig()->heapBytesDom0, -1, -1, NULL, -1,
                       getJVMConfig()->codeBytesDom0, NULL, (ObjectDesc *) domainZero->initialNamingProxy, NULL,
                       GC_IMPLEMENTATION_DEFAULT, NULL);
    domainInit = domainProxy->domain;

    printk(KERN_INFO "DomainZero initial thread done.\n");

    rt_event_signal(&jemEvents, JEM_INIT_COMPLETE);
    rt_task_yield();

    /* initial thread of DomainZero exits here */
}
static jint cpuManager_yield(ObjectDesc * self)
{
    rt_task_yield();
    return 0;
}