okra pushed a commit to branch master. http://git.enlightenment.org/core/enlightenment.git/commit/?id=20a96271ca5ce95e983b466b5a2efc4b35f60fc3
commit 20a96271ca5ce95e983b466b5a2efc4b35f60fc3 Author: Stephen 'Okra' Houston <smhousto...@gmail.com> Date: Tue Sep 12 12:10:38 2017 -0500 Update netstatus in/out in the same file read. Fix cpufreq to use powersave again. --- src/modules/cpufreq/e_mod_main.c | 17 ++++-- src/modules/sysinfo/netstatus/netstatus.c | 13 ++--- src/modules/sysinfo/netstatus/netstatus.h | 12 +++-- src/modules/sysinfo/netstatus/netstatus_proc.c | 67 +++++++----------------- src/modules/sysinfo/netstatus/netstatus_sysctl.c | 55 ++++++------------- 5 files changed, 65 insertions(+), 99 deletions(-) diff --git a/src/modules/cpufreq/e_mod_main.c b/src/modules/cpufreq/e_mod_main.c index e5b6cf5a3..f4ba259b6 100644 --- a/src/modules/cpufreq/e_mod_main.c +++ b/src/modules/cpufreq/e_mod_main.c @@ -1287,9 +1287,18 @@ typedef struct _Thread_Config Thread_Config; struct _Thread_Config { int interval; + E_Powersave_Sleeper *sleeper; }; static void +_cpufreq_cb_frequency_check_done(void *data, Ecore_Thread *th EINA_UNUSED) +{ + Thread_Config *thc = data; + e_powersave_sleeper_free(thc->sleeper); + free(thc); +} + +static void _cpufreq_cb_frequency_check_main(void *data, Ecore_Thread *th) { Thread_Config *thc = data; @@ -1304,9 +1313,8 @@ _cpufreq_cb_frequency_check_main(void *data, Ecore_Thread *th) else _cpufreq_status_free(status); if (ecore_thread_check(th)) break; - usleep((1000000.0 / 8.0) * (double)thc->interval); + e_powersave_sleeper_sleep(thc->sleeper, thc->interval); } - free(thc); } static void @@ -1380,10 +1388,13 @@ _cpufreq_poll_interval_update(void) if (thc) { thc->interval = cpufreq_config->poll_interval; + thc->sleeper = e_powersave_sleeper_new(); cpufreq_config->frequency_check_thread = ecore_thread_feedback_run(_cpufreq_cb_frequency_check_main, _cpufreq_cb_frequency_check_notify, - NULL, NULL, thc, EINA_TRUE); + _cpufreq_cb_frequency_check_done, + _cpufreq_cb_frequency_check_done, + thc, EINA_TRUE); } e_config_save_queue(); } diff --git a/src/modules/sysinfo/netstatus/netstatus.c b/src/modules/sysinfo/netstatus/netstatus.c index 0e87854a7..87ea74c18 100644 --- a/src/modules/sysinfo/netstatus/netstatus.c +++ b/src/modules/sysinfo/netstatus/netstatus.c @@ -7,14 +7,13 @@ struct _Thread_Config int interval; Instance *inst; Eina_Bool automax; + time_t checktime; int inpercent; - time_t intime; unsigned long in; unsigned long incurrent; unsigned long inmax; Eina_Stringshare *instring; int outpercent; - time_t outtime; unsigned long out; unsigned long outcurrent; unsigned long outmax; @@ -145,11 +144,13 @@ _netstatus_cb_usage_check_main(void *data, Ecore_Thread *th) if (ecore_thread_check(th)) break; #if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) - _netstatus_sysctl_getrstatus(thc->automax, &thc->in, &thc->incurrent, &thc->inmax, &thc->intime, &thc->inpercent); - _netstatus_sysctl_gettstatus(thc->automax, &thc->out, &thc->outcurrent, &thc->outmax, &thc->outtime, &thc->outpercent); + _netstatus_sysctl_getstatus(thc->automax, &thc->checktime, &thc->in, &thc->incurrent, + &thc->inmax, &thc->inpercent, &thc->out, &thc->outcurrent, &thc->outmax, + &thc->outpercent); #else - _netstatus_proc_getrstatus(thc->automax, &thc->in, &thc->incurrent, &thc->inmax, &thc->intime, &thc->inpercent); - _netstatus_proc_gettstatus(thc->automax, &thc->out, &thc->outcurrent, &thc->outmax, &thc->outtime, &thc->outpercent); + _netstatus_proc_getstatus(thc->automax, &thc->checktime, &thc->in, &thc->incurrent, + &thc->inmax, &thc->inpercent, &thc->out, &thc->outcurrent, &thc->outmax, + &thc->outpercent); #endif if (!thc->incurrent) { diff --git a/src/modules/sysinfo/netstatus/netstatus.h b/src/modules/sysinfo/netstatus/netstatus.h index 87010a04a..ee1a36f90 100644 --- a/src/modules/sysinfo/netstatus/netstatus.h +++ b/src/modules/sysinfo/netstatus/netstatus.h @@ -17,9 +17,13 @@ struct _Netstatus_Config }; EINTERN void _netstatus_config_updated(Instance *inst); -EINTERN void _netstatus_proc_getrstatus(Eina_Bool automax, unsigned long *prev_in, unsigned long *prev_incurrent, unsigned long *prev_inmax, time_t *last_checked, int *prev_inpercent); -EINTERN void _netstatus_proc_gettstatus(Eina_Bool automax, unsigned long *prev_out, unsigned long *prev_outcurrent, unsigned long *prev_outmax, time_t *last_checked, int *prev_outpercent); -EINTERN void _netstatus_sysctl_getrstatus(Eina_Bool automax, unsigned long *prev_in, unsigned long *prev_incurrent, unsigned long *prev_inmax, time_t *last_checked, int *prev_inpercent); -EINTERN void _netstatus_sysctl_gettstatus(Eina_Bool automax, unsigned long *prev_out, unsigned long *prev_outcurrent, unsigned long *prev_outmax, time_t *last_checked, int *prev_outpercent); +EINTERN void _netstatus_proc_getstatus(Eina_Bool automax, time_t *last_checked, + unsigned long *prev_in, unsigned long *prev_incurrent, unsigned long *prev_inmax, + int *prev_inpercent, unsigned long *prev_out, unsigned long *prev_outcurrent, + unsigned long *prev_outmax, int *prev_outpercent); +EINTERN void _netstatus_sysctl_getstatus(Eina_Bool automax, time_t *last_checked, + unsigned long *prev_in, unsigned long *prev_incurrent, unsigned long *prev_inmax, + int *prev_inpercent, unsigned long *prev_out, unsigned long *prev_outcurrent, + unsigned long *prev_outmax, int *prev_outpercent); EINTERN Evas_Object *netstatus_configure(Instance *inst); #endif diff --git a/src/modules/sysinfo/netstatus/netstatus_proc.c b/src/modules/sysinfo/netstatus/netstatus_proc.c index 1659ce471..1f9376ddf 100644 --- a/src/modules/sysinfo/netstatus/netstatus_proc.c +++ b/src/modules/sysinfo/netstatus/netstatus_proc.c @@ -1,15 +1,19 @@ #include "netstatus.h" void -_netstatus_proc_getrstatus(Eina_Bool automax, - unsigned long *prev_in, - unsigned long *prev_incurrent, - unsigned long *prev_inmax, - time_t *last_checked, - int *prev_inpercent) +_netstatus_proc_getstatus(Eina_Bool automax, + time_t *last_checked, + unsigned long *prev_in, + unsigned long *prev_incurrent, + unsigned long *prev_inmax, + int *prev_inpercent, + unsigned long *prev_out, + unsigned long *prev_outcurrent, + unsigned long *prev_outmax, + int *prev_outpercent) { - unsigned long in, dummy, tot_in = 0; - unsigned long diffin; + unsigned long in, out, dummy, tot_in = 0, tot_out = 0; + unsigned long diffin, diffout; int percent = 0; char buf[4096], dummys[64]; FILE *f; @@ -18,10 +22,11 @@ _netstatus_proc_getrstatus(Eina_Bool automax, if (!*last_checked) *last_checked = current; - else if ((current - *last_checked) < 1) + if ((current - *last_checked) < 1) return; else diff = current - *last_checked; + f = fopen("/proc/net/dev", "r"); if (f) { @@ -29,13 +34,15 @@ _netstatus_proc_getrstatus(Eina_Bool automax, { if (sscanf(buf, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu " "%lu %lu %lu %lu\n", dummys, &in, &dummy, &dummy, - &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, + &dummy, &dummy, &dummy, &dummy, &dummy, &out, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy) < 17) continue; tot_in += in; + tot_out += out; } fclose(f); } + diffin = tot_in - *prev_in; if (diff > 1) diffin /= diff; @@ -57,45 +64,9 @@ _netstatus_proc_getrstatus(Eina_Bool automax, percent = 0; *prev_inpercent = percent; } - *last_checked = current; -} -void -_netstatus_proc_gettstatus(Eina_Bool automax, - unsigned long *prev_out, - unsigned long *prev_outcurrent, - unsigned long *prev_outmax, - time_t *last_checked, - int *prev_outpercent) -{ - unsigned long out, dummy, tot_out = 0; - unsigned long diffout; - int percent = 0; - char buf[4096], dummys[64]; - FILE *f; - time_t current = time(NULL); - time_t diff = 0; + percent = 0; - if (!*last_checked) - *last_checked = current; - else if ((current - *last_checked) < 1) - return; - else - diff = current - *last_checked; - f = fopen("/proc/net/dev", "r"); - if (f) - { - while (fgets(buf, sizeof(buf), f) != NULL) - { - if (sscanf(buf, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu " - "%lu %lu %lu %lu\n", dummys, &dummy, &dummy, &dummy, - &dummy, &dummy, &dummy, &dummy, &dummy, &out, &dummy, - &dummy, &dummy, &dummy, &dummy, &dummy, &dummy) < 17) - continue; - tot_out += out; - } - fclose(f); - } diffout = tot_out - *prev_out; if (diff > 1) diffout /= diff; @@ -111,7 +82,7 @@ _netstatus_proc_gettstatus(Eina_Bool automax, } *prev_outcurrent = diffout; if (*prev_outcurrent > 0) - percent = 100 * ((float)*prev_outcurrent / (float)*prev_outmax); + percent = 100 * ((float)*prev_outcurrent / (float)*prev_outmax); if (percent > 100) percent = 100; else if (percent < 0) percent = 0; diff --git a/src/modules/sysinfo/netstatus/netstatus_sysctl.c b/src/modules/sysinfo/netstatus/netstatus_sysctl.c index 7d6776036..9caf2b0c3 100644 --- a/src/modules/sysinfo/netstatus/netstatus_sysctl.c +++ b/src/modules/sysinfo/netstatus/netstatus_sysctl.c @@ -107,14 +107,18 @@ _openbsd_generic_network_status(unsigned long int *in, unsigned long int *out) #endif void -_netstatus_sysctl_getrstatus(Eina_Bool automax, - unsigned long *prev_in, - unsigned long *prev_incurrent, - unsigned long *prev_inmax, - time_t *last_checked, - int *prev_inpercent) +_netstatus_sysctl_getstatus(Eina_Bool automax, + time_t *last_checked, + unsigned long *prev_in, + unsigned long *prev_incurrent, + unsigned long *prev_inmax, + int *prev_inpercent, + unsigned long *prev_out, + unsigned long *prev_outcurrent, + unsigned long *prev_outmax, + int *prev_outpercent) { - unsigned long tot_in = 0, diffin; + unsigned long tot_out = 0, tot_in = 0, diffin, diffout; int percent = 0; unsigned long int incoming = 0, outgoing = 0; time_t current = time(NULL); @@ -124,14 +128,16 @@ _netstatus_sysctl_getrstatus(Eina_Bool automax, #elif defined(__FreeBSD__) || defined(__DragonFly__) _freebsd_generic_network_status(&incoming, &outgoing); #endif - if (!*last_checked) *last_checked = current; - else if ((current - *last_checked) < 1) + if ((current - *last_checked) < 1) return; else diff = current - *last_checked; + tot_in = incoming; + tot_out = outgoing; + diffin = tot_in - *prev_in; if (diff > 1) diffin /= diff; @@ -153,35 +159,8 @@ _netstatus_sysctl_getrstatus(Eina_Bool automax, percent = 0; *prev_inpercent = percent; } - *last_checked = current; -} - -void -_netstatus_sysctl_gettstatus(Eina_Bool automax, - unsigned long *prev_out, - unsigned long *prev_outcurrent, - unsigned long *prev_outmax, - time_t *last_checked, - int *prev_outpercent) -{ - unsigned long tot_out = 0, diffout; - int percent = 0; - unsigned long int incoming = 0, outgoing = 0; - time_t current = time(NULL); - time_t diff = 0; -#if defined(__OpenBSD__) - _openbsd_generic_network_status(&incoming, &outgoing); -#elif defined(__FreeBSD__) || defined(__DragonFly__) - _freebsd_generic_network_status(&incoming, &outgoing); -#endif - tot_out = outgoing; - - if (!*last_checked) - *last_checked = current; - else if ((current - *last_checked) < 1) - return; - else - diff = current - *last_checked; + + percent = 0; diffout = tot_out - *prev_out; if (diff > 1) --