kernel/system_info: Address review comments.

* Combine "i" and "firstCPU" iteration variables.
 * Use better variable names.

Change-Id: Ifc6fcaea6519dc4a791600f4a8bcdd38f02434f3
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5111
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
Reviewed-by: Axel Dörfler <axeld@pinc-software.de>
This commit is contained in:
Augustin Cavalier 2022-03-17 16:38:35 -04:00 committed by waddlesplash
parent c0ab9f51b2
commit d5ff3cd050

View File

@ -521,7 +521,7 @@ _get_cpu_info_etc(uint32 firstCPU, uint32 cpuCount, cpu_info* info, size_t size)
if (firstCPU >= (uint32)smp_get_num_cpus())
return B_BAD_VALUE;
uint32 count = std::min(cpuCount, smp_get_num_cpus() - firstCPU);
const uint32 endCPU = firstCPU + std::min(cpuCount, smp_get_num_cpus() - firstCPU);
// This function is called very often from userland by applications
// that display CPU usage information, so we want to keep this as
@ -529,16 +529,18 @@ _get_cpu_info_etc(uint32 firstCPU, uint32 cpuCount, cpu_info* info, size_t size)
// of an allocated temporary buffer.
cpu_info localInfo[8];
for (uint32 i = 0; i < count; ) {
uint32 j;
for (j = 0; i < count && j < B_COUNT_OF(localInfo); i++, j++) {
localInfo[j].active_time = cpu_get_active_time(firstCPU + i);
localInfo[j].enabled = !gCPU[firstCPU + i].disabled;
localInfo[j].current_frequency = cpu_frequency(firstCPU + i);
for (uint32 cpuIdx = firstCPU; cpuIdx < endCPU; ) {
uint32 localIdx;
for (localIdx = 0; cpuIdx < endCPU && localIdx < B_COUNT_OF(localInfo);
cpuIdx++, localIdx++) {
localInfo[localIdx].active_time = cpu_get_active_time(cpuIdx);
localInfo[localIdx].enabled = !gCPU[cpuIdx].disabled;
localInfo[localIdx].current_frequency = cpu_frequency(cpuIdx);
}
if (user_memcpy(info + (i - j), localInfo, sizeof(cpu_info) * j) != B_OK)
if (user_memcpy(info, localInfo, sizeof(cpu_info) * localIdx) != B_OK)
return B_BAD_ADDRESS;
info += localIdx;
}
return B_OK;