コード例 #1
0
void cthd_cpu_default_binding::do_default_binding(
    std::vector<cthd_cdev *> &cdevs) {
    int count = 0;
    int id = 0x1000;
    cthd_cdev *cdev_rapl;
    cthd_cdev *cdev_powerclamp;

    cdev_rapl = thd_engine->search_cdev("rapl_controller");
    cdev_powerclamp = thd_engine->search_cdev("intel_powerclamp");

    if (!cdev_rapl && !cdev_powerclamp) {
        thd_log_info(
            "cthd_cpu_default_binding::do_default_binding: No relavent cpu cdevs\n");
        return;
    }

    for (unsigned int i = 0; i < thd_engine->get_zone_count(); ++i) {
        cthd_zone *zone = thd_engine->get_zone(i);

        if (blacklist_match(zone->get_zone_type())) {
            continue;
        }
        if (!zone->zone_cdev_binded()) {
            cpu_zone_binding_t *cdev_binding_info;

            cdev_binding_info = new cpu_zone_binding_t;

            cdev_binding_info->zone_name = zone->get_zone_type();
            cdev_binding_info->zone = zone;

            cdev_binding_info->cdev_gate_entry = new cthd_gating_cdev(id++,
                    this, cdev_binding_info, true);
            if (cdev_binding_info->cdev_gate_entry) {
                cdev_binding_info->cdev_gate_entry->set_cdev_type(
                    cdev_binding_info->zone_name + "_" + "cpu_gate_entry");
            } else {
                thd_log_info("do_default_binding failed \n");
                cdev_binding_info->cdev_gate_entry = NULL;
                delete cdev_binding_info;
                continue;
            }

            cdev_binding_info->cdev_gate_exit = new cthd_gating_cdev(id++, this,
                    cdev_binding_info, false);
            if (cdev_binding_info->cdev_gate_exit) {
                cdev_binding_info->cdev_gate_exit->set_cdev_type(
                    cdev_binding_info->zone_name + "_" + "cpu_gate_exit");
            } else {
                thd_log_info("do_default_binding failed \n");
                delete cdev_binding_info->cdev_gate_entry;
                cdev_binding_info->cdev_gate_entry = NULL;
                delete cdev_binding_info;
                return;
            }

            thd_log_info("unbound zone %s\n", zone->get_zone_type().c_str());
            int status = zone->bind_cooling_device(PASSIVE, 0,
                                                   cdev_binding_info->cdev_gate_entry, 0,
                                                   def_gating_cdev_sampling_period);
            if (status == THD_ERROR) {
                thd_log_info("unbound zone: Bind attempt failed\n");
                delete cdev_binding_info->cdev_gate_exit;
                cdev_binding_info->cdev_gate_exit = NULL;
                delete cdev_binding_info->cdev_gate_entry;
                cdev_binding_info->cdev_gate_entry = NULL;
                delete cdev_binding_info;
                continue;
            }

            if (cdev_rapl) {
                zone->bind_cooling_device(PASSIVE, 0, cdev_rapl, 20);
            }
            if (cdev_powerclamp) {
                zone->bind_cooling_device(PASSIVE, 0, cdev_powerclamp, 20);
            }

            status = zone->bind_cooling_device(PASSIVE, 0,
                                               cdev_binding_info->cdev_gate_exit, 0,
                                               def_gating_cdev_sampling_period);
            if (status == THD_ERROR) {
                thd_log_info("unbound zone: Bind attempt failed\n");
                delete cdev_binding_info->cdev_gate_exit;
                cdev_binding_info->cdev_gate_exit = NULL;
                delete cdev_binding_info->cdev_gate_entry;
                cdev_binding_info->cdev_gate_entry = NULL;
                delete cdev_binding_info;
                continue;
            }
            thd_log_info("unbound zone %s\n", zone->get_zone_type().c_str());

            count++;
            zone->set_zone_active();
            cdev_list.push_back(cdev_binding_info);
        }
    }
    if (count) {
        thd_engine->rapl_power_meter.rapl_start_measure_power();
        cpu_package_max_power =
            thd_engine->rapl_power_meter.rapl_action_get_max_power(PACKAGE);
        thd_log_info("do_default_binding  max power CPU package :%u\n",
                     cpu_package_max_power);
    }
}
コード例 #2
0
ファイル: test-jolla-blacklist.c プロジェクト: hmallat/bluez5
static void test_blacklist_matching(void)
{
	const gchar *test_blacklists[] = {
		home_nemo_blacklist,
		home_nemo_Documents_blacklist,
		sdcard_blacklist,
		NULL
	};
	const gchar *test_blacklist_roots[] = {
		"/home/nemo",
		"/home/nemo/Documents",
		"/media/sdcard",
		NULL
	};
	const gchar *matching_paths[] = {
		"/home/nemo/.ssh",
		"/home/nemo/.ssh/",
		"/home/nemo/.ssh/./",
		"/home/nemo/../nemo/.ssh",
		"/home/nemo/.invisible_file",
		"/home/nemo/Music/DRM/BoringArtist/BoringAlbum",
		"/home/nemo/Documents/Mailbox/John_Doe",
		"/home/nemo/Documents/Work/Restricted/schedule.ppt",
		"/media/sdcard/Music/DRM/BoringArtist/BoringAlbum",

		NULL
	};
	const gchar *non_matching_paths[] = {
		"/home/nemo",
		"/home/nemo/.invisible_file2",
		"/home/nemo/Documents",
		"/home/nemo/Documents/Shared",
		"/home/nemo/Music",
		"/home/nemo/Music/GoodArtist",
		"/home",
		"/usr",
		"/",
		"/media/sdcard/Music/GoodArtist",

		NULL
	};
	int i;

	blacklist_clear();

	for (i = 0; test_blacklists[i]; i++) {
		char tmplate[] = "/tmp/test-jolla-blacklist.XXXXXX";
		int fd = mkstemp(tmplate);
		g_assert_cmpint(fd, >=, 0);
		g_assert(g_file_set_contents(tmplate,
						test_blacklists[i],
						strlen(test_blacklists[i]),
						NULL) == TRUE);
		g_assert(blacklist_add(test_blacklist_roots[i], tmplate) == 0);

		close(fd);
		unlink(tmplate);
	}

	for (i = 0; matching_paths[i]; i++)
		g_assert(blacklist_match(matching_paths[i]) == TRUE);

	for (i = 0; non_matching_paths[i]; i++)
		g_assert(blacklist_match(non_matching_paths[i]) == FALSE);

	g_assert(blacklist_match(NULL) == FALSE);
	g_assert(blacklist_match("not/absolute/path") == FALSE);

	blacklist_clear();
}