static void uevent_event() {
    char msg[UEVENT_MSG_LEN+2];
    char *cp;
    int n;

    n = uevent_kernel_multicast_recv(uevent_fd, msg, UEVENT_MSG_LEN);
    if (n <= 0)
        return;
    if (n >= UEVENT_MSG_LEN)   /* overflow -- discard */
        return;

    msg[n] = '\0';
    msg[n+1] = '\0';
    cp = msg;

    while (*cp) {
        if (!strcmp(cp, POWER_SUPPLY_SUBSYSTEM)) {
            chargeled_update();
            break;
        }

        /* advance to after the next \0 */
        while (*cp++)
            ;
    }
}
示例#2
0
void handle_device_fd(int sock)
{
    char msg[UEVENT_MSG_LEN+2];
    int n;
    while ((n = uevent_kernel_multicast_recv(sock, msg, UEVENT_MSG_LEN)) > 0) {
        if(n >= UEVENT_MSG_LEN)   /* overflow -- discard */
            continue;

        msg[n] = '\0';
        msg[n+1] = '\0';

        struct uevent uevent;
        parse_event(msg, &uevent);
        handle_device_event(&uevent);
    }
}
示例#3
0
文件: event.c 项目: liangxiaoju/codes
int handle_uevent(event_t *event)
{
    char msg[UEVENT_MSG_LEN + 2];
    int n, ret = 0;

    while (true) {
        struct uevent uevent;

        n = uevent_kernel_multicast_recv(event->uevent_fd, msg, UEVENT_MSG_LEN);
        if (n <= 0)
            break;
        if (n >= UEVENT_MSG_LEN)
            continue;

        msg[n] = '\0';
        msg[n+1] = '\0';

        parse_uevent(msg, &uevent);
        ret = process_uevent(event, &uevent);
    }

    return ret;
}
示例#4
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;
}