Linux Kernel Architecture

(Jacob Rumans) #1
Mauerer runapp01.tex V1 - 09/04/2008 6:08pm Page 1137

Appendix A: Architecture Specifics


#define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
#define __cpu_to_le16(x) ((__force __le16)(__u16)(x))
#define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
#define __cpu_to_be64(x) ((__force __be64)__swab64((x)))
#define __be64_to_cpu(x) __swab64((__force __u64)(__be64)(x))
#define __cpu_to_be32(x) ((__force __be32)__swab32((x)))
#define __be32_to_cpu(x) __swab32((__force __u32)(__be32)(x))
#define __cpu_to_be16(x) ((__force __be16)__swab16((x)))
#define __be16_to_cpu(x) __swab16((__force __u16)(__be16)(x))

The names of the functions indicate their purpose. For example,__be32_to_cpusconverts a 32-bit big
endian value to the CPU-specific format, and__cpu_to_le64converts the CPU-specific format to little
endian for a 64-bit value.

The functions for big endian hosts are implemented using the same means (only the conversions made
are different).

A.9 Page Tables


To simplify memory management and to provide a memory model that abstracts the differences between
the various architectures, the ports must offer functions to manipulate page tables and their entries. These
are declared in<asm-arch/pgtable.h>. Chapter 3 discusses the most interesting definitions in this file,
so there’s no need to repeat them here.

A.10 Miscellaneous


This section covers three additional architecture-specific topics, which don’t fit into any of the previous
categories.

A.10.1 Checksum Calculation


Calculating checksums for packets is a key aspect of communication via IP networks and takes consid-
erable time. If possible, each architecture should therefore employ manually optimized assembler code
to calculate the checksums. The code needed to do this is declared in<asm-arch/checksum.h>.Two
functions are of prime importance:

❑ unsigned short ip_fast_csumcalculates the requisite checksum based on the IP header and the
header length.
❑ csum_partialcalculates the checksum for a packet from the fragments that are received one
by one.

A.10.2 Context Switch


The hardware-dependent part of context switchingtakes place once the scheduler has decided to instruct
the current process to relinquish the CPU so that anotherprocesscanrun.Forthispurpose,allarchitec-
tures must provide theswitch_tofunction or a corresponding macro with the following prototype in
<asm-arch/system.h>:

<asm-arch/system.h>
void switch_to(struct task_struct *prev, struct task_struct *next,
struct task_struct *last)
Free download pdf