Exemple #1
0
void *timer_init(void)
{
    struct timer_s *timer;

    timer = lib_AllocMem(sizeof(*timer), MEMF_PUBLIC);
    if (timer) {
        timer->TimerBase = NULL;
        timer->TimerMP.mp_SigBit = AllocSignal(-1);
        if ((BYTE)timer->TimerMP.mp_SigBit != -1) {
            timer->TimerMP.mp_Node.ln_Type = NT_MSGPORT;
            timer->TimerMP.mp_Flags = PA_SIGNAL;
            timer->TimerMP.mp_SigTask = FindTask(NULL);
            NEWLIST(&timer->TimerMP.mp_MsgList);
            timer->TimerIO.tr_node.io_Message.mn_Node.ln_Type = NT_REPLYMSG;
            timer->TimerIO.tr_node.io_Message.mn_ReplyPort = &timer->TimerMP;
            timer->TimerIO.tr_node.io_Message.mn_Length = sizeof(timer->TimerIO);
            if (OpenDevice(TIMERNAME, UNIT_MICROHZ, (struct IORequest *)&timer->TimerIO, 0) == 0) {
                timer->TimerBase = &timer->TimerIO.tr_node.io_Device->dd_Library;
                return timer;
            }
        }

        timer_exit(timer);
    }

    return NULL;
}
Exemple #2
0
void teardownStatemachine(Test_ShallowHistoryStatemachine* machine, Timer* dummyTimer, EventPool* eventPool)
{
	test_ShallowHistoryStatemachine_exit(machine);
	timer_exit(dummyTimer);
	eventPool_exit(eventPool);

}
Exemple #3
0
void sunxi_board_close_source(void)
{
//	axp_set_vbus_limit_dc();

#ifdef CONFIG_BOOT_A15
    extern int do_savecfg(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
    extern void clear_boot_cpu_flag(void);
    do_savecfg(0,0,1,NULL);
    clear_boot_cpu_flag();
#endif
	mmc_exit();  
	timer_exit();

	sunxi_key_exit();
#ifdef CONFIG_SUN6I
	p2wi_exit();
#endif
	sunxi_flash_exit(1);	//强制关闭FLASH
	sunxi_sprite_exit(1);
	sunxi_dma_exit();
	disable_interrupts();
	interrupt_exit();

#if defined(CONFIG_ARCH_SUN9IW1P1)
	*( volatile unsigned int *)(0x008000e0) = 0x16aa0000;
#endif

	return ;
}
Exemple #4
0
/*
************************************************************************************************************
*
*                                             function
*
*    name          :
*
*    parmeters     :
*
*    return        :
*
*    note          :
*
*
************************************************************************************************************
*/
int sunxi_board_run_fel_eraly(void)
{
#if defined(CONFIG_SUN6I) || defined(CONFIG_ARCH_SUN8IW3P1) || defined(CONFIG_ARCH_SUN8IW5P1)|| defined(CONFIG_ARCH_SUN7I)||defined(CONFIG_ARCH_SUN8IW8P1)
	*((volatile unsigned int *)(SUNXI_RUN_EFEX_ADDR)) = SUNXI_RUN_EFEX_FLAG;
#elif defined(CONFIG_ARCH_SUN9IW1P1) || defined(CONFIG_ARCH_SUN8IW7P1) || defined(CONFIG_ARCH_SUN8IW6P1)
	sunxi_set_fel_flag();
#endif
	printf("set next system status\n");
    axp_set_next_poweron_status(PMU_PRE_SYS_MODE);
	timer_exit();
	sunxi_key_exit();
#ifdef CONFIG_SUN6I
	p2wi_exit();
#endif
	sunxi_dma_exit();
#if defined(CONFIG_ARCH_SUN5I)
	printf("jump to fel_base\n");
	jump_to(FEL_BASE);
#else
	printf("reset cpu\n");
//#if defined(CONFIG_ARCH_SUN9IW1P1)
//	*( volatile unsigned int *)(0x008000e0) = 0x16aa0000;
//#endif
	reset_cpu(0);
#endif
	return 0;
}
Exemple #5
0
void teardownStatemachine(InterfaceTestStatemachine* machine, Timer* dummyTimer, EventPool* eventPool)
{
	interfaceTestStatemachine_exit(machine);
	timer_exit(dummyTimer);
	eventPool_exit(eventPool);

}
Exemple #6
0
void sunxi_board_close_source(void)
{
	mmc_exit();
	timer_exit();
	sunxi_key_exit();
	sunxi_flash_exit(1);
	sunxi_sprite_exit(1);
	sunxi_dma_exit();
	disable_interrupts();
	interrupt_exit();
	return ;
}
Exemple #7
0
int sunxi_board_run_fel_eraly(void)
{
	sunxi_set_fel_flag();
	printf("set next system status\n");
	axp_set_next_poweron_status(PMU_PRE_SYS_MODE);
	timer_exit();
	sunxi_key_exit();
	printf("reset cpu\n");
	reset_cpu(0);

	return 0;
}
static void ascii_exit(void) {

	timer_exit();
	exitEmptyArray();
	queue_exit();
	exit_semaphores();
	device_destroy(class_ascii, MKDEV(major, 0));
	class_destroy(class_ascii);

	printk(KERN_INFO "Device unregistering succeed\n");

	return unregister_chrdev(major, DEVICE_NAME);
}
Exemple #9
0
void teardownStatemachine(Test_ShallowHistoryStatemachine* machine, Timer* dummyTimer, EventPool* eventPool)
{
	/* call all exit actions for this state machine */
	test_ShallowHistoryStatemachine_exit(machine);

	/* free all internal memory for this state machine */
	test_ShallowHistoryStatemachine_destruct(machine);

	/* free the timer */
	timer_exit(dummyTimer);

	/* free all events in the event pool */
	eventPool_exit(eventPool);

}
Exemple #10
0
/*
************************************************************************************************************
*
*                                             function
*
*    name          :
*
*    parmeters     :
*
*    return        :
*
*    note          :
*
*
************************************************************************************************************
*/
int sunxi_board_run_fel_eraly(void)
{
#if defined(CONFIG_SUN6I) || defined(CONFIG_ARCH_SUN8IW3P1) || defined(CONFIG_ARCH_SUN8IW5P1)|| defined(CONFIG_ARCH_SUN7I)
	*((volatile unsigned int *)(SUNXI_RUN_EFEX_ADDR)) = SUNXI_RUN_EFEX_FLAG;
#elif defined(CONFIG_ARCH_SUN9IW1P1)
    volatile unsigned int *rtc_addr = (volatile unsigned int *)(0x08001400 + 0x1f0);

	do
	{
    	*rtc_addr = (1<<16) | (SUNXI_RUN_EFEX_FLAG<<8);
        *rtc_addr = (1<<31) | (1<<16) | (SUNXI_RUN_EFEX_FLAG<<8);
        __usdelay(10);
        *rtc_addr = (1<<16) | (SUNXI_RUN_EFEX_FLAG<<8);
    }
    while((*rtc_addr & 0xff) != SUNXI_RUN_EFEX_FLAG);
#elif defined(CONFIG_ARCH_SUN8IW6P1)
        volatile unsigned int *rtc_addr = (volatile unsigned int *)(0x01f01400 + 0x1f0);
    
        do
        {
            *rtc_addr = (1<<16) | (SUNXI_RUN_EFEX_FLAG<<8);
            *rtc_addr = (1<<31) | (1<<16) | (SUNXI_RUN_EFEX_FLAG<<8);
            __usdelay(10);
            *rtc_addr = (1<<16) | (SUNXI_RUN_EFEX_FLAG<<8);
        }
        while((*rtc_addr & 0xff) != SUNXI_RUN_EFEX_FLAG);

#endif
	printf("set next system status\n");
    axp_set_next_poweron_status(PMU_PRE_SYS_MODE);
	timer_exit();
	sunxi_key_exit();
#ifdef CONFIG_SUN6I
	p2wi_exit();
#endif
	sunxi_dma_exit();
#if defined(CONFIG_ARCH_SUN5I)
	printf("jump to fel_base\n");
	jump_to(FEL_BASE);
#else
	printf("reset cpu\n");
#if defined(CONFIG_ARCH_SUN9IW1P1)
	*( volatile unsigned int *)(0x008000e0) = 0x16aa0000;
#endif
	reset_cpu(0);
#endif
	return 0;
}
ssize_t _write(struct file *mfile, const char *gdata, size_t length, loff_t *off_what){
	int ret;
	if(interruptCount == 0){
		ret = request_irq(gpio_to_irq(S5PV310_GPX2(0)), &StartButton, IRQF_TRIGGER_RISING, "X2.0", NULL);
		ret = request_irq(gpio_to_irq(S5PV310_GPX2(1)), &PauseButton, IRQF_TRIGGER_RISING, "X2.1", NULL);
		ret = request_irq(gpio_to_irq(S5PV310_GPX2(2)), &ResetButton, IRQF_TRIGGER_RISING, "X2.2", NULL);
		ret = request_irq(gpio_to_irq(S5PV310_GPX2(4)), &ExitButton, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "X2.4", NULL);
		Reset(&my_stopwatch);
		timer_init(&my_stopwatch);
		printk("SleepStart!\n");
		while(true){
			gpio_fnd_write(my_gpio_fnd(1, my_stopwatch.min / 10));
			msleep(5);
			gpio_fnd_write(my_gpio_fnd(2, my_stopwatch.min % 10));
			msleep(5);
			gpio_fnd_write(my_gpio_fnd(3, my_stopwatch.sec / 10));
			msleep(5);
			gpio_fnd_write(my_gpio_fnd(4, my_stopwatch.sec % 10));
			msleep(5);
			if(shutdown_timer_start){
				if(!shutdown_timer_watch_start){ // timer start.
					shutdown_timer_watch_start = true;
					time = get_jiffies_64();
					printk("add timer %u\n", time);
				}else{
					; // ignore.
				}
			}else{
				if(shutdown_timer_watch_start){
					shutdown_timer_watch_start = false;
					unsigned int now = get_jiffies_64();
					printk("get timer %u\n", now);
					if(now - time >= 3*HZ)
						break;
				}
			}
		}
		gpio_fnd_write(0xFF);
		timer_exit();
		free_irq(gpio_to_irq(S5PV310_GPX2(0)), NULL);
		free_irq(gpio_to_irq(S5PV310_GPX2(1)), NULL);
		free_irq(gpio_to_irq(S5PV310_GPX2(2)), NULL);
		free_irq(gpio_to_irq(S5PV310_GPX2(4)), NULL);
	}
	return 0;
}
void sunxi_board_close_source(void)
{
//	axp_set_vbus_limit_dc();
	mmc_exit();
	timer_exit();

	sunxi_key_exit();
#ifdef CONFIG_SUN6I
	p2wi_exit();
#endif
	sunxi_flash_exit(1);	//强制关闭FLASH
	sunxi_sprite_exit(1);
	sunxi_dma_exit();
	disable_interrupts();
	interrupt_exit();

	return ;
}
void kpd_pwrkey_pmic_handler(unsigned long pressed)
{
	printk(KPD_SAY "Power Key generate, pressed=%ld\n", pressed);
	if (!kpd_input_dev) {
		printk("KPD input device not ready\n");
		return;
	}
		#ifdef FORCE_POWERKEY
		  if(pressed == 1)
		  {
		      printk(KPD_SAY "timer_init for FORCE_POWERKEY\n"); 
		      timer_init();
		  }
		  else if(pressed == 0)
		  {
		      printk(KPD_SAY "timer_exit for FORCE_POWERKEY\n"); 
		      timer_exit();
		  }
		#endif	
	kpd_pmic_pwrkey_hal(pressed);
}
Exemple #14
0
int main(int argc, char **argv)
{
	/* module init */
	timer_init();

	add_timer(&timer);

	while(1)
	{
		sleep(5);
		printf("runing jiffies=%ld\n", jiffies);
		break;
	}

	/* module exit */
	timer_exit();

	printf("module exit over\n");
	sleep(10);
	return 0;
}
/*
************************************************************************************************************
*
*                                             function
*
*    name          :
*
*    parmeters     :
*
*    return        :
*
*    note          :
*
*
************************************************************************************************************
*/
int sunxi_board_run_fel_eraly(void)
{
#if defined(CONFIG_SUN6I) || defined(CONFIG_ARCH_SUN8IW3P1) || defined(CONFIG_ARCH_SUN7I)
	*((volatile unsigned int *)(SUNXI_RUN_EFEX_ADDR)) = SUNXI_RUN_EFEX_FLAG;
#endif
	printf("set next system status\n");

    axp_set_next_poweron_status(PMU_PRE_SYS_MODE);

	timer_exit();
	sunxi_key_exit();
#ifdef CONFIG_SUN6I
	p2wi_exit();
#endif
	sunxi_dma_exit();

	printf("reset cpu\n");

	reset_cpu(0);

	return 0;
}
/*
************************************************************************************************************
*
*                                             function
*
*    name          :
*
*    parmeters     :
*
*    return        :
*
*    note          :
*
*
************************************************************************************************************
*/
void sunxi_board_close_source(void)
{
//	axp_set_vbus_limit_dc();

	timer_exit();

	sunxi_key_exit();
#ifdef CONFIG_SUN6I
	p2wi_exit();
#endif
	sunxi_dma_exit();
	sunxi_flash_exit(1);	//强制关闭FLASH
	sunxi_sprite_exit(1);
	disable_interrupts();
	interrupt_exit();

#if defined(CONFIG_ARCH_SUN9IW1P1)
	*( volatile unsigned int *)(0x008000e0) = 0x16aa0000;
#endif

	return ;
}
Exemple #17
0
int silly_run(struct silly_config *config)
{
        int i, j;
        int err;
        int tcnt;

        if (config->daemon && silly_daemon(1, 0) == -1) {
                fprintf(stderr, "daemon error:%d\n", errno);
                exit(0);
        }

        signal(SIGPIPE, SIG_IGN);
        signal(SIGHUP, _sig_term);
        signal(SIGINT, _sig_term);
        signal(SIGTERM, _sig_term);

        timer_init();
        silly_socket_init();
        silly_server_init();

        for (i = 0; i < config->listen_count; i++) {
                int n;
                char ip[32];
                char port[32];
                char backlog[32];
                
                uint16_t        nport;
                int             nbacklog;

                backlog[0] = '\0';
                n = sscanf(config->listen[i].addr, "%[0-9.]:%[0-9]:%[0-9]", ip, port, backlog);
                if (n < 2) {
                        fprintf(stderr, "Invalid listen of %s\n", config->listen[i].name);
                        return -1;
                }
                nport = (uint16_t)strtoul(port, NULL, 0);
                nbacklog = (int)strtol(backlog, NULL, 0);
                if (nbacklog == 0)
                        nbacklog = 10;

                err = silly_socket_listen(ip, nport, nbacklog, -1);
                if (err == -1) {
                        fprintf(stderr, "listen :%s(%s) error\n", config->listen[i].addr, config->listen[i].name);
                        return -1;
                }

                snprintf(port, sizeof(port) / sizeof(port[0]), "%d", err);
                silly_env_set(config->listen[i].name, port);
        }
        
        srand(time(NULL));

        //start
        int     workid[config->worker_count];
        for (i = 0; i < config->worker_count; i++) {
                workid[i] = silly_server_open();
                silly_server_start(workid[i], config);
        }
 
        tcnt = 2;
        if (config->debug > 0)
                ++tcnt;
        tcnt += config->worker_count;
        pthread_t pid[tcnt];
        
        i = 0;
        pthread_create(&pid[i++], NULL, _socket, NULL);
        pthread_create(&pid[i++], NULL, _timer, NULL);
        if (config->debug > 0)
                pthread_create(&pid[i++], NULL, _debug, NULL);

        for (j = 0; j < config->worker_count; i++, j++)
                pthread_create(&pid[i], NULL, _worker, &workid[j]);

        fprintf(stderr, "Silly is running...\n");

        for (i = 0; i < tcnt; i++)
                pthread_join(pid[i], NULL);

        silly_server_exit();
        silly_socket_exit();
        timer_exit();

        fprintf(stderr, "silly has already exit...\n");

        return 0;
}
void __exit dev_device_exit(void){
	timer_exit();
	gpio_fnd_exit();
	unregister_chrdev(DEV_MAJOR, DEV_NAME);
	printk("20091631 Exit\n");
}
Exemple #19
0
/*
 * Return value:
 *   1 - exitlwps() failed, call (or continue) lwp_exit()
 *   0 - restarting init.  Return through system call path
 */
int
proc_exit(int why, int what)
{
	kthread_t *t = curthread;
	klwp_t *lwp = ttolwp(t);
	proc_t *p = ttoproc(t);
	zone_t *z = p->p_zone;
	timeout_id_t tmp_id;
	int rv;
	proc_t *q;
	task_t *tk;
	vnode_t *exec_vp, *execdir_vp, *cdir, *rdir;
	sigqueue_t *sqp;
	lwpdir_t *lwpdir;
	uint_t lwpdir_sz;
	tidhash_t *tidhash;
	uint_t tidhash_sz;
	ret_tidhash_t *ret_tidhash;
	refstr_t *cwd;
	hrtime_t hrutime, hrstime;
	int evaporate;

	/*
	 * Stop and discard the process's lwps except for the current one,
	 * unless some other lwp beat us to it.  If exitlwps() fails then
	 * return and the calling lwp will call (or continue in) lwp_exit().
	 */
	proc_is_exiting(p);
	if (exitlwps(0) != 0)
		return (1);

	mutex_enter(&p->p_lock);
	if (p->p_ttime > 0) {
		/*
		 * Account any remaining ticks charged to this process
		 * on its way out.
		 */
		(void) task_cpu_time_incr(p->p_task, p->p_ttime);
		p->p_ttime = 0;
	}
	mutex_exit(&p->p_lock);

	DTRACE_PROC(lwp__exit);
	DTRACE_PROC1(exit, int, why);

	/*
	 * Will perform any brand specific proc exit processing, since this
	 * is always the last lwp, will also perform lwp_exit and free brand
	 * data
	 */
	if (PROC_IS_BRANDED(p)) {
		lwp_detach_brand_hdlrs(lwp);
		brand_clearbrand(p, B_FALSE);
	}

	/*
	 * Don't let init exit unless zone_start_init() failed its exec, or
	 * we are shutting down the zone or the machine.
	 *
	 * Since we are single threaded, we don't need to lock the
	 * following accesses to zone_proc_initpid.
	 */
	if (p->p_pid == z->zone_proc_initpid) {
		if (z->zone_boot_err == 0 &&
		    zone_status_get(z) < ZONE_IS_SHUTTING_DOWN &&
		    zone_status_get(global_zone) < ZONE_IS_SHUTTING_DOWN &&
		    z->zone_restart_init == B_TRUE &&
		    restart_init(what, why) == 0)
			return (0);
		/*
		 * Since we didn't or couldn't restart init, we clear
		 * the zone's init state and proceed with exit
		 * processing.
		 */
		z->zone_proc_initpid = -1;
	}

	lwp_pcb_exit();

	/*
	 * Allocate a sigqueue now, before we grab locks.
	 * It will be given to sigcld(), below.
	 * Special case:  If we will be making the process disappear
	 * without a trace because it is either:
	 *	* an exiting SSYS process, or
	 *	* a posix_spawn() vfork child who requests it,
	 * we don't bother to allocate a useless sigqueue.
	 */
	evaporate = (p->p_flag & SSYS) || ((p->p_flag & SVFORK) &&
	    why == CLD_EXITED && what == _EVAPORATE);
	if (!evaporate)
		sqp = kmem_zalloc(sizeof (sigqueue_t), KM_SLEEP);

	/*
	 * revoke any doors created by the process.
	 */
	if (p->p_door_list)
		door_exit();

	/*
	 * Release schedctl data structures.
	 */
	if (p->p_pagep)
		schedctl_proc_cleanup();

	/*
	 * make sure all pending kaio has completed.
	 */
	if (p->p_aio)
		aio_cleanup_exit();

	/*
	 * discard the lwpchan cache.
	 */
	if (p->p_lcp != NULL)
		lwpchan_destroy_cache(0);

	/*
	 * Clean up any DTrace helper actions or probes for the process.
	 */
	if (p->p_dtrace_helpers != NULL) {
		ASSERT(dtrace_helpers_cleanup != NULL);
		(*dtrace_helpers_cleanup)();
	}

	/* untimeout the realtime timers */
	if (p->p_itimer != NULL)
		timer_exit();

	if ((tmp_id = p->p_alarmid) != 0) {
		p->p_alarmid = 0;
		(void) untimeout(tmp_id);
	}

	/*
	 * Remove any fpollinfo_t's for this (last) thread from our file
	 * descriptors so closeall() can ASSERT() that they're all gone.
	 */
	pollcleanup();

	if (p->p_rprof_cyclic != CYCLIC_NONE) {
		mutex_enter(&cpu_lock);
		cyclic_remove(p->p_rprof_cyclic);
		mutex_exit(&cpu_lock);
	}

	mutex_enter(&p->p_lock);

	/*
	 * Clean up any DTrace probes associated with this process.
	 */
	if (p->p_dtrace_probes) {
		ASSERT(dtrace_fasttrap_exit_ptr != NULL);
		dtrace_fasttrap_exit_ptr(p);
	}

	while ((tmp_id = p->p_itimerid) != 0) {
		p->p_itimerid = 0;
		mutex_exit(&p->p_lock);
		(void) untimeout(tmp_id);
		mutex_enter(&p->p_lock);
	}

	lwp_cleanup();

	/*
	 * We are about to exit; prevent our resource associations from
	 * being changed.
	 */
	pool_barrier_enter();

	/*
	 * Block the process against /proc now that we have really
	 * acquired p->p_lock (to manipulate p_tlist at least).
	 */
	prbarrier(p);

	sigfillset(&p->p_ignore);
	sigemptyset(&p->p_siginfo);
	sigemptyset(&p->p_sig);
	sigemptyset(&p->p_extsig);
	sigemptyset(&t->t_sig);
	sigemptyset(&t->t_extsig);
	sigemptyset(&p->p_sigmask);
	sigdelq(p, t, 0);
	lwp->lwp_cursig = 0;
	lwp->lwp_extsig = 0;
	p->p_flag &= ~(SKILLED | SEXTKILLED);
	if (lwp->lwp_curinfo) {
		siginfofree(lwp->lwp_curinfo);
		lwp->lwp_curinfo = NULL;
	}

	t->t_proc_flag |= TP_LWPEXIT;
	ASSERT(p->p_lwpcnt == 1 && p->p_zombcnt == 0);
	prlwpexit(t);		/* notify /proc */
	lwp_hash_out(p, t->t_tid);
	prexit(p);

	p->p_lwpcnt = 0;
	p->p_tlist = NULL;
	sigqfree(p);
	term_mstate(t);
	p->p_mterm = gethrtime();

	exec_vp = p->p_exec;
	execdir_vp = p->p_execdir;
	p->p_exec = NULLVP;
	p->p_execdir = NULLVP;
	mutex_exit(&p->p_lock);

	pr_free_watched_pages(p);

	closeall(P_FINFO(p));

	/* Free the controlling tty.  (freectty() always assumes curproc.) */
	ASSERT(p == curproc);
	(void) freectty(B_TRUE);

#if defined(__sparc)
	if (p->p_utraps != NULL)
		utrap_free(p);
#endif
	if (p->p_semacct)			/* IPC semaphore exit */
		semexit(p);
	rv = wstat(why, what);

	acct(rv & 0xff);
	exacct_commit_proc(p, rv);

	/*
	 * Release any resources associated with C2 auditing
	 */
	if (AU_AUDITING()) {
		/*
		 * audit exit system call
		 */
		audit_exit(why, what);
	}

	/*
	 * Free address space.
	 */
	relvm();

	if (exec_vp) {
		/*
		 * Close this executable which has been opened when the process
		 * was created by getproc().
		 */
		(void) VOP_CLOSE(exec_vp, FREAD, 1, (offset_t)0, CRED(), NULL);
		VN_RELE(exec_vp);
	}
	if (execdir_vp)
		VN_RELE(execdir_vp);

	/*
	 * Release held contracts.
	 */
	contract_exit(p);

	/*
	 * Depart our encapsulating process contract.
	 */
	if ((p->p_flag & SSYS) == 0) {
		ASSERT(p->p_ct_process);
		contract_process_exit(p->p_ct_process, p, rv);
	}

	/*
	 * Remove pool association, and block if requested by pool_do_bind.
	 */
	mutex_enter(&p->p_lock);
	ASSERT(p->p_pool->pool_ref > 0);
	atomic_add_32(&p->p_pool->pool_ref, -1);
	p->p_pool = pool_default;
	/*
	 * Now that our address space has been freed and all other threads
	 * in this process have exited, set the PEXITED pool flag.  This
	 * tells the pools subsystems to ignore this process if it was
	 * requested to rebind this process to a new pool.
	 */
	p->p_poolflag |= PEXITED;
	pool_barrier_exit();
	mutex_exit(&p->p_lock);

	mutex_enter(&pidlock);

	/*
	 * Delete this process from the newstate list of its parent. We
	 * will put it in the right place in the sigcld in the end.
	 */
	delete_ns(p->p_parent, p);

	/*
	 * Reassign the orphans to the next of kin.
	 * Don't rearrange init's orphanage.
	 */
	if ((q = p->p_orphan) != NULL && p != proc_init) {

		proc_t *nokp = p->p_nextofkin;

		for (;;) {
			q->p_nextofkin = nokp;
			if (q->p_nextorph == NULL)
				break;
			q = q->p_nextorph;
		}
		q->p_nextorph = nokp->p_orphan;
		nokp->p_orphan = p->p_orphan;
		p->p_orphan = NULL;
	}

	/*
	 * Reassign the children to init.
	 * Don't try to assign init's children to init.
	 */
	if ((q = p->p_child) != NULL && p != proc_init) {
		struct proc	*np;
		struct proc	*initp = proc_init;
		boolean_t	setzonetop = B_FALSE;

		if (!INGLOBALZONE(curproc))
			setzonetop = B_TRUE;

		pgdetach(p);

		do {
			np = q->p_sibling;
			/*
			 * Delete it from its current parent new state
			 * list and add it to init new state list
			 */
			delete_ns(q->p_parent, q);

			q->p_ppid = 1;
			q->p_pidflag &= ~(CLDNOSIGCHLD | CLDWAITPID);
			if (setzonetop) {
				mutex_enter(&q->p_lock);
				q->p_flag |= SZONETOP;
				mutex_exit(&q->p_lock);
			}
			q->p_parent = initp;

			/*
			 * Since q will be the first child,
			 * it will not have a previous sibling.
			 */
			q->p_psibling = NULL;
			if (initp->p_child) {
				initp->p_child->p_psibling = q;
			}
			q->p_sibling = initp->p_child;
			initp->p_child = q;
			if (q->p_proc_flag & P_PR_PTRACE) {
				mutex_enter(&q->p_lock);
				sigtoproc(q, NULL, SIGKILL);
				mutex_exit(&q->p_lock);
			}
			/*
			 * sigcld() will add the child to parents
			 * newstate list.
			 */
			if (q->p_stat == SZOMB)
				sigcld(q, NULL);
		} while ((q = np) != NULL);

		p->p_child = NULL;
		ASSERT(p->p_child_ns == NULL);
	}

	TRACE_1(TR_FAC_PROC, TR_PROC_EXIT, "proc_exit: %p", p);

	mutex_enter(&p->p_lock);
	CL_EXIT(curthread); /* tell the scheduler that curthread is exiting */

	/*
	 * Have our task accummulate our resource usage data before they
	 * become contaminated by p_cacct etc., and before we renounce
	 * membership of the task.
	 *
	 * We do this regardless of whether or not task accounting is active.
	 * This is to avoid having nonsense data reported for this task if
	 * task accounting is subsequently enabled. The overhead is minimal;
	 * by this point, this process has accounted for the usage of all its
	 * LWPs. We nonetheless do the work here, and under the protection of
	 * pidlock, so that the movement of the process's usage to the task
	 * happens at the same time as the removal of the process from the
	 * task, from the point of view of exacct_snapshot_task_usage().
	 */
	exacct_update_task_mstate(p);

	hrutime = mstate_aggr_state(p, LMS_USER);
	hrstime = mstate_aggr_state(p, LMS_SYSTEM);
	p->p_utime = (clock_t)NSEC_TO_TICK(hrutime) + p->p_cutime;
	p->p_stime = (clock_t)NSEC_TO_TICK(hrstime) + p->p_cstime;

	p->p_acct[LMS_USER]	+= p->p_cacct[LMS_USER];
	p->p_acct[LMS_SYSTEM]	+= p->p_cacct[LMS_SYSTEM];
	p->p_acct[LMS_TRAP]	+= p->p_cacct[LMS_TRAP];
	p->p_acct[LMS_TFAULT]	+= p->p_cacct[LMS_TFAULT];
	p->p_acct[LMS_DFAULT]	+= p->p_cacct[LMS_DFAULT];
	p->p_acct[LMS_KFAULT]	+= p->p_cacct[LMS_KFAULT];
	p->p_acct[LMS_USER_LOCK] += p->p_cacct[LMS_USER_LOCK];
	p->p_acct[LMS_SLEEP]	+= p->p_cacct[LMS_SLEEP];
	p->p_acct[LMS_WAIT_CPU]	+= p->p_cacct[LMS_WAIT_CPU];
	p->p_acct[LMS_STOPPED]	+= p->p_cacct[LMS_STOPPED];

	p->p_ru.minflt	+= p->p_cru.minflt;
	p->p_ru.majflt	+= p->p_cru.majflt;
	p->p_ru.nswap	+= p->p_cru.nswap;
	p->p_ru.inblock	+= p->p_cru.inblock;
	p->p_ru.oublock	+= p->p_cru.oublock;
	p->p_ru.msgsnd	+= p->p_cru.msgsnd;
	p->p_ru.msgrcv	+= p->p_cru.msgrcv;
	p->p_ru.nsignals += p->p_cru.nsignals;
	p->p_ru.nvcsw	+= p->p_cru.nvcsw;
	p->p_ru.nivcsw	+= p->p_cru.nivcsw;
	p->p_ru.sysc	+= p->p_cru.sysc;
	p->p_ru.ioch	+= p->p_cru.ioch;

	p->p_stat = SZOMB;
	p->p_proc_flag &= ~P_PR_PTRACE;
	p->p_wdata = what;
	p->p_wcode = (char)why;

	cdir = PTOU(p)->u_cdir;
	rdir = PTOU(p)->u_rdir;
	cwd = PTOU(p)->u_cwd;

	ASSERT(cdir != NULL || p->p_parent == &p0);

	/*
	 * Release resource controls, as they are no longer enforceable.
	 */
	rctl_set_free(p->p_rctls);

	/*
	 * Decrement tk_nlwps counter for our task.max-lwps resource control.
	 * An extended accounting record, if that facility is active, is
	 * scheduled to be written.  We cannot give up task and project
	 * membership at this point because that would allow zombies to escape
	 * from the max-processes resource controls.  Zombies stay in their
	 * current task and project until the process table slot is released
	 * in freeproc().
	 */
	tk = p->p_task;

	mutex_enter(&p->p_zone->zone_nlwps_lock);
	tk->tk_nlwps--;
	tk->tk_proj->kpj_nlwps--;
	p->p_zone->zone_nlwps--;
	mutex_exit(&p->p_zone->zone_nlwps_lock);

	/*
	 * Clear the lwp directory and the lwpid hash table
	 * now that /proc can't bother us any more.
	 * We free the memory below, after dropping p->p_lock.
	 */
	lwpdir = p->p_lwpdir;
	lwpdir_sz = p->p_lwpdir_sz;
	tidhash = p->p_tidhash;
	tidhash_sz = p->p_tidhash_sz;
	ret_tidhash = p->p_ret_tidhash;
	p->p_lwpdir = NULL;
	p->p_lwpfree = NULL;
	p->p_lwpdir_sz = 0;
	p->p_tidhash = NULL;
	p->p_tidhash_sz = 0;
	p->p_ret_tidhash = NULL;

	/*
	 * If the process has context ops installed, call the exit routine
	 * on behalf of this last remaining thread. Normally exitpctx() is
	 * called during thread_exit() or lwp_exit(), but because this is the
	 * last thread in the process, we must call it here. By the time
	 * thread_exit() is called (below), the association with the relevant
	 * process has been lost.
	 *
	 * We also free the context here.
	 */
	if (p->p_pctx) {
		kpreempt_disable();
		exitpctx(p);
		kpreempt_enable();

		freepctx(p, 0);
	}

	/*
	 * curthread's proc pointer is changed to point to the 'sched'
	 * process for the corresponding zone, except in the case when
	 * the exiting process is in fact a zsched instance, in which
	 * case the proc pointer is set to p0.  We do so, so that the
	 * process still points at the right zone when we call the VN_RELE()
	 * below.
	 *
	 * This is because curthread's original proc pointer can be freed as
	 * soon as the child sends a SIGCLD to its parent.  We use zsched so
	 * that for user processes, even in the final moments of death, the
	 * process is still associated with its zone.
	 */
	if (p != t->t_procp->p_zone->zone_zsched)
		t->t_procp = t->t_procp->p_zone->zone_zsched;
	else
		t->t_procp = &p0;

	mutex_exit(&p->p_lock);
	if (!evaporate) {
		p->p_pidflag &= ~CLDPEND;
		sigcld(p, sqp);
	} else {
		/*
		 * Do what sigcld() would do if the disposition
		 * of the SIGCHLD signal were set to be ignored.
		 */
		cv_broadcast(&p->p_srwchan_cv);
		freeproc(p);
	}
	mutex_exit(&pidlock);

	/*
	 * We don't release u_cdir and u_rdir until SZOMB is set.
	 * This protects us against dofusers().
	 */
	if (cdir)
		VN_RELE(cdir);
	if (rdir)
		VN_RELE(rdir);
	if (cwd)
		refstr_rele(cwd);

	/*
	 * task_rele() may ultimately cause the zone to go away (or
	 * may cause the last user process in a zone to go away, which
	 * signals zsched to go away).  So prior to this call, we must
	 * no longer point at zsched.
	 */
	t->t_procp = &p0;

	kmem_free(lwpdir, lwpdir_sz * sizeof (lwpdir_t));
	kmem_free(tidhash, tidhash_sz * sizeof (tidhash_t));
	while (ret_tidhash != NULL) {
		ret_tidhash_t *next = ret_tidhash->rth_next;
		kmem_free(ret_tidhash->rth_tidhash,
		    ret_tidhash->rth_tidhash_sz * sizeof (tidhash_t));
		kmem_free(ret_tidhash, sizeof (*ret_tidhash));
		ret_tidhash = next;
	}

	thread_exit();
	/* NOTREACHED */
}
static void timer_function() 
{ 
    timer_exit();
    //arch_reset(0, "charger");
    mt_power_off();
}