From 4ebe1d6b2bc615acbe28aa8defdeda2c71d1c57f Mon Sep 17 00:00:00 2001 From: Burt P Date: Sat, 3 Aug 2019 10:49:30 -0500 Subject: arm: use arm.ids for implementer/part lookup Signed-off-by: Burt P --- modules/devices/arm/arm_data.c | 112 +++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 71 deletions(-) (limited to 'modules/devices/arm/arm_data.c') diff --git a/modules/devices/arm/arm_data.c b/modules/devices/arm/arm_data.c index 60e8ea34..58779c08 100644 --- a/modules/devices/arm/arm_data.c +++ b/modules/devices/arm/arm_data.c @@ -81,47 +81,6 @@ static struct { { NULL, NULL } }; -static struct { - int code; char *name; -} tab_arm_implementer[] = { - { 0x41, "ARM" }, - { 0x44, "Intel (formerly DEC) StrongARM" }, - { 0x4e, "nVidia" }, - { 0x54, "Texas Instruments" }, - { 0x56, "Marvell" }, - { 0x69, "Intel XScale" }, - { 0, NULL}, -}; - -static struct { - /* source: t = tested, d = official docs, f = web */ - int code; char *part_desc; -} tab_arm_arm_part[] = { /* only valid for implementer 0x41 ARM */ - /*d */ { 0x920, "ARM920" }, - /*d */ { 0x926, "ARM926" }, - /*d */ { 0x946, "ARM946" }, - /*d */ { 0x966, "ARM966" }, - /*d */ { 0xb02, "ARM11 MPCore" }, - /*d */ { 0xb36, "ARM1136" }, - /*d */ { 0xb56, "ARM1156" }, - /*dt*/ { 0xb76, "ARM1176" }, - /*dt*/ { 0xc05, "Cortex-A5" }, - /*d */ { 0xc07, "Cortex-A7 MPCore" }, - /*dt*/ { 0xc08, "Cortex-A8" }, - /*dt*/ { 0xc09, "Cortex-A9" }, - /*d */ { 0xc0e, "Cortex-A17 MPCore" }, - /*d */ { 0xc0f, "Cortex-A15" }, - /*d */ { 0xd01, "Cortex-A32" }, - /*dt*/ { 0xd03, "Cortex-A53" }, - /*d */ { 0xd04, "Cortex-A35" }, - /*d */ { 0xd05, "Cortex-A55" }, - /*d */ { 0xd07, "Cortex-A57 MPCore" }, - /*d */ { 0xd08, "Cortex-A72" }, - /*d */ { 0xd09, "Cortex-A73" }, - /*d */ { 0xd0a, "Cortex-A75" }, - { 0, NULL}, -}; - static struct { char *code; char *name; char *more; } tab_arm_arch[] = { @@ -161,37 +120,47 @@ const char *arm_flag_meaning(const char *flag) { return NULL; } -static int code_match(int c0, const char* code1) { - int c1; - if (code1 == NULL) return 0; - c1 = strtol(code1, NULL, 0); - return (c0 == c1) ? 1 : 0; -} - -const char *arm_implementer(const char *code) { - int i = 0; - if (code) - while(tab_arm_implementer[i].code) { - if (code_match(tab_arm_implementer[i].code, code)) - return tab_arm_implementer[i].name; - i++; +#include "util_ids.h" + +gchar *arm_ids_file = NULL; + +void find_arm_ids_file() { + if (arm_ids_file) return; + char *file_search_order[] = { + g_build_filename(g_get_user_config_dir(), "hardinfo", "arm.ids", NULL), + g_build_filename(params.path_data, "arm.ids", NULL), + NULL + }; + int n; + for(n = 0; file_search_order[n]; n++) { + if (!access(file_search_order[n], R_OK)) + arm_ids_file = file_search_order[n]; + else + g_free(file_search_order[n]); } - return NULL; } -const char *arm_part(const char *imp_code, const char *part_code) { - int i = 0; - if (imp_code && part_code) { - if (code_match(0x41, imp_code)) { - /* 0x41=ARM parts */ - while(tab_arm_arm_part[i].code) { - if (code_match(tab_arm_arm_part[i].code, part_code)) - return tab_arm_arm_part[i].part_desc; - i++; - } - } - } - return NULL; +void arm_part(const char *imp_code, const char *part_code, char **imp, char **part) { + gchar *qpath = NULL; + ids_query_result result = {}; + unsigned int i,p; + + if (!arm_ids_file) + find_arm_ids_file(); + + i = strtol(imp_code, NULL, 0); + p = strtol(part_code, NULL, 0); + qpath = g_strdup_printf("%02x/%03x", i, p); + scan_ids_file(arm_ids_file, qpath, &result, -1); + g_free(qpath); + if (imp) + *imp = result.results[0] + ? g_strdup(result.results[0]) + : NULL; + if (part) + *part = result.results[1] + ? g_strdup(result.results[1]) + : NULL; } const char *arm_arch(const char *cpuinfo_arch_str) { @@ -229,8 +198,7 @@ char *arm_decoded_name(const char *imp, const char *part, const char *var, const * variant and revision can be rendered r{variant}p{revision} */ r = strtol(var, NULL, 0); p = strtol(rev, NULL, 0); - imp_name = (char*) arm_implementer(imp); - part_desc = (char*) arm_part(imp, part); + arm_part(imp, part, &imp_name, &part_desc); arch_name = (char*) arm_arch(arch); if (imp_name || part_desc) { if (arch_name != arch) @@ -251,6 +219,8 @@ char *arm_decoded_name(const char *imp, const char *part, const char *var, const (part_desc) ? part_desc : part, r, p, arch); } + g_free(imp_name); + g_free(part_desc); } else { /* prolly not ARM arch at all */ if (model_name) -- cgit v1.2.3 From a071cf575cafc3d8c15e4886fd65b8763086016f Mon Sep 17 00:00:00 2001 From: Burt P Date: Sat, 3 Aug 2019 13:15:12 -0500 Subject: auto_free: update with auto_free_on_exit(), use to free arm_ids_file in arm_data.c Signed-off-by: Burt P --- deps/sysobj_early/include/auto_free.h | 19 ++++++++--- deps/sysobj_early/src/auto_free.c | 61 ++++++++++++++++++++++++++--------- modules/devices/arm/arm_data.c | 2 +- 3 files changed, 60 insertions(+), 22 deletions(-) (limited to 'modules/devices/arm/arm_data.c') diff --git a/deps/sysobj_early/include/auto_free.h b/deps/sysobj_early/include/auto_free.h index e038783d..bddaa321 100644 --- a/deps/sysobj_early/include/auto_free.h +++ b/deps/sysobj_early/include/auto_free.h @@ -36,20 +36,29 @@ /* the minimum time between auto_free(p) and free(p) */ #define AF_DELAY_SECONDS 10 +#define AF_USE_SYSOBJ 0 + #if (DEBUG_AUTO_FREE > 0) -#define auto_free(p) auto_free_(p, __FILE__, __LINE__, __FUNCTION__) +#define auto_free(p) auto_free_ex_(p, (GDestroyNotify)g_free, __FILE__, __LINE__, __FUNCTION__) #define auto_free_ex(p, f) auto_free_ex_(p, f, __FILE__, __LINE__, __FUNCTION__) +#define auto_free_on_exit(p) auto_free_on_exit_ex_(p, (GDestroyNotify)g_free, __FILE__, __LINE__, __FUNCTION__) +#define auto_free_on_exit_ex(p, f) auto_free_on_exit_ex_(p, f, __FILE__, __LINE__, __FUNCTION__) #else -#define auto_free(p) auto_free_(p, NULL, 0, NULL) +#define auto_free(p) auto_free_ex_(p, (GDestroyNotify)g_free, NULL, 0, NULL) #define auto_free_ex(p, f) auto_free_ex_(p, f, NULL, 0, NULL) +#define auto_free_on_exit(p) auto_free_on_exit_ex_(p, (GDestroyNotify)g_free, NULL, 0, NULL) +#define auto_free_on_exit_ex(p, f) auto_free_on_exit_ex_(p, f, NULL, 0, NULL) #endif -gpointer auto_free_(gpointer p, const char *file, int line, const char *func); gpointer auto_free_ex_(gpointer p, GDestroyNotify f, const char *file, int line, const char *func); +gpointer auto_free_on_exit_ex_(gpointer p, GDestroyNotify f, const char *file, int line, const char *func); -/* free all the auto_free marked items in the current thread */ +/* free all the auto_free marked items in the + * current thread with age > AF_DELAY_SECONDS */ void free_auto_free(); -/* call at thread termination */ +/* call at thread termination: + * free all the auto_free marked items in the + * current thread regardless of age */ void free_auto_free_thread_final(); /* call at program termination */ diff --git a/deps/sysobj_early/src/auto_free.c b/deps/sysobj_early/src/auto_free.c index 78f11690..3d75c169 100644 --- a/deps/sysobj_early/src/auto_free.c +++ b/deps/sysobj_early/src/auto_free.c @@ -19,15 +19,26 @@ */ #include "auto_free.h" +#if (AF_USE_SYSOBJ) +#include "sysobj.h" +#else #include -//#include "sysobj.h" +#define sysobj_elapsed() af_elapsed() +#define sysobj_stats af_stats +static struct { + double auto_free_next; + unsigned long long + auto_freed, + auto_free_len; +} af_stats; +#endif static GMutex free_lock; static GSList *free_list = NULL; static gboolean free_final = FALSE; static GTimer *auto_free_timer = NULL; static guint free_event_source = 0; -#define _elapsed() (auto_free_timer ? g_timer_elapsed(auto_free_timer, NULL) : 0) +#define af_elapsed() (auto_free_timer ? g_timer_elapsed(auto_free_timer, NULL) : 0) #define auto_free_msg(msg, ...) fprintf (stderr, "[%s] " msg "\n", __FUNCTION__, ##__VA_ARGS__) /**/ @@ -49,7 +60,7 @@ gboolean free_auto_free_sf(gpointer trash) { return G_SOURCE_REMOVE; } free_auto_free(); - //sysobj_stats.auto_free_next = sysobj_elapsed() + AF_SECONDS; + sysobj_stats.auto_free_next = sysobj_elapsed() + AF_SECONDS; return G_SOURCE_CONTINUE; } @@ -73,7 +84,7 @@ gpointer auto_free_ex_(gpointer p, GDestroyNotify f, const char *file, int line, * will be called at sysobj_cleanup() and when exiting * threads, as in sysobj_foreach(). */ free_event_source = g_timeout_add_seconds(AF_SECONDS, (GSourceFunc)free_auto_free_sf, NULL); - //sysobj_stats.auto_free_next = sysobj_elapsed() + AF_SECONDS; + sysobj_stats.auto_free_next = sysobj_elapsed() + AF_SECONDS; } auto_free_item *z = g_new0(auto_free_item, 1); @@ -83,22 +94,41 @@ gpointer auto_free_ex_(gpointer p, GDestroyNotify f, const char *file, int line, z->file = file; z->line = line; z->func = func; - z->stamp = _elapsed(); + z->stamp = af_elapsed(); g_mutex_lock(&free_lock); free_list = g_slist_prepend(free_list, z); - //sysobj_stats.auto_free_len++; + sysobj_stats.auto_free_len++; g_mutex_unlock(&free_lock); return p; } -gpointer auto_free_(gpointer p, const char *file, int line, const char *func) { - return auto_free_ex_(p, (GDestroyNotify)g_free, file, line, func); +gpointer auto_free_on_exit_ex_(gpointer p, GDestroyNotify f, const char *file, int line, const char *func) { + if (!p) return p; + + auto_free_item *z = g_new0(auto_free_item, 1); + z->ptr = p; + z->f_free = f; + z->thread = g_thread_self(); + z->file = file; + z->line = line; + z->func = func; + z->stamp = -1.0; + g_mutex_lock(&free_lock); + free_list = g_slist_prepend(free_list, z); + sysobj_stats.auto_free_len++; + g_mutex_unlock(&free_lock); + return p; } static struct { GDestroyNotify fptr; char *name; } free_function_tab[] = { { (GDestroyNotify) g_free, "g_free" }, - // ... +#if (AF_USE_SYSOBJ) + { (GDestroyNotify) sysobj_free, "sysobj_free" }, + { (GDestroyNotify) class_free, "class_free" }, + { (GDestroyNotify) sysobj_filter_free, "sysobj_filter_free" }, + { (GDestroyNotify) sysobj_virt_free, "sysobj_virt_free" }, +#endif { NULL, "(null)" }, }; @@ -106,18 +136,17 @@ static void free_auto_free_ex(gboolean thread_final) { GThread *this_thread = g_thread_self(); GSList *l = NULL, *n = NULL; long long unsigned fc = 0; - double now = _elapsed(); + double now = af_elapsed(); if (!free_list) return; g_mutex_lock(&free_lock); - if (DEBUG_AUTO_FREE) { - unsigned long long ll = g_slist_length(free_list); - auto_free_msg("%llu total items in queue, but will free from thread %p only... ", ll, this_thread); - } + if (DEBUG_AUTO_FREE) + auto_free_msg("%llu total items in queue, but will free from thread %p only... ", sysobj_stats.auto_free_len, this_thread); for(l = free_list; l; l = n) { auto_free_item *z = (auto_free_item*)l->data; n = l->next; + if (!free_final && z->stamp < 0) continue; double age = now - z->stamp; if (free_final || (z->thread == this_thread && (thread_final || age > AF_DELAY_SECONDS) ) ) { if (DEBUG_AUTO_FREE == 2) { @@ -143,8 +172,8 @@ static void free_auto_free_ex(gboolean thread_final) { } if (DEBUG_AUTO_FREE) auto_free_msg("... freed %llu (from thread %p)", fc, this_thread); - //sysobj_stats.auto_freed += fc; - //sysobj_stats.auto_free_len -= fc; + sysobj_stats.auto_freed += fc; + sysobj_stats.auto_free_len -= fc; g_mutex_unlock(&free_lock); } diff --git a/modules/devices/arm/arm_data.c b/modules/devices/arm/arm_data.c index 58779c08..179771dc 100644 --- a/modules/devices/arm/arm_data.c +++ b/modules/devices/arm/arm_data.c @@ -134,7 +134,7 @@ void find_arm_ids_file() { int n; for(n = 0; file_search_order[n]; n++) { if (!access(file_search_order[n], R_OK)) - arm_ids_file = file_search_order[n]; + arm_ids_file = (gchar*) auto_free_on_exit( file_search_order[n] ); else g_free(file_search_order[n]); } -- cgit v1.2.3 From 44841ef5d06a6c7d0e22491901afc067228f7e64 Mon Sep 17 00:00:00 2001 From: Burt P Date: Fri, 9 Aug 2019 21:21:46 -0500 Subject: bug fix for ids file search Signed-off-by: Burt P --- hardinfo/udisks2_util.c | 2 +- modules/devices/arm/arm_data.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/devices/arm/arm_data.c') diff --git a/hardinfo/udisks2_util.c b/hardinfo/udisks2_util.c index 0687b14a..8aa54f72 100644 --- a/hardinfo/udisks2_util.c +++ b/hardinfo/udisks2_util.c @@ -30,7 +30,7 @@ void find_sdcard_ids_file() { }; int n; for(n = 0; file_search_order[n]; n++) { - if (!access(file_search_order[n], R_OK)) + if (!sdcard_ids_file && !access(file_search_order[n], R_OK)) sdcard_ids_file = file_search_order[n]; else g_free(file_search_order[n]); diff --git a/modules/devices/arm/arm_data.c b/modules/devices/arm/arm_data.c index 179771dc..4ca77be9 100644 --- a/modules/devices/arm/arm_data.c +++ b/modules/devices/arm/arm_data.c @@ -133,7 +133,7 @@ void find_arm_ids_file() { }; int n; for(n = 0; file_search_order[n]; n++) { - if (!access(file_search_order[n], R_OK)) + if (!arm_ids_file && !access(file_search_order[n], R_OK)) arm_ids_file = (gchar*) auto_free_on_exit( file_search_order[n] ); else g_free(file_search_order[n]); -- cgit v1.2.3