Example #1
0
void* eng_uevt_thread(void *x)
{
    struct pollfd ufd;
    int sock = -1;
    int nr;

    sock = uevent_open_socket(256*1024, true);
    if(-1 == sock){
        ENG_LOG("%s: socket init failed !\n", __FUNCTION__);
        return 0;
    }
    if(eng_usb_state()) {
	g_armlog_enable = 1;
	sem_post(&g_armlog_sem);
    }
    ufd.events = POLLIN;
    ufd.fd = sock;
    while(1) {
        ufd.revents = 0;
        nr = poll(&ufd, 1, -1);
        if (nr <= 0)
            continue;
        if (ufd.revents == POLLIN)
            handle_device_fd(sock);
    }

    return 0;    
}
static int uevent_init() {
    uevent_fd = uevent_open_socket(UEVENT_BUF_SIZE, true);

    if (uevent_fd >= 0) {
        fcntl(uevent_fd, F_SETFL, O_NONBLOCK);
    } else {
        KLOG_ERROR(LOG_TAG, "%s: uevent_open_socket failed; errno=%s\n",
            __func__, strerror(errno));
        return errno;
    }

    return 0;
}
Example #3
0
void *do_hotplug(void *data)
{
	int err = 0;
	int cpu = (int) data;
	struct pollfd fds;
	char buf[1024] = {0};
	char cpu_online[MAX_BUF * 2] = {0};
	char cpu_offline[MAX_BUF * 2] = {0};
	unsigned int online;
	int recv_bytes = 0;

	/* Looking for online@/devices/system/cpu/cpu1 or
	 * offline@/devices/system/cpu/cpu1 */

	snprintf(cpu_online, MAX_BUF * 2, "online@/devices/system/cpu/cpu1" );
	snprintf(cpu_offline, MAX_BUF * 2, "offline@/devices/system/cpu/cpu1");

	fds.events = POLLIN;
	fds.fd = uevent_open_socket(64*1024, true);
	if (fds.fd == -1) {
		msg("Error opening socket for hotplug uevent.\n");
		return NULL;
	}

	while (1) {

		err = poll(&fds, 1, -1);
		if (err == -1) {
			msg("Error in hotplug CPU[%d] poll.\n", cpu);
			break;
		}

		recv_bytes = uevent_kernel_multicast_recv(fds.fd, buf, sizeof(buf));
		if (recv_bytes == -1)
			continue;
		if (recv_bytes >= 1024)
			buf[1023] = '\0';
		else
			buf[recv_bytes] = '\0';

		if (!strcmp(buf, cpu_online))
			online = 1;
		else if (!strcmp(buf, cpu_offline))
			online = 0;
		else
			continue;

		pthread_mutex_lock(&hotplug_mutex);

		if (stall_decision_external && !thermal_condition) {
			pthread_mutex_unlock(&hotplug_mutex);
			continue;
		}

		dbgmsg("Online %u core1_status %d stalled %d\n",
		       online, core1_status, stall_decision);
		if (thermal_condition && online == 1) {
			/* hotplug core back off, since we are in thermal state */
			msg("System in thermal condition, bring core back down.");
			core1_status = CORE_DOWN;
			cpu_up(1, CORE_DOWN);
		} else if (!stall_decision && online != core1_status && boost_time == 0) {
			msg("CPU[%d] has been hotplugged outside MP-Decision.", cpu);
			msg("MP-Decision will be stalled until enabled.");
			core1_status = online ? CORE_UP : CORE_DOWN;
			stall_decision = 1;
		} else if (stall_decision) {
			msg("Enabling MP decision for CPU[%d]\n", cpu);
			stall_decision = 0;
			core1_status = online ? CORE_UP : CORE_DOWN;
			pthread_cond_broadcast(&hotplug_condition);
		}
		pthread_mutex_unlock(&hotplug_mutex);
	}

	return NULL;
}