summaryrefslogtreecommitdiffstats
path: root/src/include/kernel/cpu.H
blob: 8f6fedb693c646ed112489f9bfbcba1017891480 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/** @file cpu.H
 *  @brief Defines kernel information and functions about CPUs.
 *  
 *  In this kernel the term CPU refers to a hardware thread (SMT), not core.
 */
#ifndef __KERNEL_CPU_H
#define __KERNEL_CPU_H

#include <kernel/types.h>
#include <arch/ppc.H>
#include <builtins.h>
#include <sys/sync.h>

// Thread ID support only, Power7 (4 threads).
#define KERNEL_MAX_SUPPORTED_CPUS (4 * 8 * 4) // Sockets, cores, threads.

class Scheduler;

/** @struct cpu_t
 *  @brief Stores per-CPU kernel information.
 */
struct cpu_t
{
        /** Stack to use while in kernel mode. */
    void* kernel_stack;
        /** ID of the CPU (PIR value) */
    cpuid_t cpu;
        
        /** Pointer to the scheduler for this CPU (may not be unique) */
    Scheduler* scheduler;
        /** Location for scheduler to store per-CPU data, currently used
         *  for the local run-queue for processor affinity.
         */
    void* scheduler_extra;
        /** Pointer to the idle task for this CPU */
    task_t* idle_task;

        /** XSCOM mutex to serialize access per CPU */
    mutex_t xscom_mutex;
};

/** @fn getCpuId
 *  @brief Read the PIR value to determine the cpuid_t of this CPU.
 */
ALWAYS_INLINE
inline cpuid_t getCpuId()
{
    return getPIR() & (KERNEL_MAX_SUPPORTED_CPUS - 1);
}

#endif
OpenPOWER on IntegriCloud