Linux Kernel Architecture

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

Appendix A: Architecture Specifics


to thetask_structassociated with the process,currentcan be implemented in a roundabout way as
demonstrated below for the Arm architecture:

include/asm-arm/current.h
static __always_inline struct task_struct * get_current(void)
{
return current_thread_info()->task;
}

#define current get_current()

The pointer to the currentthread_infoinstance found usingcurrent_thread_infois stored in register
sp, as shown here:

include/asm-arm/thread_info.h
static inline struct thread_info *current_thread_info(void)
{
register unsigned long sp asm ("sp");
return (struct thread_info *)(sp & ~(THREAD_SIZE - 1));
}

The AMD64 and IA-32 architectures are not included in Table A-1 because they adopt their own method
of finding the current process. Each CPU in the system has a per-processor private data area which holds
various interesting items of information. For AMD64, it is defined as follows:

include/asm-x86/pda.h
struct x8664_pda {
struct task_struct *pcurrent; /* 0 Current process */
unsigned long data_offset; /* 8 Per cpu data offset from linker
address */
unsigned long kernelstack; /* 16 top of kernel stack for current */
...
unsigned irq_call_count;
unsigned irq_tlb_count;
unsigned irq_thermal_count;
unsigned irq_threshold_count;
unsigned irq_spurious_count;
} ____cacheline_aligned_in_smp;

The segment selector registergsalways points to the data structure, and elements of it can therefore be
simply addressed as offsets to the segment. This structure includes thepcurrentpointer that points to
thetask_structinstance of the current process.

A.11 Summary


The largest part of the Linux kernel is written in architecture-independent C, and this is one of the pre-
requisites that enables Linux to be ported to a huge number of platforms. However, a small core of
hardware-specific data structures and functions must be provided by every platform. This appendix
explored some examples of definitions for a number of important architectures, and described the generic
mechanisms provided by the kernel to bridge differences between various platforms.
Free download pdf