diff options
author | Alexey Skidanov <Alexey.Skidanov@amd.com> | 2014-11-11 13:23:09 +0200 |
---|---|---|
committer | Oded Gabbay <oded.gabbay@amd.com> | 2014-12-10 14:47:40 +0200 |
commit | 4a16f41259f83b7b16e1fa3a41538588ccef18d1 (patch) | |
tree | aa63d75971aafce9abe251654e87b7cdab056a41 | |
parent | c12b26c9d55136e3a7e8fd286b34e481ea791ee4 (diff) |
Add chip revision and fw version to topology
Reviewed-by: Oded Gabbay <oded.gabbay@amd.com>
Signed-off-by: Alexey Skidanov <Alexey.Skidanov@amd.com>
-rw-r--r-- | src/topology.c | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/src/topology.c b/src/topology.c index 492b5a3..e50b745 100644 --- a/src/topology.c +++ b/src/topology.c @@ -52,6 +52,7 @@ static node_t *node = NULL; static HSAKMT_STATUS topology_take_snapshot(void); static HSAKMT_STATUS topology_drop_snapshot(void); +static int get_cpu_stepping(uint16_t* stepping); static void free_node(node_t *n) @@ -192,7 +193,9 @@ topology_sysfs_get_node_props(uint32_t node_id, HsaNodeProperties *props, uint32 char path[256]; long long unsigned int prop_val; uint32_t i, prog; + uint16_t stepping = 0, fw_version = 0; int read_size; + HSAKMT_STATUS ret = HSAKMT_STATUS_SUCCESS; assert(props); @@ -289,8 +292,8 @@ topology_sysfs_get_node_props(uint32_t node_id, HsaNodeProperties *props, uint32 props->NumSIMDPerCU = (uint32_t)prop_val; else if (strcmp(prop_name,"max_slots_scratch_cu") == 0) props->MaxSlotsScratchCU = (uint32_t)prop_val; - else if (strcmp(prop_name,"engine_id") == 0) - props->EngineId = (uint32_t)prop_val; + else if (strcmp(prop_name,"fw_version") == 0) + fw_version = (uint16_t)prop_val; else if (strcmp(prop_name,"vendor_id") == 0) props->VendorId = (uint32_t)prop_val; else if (strcmp(prop_name,"device_id") == 0) @@ -303,8 +306,12 @@ topology_sysfs_get_node_props(uint32_t node_id, HsaNodeProperties *props, uint32 props->MaxEngineClockMhzCCompute = (uint32_t)prop_val; else if (strcmp(prop_name,"local_mem_size") == 0) props->LocalMemSize = (uint32_t)prop_val; + } + get_cpu_stepping(&stepping); + props->EngineId = ((stepping << 16) | fw_version); + err2: free(read_buf); err1: @@ -930,3 +937,41 @@ uint16_t get_device_id_by_node(HSAuint32 node_id) return node[node_id].node.DeviceId; } + +static int get_cpu_stepping(uint16_t* stepping) +{ + int ret; + FILE* fd = fopen("/proc/cpuinfo", "r"); + if (!fd) + return -1; + + char* read_buf = malloc(PAGE_SIZE); + if (!read_buf) { + ret = -1; + goto err1; + } + + int read_size = fread(read_buf, 1, PAGE_SIZE, fd); + if (read_size <= 0) { + ret = -2; + goto err2; + } + + /* Since we're using the buffer as a string, we make sure the string terminates */ + if(read_size >= PAGE_SIZE) + read_size = PAGE_SIZE-1; + read_buf[read_size] = 0; + + *stepping = 0; + + char* p = strstr(read_buf, "stepping"); + if (p) + sscanf(p , "stepping\t: %hu\n", stepping); + +err2: + free(read_buf); +err1: + fclose(fd); + + return ret; +} |