Gathering minimal system information
At times, especially when writing a module that’s meant to be portable across various architectures (CPUs), we need to conditionally perform work based on the actual processor family we’re running upon. The kernel provides a few macros and ways to figure this out; here, we build a simple demo module (ch5/min_sysinfo/min_sysinfo.c
) that, though still quite simplistic, shows a few ways to “detect” some system details (such as the CPU family, bit-width, and endian-ness). In the following code snippet, we show only the relevant function:
// ch5/min_sysinfo/min_sysinfo.c
[ ... ]
void llkd_sysinfo(void)
{
char msg[128];
memset(msg, 0, 128);
my_snprintf_lkp(msg, 47, "%s(): minimal Platform Info:\nCPU: ", __func__);
/* Strictly speaking, all this #if...#endif is considered ugly and should be
* isolated as far as is possible */
#ifdef CONFIG_X86
#if(BITS_PER_LONG == 32)
strncat(msg, "...