lscpu: add helper to get physical sockets
Add a helper function, get_number_of_physical_sockets_from_dmi(), to get physical sockets from DMI table in case of the sysfs for cpu topology doesn't have the physical socket information. get_number_of_physical_sockets_from_dmi() parse the DMI table and counts the number of SMBIOS Processor Information (Type04) structure. Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
This commit is contained in:
parent
3cd676f5ec
commit
788f90d69a
|
@ -66,6 +66,9 @@ int parse_dmi_table(uint16_t len, uint16_t num,
|
||||||
di->manufacturer = dmi_string(&h, data[0x04]);
|
di->manufacturer = dmi_string(&h, data[0x04]);
|
||||||
di->product = dmi_string(&h, data[0x05]);
|
di->product = dmi_string(&h, data[0x05]);
|
||||||
break;
|
break;
|
||||||
|
case 4:
|
||||||
|
di->sockets++;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -77,3 +80,29 @@ int parse_dmi_table(uint16_t len, uint16_t num,
|
||||||
done:
|
done:
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t get_number_of_physical_sockets_from_dmi(void)
|
||||||
|
{
|
||||||
|
static char const sys_fw_dmi_tables[] = _PATH_SYS_DMI;
|
||||||
|
struct dmi_info di;
|
||||||
|
struct stat st;
|
||||||
|
uint8_t *data;
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
|
if (stat(sys_fw_dmi_tables, &st))
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
data = get_mem_chunk(0, st.st_size, sys_fw_dmi_tables);
|
||||||
|
if (!data)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
memset(&di, 0, sizeof(struct dmi_info));
|
||||||
|
rc = parse_dmi_table(st.st_size, st.st_size/4, data, &di);
|
||||||
|
|
||||||
|
free(data);
|
||||||
|
|
||||||
|
if ((rc < 0) || !di.sockets)
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return di.sockets;
|
||||||
|
}
|
||||||
|
|
|
@ -311,10 +311,12 @@ struct dmi_info {
|
||||||
char *vendor;
|
char *vendor;
|
||||||
char *product;
|
char *product;
|
||||||
char *manufacturer;
|
char *manufacturer;
|
||||||
|
int sockets;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void to_dmi_header(struct lscpu_dmi_header *h, uint8_t *data);
|
void to_dmi_header(struct lscpu_dmi_header *h, uint8_t *data);
|
||||||
char *dmi_string(const struct lscpu_dmi_header *dm, uint8_t s);
|
char *dmi_string(const struct lscpu_dmi_header *dm, uint8_t s);
|
||||||
int parse_dmi_table(uint16_t len, uint16_t num, uint8_t *data, struct dmi_info *di);
|
int parse_dmi_table(uint16_t len, uint16_t num, uint8_t *data, struct dmi_info *di);
|
||||||
|
size_t get_number_of_physical_sockets_from_dmi(void);
|
||||||
#endif /* LSCPU_H */
|
#endif /* LSCPU_H */
|
||||||
|
|
Loading…
Reference in New Issue