Skip to content

Commit

Permalink
Fixing Indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Dec 5, 2024
1 parent 68fecdb commit 71c527b
Show file tree
Hide file tree
Showing 10 changed files with 627 additions and 597 deletions.
24 changes: 12 additions & 12 deletions include/cpuinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,19 +603,19 @@ enum cpuinfo_uarch {
cpuinfo_uarch_taishan_v110 = 0x00C00100,

/** IBM POWER 7. */
cpuinfo_uarch_power7 = 0x00D00100,
cpuinfo_uarch_power7 = 0x00D00100,
/** IBM POWER 7p. */
cpuinfo_uarch_power7p = 0x00D00101,
cpuinfo_uarch_power7p = 0x00D00101,
/** IBM POWER 8. */
cpuinfo_uarch_power8 = 0x00D00200,
cpuinfo_uarch_power8 = 0x00D00200,
/** IBM POWER8E. */
cpuinfo_uarch_power8e = 0x00D00201,
cpuinfo_uarch_power8e = 0x00D00201,
/** IBM POWER8NVL */
cpuinfo_uarch_power8nvl = 0x00D00202,
/** IBM POWER 9. */
cpuinfo_uarch_power9 = 0x00D00303,
cpuinfo_uarch_power9 = 0x00D00303,
/** IBM POWER 10. */
cpuinfo_uarch_power10 = 0x00D00400,
cpuinfo_uarch_power10 = 0x00D00400,
};

struct cpuinfo_processor {
Expand Down Expand Up @@ -2245,13 +2245,13 @@ static inline bool cpuinfo_has_riscv_v(void) {
}

#if CPUINFO_ARCH_PPC64
struct cpuinfo_powerpc_isa {
bool vsx;
bool htm;
bool mma;
};
struct cpuinfo_powerpc_isa {
bool vsx;
bool htm;
bool mma;
};

extern struct cpuinfo_powerpc_isa cpuinfo_isa;
extern struct cpuinfo_powerpc_isa cpuinfo_isa;
#endif

static inline bool cpuinfo_has_powerpc_vsx(void) {
Expand Down
22 changes: 12 additions & 10 deletions src/linux/processors.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,29 +285,31 @@ bool cpuinfo_linux_get_processor_package_id(uint32_t processor, uint32_t package

bool cpuinfo_linux_get_processor_online_status(uint32_t processor, uint32_t* online_status_ptr) {
char processor_online_filename[PROCESSOR_ONLINE_FILENAME_SIZE];
const int chars_formatted =
snprintf(processor_online_filename, PROCESSOR_ONLINE_FILENAME_SIZE, PROCESSOR_ONLINE_FILENAME_FORMAT, processor);
if ((unsigned int)chars_formatted >= PROCESSOR_ONLINE_FILENAME_SIZE) {
const int chars_formatted = snprintf(
processor_online_filename, PROCESSOR_ONLINE_FILENAME_SIZE, PROCESSOR_ONLINE_FILENAME_FORMAT, processor);
if ((unsigned int)chars_formatted >= PROCESSOR_ONLINE_FILENAME_SIZE) {
cpuinfo_log_warning("failed to format filename for online status of processor %" PRIu32, processor);
return 0;
}
uint32_t online_status;
if (cpuinfo_linux_parse_small_file(processor_online_filename, PROCESSOR_ONLINE_FILESIZE, uint32_parser, &online_status)) {
if (cpuinfo_linux_parse_small_file(
processor_online_filename, PROCESSOR_ONLINE_FILESIZE, uint32_parser, &online_status)) {
cpuinfo_log_debug(
"parsed online status value of %" PRIu32 " for logical processor %" PRIu32 " from %s",
online_status,
processor,
processor_online_filename);
*online_status_ptr = online_status;
return true;
*online_status_ptr = online_status;
return true;
} else {
cpuinfo_log_info(
"failed to parse online status for processor %" PRIu32 " from %s", processor, processor_online_filename);
return false;
cpuinfo_log_info(
"failed to parse online status for processor %" PRIu32 " from %s",
processor,
processor_online_filename);
return false;
}
}


static bool max_processor_number_parser(uint32_t processor_list_start, uint32_t processor_list_end, void* context) {
uint32_t* processor_number_ptr = (uint32_t*)context;
const uint32_t processor_list_last = processor_list_end - 1;
Expand Down
13 changes: 5 additions & 8 deletions src/powerpc/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@

#include <cpuinfo.h>

enum cpuinfo_powerpc_chipset_vendor {
cpuinfo_powerpc_chipset_vendor_unknown = 0,
cpuinfo_powerpc_chipset_vendor_ibm
};
enum cpuinfo_powerpc_chipset_vendor { cpuinfo_powerpc_chipset_vendor_unknown = 0, cpuinfo_powerpc_chipset_vendor_ibm };
void cpuinfo_powerpc_decode_vendor_uarch(
uint32_t vendor_id,
enum cpuinfo_vendor vendor[restrict static 1],
enum cpuinfo_uarch uarch[restrict static 1]);

void cpuinfo_powerpc_decode_cache(
struct cpuinfo_cache l1i[restrict static 1],
struct cpuinfo_cache l1d[restrict static 1],
struct cpuinfo_cache l2[restrict static 1],
struct cpuinfo_cache l3[restrict static 1]);
struct cpuinfo_cache l1i[restrict static 1],
struct cpuinfo_cache l1d[restrict static 1],
struct cpuinfo_cache l2[restrict static 1],
struct cpuinfo_cache l3[restrict static 1]);
64 changes: 28 additions & 36 deletions src/powerpc/cache.c
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
#include <stdint.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>

#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include <cpuinfo.h>
#include <cpuinfo/log.h>
#include <powerpc/api.h>
#include <sys/auxv.h>

#define NUM_CACHE 4
#define BUF_SIZE 128
#define NUM_CACHE 4
#define BUF_SIZE 128

int path_exist(const char *path)
{
int path_exist(const char* path) {
return (access(path, F_OK) == 0);
}

void read_str(char *result, size_t len, const char *path)
{
FILE *f;
void read_str(char* result, size_t len, const char* path) {
FILE* f;

f = fopen(path, "r");

Expand All @@ -34,33 +32,31 @@ void read_str(char *result, size_t len, const char *path)
result[len - 1] = '\0';
}

void decode_cache_features(uint32_t cache_features[], unsigned long geometry)
{
void decode_cache_features(uint32_t cache_features[], unsigned long geometry) {
cache_features[1] = (geometry >> 16) & 0xffff;
cache_features[2] = geometry & 0xffff;
/* If associativity = 65535 it means upper limit of 16 bit of AT_L%d_CACHEGEOMETRY has reached so we calculate it from, size, sets and line_size*/
if(cache_features[1] == 65535)
cache_features[1] = cache_features[0]/(cache_features[2]*cache_features[3]);
/* If associativity = 65535 it means upper limit of 16 bit of AT_L%d_CACHEGEOMETRY has reached so we calculate
* it from, size, sets and line_size*/
if (cache_features[1] == 65535)
cache_features[1] = cache_features[0] / (cache_features[2] * cache_features[3]);
}

void cpuinfo_powerpc_decode_cache(
struct cpuinfo_cache l1i[restrict static 1],
struct cpuinfo_cache l1d[restrict static 1],
struct cpuinfo_cache l2[restrict static 1],
struct cpuinfo_cache l3[restrict static 1])
{
struct cpuinfo_cache l3[restrict static 1]) {
char buf[BUF_SIZE];
char result[BUF_SIZE];
uint32_t cache_features[NUM_CACHE];
uint32_t i;
uint32_t size = 0, sets = 0;
size_t len;

for(i = 0; i < NUM_CACHE; i++) {

sprintf (buf, "/sys/devices/system/cpu/cpu%d/cache/index%d/number_of_sets", i);
if(path_exist(buf))
read_str(result, sizeof(result), buf);
for (i = 0; i < NUM_CACHE; i++) {
sprintf(buf, "/sys/devices/system/cpu/cpu%d/cache/index%d/number_of_sets", i);
if (path_exist(buf))
read_str(result, sizeof(result), buf);

sets = atoi(result);
cache_features[3] = sets;
Expand All @@ -73,8 +69,8 @@ void cpuinfo_powerpc_decode_cache(
size = getauxval(AT_L1D_CACHESIZE);
cache_features[0] = size;
decode_cache_features(cache_features, geometry);
sets = size/(cache_features[1] * cache_features[2]);
*l1d = (struct cpuinfo_cache) {
sets = size / (cache_features[1] * cache_features[2]);
*l1d = (struct cpuinfo_cache){
.size = size,
.associativity = cache_features[1],
.line_size = cache_features[2],
Expand All @@ -88,44 +84,40 @@ void cpuinfo_powerpc_decode_cache(
size = getauxval(AT_L1I_CACHESIZE);
cache_features[0] = size;
decode_cache_features(cache_features, geometry);
sets = size/(cache_features[1] * cache_features[2]);
*l1i = (struct cpuinfo_cache) {
sets = size / (cache_features[1] * cache_features[2]);
*l1i = (struct cpuinfo_cache){
.size = size,
.associativity = cache_features[1],
.line_size = cache_features[2],
.sets = sets,
.partitions = 1
};
.partitions = 1};
break;
case 2:
geometry = getauxval(AT_L2_CACHEGEOMETRY);
size = getauxval(AT_L2_CACHESIZE);
cache_features[0] = size;
decode_cache_features(cache_features, geometry);
sets = size/(cache_features[1] * cache_features[2]);
*l2 = (struct cpuinfo_cache) {
sets = size / (cache_features[1] * cache_features[2]);
*l2 = (struct cpuinfo_cache){
.size = size,
.associativity = cache_features[1],
.line_size = cache_features[2],
.sets = sets,
.partitions = 1
};
.partitions = 1};
break;
case 3:
geometry = getauxval(AT_L3_CACHEGEOMETRY);
size = getauxval(AT_L3_CACHESIZE);
cache_features[0] = size;
decode_cache_features(cache_features, geometry);
sets = size/(cache_features[1] * cache_features[2]);
*l3 = (struct cpuinfo_cache) {
sets = size / (cache_features[1] * cache_features[2]);
*l3 = (struct cpuinfo_cache){
.size = size,
.associativity = cache_features[1],
.line_size = cache_features[2],
.sets = sets,
.partitions = 1
};
.partitions = 1};
break;

}
}
}
72 changes: 38 additions & 34 deletions src/powerpc/linux/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,47 @@

#include <cpuinfo.h>
#include <cpuinfo/common.h>
#include <powerpc/api.h>
#include <linux/api.h>
#include <powerpc/api.h>

/* No hard limit in the kernel, maximum length observed on non-rogue kernels is 64 */
#define CPUINFO_HARDWARE_VALUE_MAX 64

/* from /arch/powerpc/kernel/cputable.c */
#define CPUINFO_POWERPC_LINUX_FEATURE_64 UINT32_C(0x40000000)
#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_ALTIVEC UINT32_C(0x10000000)
#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_FPU UINT32_C(0x08000000)
#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_MMU UINT32_C(0x04000000)
#define CPUINFO_POWERPC_LINUX_FEATURE_NO_TB UINT32_C(0x00100000)
#define CPUINFO_POWERPC_LINUX_FEATURE_SMT UINT32_C(0x00004000)
#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_DFP UINT32_C(0x00000400)
#define CPUINFO_POWERPC_LINUX_FEATURE_POWER6_EXT UINT32_C(0x00000200)
#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_VSX UINT32_C(0x00000080)
#define CPUINFO_POWERPC_LINUX_FEATURE_TRUE_LE UINT32_C(0x00000002)
#define CPUINFO_POWERPC_LINUX_FEATURE_64 UINT32_C(0x40000000)
#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_ALTIVEC UINT32_C(0x10000000)
#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_FPU UINT32_C(0x08000000)
#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_MMU UINT32_C(0x04000000)
#define CPUINFO_POWERPC_LINUX_FEATURE_NO_TB UINT32_C(0x00100000)
#define CPUINFO_POWERPC_LINUX_FEATURE_SMT UINT32_C(0x00004000)
#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_DFP UINT32_C(0x00000400)
#define CPUINFO_POWERPC_LINUX_FEATURE_POWER6_EXT UINT32_C(0x00000200)
#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_VSX UINT32_C(0x00000080)
#define CPUINFO_POWERPC_LINUX_FEATURE_TRUE_LE UINT32_C(0x00000002)
#define CPUINFO_POWERPC_LINUX_FEATURE_PPC_LE UINT32_C(0x00000001
#define CPUINFO_POWERPC_LINUX_FEATURE_ARCH_2_07 UINT32_C(0x80000000)
#define CPUINFO_POWERPC_LINUX_FEATURE_HTM UINT32_C(0x40000000)
#define CPUINFO_POWERPC_LINUX_FEATURE_DSCR UINT32_C(0x20000000)
#define CPUINFO_POWERPC_LINUX_FEATURE_EBB UINT32_C(0x10000000)
#define CPUINFO_POWERPC_LINUX_FEATURE_ISEL UINT32_C(0x08000000)
#define CPUINFO_POWERPC_LINUX_FEATURE_TAR UINT32_C(0x04000000)
#define CPUINFO_POWERPC_LINUX_FEATURE_VEC_CRYPTO UINT32_C(0x02000000)
#define CPUINFO_POWERPC_LINUX_FEATURE_HTM_NOSC UINT32_C(0x01000000)
#define CPUINFO_POWERPC_LINUX_FEATURE_ARCH_3_00 UINT32_C(0x00800000)
#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_IEEE128 UINT32_C(0x00400000)
#define CPUINFO_POWERPC_LINUX_FEATURE_DARN UINT32_C(0x00200000)
#define CPUINFO_POWERPC_LINUX_FEATURE_SCV UINT32_C(0x00100000)
#define CPUINFO_POWERPC_LINUX_FEATURE_HTM_NO_SUSPEND UINT32_C(0x00080000)
#define CPUINFO_POWERPC_LINUX_FEATURE_ARCH_3_1 UINT32_C(0x00040000)
#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_MMA UINT32_C(0x00020000)
#define CPUINFO_POWERPC_LINUX_FEATURE_ARCH_2_07 UINT32_C(0x80000000)
#define CPUINFO_POWERPC_LINUX_FEATURE_HTM UINT32_C(0x40000000)
#define CPUINFO_POWERPC_LINUX_FEATURE_DSCR UINT32_C(0x20000000)
#define CPUINFO_POWERPC_LINUX_FEATURE_EBB UINT32_C(0x10000000)
#define CPUINFO_POWERPC_LINUX_FEATURE_ISEL UINT32_C(0x08000000)
#define CPUINFO_POWERPC_LINUX_FEATURE_TAR UINT32_C(0x04000000)
#define CPUINFO_POWERPC_LINUX_FEATURE_VEC_CRYPTO UINT32_C(0x02000000)
#define CPUINFO_POWERPC_LINUX_FEATURE_HTM_NOSC UINT32_C(0x01000000)
#define CPUINFO_POWERPC_LINUX_FEATURE_ARCH_3_00 UINT32_C(0x00800000)
#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_IEEE128 UINT32_C(0x00400000)
#define CPUINFO_POWERPC_LINUX_FEATURE_DARN UINT32_C(0x00200000)
#define CPUINFO_POWERPC_LINUX_FEATURE_SCV UINT32_C(0x00100000)
#define CPUINFO_POWERPC_LINUX_FEATURE_HTM_NO_SUSPEND UINT32_C(0x00080000)
#define CPUINFO_POWERPC_LINUX_FEATURE_ARCH_3_1 UINT32_C(0x00040000)
#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_MMA UINT32_C(0x00020000)

#define CPUINFO_POWERPC_LINUX_VALID_ARCHITECTURE UINT32_C(0x00010000)
#define CPUINFO_POWERPC_LINUX_VALID_IMPLEMENTER UINT32_C(0x00020000)
#define CPUINFO_POWERPC_LINUX_VALID_REVISION UINT32_C(0x00040000)
#define CPUINFO_POWERPC_LINUX_VALID_PROCESSOR UINT32_C(0x00080000)
#define CPUINFO_POWERPC_LINUX_VALID_VERSION UINT32_C(0x00100000)
#define CPUINFO_POWERPC_LINUX_VALID_FEATURES UINT32_C(0x00200000)
#define CPUINFO_POWERPC_LINUX_VALID_PVR UINT32_C(0x001F0000)
#define CPUINFO_POWERPC_LINUX_VALID_IMPLEMENTER UINT32_C(0x00020000)
#define CPUINFO_POWERPC_LINUX_VALID_REVISION UINT32_C(0x00040000)
#define CPUINFO_POWERPC_LINUX_VALID_PROCESSOR UINT32_C(0x00080000)
#define CPUINFO_POWERPC_LINUX_VALID_VERSION UINT32_C(0x00100000)
#define CPUINFO_POWERPC_LINUX_VALID_FEATURES UINT32_C(0x00200000)
#define CPUINFO_POWERPC_LINUX_VALID_PVR UINT32_C(0x001F0000)

/**
* Definition of a powerpc64 Linux processor. It is composed of the base processor
Expand Down Expand Up @@ -99,10 +99,14 @@ struct cpuinfo_powerpc_linux_processor {
* @param[isa] - Reference to cpuinfo_powerpc_isa structure to populate.
*/
void cpuinfo_powerpc_linux_hwcap_from_getauxval(uint32_t isa_feature[]);
CPUINFO_INTERNAL void cpuinfo_ppc64_linux_decode_isa_from_hwcap(uint32_t hwcap, uint32_t hwcap2, struct cpuinfo_powerpc_isa isa[restrict static 1]);
CPUINFO_INTERNAL void cpuinfo_ppc64_linux_decode_isa_from_hwcap(
uint32_t hwcap,
uint32_t hwcap2,
struct cpuinfo_powerpc_isa isa[restrict static 1]);

bool cpuinfo_powerpc_linux_parse_proc_cpuinfo(
uint32_t max_processors_count,struct cpuinfo_powerpc_linux_processor processors[restrict static max_processors_count]);
uint32_t max_processors_count,
struct cpuinfo_powerpc_linux_processor processors[restrict static max_processors_count]);

/* Used to determine which uarch is associated with the current thread. */
extern CPUINFO_INTERNAL const uint32_t* cpuinfo_linux_cpu_to_uarch_index_map;
Loading

0 comments on commit 71c527b

Please sign in to comment.