Sysinfo Gadget: More thread vs object lifetime work: Make threads no longer dependent on the main loop objects and vice versa.

devs/bu5hm4n/debug_code
Stephen 'Okra' Houston 5 years ago
parent 139045c120
commit 5370793399
  1. 15
      src/modules/sysinfo/batman/batman.c
  2. 2
      src/modules/sysinfo/batman/batman_config.c
  3. 36
      src/modules/sysinfo/batman/batman_fallback.c
  4. 14
      src/modules/sysinfo/batman/batman_sysctl.c
  5. 8
      src/modules/sysinfo/batman/batman_udev.c
  6. 8
      src/modules/sysinfo/batman/batman_upower.c
  7. 131
      src/modules/sysinfo/cpuclock/cpuclock.c
  8. 2
      src/modules/sysinfo/cpuclock/cpuclock_config.c
  9. 131
      src/modules/sysinfo/cpumonitor/cpumonitor.c
  10. 4
      src/modules/sysinfo/cpumonitor/cpumonitor.h
  11. 21
      src/modules/sysinfo/cpumonitor/cpumonitor_proc.c
  12. 54
      src/modules/sysinfo/cpumonitor/cpumonitor_sysctl.c
  13. 81
      src/modules/sysinfo/memusage/memusage.c
  14. 4
      src/modules/sysinfo/memusage/memusage_sysctl.c
  15. 28
      src/modules/sysinfo/mod.c
  16. 175
      src/modules/sysinfo/netstatus/netstatus.c
  17. 8
      src/modules/sysinfo/netstatus/netstatus.h
  18. 2
      src/modules/sysinfo/netstatus/netstatus_config.c
  19. 96
      src/modules/sysinfo/netstatus/netstatus_proc.c
  20. 90
      src/modules/sysinfo/netstatus/netstatus_sysctl.c
  21. 35
      src/modules/sysinfo/sysinfo.c
  22. 27
      src/modules/sysinfo/sysinfo.h
  23. 60
      src/modules/sysinfo/thermal/thermal.c
  24. 2
      src/modules/sysinfo/thermal/thermal_config.c
  25. 8
      src/modules/sysinfo/thermal/thermal_fallback.c

@ -617,19 +617,6 @@ sysinfo_batman_remove(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNU
(void) inst;
_batman_fallback_stop();
#endif
inst->cfg->batman.done = EINA_TRUE;
if (inst->cfg->esm == E_SYSINFO_MODULE_SYSINFO)
{
if (inst->cfg->memusage.done && inst->cfg->thermal.done &&
inst->cfg->netstatus.done && inst->cfg->cpuclock.done && inst->cfg->cpumonitor.done)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, inst->cfg);
if (inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, inst);
E_FREE(inst->cfg);
E_FREE(inst);
}
}
}
static void
@ -678,7 +665,6 @@ sysinfo_batman_create(Evas_Object *parent, Instance *inst)
inst->cfg->batman.time_left = -2;
inst->cfg->batman.have_battery = -2;
inst->cfg->batman.have_power = -2;
inst->cfg->batman.done = EINA_FALSE;
inst->cfg->batman.o_gadget = elm_layout_add(parent);
e_theme_edje_object_set(inst->cfg->batman.o_gadget, "base/theme/gadget/batman",
@ -750,7 +736,6 @@ batman_create(Evas_Object *parent, int *id, E_Gadget_Site_Orient orient EINA_UNU
inst = E_NEW(Instance, 1);
inst->cfg = _conf_item_get(id);
*id = inst->cfg->id;
inst->cfg->batman.done = EINA_FALSE;
inst->o_main = elm_box_add(parent);
E_EXPAND(inst->o_main);
evas_object_data_set(inst->o_main, "Instance", inst);

@ -7,7 +7,7 @@ _config_close(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, voi
Instance *inst = bc->inst;
E_FREE_FUNC(inst->cfg->batman.configure, evas_object_del);
E_FREE_FUNC(bc, free);
E_FREE(bc);
e_config_save_queue();
}

@ -277,8 +277,8 @@ linux_sys_class_power_supply_cb_re_init(void *data)
// if (sysev->fd_handler)
// ecore_main_fd_handler_del(sysev->fd_handler);
// if (sysev->fd >= 0) close(sysev->fd);
free(sysev->name);
free(sysev);
E_FREE(sysev->name);
E_FREE(sysev);
}
}
linux_sys_class_power_supply_init();
@ -319,8 +319,8 @@ linux_sys_class_power_supply_cb_event_fd_active(void *data,
// if (sysev->fd_handler)
// ecore_main_fd_handler_del(sysev->fd_handler);
// if (sysev->fd >= 0) close(sysev->fd);
free(sysev->name);
free(sysev);
E_FREE(sysev->name);
E_FREE(sysev);
if (re_init_timer) ecore_timer_del(re_init_timer);
re_init_timer = ecore_timer_loop_add(1.0, linux_sys_class_power_supply_cb_re_init, NULL);
@ -476,7 +476,7 @@ linux_sys_class_power_supply_init(void)
if (!(linux_sys_class_power_supply_is_battery(name)))
{
free(name);
E_FREE(name);
continue;
}
sysev = (Sys_Class_Power_Supply_Uevent *)calloc(1, sizeof(Sys_Class_Power_Supply_Uevent));
@ -573,7 +573,7 @@ linux_sys_class_power_supply_check(void)
full = 1;
charging = 0;
}
free(tmp);
E_FREE(tmp);
}
/* some batteries can/will/want to predict how long they will
* last. if so - take what the battery says. too bad if it's
@ -825,7 +825,7 @@ linux_acpi_init(void)
if (tmp)
{
if (!strcmp(tmp, "on-line")) have_power = 1;
free(tmp);
E_FREE(tmp);
}
fclose(f);
}
@ -853,7 +853,7 @@ linux_acpi_init(void)
if (tmp)
{
if (!strcmp(tmp, "yes")) have_battery = 1;
free(tmp);
E_FREE(tmp);
}
/* design cap */
tmp = fgets(buf, sizeof(buf), f);
@ -861,7 +861,7 @@ linux_acpi_init(void)
if (tmp)
{
if (strcmp(tmp, "unknown")) acpi_max_design += atoi(tmp);
free(tmp);
E_FREE(tmp);
}
/* last full cap */
tmp = fgets(buf, sizeof(buf), f);
@ -869,7 +869,7 @@ linux_acpi_init(void)
if (tmp)
{
if (strcmp(tmp, "unknown")) acpi_max_full += atoi(tmp);
free(tmp);
E_FREE(tmp);
}
fclose(f);
}
@ -930,34 +930,34 @@ linux_acpi_check(void)
FILE *f;
snprintf(buf, sizeof(buf), "/proc/acpi/battery/%s/state", name);
free(name);
E_FREE(name);
f = fopen(buf, "r");
if (!f) continue;
tmp = file_str_entry_get(f, "present:");
if (!tmp) goto fclose_and_continue;
if (!strcasecmp(tmp, "yes")) have_battery = 1;
free(tmp);
E_FREE(tmp);
tmp = file_str_entry_get(f, "capacity state:");
if (!tmp) goto fclose_and_continue;
free(tmp);
E_FREE(tmp);
tmp = file_str_entry_get(f, "charging state:");
if (!tmp) goto fclose_and_continue;
if ((have_power == 0) && (!strcasecmp(tmp, "charging")))
have_power = 1;
free(tmp);
E_FREE(tmp);
tmp = file_str_entry_get(f, "present rate:");
if (!tmp) goto fclose_and_continue;
if (strcasecmp(tmp, "unknown")) rate += atoi(tmp);
free(tmp);
E_FREE(tmp);
tmp = file_str_entry_get(f, "remaining capacity:");
if (!tmp) goto fclose_and_continue;
if (strcasecmp(tmp, "unknown")) capacity += atoi(tmp);
free(tmp);
E_FREE(tmp);
fclose_and_continue:
fclose(f);
@ -1182,7 +1182,7 @@ fclose_and_continue:
}
}
free(name);
E_FREE(name);
}
if (max_charge > 0) battery_full = ((long long)charge * 100) / max_charge;
else battery_full = 0;
@ -1251,7 +1251,7 @@ dir_has_contents(const char *dir)
count = eina_list_count(bats);
EINA_LIST_FREE(bats, file)
free(file);
E_FREE(file);
if (count > 0) return 1;
return 0;
}

@ -144,8 +144,8 @@ _batman_sysctl_stop(void)
EINA_LIST_FREE(batman_device_ac_adapters, ac)
{
E_FREE_FUNC(ac->udi, eina_stringshare_del);
E_FREE_FUNC(ac->mib, free);
E_FREE_FUNC(ac, free);
E_FREE(ac->mib);
E_FREE(ac);
}
EINA_LIST_FREE(batman_device_batteries, bat)
@ -156,12 +156,12 @@ _batman_sysctl_stop(void)
E_FREE_FUNC(bat->vendor, eina_stringshare_del);
E_FREE_FUNC(bat->poll, ecore_poller_del);
#if defined(__FreeBSD__) || defined(__DragonFly__)
E_FREE_FUNC(bat->mib_state, free);
E_FREE_FUNC(bat->mib_time, free);
E_FREE_FUNC(bat->mib_units, free);
E_FREE(bat->mib_state);
E_FREE(bat->mib_time);
E_FREE(bat->mib_units);
#endif
E_FREE_FUNC(bat->mib, free);
E_FREE_FUNC(bat, free);
E_FREE(bat->mib);
E_FREE(bat);
}
}

@ -50,7 +50,7 @@ _batman_udev_stop(Instance *inst)
EINA_LIST_FREE(batman_device_ac_adapters, ac)
{
E_FREE_FUNC(ac, free);
E_FREE(ac);
}
EINA_LIST_FREE(batman_device_batteries, bat)
{
@ -59,7 +59,7 @@ _batman_udev_stop(Instance *inst)
eina_stringshare_del(bat->model);
eina_stringshare_del(bat->vendor);
E_FREE_FUNC(bat->poll, ecore_poller_del);
E_FREE_FUNC(bat, free);
E_FREE(bat);
}
}
@ -190,7 +190,7 @@ _batman_udev_battery_del(const char *syspath, Instance *inst)
eina_stringshare_del(bat->model);
eina_stringshare_del(bat->vendor);
E_FREE_FUNC(bat->poll, ecore_poller_del);
E_FREE_FUNC(bat, free);
E_FREE(bat);
}
}
eina_stringshare_del(syspath);
@ -214,7 +214,7 @@ _batman_udev_ac_del(const char *syspath, Instance *inst)
{
batman_device_ac_adapters = eina_list_remove_list(batman_device_ac_adapters, l);
eina_stringshare_del(ac->udi);
E_FREE_FUNC(ac, free);
E_FREE(ac);
}
}
eina_stringshare_del(syspath);

@ -31,7 +31,7 @@ _battery_free(Battery *bat)
eina_stringshare_del(bat->model);
if (bat->vendor)
eina_stringshare_del(bat->vendor);
free(bat);
E_FREE(bat);
}
static void
@ -43,7 +43,7 @@ _ac_free(Ac_Adapter *ac)
batman_device_ac_adapters = eina_list_remove(batman_device_ac_adapters, ac);
eina_stringshare_del(ac->udi);
free(ac);
E_FREE(ac);
}
static void
@ -244,7 +244,7 @@ _device_type_cb(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending E
else
goto error;
free(ud);
E_FREE(ud);
return;
@ -252,7 +252,7 @@ error:
obj = eldbus_proxy_object_get(ud->proxy);
eldbus_proxy_unref(ud->proxy);
eldbus_object_unref(obj);
free(ud);
E_FREE(ud);
return;
}

@ -44,16 +44,16 @@ _cpuclock_status_free(Cpu_Status *s)
{
Eina_List *l;
if (s->frequencies) eina_list_free(s->frequencies);
if (eina_list_count(s->frequencies)) eina_list_free(s->frequencies);
if (s->governors)
{
for (l = s->governors; l; l = l->next)
E_FREE_FUNC(l->data, free);
E_FREE(l->data);
eina_list_free(s->governors);
}
E_FREE_FUNC(s->cur_governor, free);
E_FREE(s->cur_governor);
if (s->orig_governor) eina_stringshare_del(s->orig_governor);
E_FREE_FUNC(s, free);
E_FREE(s);
}
static int
@ -370,7 +370,7 @@ _cpuclock_config_updated(Instance *inst)
for (l = inst->cfg->cpuclock.status->frequencies, i = 0; l; l = l->next, i++)
frequency_msg->val[i] = (long)l->data;
edje_object_message_send(elm_layout_edje_get(inst->cfg->cpuclock.o_gadget), EDJE_MESSAGE_INT_SET, 1, frequency_msg);
free(frequency_msg);
E_FREE(frequency_msg);
}
if (inst->cfg->cpuclock.status->governors)
@ -381,7 +381,7 @@ _cpuclock_config_updated(Instance *inst)
for (l = inst->cfg->cpuclock.status->governors, i = 0; l; l = l->next, i++)
governor_msg->str[i] = (char *)l->data;
edje_object_message_send(elm_layout_edje_get(inst->cfg->cpuclock.o_gadget), EDJE_MESSAGE_STRING_SET, 2, governor_msg);
free(governor_msg);
E_FREE(governor_msg);
}
_cpuclock_poll_interval_update(inst);
}
@ -402,7 +402,7 @@ _cpuclock_face_update_current(Instance *inst)
frequency_msg->val[4] = 0; // pad
edje_object_message_send(elm_layout_edje_get(inst->cfg->cpuclock.o_gadget), EDJE_MESSAGE_INT_SET, 3,
frequency_msg);
free(frequency_msg);
E_FREE(frequency_msg);
/* BSD crashes here without the if-condition
* since it has no governors (yet) */
@ -499,7 +499,7 @@ _cpuclock_status_check_available(Cpu_Status *s)
if (s->governors)
{
for (l = s->governors; l; l = l->next)
free(l->data);
E_FREE(l->data);
eina_list_free(s->governors);
s->governors = NULL;
}
@ -586,7 +586,7 @@ _cpuclock_status_check_available(Cpu_Status *s)
if (s->governors)
{
for (l = s->governors; l; l = l->next)
free(l->data);
E_FREE(l->data);
eina_list_free(s->governors);
s->governors = NULL;
}
@ -749,7 +749,7 @@ _cpuclock_status_check_current(Cpu_Status *s)
{
ret = 1;
free(s->cur_governor);
E_FREE(s->cur_governor);
s->cur_governor = strdup(buf);
for (i = strlen(s->cur_governor) - 1; i >= 0; i--)
@ -845,37 +845,36 @@ _cpuclock_cb_frequency_check_notify(void *data,
Eina_Bool freq_changed = EINA_FALSE;
Eina_Bool init_set = EINA_FALSE;
Thread_Config *thc = data;
Instance *inst = thc->inst;
if (!inst->cfg) return;
if (inst->cfg->esm != E_SYSINFO_MODULE_CPUCLOCK && inst->cfg->esm != E_SYSINFO_MODULE_SYSINFO) return;
if (!thc->inst && !thc->inst->cfg) return;
if (thc->inst->cfg->esm != E_SYSINFO_MODULE_CPUCLOCK && thc->inst->cfg->esm != E_SYSINFO_MODULE_SYSINFO) return;
if ((inst->cfg->cpuclock.status) && (status) &&
if ((thc->inst->cfg->cpuclock.status) && (status) &&
(
#if defined(__OpenBSD__)
(status->cur_percent != inst->cfg->cpuclock.status->cur_percent ) ||
(status->cur_percent != thc->inst->cfg->cpuclock.status->cur_percent ) ||
#endif
(status->cur_frequency != inst->cfg->cpuclock.status->cur_frequency ) ||
(status->cur_min_frequency != inst->cfg->cpuclock.status->cur_min_frequency) ||
(status->cur_max_frequency != inst->cfg->cpuclock.status->cur_max_frequency) ||
(status->can_set_frequency != inst->cfg->cpuclock.status->can_set_frequency)))
(status->cur_frequency != thc->inst->cfg->cpuclock.status->cur_frequency ) ||
(status->cur_min_frequency != thc->inst->cfg->cpuclock.status->cur_min_frequency) ||
(status->cur_max_frequency != thc->inst->cfg->cpuclock.status->cur_max_frequency) ||
(status->can_set_frequency != thc->inst->cfg->cpuclock.status->can_set_frequency)))
freq_changed = EINA_TRUE;
E_FREE_FUNC(inst->cfg->cpuclock.status, _cpuclock_status_free);
inst->cfg->cpuclock.status = status;
E_FREE_FUNC(thc->inst->cfg->cpuclock.status, _cpuclock_status_free);
thc->inst->cfg->cpuclock.status = status;
if (freq_changed)
{
_cpuclock_face_update_current(inst);
_cpuclock_face_update_current(thc->inst);
}
if (inst->cfg->cpuclock.status->active == 0)
elm_layout_signal_emit(inst->cfg->cpuclock.o_gadget, "e,state,disabled", "e");
else if (inst->cfg->cpuclock.status->active == 1)
elm_layout_signal_emit(inst->cfg->cpuclock.o_gadget, "e,state,enabled", "e");
if (thc->inst->cfg->cpuclock.status->active == 0)
elm_layout_signal_emit(thc->inst->cfg->cpuclock.o_gadget, "e,state,disabled", "e");
else if (thc->inst->cfg->cpuclock.status->active == 1)
elm_layout_signal_emit(thc->inst->cfg->cpuclock.o_gadget, "e,state,enabled", "e");
if (!init_set)
{
_cpuclock_set_pstate(inst->cfg->cpuclock.pstate_min - 1,
inst->cfg->cpuclock.pstate_max - 1,
inst->cfg->cpuclock.status->pstate_turbo);
_cpuclock_set_pstate(thc->inst->cfg->cpuclock.pstate_min - 1,
thc->inst->cfg->cpuclock.pstate_max - 1,
thc->inst->cfg->cpuclock.status->pstate_turbo);
init_set = EINA_TRUE;
}
}
@ -884,38 +883,9 @@ static void
_cpuclock_cb_frequency_check_end(void *data, Ecore_Thread *th EINA_UNUSED)
{
Thread_Config *thc = data;
e_powersave_sleeper_free(thc->sleeper);
if (thc->inst->cfg->cpuclock.defer)
{
if (thc->inst->cfg->cpuclock.handler)
ecore_event_handler_del(thc->inst->cfg->cpuclock.handler);
if (thc->inst->cfg->cpuclock.governor)
eina_stringshare_del(thc->inst->cfg->cpuclock.governor);
E_FREE_FUNC(thc->inst->cfg->cpuclock.status, _cpuclock_status_free);
thc->inst->cfg->cpuclock.defer = EINA_FALSE;
thc->inst->cfg->cpuclock.done = EINA_TRUE;
if (thc->inst->cfg->esm == E_SYSINFO_MODULE_CPUCLOCK)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, thc->inst->cfg);
if (thc->inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, thc->inst);
E_FREE(thc->inst->cfg);
E_FREE(thc->inst);
}
else
{
if (thc->inst->cfg->memusage.done && thc->inst->cfg->thermal.done &&
thc->inst->cfg->netstatus.done && thc->inst->cfg->cpumonitor.done && thc->inst->cfg->batman.done)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, thc->inst->cfg);
if (thc->inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, thc->inst);
E_FREE(thc->inst->cfg);
E_FREE(thc->inst);
}
}
}
E_FREE_FUNC(thc, free);
E_FREE(thc);
}
EINTERN void
@ -987,13 +957,10 @@ _cpuclock_removed_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_data)
_cpuclock_removed_cb, inst);
if (inst->cfg->cpuclock.frequency_check_thread)
{
inst->cfg->cpuclock.defer = EINA_TRUE;
ecore_thread_cancel(inst->cfg->cpuclock.frequency_check_thread);
inst->cfg->cpuclock.frequency_check_thread = NULL;
return;
}
if (inst->cfg->cpuclock.handler)
ecore_event_handler_del(inst->cfg->cpuclock.handler);
if (inst->cfg->cpuclock.governor)
eina_stringshare_del(inst->cfg->cpuclock.governor);
E_FREE_FUNC(inst->cfg->cpuclock.status, _cpuclock_status_free);
@ -1021,31 +988,13 @@ sysinfo_cpuclock_remove(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_U
ecore_event_handler_del(handler);
if (inst->cfg->cpuclock.frequency_check_thread)
{
inst->cfg->cpuclock.defer = EINA_TRUE;
ecore_thread_cancel(inst->cfg->cpuclock.frequency_check_thread);
inst->cfg->cpuclock.frequency_check_thread = NULL;
return;
}
if (inst->cfg->cpuclock.handler)
ecore_event_handler_del(inst->cfg->cpuclock.handler);
if (inst->cfg->cpuclock.governor)
eina_stringshare_del(inst->cfg->cpuclock.governor);
E_FREE_FUNC(inst->cfg->cpuclock.status, _cpuclock_status_free);
inst->cfg->cpuclock.done = EINA_TRUE;
if (inst->cfg->esm == E_SYSINFO_MODULE_SYSINFO)
{
if (inst->cfg->memusage.done && inst->cfg->thermal.done &&
inst->cfg->netstatus.done && inst->cfg->cpumonitor.done && inst->cfg->batman.done)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, inst->cfg);
if (inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, inst);
E_FREE(inst->cfg);
E_FREE(inst);
}
}
}
static void
@ -1084,13 +1033,13 @@ _cpuclock_created_cb(void *data, Evas_Object *obj, void *event_data EINA_UNUSED)
evas_object_show(inst->cfg->cpuclock.o_gadget);
evas_object_smart_callback_del_full(obj, "gadget_created", _cpuclock_created_cb, data);
inst->cfg->cpuclock.status = _cpuclock_status_new();
_cpuclock_status_check_available(inst->cfg->cpuclock.status);
E_LIST_HANDLER_APPEND(inst->cfg->cpuclock.handlers, E_EVENT_SCREENSAVER_ON, _screensaver_on, inst);
E_LIST_HANDLER_APPEND(inst->cfg->cpuclock.handlers, E_EVENT_SCREENSAVER_OFF, _screensaver_off, inst);
E_LIST_HANDLER_APPEND(inst->cfg->cpuclock.handlers, E_EVENT_POWERSAVE_UPDATE, _cpuclock_event_cb_powersave, inst);
inst->cfg->cpuclock.status = _cpuclock_status_new();
_cpuclock_status_check_available(inst->cfg->cpuclock.status);
inst->cfg->cpuclock.handler = ecore_event_handler_add(E_EVENT_POWERSAVE_UPDATE,
_cpuclock_event_cb_powersave, inst);
_cpuclock_config_updated(inst);
if ((inst->cfg->cpuclock.restore_governor) && (inst->cfg->cpuclock.governor))
{
@ -1110,8 +1059,6 @@ sysinfo_cpuclock_create(Evas_Object *parent, Instance *inst)
{
Eina_List *l = NULL;
inst->cfg->cpuclock.defer = EINA_FALSE;
inst->cfg->cpuclock.done = EINA_FALSE;
if (inst->cfg->cpuclock.pstate_min == 0) inst->cfg->cpuclock.pstate_min = 1;
if (inst->cfg->cpuclock.pstate_max == 0) inst->cfg->cpuclock.pstate_max = 101;
@ -1132,13 +1079,13 @@ sysinfo_cpuclock_create(Evas_Object *parent, Instance *inst)
evas_object_event_callback_add(inst->cfg->cpuclock.o_gadget, EVAS_CALLBACK_RESIZE, _cpuclock_resize_cb, inst);
evas_object_show(inst->cfg->cpuclock.o_gadget);
inst->cfg->cpuclock.status = _cpuclock_status_new();
_cpuclock_status_check_available(inst->cfg->cpuclock.status);
E_LIST_HANDLER_APPEND(inst->cfg->cpuclock.handlers, E_EVENT_SCREENSAVER_ON, _screensaver_on, inst);
E_LIST_HANDLER_APPEND(inst->cfg->cpuclock.handlers, E_EVENT_SCREENSAVER_OFF, _screensaver_off, inst);
E_LIST_HANDLER_APPEND(inst->cfg->cpuclock.handlers, E_EVENT_POWERSAVE_UPDATE, _cpuclock_event_cb_powersave, inst);
inst->cfg->cpuclock.status = _cpuclock_status_new();
_cpuclock_status_check_available(inst->cfg->cpuclock.status);
inst->cfg->cpuclock.handler = ecore_event_handler_add(E_EVENT_POWERSAVE_UPDATE,
_cpuclock_event_cb_powersave, inst);
_cpuclock_config_updated(inst);
if ((inst->cfg->cpuclock.restore_governor) && (inst->cfg->cpuclock.governor))
{
@ -1197,8 +1144,6 @@ cpuclock_create(Evas_Object *parent, int *id, E_Gadget_Site_Orient orient EINA_U
inst = E_NEW(Instance, 1);
inst->cfg = _conf_item_get(id);
*id = inst->cfg->id;
inst->cfg->cpuclock.defer = EINA_FALSE;
inst->cfg->cpuclock.done = EINA_FALSE;
inst->o_main = elm_box_add(parent);
E_EXPAND(inst->o_main);
evas_object_data_set(inst->o_main, "Instance", inst);

@ -8,7 +8,7 @@ _config_close(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, voi
E_FREE_FUNC(inst->cfg->cpuclock.configure, evas_object_del);
E_FREE_FUNC(cc->powersaves, eina_list_free);
E_FREE_FUNC(cc, free);
E_FREE(cc);
e_config_save_queue();
}

@ -5,18 +5,22 @@ typedef struct _Thread_Config Thread_Config;
struct _Thread_Config
{
int interval;
int cores;
int num_cores;
int percent;
unsigned long total;
unsigned long idle;
Instance *inst;
E_Powersave_Sleeper *sleeper;
Eina_List *cores;
};
static void
_cpumonitor_face_update(Instance *inst)
_cpumonitor_face_update(Thread_Config *thc)
{
Eina_List *l;
CPU_Core *core;
EINA_LIST_FOREACH(inst->cfg->cpumonitor.cores, l, core)
EINA_LIST_FOREACH(thc->cores, l, core)
{
Edje_Message_Int_Set *usage_msg;
usage_msg = malloc(sizeof(Edje_Message_Int_Set) + 1 * sizeof(int));
@ -25,12 +29,12 @@ _cpumonitor_face_update(Instance *inst)
usage_msg->val[0] = core->percent;
edje_object_message_send(elm_layout_edje_get(core->layout), EDJE_MESSAGE_INT_SET, 1,
usage_msg);
free(usage_msg);
E_FREE(usage_msg);
}
if (inst->cfg->cpumonitor.popup)
if (thc->inst->cfg->cpumonitor.popup)
{
elm_progressbar_value_set(inst->cfg->cpumonitor.popup_pbar,
(float)inst->cfg->cpumonitor.percent / 100);
elm_progressbar_value_set(thc->inst->cfg->cpumonitor.popup_pbar,
(float)thc->percent / 100);
}
}
@ -123,7 +127,7 @@ _cpumonitor_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *e
{
Evas_Coord w = 1, h = 1, sw, sh;
Instance *inst = data;
int num_cores = eina_list_count(inst->cfg->cpumonitor.cores);
int num_cores = inst->cfg->cpumonitor.cores;
if (!num_cores || !inst->o_main) return;
@ -164,9 +168,9 @@ _cpumonitor_cb_usage_check_main(void *data, Ecore_Thread *th)
{
if (ecore_thread_check(th)) break;
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
_cpumonitor_sysctl_getusage(thc->inst);
_cpumonitor_sysctl_getusage(&thc->total, &thc->idle, &thc->percent, thc->cores);
#else
_cpumonitor_proc_getusage(thc->inst);
_cpumonitor_proc_getusage(&thc->total, &thc->idle, &thc->percent, thc->cores);
#endif
ecore_thread_feedback(th, NULL);
if (ecore_thread_check(th)) break;
@ -185,12 +189,11 @@ _cpumonitor_cb_usage_check_notify(void *data,
void *msg EINA_UNUSED)
{
Thread_Config *thc = data;
Instance *inst = thc->inst;
if (!inst->cfg) return;
if (inst->cfg->esm != E_SYSINFO_MODULE_CPUMONITOR && inst->cfg->esm != E_SYSINFO_MODULE_SYSINFO) return;
_cpumonitor_face_update(inst);
if (!thc->inst || !thc->inst->cfg) return;
if (thc->inst->cfg->esm != E_SYSINFO_MODULE_CPUMONITOR && thc->inst->cfg->esm != E_SYSINFO_MODULE_SYSINFO) return;
thc->inst->cfg->cpumonitor.percent = thc->percent;
_cpumonitor_face_update(thc);
}
static void
@ -200,37 +203,12 @@ _cpumonitor_cb_usage_check_end(void *data, Ecore_Thread *th EINA_UNUSED)
CPU_Core *core;
e_powersave_sleeper_free(thc->sleeper);
if (thc->inst->cfg->cpumonitor.defer)
EINA_LIST_FREE(thc->cores, core)
{
EINA_LIST_FREE(thc->inst->cfg->cpumonitor.cores, core)
{
evas_object_del(core->layout);
E_FREE_FUNC(core, free);
}
thc->inst->cfg->cpumonitor.defer = EINA_FALSE;
thc->inst->cfg->cpumonitor.done = EINA_TRUE;
if (thc->inst->cfg->esm == E_SYSINFO_MODULE_CPUMONITOR)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, thc->inst->cfg);
if (thc->inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, thc->inst);
E_FREE(thc->inst->cfg);
E_FREE(thc->inst);
}
else
{
if (thc->inst->cfg->memusage.done && thc->inst->cfg->thermal.done &&
thc->inst->cfg->netstatus.done && thc->inst->cfg->cpuclock.done && thc->inst->cfg->batman.done)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, thc->inst->cfg);
if (thc->inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, thc->inst);
E_FREE(thc->inst->cfg);
E_FREE(thc->inst);
}
}
evas_object_del(core->layout);
E_FREE(core);
}
E_FREE_FUNC(thc, free);
E_FREE(thc);
}
Evas_Object *
@ -259,15 +237,9 @@ static Eina_Bool
_screensaver_on(void *data)
{
Instance *inst = data;
CPU_Core *core;
if (inst->cfg->cpumonitor.usage_check_thread)
{
EINA_LIST_FREE(inst->cfg->cpumonitor.cores, core)
{
evas_object_del(core->layout);
E_FREE_FUNC(core, free);
}
ecore_thread_cancel(inst->cfg->cpumonitor.usage_check_thread);
inst->cfg->cpumonitor.usage_check_thread = NULL;
}
@ -293,11 +265,6 @@ _cpumonitor_config_updated(Instance *inst)
if (inst->cfg->cpumonitor.usage_check_thread)
{
EINA_LIST_FREE(inst->cfg->cpumonitor.cores, core)
{
evas_object_del(core->layout);
E_FREE_FUNC(core, free);
}
ecore_thread_cancel(inst->cfg->cpumonitor.usage_check_thread);
inst->cfg->cpumonitor.usage_check_thread = NULL;
}
@ -305,14 +272,17 @@ _cpumonitor_config_updated(Instance *inst)
if (thc)
{
thc->inst = inst;
thc->total = 0;
thc->idle = 0;
thc->percent = 0;
thc->interval = inst->cfg->cpumonitor.poll_interval;
thc->sleeper = e_powersave_sleeper_new();
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
thc->cores = _cpumonitor_sysctl_getcores();
thc->num_cores = _cpumonitor_sysctl_getcores();
#else
thc->cores = _cpumonitor_proc_getcores();
thc->num_cores = _cpumonitor_proc_getcores();
#endif
for (i = 0; i < thc->cores; i++)
for (i = 0; i < thc->num_cores; i++)
{
core = E_NEW(CPU_Core, 1);
core->layout = _cpumonitor_add_layout(inst);
@ -321,7 +291,7 @@ _cpumonitor_config_updated(Instance *inst)
core->percent = 0;
core->total = 0;
core->idle = 0;
inst->cfg->cpumonitor.cores = eina_list_append(inst->cfg->cpumonitor.cores, core);
thc->cores = eina_list_append(thc->cores, core);
}
inst->cfg->cpumonitor.usage_check_thread =
ecore_thread_feedback_run(_cpumonitor_cb_usage_check_main,
@ -336,7 +306,6 @@ static void
_cpumonitor_removed_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_data)
{
Instance *inst = data;
CPU_Core *core;
Ecore_Event_Handler *handler;
if (inst->o_main != event_data) return;
@ -347,23 +316,14 @@ _cpumonitor_removed_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_dat
E_FREE_FUNC(inst->cfg->cpumonitor.configure, evas_object_del);
EINA_LIST_FREE(inst->cfg->cpumonitor.handlers, handler)
ecore_event_handler_del(handler);
EINA_LIST_FREE(inst->cfg->cpumonitor.cores, core)
evas_object_smart_callback_del_full(e_gadget_site_get(inst->o_main), "gadget_removed",
_cpumonitor_removed_cb, inst);
evas_object_event_callback_del_full(inst->o_main, EVAS_CALLBACK_DEL, sysinfo_cpumonitor_remove, data);
if (inst->cfg->cpumonitor.usage_check_thread)
{
inst->cfg->cpumonitor.defer = EINA_TRUE;
ecore_thread_cancel(inst->cfg->cpumonitor.usage_check_thread);
inst->cfg->cpumonitor.usage_check_thread = NULL;
return;
}
EINA_LIST_FREE(inst->cfg->cpumonitor.cores, core)
{
evas_object_del(core->layout);
E_FREE_FUNC(core, free);
}
sysinfo_config->items = eina_list_remove(sysinfo_config->items, inst->cfg);
if (inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, inst);
@ -375,7 +335,6 @@ void
sysinfo_cpumonitor_remove(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_data EINA_UNUSED)
{
Instance *inst = data;
CPU_Core *core;
Ecore_Event_Handler *handler;
if (inst->cfg->cpumonitor.popup)
@ -386,28 +345,8 @@ sysinfo_cpumonitor_remove(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA
ecore_event_handler_del(handler);
if (inst->cfg->cpumonitor.usage_check_thread)
{
inst->cfg->cpumonitor.defer = EINA_TRUE;
ecore_thread_cancel(inst->cfg->cpumonitor.usage_check_thread);
inst->cfg->cpumonitor.usage_check_thread = NULL;
return;
}
EINA_LIST_FREE(inst->cfg->cpumonitor.cores, core)
{
evas_object_del(core->layout);
E_FREE_FUNC(core, free);
}
inst->cfg->cpumonitor.done = EINA_TRUE;
if (inst->cfg->esm == E_SYSINFO_MODULE_SYSINFO)
{
if (inst->cfg->memusage.done && inst->cfg->thermal.done &&
inst->cfg->netstatus.done && inst->cfg->cpuclock.done && inst->cfg->batman.done)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, inst->cfg);
if (inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, inst);
E_FREE(inst->cfg);
E_FREE(inst);
}
}
}
@ -455,10 +394,6 @@ _cpumonitor_created_cb(void *data, Evas_Object *obj, void *event_data EINA_UNUSE
Evas_Object *
sysinfo_cpumonitor_create(Evas_Object *parent, Instance *inst)
{
inst->cfg->cpumonitor.defer = EINA_FALSE;
inst->cfg->cpumonitor.done = EINA_FALSE;
inst->cfg->cpumonitor.total = 0;
inst->cfg->cpumonitor.idle = 0;
inst->cfg->cpumonitor.percent = 0;
inst->cfg->cpumonitor.popup = NULL;
inst->cfg->cpumonitor.configure = NULL;
@ -514,9 +449,6 @@ _conf_item_get(int *id)
ci->esm = E_SYSINFO_MODULE_CPUMONITOR;
ci->cpumonitor.poll_interval = 32;
ci->cpumonitor.total = 0;
ci->cpumonitor.percent = 0;
ci->cpumonitor.idle = 0;
ci->cpumonitor.popup = NULL;
ci->cpumonitor.configure = NULL;
sysinfo_config->items = eina_list_append(sysinfo_config->items, ci);
@ -532,11 +464,6 @@ cpumonitor_create(Evas_Object *parent, int *id, E_Gadget_Site_Orient orient EINA
inst = E_NEW(Instance, 1);
inst->cfg = _conf_item_get(id);
*id = inst->cfg->id;
inst->cfg->cpumonitor.defer = EINA_FALSE;
inst->cfg->cpumonitor.done = EINA_FALSE;
inst->cfg->cpumonitor.total = 0;
inst->cfg->cpumonitor.idle = 0;
inst->cfg->cpumonitor.percent = 0;
inst->cfg->cpumonitor.popup = NULL;
inst->cfg->cpumonitor.configure = NULL;
inst->o_main = elm_box_add(parent);

@ -5,8 +5,8 @@
EINTERN void _cpumonitor_config_updated(Instance *inst);
EINTERN int _cpumonitor_proc_getcores(void);
EINTERN void _cpumonitor_proc_getusage(Instance *inst);
EINTERN int _cpumonitor_sysctl_getcores(void);
EINTERN void _cpumonitor_proc_getusage(unsigned long *prev_total, unsigned long *prev_idle, int *prev_precent, Eina_List *cores);
EINTERN int _cpumonitor_sysctl_getcores(unsigned long *prev_total, unsigned long *prev_idle, int *prev_precent, Eina_List *cores);
EINTERN void _cpumonitor_sysctl_getusage(Instance *inst);
EINTERN Evas_Object *cpumonitor_configure(Instance *inst);
#endif

@ -28,7 +28,10 @@ _cpumonitor_proc_getcores(void)
}
void
_cpumonitor_proc_getusage(Instance *inst)
_cpumonitor_proc_getusage(unsigned long *prev_total,
unsigned long *prev_idle,
int *prev_percent,
Eina_List *cores)
{
int k = 0, j = 0;
char buf[4096];
@ -42,7 +45,7 @@ _cpumonitor_proc_getusage(Instance *inst)
{
if (k == 0)
{
long total = 0, idle = 0, use = 0, total_change = 0, idle_change = 0;
unsigned long total = 0, idle = 0, use = 0, total_change = 0, idle_change = 0;
int percent = 0;
char *line, *tok;
int i = 0;
@ -58,19 +61,19 @@ _cpumonitor_proc_getusage(Instance *inst)
idle = use;
tok = strtok(NULL, " ");
}
total_change = total - inst->cfg->cpumonitor.total;
idle_change = idle - inst->cfg->cpumonitor.idle;
total_change = total - *prev_total;
idle_change = idle - *prev_idle;
if (total_change != 0)
percent = 100 * (1 - ((float)idle_change / (float)total_change));
if (percent > 100) percent = 100;
else if (percent < 0) percent = 0;
inst->cfg->cpumonitor.total = total;
inst->cfg->cpumonitor.idle = idle;
inst->cfg->cpumonitor.percent = percent;
*prev_total = total;
*prev_idle = idle;
*prev_percent = percent;
}
if (k > 0)
{
long total = 0, idle = 0, use = 0, total_change = 0, idle_change = 0;
unsigned long total = 0, idle = 0, use = 0, total_change = 0, idle_change = 0;
int percent = 0;
if (!strncmp(buf, "cpu", 3))
{
@ -89,7 +92,7 @@ _cpumonitor_proc_getusage(Instance *inst)
}
}
else break;
core = eina_list_nth(inst->cfg->cpumonitor.cores, j);
core = eina_list_nth(cores, j);
total_change = total - core->total;
idle_change = idle - core->idle;
if (total_change != 0)

@ -27,7 +27,7 @@ _cpumonitor_sysctl_getcores(void)
void
_cpumonitor_sysctl_getusage(Instance *inst)
_cpumonitor_sysctl_getusage(unsigned long *prev_total, unsigned long *prev_idle, int *prev_precent, Eina_List *cores)
{
CPU_Core *core;
size_t size;
@ -36,21 +36,21 @@ _cpumonitor_sysctl_getusage(Instance *inst)
#if defined(__FreeBSD__) || defined(__DragonFly__)
int ncpu = _cpumonitor_sysctl_getcores();
if (!ncpu) return;
size = sizeof(long) * (CPU_STATES * ncpu);
long cpu_times[ncpu][CPU_STATES];
size = sizeof(unsigned long) * (CPU_STATES * ncpu);
unsigned long cpu_times[ncpu][CPU_STATES];
if (sysctlbyname("kern.cp_times", cpu_times, &size, NULL, 0) < 0)
return;
for (i = 0; i < ncpu; i++)
{
long *cpu = cpu_times[i];
unsigned long *cpu = cpu_times[i];
double total = 0;
for (j = 0; j < CPU_STATES; j++)
total += cpu[j];
core = eina_list_nth(inst->cfg->cpumonitor.cores, i);
core = eina_list_nth(cores, i);
int diff_total = total - core->total;
int diff_idle = cpu[4] - core->idle;
@ -58,7 +58,7 @@ _cpumonitor_sysctl_getusage(Instance *inst)
if (diff_total == 0) diff_total = 1;
double ratio = diff_total / 100.0;
long used = diff_total - diff_idle;
unsigned long used = diff_total - diff_idle;
int percent = used / ratio;
if (percent > 100)
@ -74,59 +74,59 @@ _cpumonitor_sysctl_getusage(Instance *inst)
total_all += total;
idle_all += core->idle;
}
inst->cfg->cpumonitor.total = total_all / ncpu;
inst->cfg->cpumonitor.idle = idle_all / ncpu;
inst->cfg->cpumonitor.percent = (int) (percent_all / ncpu);
*prev_total = total_all / ncpu;
*prev_idle = idle_all / ncpu;
*prev_percent = (int) (percent_all / ncpu);
#elif defined(__OpenBSD__)
int ncpu = _cpumonitor_sysctl_getcores();
if (!ncpu) return;
if (ncpu == 1)
{
long cpu_times[CPU_STATES];
unsigned long cpu_times[CPU_STATES];
int cpu_time_mib[] = { CTL_KERN, KERN_CPTIME };
size = CPU_STATES * sizeof(long);
size = CPU_STATES * sizeof(unsigned long);
if (sysctl(cpu_time_mib, 2, &cpu_times, &size, NULL, 0) < 0)
return;
long total = 0;
unsigned long total = 0;
for (j = 0; j < CPU_STATES; j++)
total += cpu_times[j];
long idle = cpu_times[4];
unsigned long idle = cpu_times[4];
int diff_total = total - inst->cfg->cpumonitor.total;
int diff_idle = idle - inst->cfg->cpumonitor.idle;
int diff_total = total - *prev_total;
int diff_idle = idle - *prev_idle;
if (diff_total == 0) diff_total = 1;
double ratio = diff_total / 100.0;
long used = diff_total - diff_idle;
unsigned long used = diff_total - diff_idle;
int percent = used / ratio;
if (percent > 100)
percent = 100;
else if (percent < 0)
percent = 0;
inst->cfg->cpumonitor.total = total;
inst->cfg->cpumonitor.idle = idle; // cpu_times[3];
inst->cfg->cpumonitor.percent = (int) percent;
*prev_total = total;
*prev_idle = idle; // cpu_times[3];
*prev_percent = (int) percent;
}
else if (ncpu > 1)
{
for (i = 0; i < ncpu; i++)
{
long cpu_times[CPU_STATES];
size = CPU_STATES * sizeof(long);
unsigned long cpu_times[CPU_STATES];
size = CPU_STATES * sizeof(unsigned long);
int cpu_time_mib[] = { CTL_KERN, KERN_CPTIME2, 0 };
cpu_time_mib[2] = i;
if (sysctl(cpu_time_mib, 3, &cpu_times, &size, NULL, 0) < 0)
return;
long total = 0;
unsigned long total = 0;
for (j = 0; j < CPU_STATES - 1; j++)
total += cpu_times[j];
core = eina_list_nth(inst->cfg->cpumonitor.cores, i);
core = eina_list_nth(cores, i);
int diff_total = total - core->total;
int diff_idle = cpu_times[4] - core->idle;
@ -135,7 +135,7 @@ _cpumonitor_sysctl_getusage(Instance *inst)
if (diff_total == 0) diff_total = 1;
double ratio = diff_total / 100;
long used = diff_total - diff_idle;
unsigned long used = diff_total - diff_idle;
int percent = used / ratio;
core->percent = percent;
@ -145,9 +145,9 @@ _cpumonitor_sysctl_getusage(Instance *inst)
idle_all += core->idle;
}
inst->cfg->cpumonitor.total = (total_all / ncpu);
inst->cfg->cpumonitor.idle = (idle_all / ncpu);
inst->cfg->cpumonitor.percent = (percent_all / ncpu) + (percent_all % ncpu);
*prev_total = (total_all / ncpu);
*prev_idle = (idle_all / ncpu);
*prev_percent = (percent_all / ncpu) + (percent_all % ncpu);
}
#endif
}

@ -94,7 +94,7 @@ _memusage_face_update(Instance *inst)
msg->val[8] = inst->cfg->memusage.swp_used;
edje_object_message_send(elm_layout_edje_get(inst->cfg->memusage.o_gadget),
EDJE_MESSAGE_INT_SET, 1, msg);
free(msg);
E_FREE(msg);
if (inst->cfg->memusage.popup)
_memusage_popup_update(inst);
@ -308,32 +308,7 @@ _memusage_cb_usage_check_end(void *data, Ecore_Thread *th EINA_UNUSED)
{
Thread_Config *thc = data;
e_powersave_sleeper_free(thc->sleeper);
if (thc->inst->cfg->memusage.defer)
{
thc->inst->cfg->memusage.defer = EINA_FALSE;
thc->inst->cfg->memusage.done = EINA_TRUE;
if (thc->inst->cfg->esm == E_SYSINFO_MODULE_MEMUSAGE)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, thc->inst->cfg);
if (thc->inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, thc->inst);
E_FREE(thc->inst->cfg);
E_FREE(thc->inst);
}
else
{
if (thc->inst->cfg->cpumonitor.done && thc->inst->cfg->thermal.done &&
thc->inst->cfg->netstatus.done && thc->inst->cfg->cpuclock.done && thc->inst->cfg->batman.done)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, thc->inst->cfg);
if (thc->inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, thc->inst);
E_FREE(thc->inst->cfg);