kernel: add frequency in cpu_info
use this in sysinfo. Change-Id: I270ef1ab18c27c4804cb0cca2cb5088a17162636 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3214 Tested-by: Commit checker robot <[email protected]> Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
@@ -426,6 +426,7 @@ extern void ktrace_vprintf(const char *format, va_list args);
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
bigtime_t active_time; /* usec of doing useful work since boot */
|
bigtime_t active_time; /* usec of doing useful work since boot */
|
||||||
bool enabled;
|
bool enabled;
|
||||||
|
uint64 current_frequency;
|
||||||
} cpu_info;
|
} cpu_info;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -537,8 +538,11 @@ typedef struct {
|
|||||||
|
|
||||||
|
|
||||||
extern status_t get_system_info(system_info* info);
|
extern status_t get_system_info(system_info* info);
|
||||||
extern status_t get_cpu_info(uint32 firstCPU, uint32 cpuCount,
|
extern status_t _get_cpu_info_etc(uint32 firstCPU, uint32 cpuCount,
|
||||||
cpu_info* info);
|
cpu_info* info, size_t size);
|
||||||
|
#define get_cpu_info(firstCPU, cpuCount, info) \
|
||||||
|
_get_cpu_info_etc((firstCPU), (cpuCount), (info), sizeof(*(info)))
|
||||||
|
|
||||||
extern status_t get_cpu_topology_info(cpu_topology_node_info* topologyInfos,
|
extern status_t get_cpu_topology_info(cpu_topology_node_info* topologyInfos,
|
||||||
uint32* topologyInfoCount);
|
uint32* topologyInfoCount);
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ extern "C" {
|
|||||||
|
|
||||||
|
|
||||||
status_t __get_system_info(system_info* info);
|
status_t __get_system_info(system_info* info);
|
||||||
status_t __get_cpu_info(uint32 firstCPU, uint32 cpuCount, cpu_info* info);
|
|
||||||
status_t __get_cpu_topology_info(cpu_topology_node_info* topologyInfos,
|
status_t __get_cpu_topology_info(cpu_topology_node_info* topologyInfos,
|
||||||
uint32* topologyInfoCount);
|
uint32* topologyInfoCount);
|
||||||
|
|
||||||
|
|||||||
@@ -581,6 +581,14 @@ dump_cpu(enum cpu_vendor vendor, uint32 model, int32 cpu)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cpu_info frequencyInfo;
|
||||||
|
if (get_cpu_info(cpu, 1, &frequencyInfo) == B_OK
|
||||||
|
&& frequencyInfo.current_frequency != 0) {
|
||||||
|
printf("\tFrequency: %" B_PRId32 ".%03" B_PRId32 "\n",
|
||||||
|
int32(frequencyInfo.current_frequency / 1000000),
|
||||||
|
int32((frequencyInfo.current_frequency % 1000000) / 1000));
|
||||||
|
}
|
||||||
|
|
||||||
get_cpuid(&cpuInfo, 1, cpu);
|
get_cpuid(&cpuInfo, 1, cpu);
|
||||||
print_processor_signature(vendor, &cpuInfo);
|
print_processor_signature(vendor, &cpuInfo);
|
||||||
printf("\tFeatures: 0x%08" B_PRIx32 "\n", cpuInfo.eax_1.features);
|
printf("\tFeatures: 0x%08" B_PRIx32 "\n", cpuInfo.eax_1.features);
|
||||||
|
|||||||
@@ -490,11 +490,34 @@ get_system_info(system_info* info)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
bigtime_t active_time;
|
||||||
|
bool enabled;
|
||||||
|
} beta2_cpu_info;
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" status_t
|
||||||
|
__get_cpu_info(uint32 firstCPU, uint32 cpuCount, beta2_cpu_info* beta2_info)
|
||||||
|
{
|
||||||
|
cpu_info info[cpuCount];
|
||||||
|
status_t err = _get_cpu_info_etc(firstCPU, cpuCount, info, sizeof(cpu_info));
|
||||||
|
if (err == B_OK) {
|
||||||
|
for (uint32 i = 0; i < cpuCount; i++) {
|
||||||
|
beta2_info[i].active_time = info[i].active_time;
|
||||||
|
beta2_info[i].enabled = info[i].enabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
get_cpu_info(uint32 firstCPU, uint32 cpuCount, cpu_info* info)
|
_get_cpu_info_etc(uint32 firstCPU, uint32 cpuCount, cpu_info* info, size_t size)
|
||||||
{
|
{
|
||||||
if (cpuCount == 0)
|
if (cpuCount == 0)
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
if (size != sizeof(cpu_info))
|
||||||
|
return B_BAD_VALUE;
|
||||||
if (firstCPU >= (uint32)smp_get_num_cpus())
|
if (firstCPU >= (uint32)smp_get_num_cpus())
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
@@ -516,6 +539,7 @@ get_cpu_info(uint32 firstCPU, uint32 cpuCount, cpu_info* info)
|
|||||||
for (uint32 i = 0; i < count; i++) {
|
for (uint32 i = 0; i < count; i++) {
|
||||||
info[i].active_time = cpu_get_active_time(firstCPU + i);
|
info[i].active_time = cpu_get_active_time(firstCPU + i);
|
||||||
info[i].enabled = !gCPU[firstCPU + i].disabled;
|
info[i].enabled = !gCPU[firstCPU + i].disabled;
|
||||||
|
info[i].current_frequency = cpu_frequency(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_USER_ADDRESS(info)) {
|
if (IS_USER_ADDRESS(info)) {
|
||||||
@@ -578,7 +602,7 @@ _user_get_cpu_info(uint32 firstCPU, uint32 cpuCount, cpu_info* userInfo)
|
|||||||
if (userInfo == NULL || !IS_USER_ADDRESS(userInfo))
|
if (userInfo == NULL || !IS_USER_ADDRESS(userInfo))
|
||||||
return B_BAD_ADDRESS;
|
return B_BAD_ADDRESS;
|
||||||
|
|
||||||
return get_cpu_info(firstCPU, cpuCount, userInfo);
|
return _get_cpu_info_etc(firstCPU, cpuCount, userInfo, sizeof(cpu_info));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -153,9 +153,31 @@ __get_system_info(system_info* info)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
typedef struct {
|
||||||
__get_cpu_info(uint32 firstCPU, uint32 cpuCount, cpu_info* info)
|
bigtime_t active_time;
|
||||||
|
bool enabled;
|
||||||
|
} beta2_cpu_info;
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" status_t
|
||||||
|
__get_cpu_info(uint32 firstCPU, uint32 cpuCount, beta2_cpu_info* beta2_info)
|
||||||
{
|
{
|
||||||
|
cpu_info info;
|
||||||
|
status_t err = _get_cpu_info_etc(firstCPU, cpuCount, &info, sizeof(info));
|
||||||
|
if (err == B_OK) {
|
||||||
|
beta2_info->active_time = info.active_time;
|
||||||
|
beta2_info->enabled = info.enabled;
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
_get_cpu_info_etc(uint32 firstCPU, uint32 cpuCount, cpu_info* info,
|
||||||
|
size_t size)
|
||||||
|
{
|
||||||
|
if (info == NULL || size != sizeof(cpu_info))
|
||||||
|
return B_BAD_VALUE;
|
||||||
return _kern_get_cpu_info(firstCPU, cpuCount, info);
|
return _kern_get_cpu_info(firstCPU, cpuCount, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user